licence final
This commit is contained in:
@@ -65,6 +65,9 @@ map<string, string> getArguments(int argc, char *argv[]);
|
||||
map<string, const char*> mapArguments(int argc, char *argv[]);
|
||||
char* getCharArray(string source);
|
||||
void getCharsFromString1(string source, char *charArray);
|
||||
void getCharsFromString(string& source, char *charArray, int length);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -9,11 +9,13 @@
|
||||
#define FILEBUFFER 300
|
||||
#define TWO_HOURSE_SECONDS 7200
|
||||
|
||||
void signalHandler(int signum) {
|
||||
if (signum == SIGSEGV) {
|
||||
std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl;
|
||||
// You can perform some recovery actions here if needed
|
||||
}
|
||||
void signalHandler(int signum)
|
||||
{
|
||||
if (signum == SIGSEGV)
|
||||
{
|
||||
std::cerr << "Caught segmentation fault (SIGSEGV)" << std::endl;
|
||||
// You can perform some recovery actions here if needed
|
||||
}
|
||||
}
|
||||
|
||||
/// @brief hlavní funkce
|
||||
@@ -24,14 +26,13 @@ void signalHandler(int signum) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
std::signal(SIGSEGV, signalHandler);
|
||||
std::signal(SIGSEGV, signalHandler);
|
||||
|
||||
// a segmentation fault
|
||||
//int* ptr = nullptr;
|
||||
//*ptr = 42; // This will trigger a segmentation fault
|
||||
// a segmentation fault
|
||||
// int* ptr = nullptr;
|
||||
//*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);
|
||||
|
||||
// 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)
|
||||
// {
|
||||
// std::cout << "Key: " << it->first << ", Value: " << it->second << std::endl;
|
||||
// std::cout << it->second.length() << std::endl;
|
||||
// }
|
||||
|
||||
// generatePause();
|
||||
@@ -100,21 +102,35 @@ std::signal(SIGSEGV, signalHandler);
|
||||
// cout << "binaryType: " << binaryType;
|
||||
// cout << "CID:" << argumentsString["-cid"];
|
||||
|
||||
const int cidLength = argumentsString["-cid"].length();
|
||||
char cidArg[cidLength] = {};
|
||||
getCharsFromString(argumentsString["-cid"], cidArg);
|
||||
// cout << "final-cids: " << argumentsString["-cid"].length() << endl;
|
||||
// cout << "final-cds: " << argumentsString["-csd"].length() << endl;
|
||||
// cout << "-----------------------------------\n";
|
||||
|
||||
const int csdLength = argumentsString["-csd"].length();
|
||||
char csdArg[csdLength] = {};
|
||||
getCharsFromString(argumentsString["-csd"], csdArg);
|
||||
char csdArg[32] = {};
|
||||
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(arguments["-cid"], arguments["-csd"], stationName, switchName, licenceType, binaryType, nullptr);
|
||||
if (plcWriteLicence.CreateLicence() == false)
|
||||
{
|
||||
cerr << "Licence creation failed";
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
#include "plcLicence.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_licencfilepath_f21 = "/mnt/mmc/ez_sys/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()
|
||||
{
|
||||
int length = strlen(cid); // Get the length of the char array
|
||||
for (int i = 0; i < length; i++)
|
||||
this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
||||
//int length = strlen(cid); // Get the length of the char array
|
||||
for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
||||
|
||||
for (int i = 0; i < cnibblescount / 2; i++)
|
||||
{
|
||||
@@ -201,9 +203,7 @@ void PlcLicence::getSDData()
|
||||
this->sdData.manufacturerDate[i] = date[i];
|
||||
|
||||
// CSD
|
||||
length = strlen(csd); // Get the length of the char array
|
||||
for (int i = 0; i < length; i++)
|
||||
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
||||
for (int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[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);
|
||||
//printf("License binary saved.\n");
|
||||
fclose(fileLicence);
|
||||
cout << licFileNameToSave << endl;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
memset(charArray, 0, sizeof(charArray));
|
||||
|
||||
Reference in New Issue
Block a user