From 721464a3c8a7994f5f68e0590a4ae7062e3d9a08 Mon Sep 17 00:00:00 2001 From: AcerExtensa Date: Thu, 13 Oct 2022 09:35:11 +0200 Subject: [PATCH] CLI variant of MBSeedKey --- ecuseedkeydll.cpp | 2 +- main_cli.cpp | 74 ++++++++++++++++++++++++++++++++++++++++------- mbseedkey_cli.pro | 2 ++ 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/ecuseedkeydll.cpp b/ecuseedkeydll.cpp index 63ce54f..7f3d84f 100644 --- a/ecuseedkeydll.cpp +++ b/ecuseedkeydll.cpp @@ -55,7 +55,7 @@ ECUSeedKeyDLL::ECUSeedKeyDLL(QString dll_path, QObject *parent) : QObject(parent emit DLLNameChanged(); QString dll_info_str = "[" + info.fileName() + "] "; - qInfo() << dll_info_str << "Loading ..."; + qDebug() << dll_info_str << "Loading ..."; this->p_dllHandle = LoadLibraryW(QDir::toNativeSeparators(info.absoluteFilePath()).toStdWString().data()); if(!this->p_dllHandle) diff --git a/main_cli.cpp b/main_cli.cpp index 581cf81..e28c19d 100644 --- a/main_cli.cpp +++ b/main_cli.cpp @@ -6,6 +6,11 @@ #include "exutils.h" #include "ecuseedkeydll.h" +QTextStream& qStdOut() +{ + static QTextStream ts( stdout ); + return ts; +} int main(int argc, char *argv[]) { @@ -20,8 +25,8 @@ int main(int argc, char *argv[]) if(args.size() <= 0) { - qDebug() << "Found dlls in folder: " << ex_utils->foldername(); - + qStdOut() << "Found dlls in folder: " << ex_utils->foldername(); + return 0; } QCommandLineParser parser; @@ -43,10 +48,15 @@ int main(int argc, char *argv[]) QCoreApplication::translate("main", "Seed") }, { - {"l", "level"}, + {"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 @@ -55,28 +65,70 @@ int main(int argc, char *argv[]) bool info = parser.isSet("i"); auto targetDll = parser.value("d"); auto seed = parser.value("s"); - auto level = parser.value("l"); - qDebug() << info << targetDll; + 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 info(targetDll); - if(!info.isFile() || !info.isReadable()) + QFileInfo dll(targetDll); + if(!dll.isFile() || !dll.isReadable()) { - qDebug() << QCoreApplication::translate("main", "can't read DLL or wrong filepath"); + qStdOut() << QCoreApplication::translate("main", "can't read DLL or wrong filepath") << "\n"; return 0; } auto ecu = new ECUSeedKeyDLL(targetDll); qDebug() << ecu->ECUName(); - qDebug() << "Access Levels" << ecu->AccessTypesString(); foreach(auto acc, ecu->AccessTypes()) { - qDebug() << "Access LeveL: " << QStringLiteral("%1 ").arg(acc, 2, 16, QLatin1Char('0')).toUpper() << "seed length " << ecu->seedLength(acc) << " key length " << ecu->keyLength(acc); + 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 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 app.exec(); + + + return 0; } diff --git a/mbseedkey_cli.pro b/mbseedkey_cli.pro index fc146df..7a07375 100644 --- a/mbseedkey_cli.pro +++ b/mbseedkey_cli.pro @@ -18,6 +18,8 @@ VERSION_PE_HEADER = $$VERSION_MAJOR'.'$$VERSION_MINOR message("VER: $$VERSION" ) +DEFINES += QT_NO_DEBUG_OUTPUT + # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0