-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain_cli.cpp
134 lines (109 loc) · 4.27 KB
/
main_cli.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <QCoreApplication>
#include <QDebug>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDir>
#include "exutils.h"
#include "ecuseedkeydll.h"
QTextStream& qStdOut()
{
static QTextStream ts( stdout );
return ts;
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
app.setOrganizationName("Xplatforms");
app.setOrganizationDomain("mbseedkey");
auto ex_utils = new ExUTILS(&app);
auto args = app.arguments();
args.removeFirst();
if(args.size() <= 0)
{
qStdOut() << "Found dlls in folder: " << ex_utils->foldername();
return 0;
}
QCommandLineParser parser;
parser.setApplicationDescription("MBSeedKey CLI");
parser.addHelpOption();
parser.addVersionOption();
parser.addOptions({
{{"i", "info"}, QCoreApplication::translate("main", "Print information from seed-key dll(ECU Name, Comments, Access Levels, Seed/Key sizes")},
{
{"d", "target-dll"},
QCoreApplication::translate("main", "DLL for seed-key generation"),
QCoreApplication::translate("main", "SeedKey DLL")
},
{
{"s", "seed"},
QCoreApplication::translate("main", "Seed for key generation in HEX: FFABEE"),
QCoreApplication::translate("main", "Seed")
},
{
{"a", "access-level"},
QCoreApplication::translate("main", "Access Level for key generation in HEX: 0B"),
QCoreApplication::translate("main", "Access Level")
},
{
{"l", "key-length"},
QCoreApplication::translate("main", "Key length (int) if default length can't be read from dll"),
QCoreApplication::translate("main", "Key Length")
},
});
// Process the actual command line arguments given by the user
parser.process(app);
bool info = parser.isSet("i");
auto targetDll = parser.value("d");
auto seed = parser.value("s");
auto level = parser.value("a");
auto keylength = parser.value("l");
if(info)
{
if(targetDll.isEmpty()){qDebug() << QCoreApplication::translate("main", "DLL not set!"); return 0;}
QFileInfo dll(targetDll);
if(!dll.isFile() || !dll.isReadable())
{
qStdOut() << QCoreApplication::translate("main", "can't read DLL or wrong filepath") << "\n";
return 0;
}
auto ecu = new ECUSeedKeyDLL(targetDll);
qDebug() << ecu->ECUName();
foreach(auto acc, ecu->AccessTypes())
{
qStdOut() << "Access Level: " << QStringLiteral("%1 ").arg(acc, 2, 16, QLatin1Char('0')).toUpper()
<< "seed length " << ecu->seedLength(acc) << " key length " << ecu->keyLength(acc) << "\n";
}
return 0;
}
if(targetDll.isEmpty())
{
qStdOut() << "run this programm with --help argument to see all cmd line switches" << "\n";
return 0;
}
if(seed.isEmpty())
{
qStdOut() << "you need to set at target dll, seed and access level for key generation. run this programm with --help to see all cmd line switches\n";
return 0;
}
QFileInfo dll(targetDll);
if(!dll.isFile() || !dll.isReadable())
{
qStdOut() << QCoreApplication::translate("main", "can't read DLL or wrong filepath") << "\n";
return 0;
}
auto ecu = new ECUSeedKeyDLL(targetDll);
qint32 access_level = level.toInt(Q_NULLPTR, 16);
qint32 key_length = keylength.isEmpty()?0:keylength.toInt(Q_NULLPTR, 10);
if(key_length <= 0)key_length = ecu->keyLength(access_level);
QByteArray datas_hex = seed.toLocal8Bit();
QList<qint32> result;
result.reserve(datas_hex.size() / 2);
for (int i = 0; i < datas_hex.size(); i += 2)
result.push_back(QString::fromLatin1(datas_hex.data() + i, 2).toInt(Q_NULLPTR,16));
//qStdOut() << "seed " << seed << " acc " << access_level << " key len " << key_length << " len arg " << keylength << "\n";
foreach(auto k, ecu->generateKeyFromSeed(result, access_level, key_length))
{
qStdOut() << QStringLiteral("%1 ").arg(k, 2, 16, QLatin1Char('0')).toUpper();
}
return 0;
}