oddeleni a lazeni ELC1
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <unordered_map>
|
||||
#include <stdint.h>
|
||||
|
||||
using namespace std;
|
||||
@@ -178,52 +179,57 @@ struct LicenceItem31
|
||||
struct LicenceInfo
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||
struct LicenceInfoCompatibility1
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 1
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 2
|
||||
struct LicenceInfoCompatibility2
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
/// @brief základní struktura, seznam polozek licencí, kompatibilita 3
|
||||
struct LicenceInfoCompatibility3
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo1
|
||||
{
|
||||
bool isValid {false};
|
||||
};
|
||||
|
||||
struct LicenceInfo11
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo21
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfo31
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
struct LicenceInfoGeneral
|
||||
{
|
||||
int reqDataPointsCount = 0;
|
||||
map<int, int> licences = {};
|
||||
unordered_map<int, int> licences = {};
|
||||
};
|
||||
|
||||
class LicenceException : public std::exception
|
||||
|
||||
@@ -40,11 +40,8 @@ int decrypt(const unsigned char *ciphertext, int ciphertext_len, unsigned char *
|
||||
string convertToString(char* a, int size);
|
||||
string base64_encode_ai(const std::string &input);
|
||||
unordered_map<string, string> getArguments(int argc, char *argv[]);
|
||||
char* getCharArray(string source);
|
||||
void getCharsFromString1(string source, char *charArray);
|
||||
void getCharsFromString(string& source, char *charArray, size_t length);
|
||||
string getCompletePath(string fileName);
|
||||
char* getFileContent(string fileName);
|
||||
void appendStringToVector(const std::string& str, std::vector<unsigned char>& charVector);
|
||||
uint16_t calculateCRC16(std::vector<unsigned char>& charVector);
|
||||
uint32_t bytesToDword(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4);
|
||||
|
||||
@@ -1,9 +1,31 @@
|
||||
#ifndef ELC1_READER__H
|
||||
#define ELC1_READER__H
|
||||
|
||||
#include "utils.h"
|
||||
#include "licenceCommon.h"
|
||||
#include "licenceELC1.h"
|
||||
#include "SDCard.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Reader
|
||||
{
|
||||
|
||||
class Licence1 : public LicenceELC1
|
||||
{
|
||||
public:
|
||||
|
||||
LicenceInfo21 licenceInfo;
|
||||
|
||||
Licence1();
|
||||
~Licence1();
|
||||
Licence1(LicenceIdentification &licIdentification);
|
||||
|
||||
bool readLicence(LicenceInfoGeneral *licences);
|
||||
bool getLicenceInfo(void *ptr);
|
||||
bool getLicenceItemInfo(int protocolId, void *returnItemStructure);
|
||||
void getLicenceItems();
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -2,8 +2,6 @@
|
||||
#define LICENCE_READER_H_
|
||||
|
||||
#include "utils.h"
|
||||
#include "licenceELC11.h"
|
||||
#include "licenceELC31.h"
|
||||
|
||||
#include "licReaderELC1.h"
|
||||
#include "licReaderELC2.h"
|
||||
@@ -31,9 +29,9 @@ public:
|
||||
string operationErrors = "";
|
||||
bool argumentsCorrect = false;
|
||||
ErrorMessage error;
|
||||
LicenceELC11 *licence11;
|
||||
LicenceELC31 *licence31;
|
||||
Licence2 *licence2;
|
||||
Licence1 *licence1;
|
||||
|
||||
|
||||
LicenceReader();
|
||||
~LicenceReader();
|
||||
|
||||
Binary file not shown.
@@ -5,7 +5,7 @@
|
||||
/// @param argc
|
||||
/// @param argv parametry pro generování licence
|
||||
/// @return
|
||||
int main(int argc, char *argv[])
|
||||
int main5(int argc, char *argv[])
|
||||
{
|
||||
unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
try
|
||||
|
||||
@@ -213,6 +213,7 @@ void LicenceELC11::initCrypto()
|
||||
memcpy(&this->cryptData.aesKey[24], &this->cryptData.aesKey[12], 8);
|
||||
}
|
||||
}
|
||||
|
||||
string LicenceELC11::getLicenceName()
|
||||
{
|
||||
string result = "";
|
||||
|
||||
@@ -1,38 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include "utils.h"
|
||||
#include "licenceReader.h"
|
||||
|
||||
|
||||
/// @brief hlavní funkce
|
||||
/// @param argc
|
||||
/// @param argv parametry pro generování licence
|
||||
/// @return
|
||||
int main5()
|
||||
int main()
|
||||
{
|
||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
// try
|
||||
// {
|
||||
// unordered_map<string, string> arguments = getArguments(argc, argv);
|
||||
// LicenceGenerator generatorOld = LicenceGenerator(arguments["-uid"], arguments["-cid"], arguments["-csd"], arguments["-configFileName"]);
|
||||
// generatorOld.createLicenceFile();
|
||||
// system("pause");
|
||||
// return SUCCES;
|
||||
// }
|
||||
// catch (...)
|
||||
// {
|
||||
// cerr << "Obecná chyba\n";
|
||||
// }
|
||||
|
||||
// system("pause");
|
||||
// return SUCCES;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
int protocolId = 444;
|
||||
|
||||
LicenceReader licenceReader1 {};
|
||||
|
||||
InitStructure initStructure;
|
||||
initStructure.licenceType = (int)LicenceType::EOS_EOV;
|
||||
initStructure.licenceVersion = 1;
|
||||
@@ -41,52 +17,77 @@ int main5()
|
||||
initStructure.licenceFilePath = "";
|
||||
initStructure.cid_csd_filePath = "";
|
||||
|
||||
cout << "-- verze #1: init a iterace" << "\n";
|
||||
|
||||
//verze #1: načtení kompletní licence a zobrazení
|
||||
if (licenceReader1.init(2, initStructure))
|
||||
// verze původní ELC 1
|
||||
LicenceReader licenceReaderELC1{};
|
||||
if (licenceReaderELC1.initread(1, initStructure)) //iniciacni nacteni
|
||||
{
|
||||
LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||
|
||||
if (licenceReader1.getLicenceInfo(&info))
|
||||
LicenceInfo1 info; // struktura pro ELC1. Nemá tam asi nic jiného smysl nez true/false
|
||||
if (licenceReaderELC1.getLicenceInfo(&info))
|
||||
{
|
||||
if (info.licences.count(protocolId) > 0) cout << "Počet z vectoru pro : " << protocolId << ": " << info.licences.at(protocolId) << endl;
|
||||
cout << "Všechny licenční body: " << endl;
|
||||
for (const auto &pair : info.licences) { std::cout << "<" << pair.first << ", " << pair.second << ">" << endl; }
|
||||
}
|
||||
else cout << "Došlo k chybě: " << licenceReader1.error.message;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Došlo k chybě: " << licenceReader1.error.message;
|
||||
}
|
||||
|
||||
cout << "\n" << "-- verze #2: init a iterace" << "\n";
|
||||
//verze #2 : iterace pro kazdý bod zvlášť
|
||||
|
||||
LicenceReader licenceReader2 {};
|
||||
|
||||
if (licenceReader2.initread(2, initStructure))
|
||||
{
|
||||
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||
|
||||
if (licenceReader2.getLicenceItemInfo(protocolId, &info))
|
||||
{
|
||||
std::cout << "Počet licenčních bodů pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||
if (info.isValid)
|
||||
cout << "Platna licence ELC1 \n";
|
||||
else
|
||||
cout << "Neplatna licence ELC1\n";
|
||||
}
|
||||
else
|
||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Došlo k chybě: " << licenceReader2.error.message;
|
||||
cout << "CHYBA: " << licenceReaderELC1.error.message;
|
||||
}
|
||||
|
||||
// verze ELC 2 pro jeden protokol
|
||||
LicenceReader licenceReaderELC2{};
|
||||
|
||||
if (licenceReaderELC2.initread(2, initStructure)) //iniciacni nacteni
|
||||
{
|
||||
LicenceItem21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||
int protocolId = 444;
|
||||
|
||||
if (licenceReaderELC2.getLicenceItemInfo(protocolId, &info))
|
||||
{
|
||||
cout << "Pocet licencních bodu pro " << info.protocolId << ": " << info.dataPointsCount << std::endl;
|
||||
}
|
||||
else
|
||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "CHYBA: " << licenceReaderELC2.error.message;
|
||||
}
|
||||
|
||||
LicenceReader licenceReaderCompleteELC2{};
|
||||
|
||||
// verze ELC 2 kompletní načtení
|
||||
if (licenceReaderCompleteELC2.init(2, initStructure)) //iniciacni nacteni
|
||||
{
|
||||
LicenceInfo21 info; // podle ELC a kompatibility určit strukuru (LicenceInfo11, LicenceInfo21, LicenceInfo31)
|
||||
int protocolId = 333;
|
||||
|
||||
if (licenceReaderCompleteELC2.getLicenceInfo(&info))
|
||||
{
|
||||
if (info.licences.count(protocolId) > 0) cout << "Pocet bodu z vectoru pro protokol : " << protocolId << ": " << info.licences.at(protocolId) << "\n";
|
||||
else cout << "Pro tento protokol nejsou definovay licencni body\n";
|
||||
cout << "Vypis vsech licencnich bodu: " << endl;
|
||||
for (const auto &pair : info.licences)
|
||||
{
|
||||
std::cout << "<" << pair.first << ", " << pair.second << ">" << endl;
|
||||
}
|
||||
}
|
||||
else
|
||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "CHYBA: " << licenceReaderCompleteELC2.error.message;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cout << "Obecná chyba\n";
|
||||
cout << "Obecna chyba\n";
|
||||
}
|
||||
|
||||
system("pause");
|
||||
// system("pause");
|
||||
return SUCCES;
|
||||
}
|
||||
|
||||
@@ -8,20 +8,24 @@ SDCard::SDCard()
|
||||
SDCard::SDCard(const string cds_cid_Path)
|
||||
{
|
||||
this->filePath = cds_cid_Path;
|
||||
if (getCIDFromFile() == false) return;
|
||||
if (getCSDFromFile() == false) return;
|
||||
if (getCIDFromFile() == false)
|
||||
return;
|
||||
if (getCSDFromFile() == false)
|
||||
return;
|
||||
this->isLoaded = SDCard::readSDCard();
|
||||
}
|
||||
|
||||
SDCard::SDCard(string cid, string csd)
|
||||
{
|
||||
for (unsigned int i = 0; i < cid.length(); i++) this->cid[i] = cid[i];
|
||||
for (unsigned int i = 0; i < csd.length(); i++) this->csd[i] = csd[i];
|
||||
for (unsigned int i = 0; i < cid.length(); i++)
|
||||
this->cid[i] = cid[i];
|
||||
for (unsigned int i = 0; i < csd.length(); i++)
|
||||
this->csd[i] = csd[i];
|
||||
|
||||
this->isLoaded = SDCard::readSDCard();
|
||||
}
|
||||
|
||||
bool SDCard:: readSDCard()
|
||||
bool SDCard::readSDCard()
|
||||
{
|
||||
|
||||
BYTE cHexNibbleToNo[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
@@ -99,7 +103,6 @@ bool SDCard:: readSDCard()
|
||||
this->cardData.CRCOK = ((sdCrc << 1) | 1) == this->cardData.CID[15];
|
||||
this->cardData.crcCorrect = (int)this->cardData.CID[15] == (int)((sdCrc << 1) | 1);
|
||||
return this->cardData.crcCorrect;
|
||||
|
||||
}
|
||||
|
||||
bool SDCard::getCIDFromFile()
|
||||
@@ -109,11 +112,14 @@ bool SDCard::getCIDFromFile()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (content.size() >= 32)
|
||||
|
||||
if (content.size() >= CID_LENGTH)
|
||||
{
|
||||
for (int i = 0; i<32;i++) this->cid[i] = content[i];
|
||||
for (int i = 0; i < 32; i++)
|
||||
this->cid[i] = content[i];
|
||||
}
|
||||
else return false;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -125,11 +131,13 @@ bool SDCard::getCSDFromFile()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (content.size() >= 32)
|
||||
if (content.size() >= CSD_LENGTH)
|
||||
{
|
||||
for (int i = 0; i<32;i++) this->csd[i] = content[i];
|
||||
for (int i = 0; i < 32; i++)
|
||||
this->csd[i] = content[i];
|
||||
}
|
||||
else return false;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -58,8 +58,7 @@ LicenceELC1::LicenceELC1(LicenceIdentification &licIdentification) : lIdentifica
|
||||
|
||||
bool LicenceELC1::getSDData()
|
||||
{
|
||||
for (int i = 0; i < CID_LENGTH; i++)
|
||||
this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
||||
for (int i = 0; i < CID_LENGTH; i++) this->sdData.CID_nibble[i] = (BYTE)cid[i];
|
||||
|
||||
for (int i = 0; i < cnibblescount / 2; i++)
|
||||
{
|
||||
@@ -91,12 +90,10 @@ bool LicenceELC1::getSDData()
|
||||
this->sdData.manufacturerDate[i] = date[i];
|
||||
|
||||
// CSD
|
||||
for (unsigned int i = 0; i < CSD_LENGTH; i++)
|
||||
this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
||||
for (unsigned int i = 0; i < CSD_LENGTH; i++) this->sdData.CSD_nibble[i] = (BYTE)csd[i];
|
||||
|
||||
for (unsigned int i = 0; i < cnibblescount / 2; i++)
|
||||
{
|
||||
//
|
||||
this->sdData.CSD[i] = cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i]] << 4 | cHexNibble_to_No1[this->sdData.CSD_nibble[2 * i + 1]];
|
||||
}
|
||||
|
||||
@@ -104,10 +101,6 @@ bool LicenceELC1::getSDData()
|
||||
{
|
||||
this->sdData.cardSize = this->sdData.CSD[7] << 16 | this->sdData.CSD[8] << 8 | this->sdData.CSD[9];
|
||||
this->sdData.cardGSize = (this->sdData.cardSize + 1) / 2048;
|
||||
|
||||
if (this->sdData.cardSize > 17200) // TODO result.cardSize
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
BYTE sdCrc = 0;
|
||||
@@ -189,10 +182,6 @@ string LicenceELC1::getLicenceName(BYTE licPostfix)
|
||||
string result = "";
|
||||
char prefixChar = 97;
|
||||
|
||||
if (licPostfix > 9) // chyba
|
||||
{
|
||||
}
|
||||
|
||||
if (licType == PlcLicenceType::LicenceOther)
|
||||
{
|
||||
result = "ezlic_";
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -60,7 +60,7 @@ LicenceReader::LicenceReader()
|
||||
// this->licIdentification.licCompatibility = compatibility;
|
||||
// }
|
||||
|
||||
/// @brief inicializace generátoru a načtení licenčních bodů
|
||||
/// @brief inicializace generátoru a načtení licenčních bodů do obecné struktury
|
||||
/// @param elcType
|
||||
/// @param licenceType
|
||||
/// @param licenceVersion
|
||||
@@ -72,18 +72,28 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
|
||||
try
|
||||
{
|
||||
elcSwitchType = elcType * 10 + licCompatibility;
|
||||
|
||||
|
||||
if (init(elcType, initStructure))
|
||||
{
|
||||
switch (elcSwitchType)
|
||||
{
|
||||
case 11:
|
||||
{ // old eoseov
|
||||
LicenceELC11 licence = LicenceELC11(this->licIdentification);
|
||||
this->licence11 = &licence;
|
||||
licence.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||
licence.licenceFilePath = initStructure.licenceFilePath;
|
||||
this->licence11->readLicence(&this->licenceInfo);
|
||||
Reader::Licence1 licenceELC1 = Reader::Licence1(this->licIdentification);
|
||||
this->licence1 = &licenceELC1;
|
||||
licenceELC1.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||
licenceELC1.licenceFilePath = initStructure.licenceFilePath;
|
||||
|
||||
try
|
||||
{
|
||||
this->licence1->readLicence(&this->licenceInfo);
|
||||
}
|
||||
catch (const LicenceException &ex)
|
||||
{
|
||||
error.code = ex.getErrorCode();
|
||||
error.message = ex.getErrorMessage();
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 21:
|
||||
@@ -93,12 +103,11 @@ bool LicenceReader::initread(int elcType, InitStructure &initStructure) // TOTO
|
||||
licenceELC2.cid_cdsPath = initStructure.cid_csd_filePath;
|
||||
licenceELC2.licenceFilePath = initStructure.licenceFilePath;
|
||||
this->licence2->readLicence(&this->licenceInfo);
|
||||
|
||||
break;
|
||||
}
|
||||
case 31:
|
||||
{
|
||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -142,9 +151,13 @@ bool LicenceReader::init(int elcType, InitStructure &initStructure)
|
||||
|
||||
elcSwitchType = elcType * 10 + licCompatibility;
|
||||
|
||||
return true; // TODO testy
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @brief vrací informace o licenčím bodu na základě id protocolu a předané návratové struktury
|
||||
/// @param protocolId
|
||||
/// @param returnItemStructure
|
||||
/// @return
|
||||
bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure)
|
||||
{
|
||||
try
|
||||
@@ -152,18 +165,14 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
||||
switch (elcSwitchType)
|
||||
{
|
||||
case 11:
|
||||
{ // old eoseov
|
||||
LicenceItem11 *resultPtr = static_cast<LicenceItem11 *>(returnItemStructure);
|
||||
resultPtr->protocolId = protocolId;
|
||||
if (this->licenceInfo.licences.count(protocolId))
|
||||
resultPtr->dataPointsCount = this->licenceInfo.licences.at(protocolId);
|
||||
else
|
||||
resultPtr->dataPointsCount = 0;
|
||||
{
|
||||
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnItemStructure);
|
||||
if (this->licenceInfo.licences.count(1)) resultPtr->isValid = true; //stare eov melo natvrdo "id" 1.
|
||||
else resultPtr->isValid = false;
|
||||
break;
|
||||
}
|
||||
case 21:
|
||||
{
|
||||
|
||||
LicenceItem21 *resultPtr = static_cast<LicenceItem21 *>(returnItemStructure);
|
||||
resultPtr->protocolId = protocolId; // protocolId;
|
||||
if (this->licenceInfo.licences.count(protocolId))
|
||||
@@ -174,7 +183,7 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
||||
}
|
||||
case 31:
|
||||
{
|
||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -195,66 +204,83 @@ bool LicenceReader::getLicenceItemInfo(int protocolId, void *returnItemStructure
|
||||
return true;
|
||||
}
|
||||
|
||||
/// @brief vrací informace o všech licenčních bodech základě předané návratové struktury
|
||||
/// @param returnStructure
|
||||
/// @return
|
||||
bool LicenceReader::getLicenceInfo(void *returnStructure)
|
||||
{
|
||||
// const type_info& ti1 = typeid(returnStructure);
|
||||
// cout << "TTTYP: " << ti1.name() << endl;
|
||||
switch (elcSwitchType)
|
||||
try
|
||||
{
|
||||
case 11:
|
||||
{ // old eoseov
|
||||
break;
|
||||
}
|
||||
case 21:
|
||||
{
|
||||
try
|
||||
switch (elcSwitchType)
|
||||
{
|
||||
case 11:
|
||||
{ // old eoseov
|
||||
|
||||
LicenceInfo1 *resultPtr = static_cast<LicenceInfo1 *>(returnStructure);
|
||||
|
||||
if (this->licenceInfo.licences.count(1))
|
||||
{
|
||||
resultPtr->isValid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
resultPtr->isValid = false;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
case 21:
|
||||
{
|
||||
|
||||
Reader::Licence2 licenceELC2 = Reader::Licence2(this->licIdentification);
|
||||
licenceELC2.readLicence(&this->licenceInfo);
|
||||
return licenceELC2.getLicenceInfo(returnStructure);
|
||||
|
||||
// catch (const LicenceException &ex)
|
||||
// {
|
||||
// error.code = ex.getErrorCode();
|
||||
// error.message = ex.getErrorMessage();
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
||||
// try
|
||||
// {
|
||||
// licence.readLicence(&this->licenceInfo);
|
||||
// return licence.getLicenceInfo(returnStructure);
|
||||
// }
|
||||
// catch (const LicenceException &ex)
|
||||
// {
|
||||
// error.code = ex.getErrorCode();
|
||||
// error.message = ex.getErrorMessage();
|
||||
// return false;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
catch (const LicenceException &ex)
|
||||
case 31:
|
||||
{
|
||||
error.code = ex.getErrorCode();
|
||||
error.message = ex.getErrorMessage();
|
||||
return false;
|
||||
// LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
// try
|
||||
// {
|
||||
// licence.readLicence();
|
||||
// return licence.getLicenceInfo(returnStructure);
|
||||
// }
|
||||
// catch (const LicenceException &ex)
|
||||
// {
|
||||
// error.code = ex.getErrorCode();
|
||||
// error.message = ex.getErrorMessage();
|
||||
// return false;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// LicenceELC21 licence = LicenceELC21(this->licIdentification);
|
||||
// try
|
||||
// {
|
||||
// licence.readLicence(&this->licenceInfo);
|
||||
// return licence.getLicenceInfo(returnStructure);
|
||||
// }
|
||||
// catch (const LicenceException &ex)
|
||||
// {
|
||||
// error.code = ex.getErrorCode();
|
||||
// error.message = ex.getErrorMessage();
|
||||
// return false;
|
||||
// }
|
||||
break;
|
||||
}
|
||||
case 31:
|
||||
catch (const LicenceException &ex)
|
||||
{
|
||||
LicenceELC31 licence = LicenceELC31(this->licIdentification);
|
||||
// try
|
||||
// {
|
||||
// licence.readLicence();
|
||||
// return licence.getLicenceInfo(returnStructure);
|
||||
// }
|
||||
// catch (const LicenceException &ex)
|
||||
// {
|
||||
// error.code = ex.getErrorCode();
|
||||
// error.message = ex.getErrorMessage();
|
||||
// return false;
|
||||
// }
|
||||
break;
|
||||
error.code = ex.getErrorCode();
|
||||
error.message = ex.getErrorMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
error.code = -1;
|
||||
error.message = "Nepodařilo se identifikovat licenci";
|
||||
return false;
|
||||
}
|
||||
|
||||
LicenceReader::~LicenceReader()
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
src/reader/LicenceReader.o: src/reader/LicenceReader.cpp \
|
||||
include/reader/licenceReader.h include/common/utils.h \
|
||||
include/licenceELC11.h include/common/licenceCommon.h \
|
||||
include/common/SDCard.h include/licenceELC31.h \
|
||||
include/generator/pugixml.hpp include/generator/pugiconfig.hpp \
|
||||
include/reader/licReaderELC1.h include/reader/licReaderELC2.h \
|
||||
include/common/licenceELC2.h include/common/licenceCommon.h \
|
||||
include/common/SDCard.h include/reader/licReaderELC3.h
|
||||
include/reader/licReaderELC1.h include/common/licenceCommon.h \
|
||||
include/common/licenceELC1.h include/common/licenceCommon.h \
|
||||
include/common/SDCard.h include/common/SDCard.h \
|
||||
include/reader/licReaderELC2.h include/common/licenceELC2.h \
|
||||
include/reader/licReaderELC3.h
|
||||
|
||||
Binary file not shown.
@@ -2,5 +2,126 @@
|
||||
|
||||
namespace Reader
|
||||
{
|
||||
Licence1::Licence1() {}
|
||||
|
||||
Licence1::~Licence1() {}
|
||||
|
||||
Licence1::Licence1(LicenceIdentification &licIdentification) : LicenceELC1(licIdentification)
|
||||
{
|
||||
}
|
||||
|
||||
bool Licence1::readLicence(LicenceInfoGeneral *licences)
|
||||
{
|
||||
sdCard = SDCard(this->cid_cdsPath);
|
||||
if (sdCard.isLoaded == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||
|
||||
for (unsigned int i = 0; i < CID_LENGTH;i++) this->cid[i] = sdCard.cid[i];
|
||||
for (unsigned int i = 0; i < CSD_LENGTH;i++) this->csd[i] = sdCard.csd[i];
|
||||
|
||||
if (getSDData() == false) throw LicenceException((int)GeneralError::SDCardReadError, "Chyba při čtení SD karty, cesta: " + cid_cdsPath);
|
||||
|
||||
for (unsigned int i = 0; i < sdCard.cidString.length(); i++)
|
||||
this->cid[i] = sdCard.cidString[i]; // nutné pro původní algoritmus
|
||||
for (unsigned int i = 0; i < sdCard.csdString.length(); i++)
|
||||
this->csd[i] = sdCard.csdString[i]; // nutné pro původní algoritmus
|
||||
|
||||
string licFileName = getLicenceName(0);
|
||||
string licFilePath = this->licenceFilePath + licFileName;
|
||||
|
||||
char licFileNameToRead[licFilePath.length()+1] = {};
|
||||
getCharsFromString(licFilePath, licFileNameToRead, licFilePath.length());
|
||||
|
||||
FILE *licenceFile;
|
||||
char ch;
|
||||
|
||||
licenceFile = fopen(licFileNameToRead, "rb"); // read mode
|
||||
|
||||
if (licenceFile == nullptr) throw LicenceException((int)GeneralError::LicenceReadError, "LicenceReadError: " + licFilePath);
|
||||
|
||||
fseek(licenceFile, 0, SEEK_END); // seek to end of file
|
||||
const int size = ftell(licenceFile); // get current file pointer
|
||||
fseek(licenceFile, 0, SEEK_SET);
|
||||
|
||||
if (size <= 0) throw LicenceException((int)GeneralError::LicenceSizeMismatch, "LicenceSizeMismatch: " + licFilePath);
|
||||
|
||||
int count = 0;
|
||||
|
||||
unsigned char licenceContent[size];
|
||||
|
||||
for (int i = 0; i < size; i++)
|
||||
{
|
||||
ch = fgetc(licenceFile);
|
||||
licenceContent[i] = ch;
|
||||
count++;
|
||||
}
|
||||
|
||||
fclose(licenceFile);
|
||||
|
||||
LicenceDataMainELC licenceHeader{};
|
||||
LicenceData licEncryptedData{};
|
||||
|
||||
memcpy(&licenceHeader, licenceContent, sizeof(LicenceDataMainELC));
|
||||
|
||||
const int sizeOfEncryptedData = size - sizeof(LicenceDataMainELC);
|
||||
unsigned char encryptedData[sizeOfEncryptedData] = {};
|
||||
for (int i = 0; i < sizeOfEncryptedData; i++)
|
||||
encryptedData[i] = licenceContent[i + sizeof(LicenceDataMainELC)];
|
||||
|
||||
BYTE prefixType = (int)licenceContent[3] - 0x30;
|
||||
if (prefixType == PrefixType::ELC1)
|
||||
{
|
||||
if (licenceHeader.licHeader.sizeData > 0)
|
||||
{
|
||||
if (licenceHeader.licHeader.licSubType == cEzLic_p78ou3_SubType_10_10)
|
||||
{
|
||||
initCrypto();
|
||||
// CryptData cryptData = initCrypto(sdData, licIdent.licIDType);
|
||||
unsigned char decrypted[2000] = {};
|
||||
int decrypted_len = decrypt(encryptedData, sizeof(encryptedData), cryptData.aesKey, cryptData.aesInitVector, decrypted);
|
||||
|
||||
if (sizeof(licEncryptedData) != decrypted_len)
|
||||
{
|
||||
throw LicenceException((int)GeneralError::LicenceSizeMismatch, "License size mismatch ");
|
||||
}
|
||||
else
|
||||
{
|
||||
// memset(&licEncryptedData, 0, sizeof(licEncryptedData));
|
||||
memcpy(&licEncryptedData, decrypted, sizeof(licEncryptedData));
|
||||
|
||||
if (licEncryptedData.id.version == cEzLic_p78ou3_HeaderType_10 && licEncryptedData.header.licVersion == cEzLic_p78ou3_HeaderType_10)
|
||||
{
|
||||
if (licEncryptedData.header.licType == cEzLic_p78ou3_IDType_EOVOSV)
|
||||
{
|
||||
if (licEncryptedData.header.licCount > 0)
|
||||
{
|
||||
for (int i = 0; i < licMaxCount; i++)
|
||||
{
|
||||
licences->licences.insert(pair<int, int>(licEncryptedData.items[i].protoId, licEncryptedData.items[i].licCount));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw LicenceException((int)GeneralError::LicenceSizeCardMismatch, "Size card info mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw LicenceException((int)GeneralError::LicenceMismatch, "Licence mismatch");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw LicenceException((int)GeneralError::LicenceReadError, "Licence error");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,5 @@
|
||||
src/reader/licReaderELC1.o: src/reader/licReaderELC1.cpp \
|
||||
include/reader/licReaderELC1.h
|
||||
include/reader/licReaderELC1.h include/common/utils.h \
|
||||
include/common/licenceCommon.h include/common/licenceELC1.h \
|
||||
include/common/licenceCommon.h include/common/SDCard.h \
|
||||
include/common/SDCard.h
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user