-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathecuseedkeydll.h
104 lines (84 loc) · 4.23 KB
/
ecuseedkeydll.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#ifndef ECUSEEDKEYDLL_H
#define ECUSEEDKEYDLL_H
#include <QObject>
#include <QString>
#include <QHash>
#include <Windows.h>
typedef int (__cdecl *_f_GetConfiguredAccessTypes)(int *);
typedef int (__cdecl *_f_GetSeedLength)(int);
typedef int (__cdecl *_f_GetKeyLength)(int);
typedef const char * (__cdecl *_f_GetECUName)();
typedef const char * (__cdecl *_f_GetComment)();
typedef int (__cdecl * _f_GenerateKeyExOpt )( const unsigned char* ipSeedArray,
unsigned int iSeedArraySize,
const unsigned int iSecurityLevel,
const char * ipVariant,
const char* ipOptions,
unsigned char* iopKeyArray,
unsigned int iMaxKeyArraySize,
unsigned int& oActualKeyArraySize );
struct ECUSeedKeyLenPairs
{
qint32 seed_len;
qint32 key_len;
}typedef ECUSeedKeyLenPairs;
class ECUSeedKeyDLL : public QObject
{
Q_OBJECT
public:
explicit ECUSeedKeyDLL(QObject *parent = nullptr);
explicit ECUSeedKeyDLL(QString dll_path, QObject *parent = nullptr);
~ECUSeedKeyDLL();
bool isSeedKeyDll(){return this->GenerateKeyExOpt != Q_NULLPTR;}
Q_PROPERTY(QString ECUName READ ECUName NOTIFY ECUNameChanged);
Q_PROPERTY(QString DLLName READ DLLName NOTIFY DLLNameChanged);
Q_PROPERTY(QString Comment READ Comment NOTIFY CommentChanged);
Q_PROPERTY(QList<qint32> AccessTypes READ AccessTypes NOTIFY AccessTypesChanged);
/// TODO: two extra funcs for QML :/
Q_PROPERTY(QString AccessTypesString READ AccessTypesString NOTIFY AccessTypesChanged);
Q_PROPERTY(QStringList AccessTypesStringList READ AccessTypesStringList NOTIFY AccessTypesChanged);
Q_PROPERTY(QString errorMsg READ errorMsg WRITE setErrorMsg NOTIFY errorMsgChanged);
QString DLLName() const {return this->p_dll_name;}
QString ECUName() const {return this->p_ecu_name;}
QString Comment() const {return this->p_comment;}
QList<qint32> AccessTypes() {return this->p_access_types.keys();}
QString AccessTypesString();
QStringList AccessTypesStringList();
QString errorMsg(){return this->p_errorMsg;}
void setErrorMsg(const QString & msg ){if(this->p_errorMsg.compare(msg) == 0)return; this->p_errorMsg = msg; emit errorMsgChanged();}
Q_INVOKABLE qint32 seedLength(qint32 access_type) {return this->p_access_types.contains(access_type)?
this->p_access_types.value(access_type).seed_len:4; }
Q_INVOKABLE qint32 seedLength(QString access_type);
Q_INVOKABLE qint32 keyLength(qint32 access_type) {return this->p_access_types.contains(access_type)?
this->p_access_types.value(access_type).key_len:4; }
Q_INVOKABLE qint32 keyLength(QString access_type);
Q_INVOKABLE QList<qint32> generateKeyFromSeed(QList<qint32> seed, qint32 access_type, qint32 key_len = 0);
Q_INVOKABLE QString generateKeyFromSeed(QString seed, qint32 access_type, qint32 key_len);
Q_INVOKABLE QString generateKeyFromSeed(QString seed, QString access_type, QString key_len);
signals:
void ECUNameChanged();
void DLLNameChanged();
void CommentChanged();
void SeedLengthChanged();
void KeyLengthChanged();
void AccessTypesChanged();
void errorMsgChanged();
private slots:
void loadDllfuncs();
private:
_f_GetConfiguredAccessTypes GetConfiguredAccessTypes;
_f_GetSeedLength GetSeedLength;
_f_GetKeyLength GetKeyLength;
_f_GetECUName GetECUName;
_f_GetComment GetComment;
_f_GenerateKeyExOpt GenerateKeyExOpt;
private:
HMODULE p_dllHandle;
QString p_dllPath;
QString p_errorMsg;
QString p_ecu_name;
QString p_dll_name;
QString p_comment;
QHash<qint32, ECUSeedKeyLenPairs> p_access_types;
};
#endif // ECUSEEDKEYDLL_H