Skip to content

Commit

Permalink
CLI variant of MBSeedKey
Browse files Browse the repository at this point in the history
  • Loading branch information
AcerExtensa committed Oct 13, 2022
1 parent 2687447 commit 721464a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
2 changes: 1 addition & 1 deletion ecuseedkeydll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
74 changes: 63 additions & 11 deletions main_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
#include "exutils.h"
#include "ecuseedkeydll.h"

QTextStream& qStdOut()
{
static QTextStream ts( stdout );
return ts;
}

int main(int argc, char *argv[])
{
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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<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 app.exec();


return 0;
}
2 changes: 2 additions & 0 deletions mbseedkey_cli.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 721464a

Please sign in to comment.