Skip to content

Commit

Permalink
Generate key from seed key
Browse files Browse the repository at this point in the history
  • Loading branch information
Xplatforms committed Oct 5, 2020
1 parent 7f562f4 commit 5838090
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ecuseedkeydll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,36 @@ void ECUSeedKeyDLL::loadDllfuncs()

}
}

QList<qint32> ECUSeedKeyDLL::GenerateKeyFromSeed(QList<qint32> seed, qint32 access_type)
{
QList<qint32> key;
if(this->GenerateKeyExOpt == Q_NULLPTR)
{
qWarning() << this->errorMsg();
return key;
}

unsigned char * seed_data = new unsigned char[seed.length()];
auto i = 0;
foreach(auto d, seed)seed_data[i++] = d;

unsigned char key_data[256] = {0};
unsigned int key_data_len = 0;

///FIX: some DLL's return zero but key is filled out
auto ret = this->GenerateKeyExOpt(seed_data, seed.length(), access_type, Q_NULLPTR, Q_NULLPTR, key_data, 256, key_data_len);
if(key_data_len <= 0 && (key_data[0] != 0 && key_data[1] != 0))
{
qWarning() << "GenerateKeyExOpt returned zero size, but data buf is set. Try to copy data";
key_data_len = this->GetKeyLength(access_type);
}

unsigned int c = 0;
do
{
key.append(key_data[c++]);
}
while(c < key_data_len);
return key;
}
1 change: 1 addition & 0 deletions ecuseedkeydll.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class ECUSeedKeyDLL : public QObject
explicit ECUSeedKeyDLL(QString dll_path, QObject *parent = nullptr);
~ECUSeedKeyDLL();

Q_INVOKABLE QList<qint32> GenerateKeyFromSeed(QList<qint32> seed, qint32 access_type);

private slots:
void loadDllfuncs();
Expand Down

0 comments on commit 5838090

Please sign in to comment.