licence final

This commit is contained in:
2023-08-17 14:30:11 +02:00
parent d531f56828
commit c07db22aba
4 changed files with 56 additions and 26 deletions

View File

@@ -65,6 +65,9 @@ map<string, string> getArguments(int argc, char *argv[]);
map<string, const char*> mapArguments(int argc, char *argv[]); map<string, const char*> mapArguments(int argc, char *argv[]);
char* getCharArray(string source); char* getCharArray(string source);
void getCharsFromString1(string source, char *charArray); void getCharsFromString1(string source, char *charArray);
void getCharsFromString(string& source, char *charArray, int length);

View File

@@ -9,11 +9,13 @@
#define FILEBUFFER 300 #define FILEBUFFER 300
#define TWO_HOURSE_SECONDS 7200 #define TWO_HOURSE_SECONDS 7200
void signalHandler(int signum) { void signalHandler(int signum)
if (signum == SIGSEGV) { {
std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl; if (signum == SIGSEGV)
// You can perform some recovery actions here if needed {
} std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl;
// You can perform some recovery actions here if needed
}
} }
/// @brief hlavní funkce /// @brief hlavní funkce
@@ -24,14 +26,13 @@ void signalHandler(int signum) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
std::signal(SIGSEGV, signalHandler); std::signal(SIGSEGV, signalHandler);
// a segmentation fault // a segmentation fault
//int* ptr = nullptr; // int* ptr = nullptr;
//*ptr = 42; // This will trigger a segmentation fault //*ptr = 42; // This will trigger a segmentation fault
// map<string, const char *> arguments = mapArguments(argc, argv);
//map<string, const char *> arguments = mapArguments(argc, argv);
map<string, string> argumentsString = getArguments(argc, argv); map<string, string> argumentsString = getArguments(argc, argv);
// std::cout << "Number of arguments: " << argc << std::endl; // std::cout << "Number of arguments: " << argc << std::endl;
@@ -48,6 +49,7 @@ std::signal(SIGSEGV, signalHandler);
// for (auto it = argumentsString.begin(); it != argumentsString.end(); ++it) // for (auto it = argumentsString.begin(); it != argumentsString.end(); ++it)
// { // {
// std::cout << "Key: " << it->first << ", Value: " << it->second << std::endl; // std::cout << "Key: " << it->first << ", Value: " << it->second << std::endl;
// std::cout << it->second.length() << std::endl;
// } // }
// generatePause(); // generatePause();
@@ -100,21 +102,35 @@ std::signal(SIGSEGV, signalHandler);
// cout << "binaryType: " << binaryType; // cout << "binaryType: " << binaryType;
// cout << "CID:" << argumentsString["-cid"]; // cout << "CID:" << argumentsString["-cid"];
const int cidLength = argumentsString["-cid"].length(); // cout << "final-cids: " << argumentsString["-cid"].length() << endl;
char cidArg[cidLength] = {}; // cout << "final-cds: " << argumentsString["-csd"].length() << endl;
getCharsFromString(argumentsString["-cid"], cidArg); // cout << "-----------------------------------\n";
const int csdLength = argumentsString["-csd"].length(); const int csdLength = argumentsString["-csd"].length();
char csdArg[csdLength] = {}; char csdArg[32] = {};
getCharsFromString(argumentsString["-csd"], csdArg); getCharsFromString(argumentsString["-csd"], csdArg, csdLength);
//cout << "csd delka pred: " << strlen(csdArg) << "\n";
//cout << "csd delka po: " << strlen(csdArg) << "\n";
//cout << "csd:" << csdArg << "\n";
const int cidLength = argumentsString["-cid"].length();
char cidArg[32] = {};
getCharsFromString(argumentsString["-cid"], cidArg, cidLength);
//cout << "cid delka pred: " << strlen(cidArg) << "\n";
//for (int i=0;i<32;i++) cidArg[i]=argumentsString["-cid"][i];
//cout << "cid delka po: " << strlen(cidArg) << "\n";
//cout << "cid delka sizeof po: " << sizeof(cidArg) << "\n";
//cout << "cid:" << cidArg;
//char cidTest = getCharArray(argumentsString["-cid"]); // char cidTest = getCharArray(argumentsString["-cid"]);
// PlcLicence plcWriteLicence = PlcLicence(argumentsString);
// PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, stationName, switchName, licenceType, binaryType, nullptr);
// PlcLicence plcWriteLicence = PlcLicence(arguments["-cid"], arguments["-csd"], stationName, switchName, licenceType, binaryType, nullptr);
//PlcLicence plcWriteLicence = PlcLicence(argumentsString);
//PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, stationName, switchName, licenceType, binaryType, nullptr);
PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, argumentsString["-outputType"], argumentsString["-configFileName"]); PlcLicence plcWriteLicence = PlcLicence(cidArg, csdArg, argumentsString["-outputType"], argumentsString["-configFileName"]);
// PlcLicence plcWriteLicence = PlcLicence(arguments["-cid"], arguments["-csd"], stationName, switchName, licenceType, binaryType, nullptr);
if (plcWriteLicence.CreateLicence() == false) if (plcWriteLicence.CreateLicence() == false)
{ {
cerr << "Licence creation failed"; cerr << "Licence creation failed";

View File

@@ -3,6 +3,9 @@
#include "plcLicence.h" #include "plcLicence.h"
#include "utils.h" #include "utils.h"
#define CID_LENGTH 32
#define CSD_LENGTH 32
const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/"; const std::string cEzLic_p78ou3_sdinfofilepath = "/sys/block/mmcblk0/device/";
const std::string cEzLic_p78ou3_licencfilepath_f21 = "/mnt/mmc/ez_sys/licence/"; const std::string cEzLic_p78ou3_licencfilepath_f21 = "/mnt/mmc/ez_sys/licence/";
const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/"; const std::string cEzLic_p78ou3_licencfilepath_f17 = "/home/admin/ez/licence/";
@@ -167,9 +170,8 @@ PlcLicence::PlcLicence(string cid, string csd, char *stationName, char *switchNa
void PlcLicence::getSDData() void PlcLicence::getSDData()
{ {
int length = strlen(cid); // Get the length of the char array //int length = strlen(cid); // Get the length of the char array
for (int i = 0; i < length; i++) for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
this->sdData.CID_nibble[i] = (BYTE)cid[i];
for (int i = 0; i < cnibblescount / 2; i++) for (int i = 0; i < cnibblescount / 2; i++)
{ {
@@ -201,9 +203,7 @@ void PlcLicence::getSDData()
this->sdData.manufacturerDate[i] = date[i]; this->sdData.manufacturerDate[i] = date[i];
// CSD // CSD
length = strlen(csd); // Get the length of the char array for (int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
for (int i = 0; i < length; i++)
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
for (int i = 0; i < cnibblescount / 2; i++) for (int i = 0; i < cnibblescount / 2; i++)
{ {
@@ -738,6 +738,7 @@ bool PlcLicence::CreateLicence()
size_t r1 = fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence); size_t r1 = fwrite(&totalEncryptedArray, sizeof(totalEncryptedArray), 1, fileLicence);
//printf("License binary saved.\n"); //printf("License binary saved.\n");
fclose(fileLicence); fclose(fileLicence);
cout << licFileNameToSave << endl;
return true; return true;
} }
} }

View File

@@ -72,6 +72,16 @@ void getCharsFromString1(string source, char *charArray)
} }
} }
void getCharsFromString(string& source, char *charArray, int length)
{
memset(charArray, 0, length);
// charArray[length]; // Character array to store the string
for (int i = 0; i < length; i++)
{
charArray[i] = source[i];
}
}
void getCharsFromString(string source, char *charArray) void getCharsFromString(string source, char *charArray)
{ {
memset(charArray, 0, sizeof(charArray)); memset(charArray, 0, sizeof(charArray));