Skip to content

Commit

Permalink
Merge pull request Xplatforms#5 from Xplatforms/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Xplatforms authored Oct 5, 2020
2 parents 2a4e7d9 + f85879c commit 1f7a8aa
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 12 deletions.
70 changes: 70 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,73 @@ Makefile.*
*.exe
*.out
*.app

# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------

*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash

# qtcreator generated files
*.pro.user*

# xemacs temporary files
*.flc

# Vim temporary files
.*.swp

# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*

# MinGW generated files
*.Debug
*.Release

# Python byte code
*.pyc


5 changes: 5 additions & 0 deletions MainPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.0

Item {

}
42 changes: 33 additions & 9 deletions ecuseedkeydll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ QString GetLastErrorAsString()
return message;
}


ECUSeedKeyDLL::ECUSeedKeyDLL(QString dll_path, QObject *parent) : QObject(parent),
GetConfiguredAccessTypes(Q_NULLPTR), GetSeedLength(Q_NULLPTR), GetKeyLength(Q_NULLPTR), GetECUName(Q_NULLPTR),
GenerateKeyExOpt(Q_NULLPTR),
Expand Down Expand Up @@ -65,40 +64,64 @@ ECUSeedKeyDLL::~ECUSeedKeyDLL()

void ECUSeedKeyDLL::loadDllfuncs()
{

this->GetECUName = (_f_GetECUName)GetProcAddress(this->p_dllHandle, "GetECUName");
if(this->GetECUName != Q_NULLPTR)
{

this->p_ecu_name = this->GetECUName();
emit this->ECUNameChanged();
}

this->GetComment = (_f_GetComment)GetProcAddress(this->p_dllHandle, "GetComment");
if(this->GetComment != Q_NULLPTR)
{

this->p_comment = this->GetComment();
emit this->CommentChanged();
}

this->GetSeedLength = (_f_GetSeedLength)GetProcAddress(this->p_dllHandle, "GetSeedLength");
if(!this->GetSeedLength)
{

qDebug() << "Function GetSeedLength not found";
this->GetSeedLength = (_f_GetSeedLength)&tmp_ret_def_seedkey_len;
}

this->GetKeyLength = (_f_GetKeyLength)GetProcAddress(this->p_dllHandle, "GetKeyLength");
if (!this->GetKeyLength)
{

qDebug() << "Function GetKeyLength not found";
this->GetKeyLength = (_f_GetKeyLength)&tmp_ret_def_seedkey_len;
}

this->GetConfiguredAccessTypes = (_f_GetConfiguredAccessTypes)GetProcAddress(this->p_dllHandle, "GetConfiguredAccessTypes");
if(this->GetConfiguredAccessTypes != Q_NULLPTR)
{

}
{
int data[256] = {0};
auto ret = this->GetConfiguredAccessTypes(data);
if(ret > 0)
{
do
{
auto atype = data[--ret];
///WARNING: Seed and Key length functions could not be called in paralell or asynchrone!
/// make sure compiler can't optimize this calls and call this funcs one by one
ECUSeedKeyLenPairs skpair;
skpair.seed_len = this->GetSeedLength(atype);
skpair.key_len = this->GetKeyLength(atype);
//qDebug() << " seed len: " << skpair.seed_len << " keylen " << skpair.key_len;
this->p_access_types.insert(atype, skpair);
}
while(ret > 0);
emit this->AccessTypesChanged();
}
}

this->GenerateKeyExOpt = (_f_GenerateKeyExOpt)GetProcAddress(this->p_dllHandle, "GenerateKeyExOpt");
if(this->GenerateKeyExOpt == Q_NULLPTR)
{

this->setErrorMsg(tr("GenerateKeyExOpt not found in DLL ") + this->p_dllPath);
qWarning() << this->errorMsg();
return;
}
}

Expand All @@ -120,6 +143,7 @@ QList<qint32> ECUSeedKeyDLL::GenerateKeyFromSeed(QList<qint32> seed, qint32 acce

///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);
Q_UNUSED(ret)
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";
Expand Down
25 changes: 22 additions & 3 deletions ecuseedkeydll.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ typedef int (__cdecl * _f_GenerateKeyExOpt )( const unsigned char* ipSeedArray,
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(QString dll_path, QObject *parent = nullptr);
~ECUSeedKeyDLL();

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);
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();}
Expand All @@ -43,9 +51,18 @@ class ECUSeedKeyDLL : public QObject
this->p_access_types.value(access_type).seed_len:4; }
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 QList<qint32> GenerateKeyFromSeed(QList<qint32> seed, qint32 access_type);

signals:
void ECUNameChanged();
void DLLNameChanged();
void CommentChanged();
void SeedLengthChanged();
void KeyLengthChanged();
void AccessTypesChanged();
void errorMsgChanged();

private slots:
void loadDllfuncs();

Expand All @@ -63,8 +80,10 @@ private slots:

QString p_errorMsg;
QString p_ecu_name;
QString p_dll_name;
QString p_comment;
};

QHash<qint32, ECUSeedKeyLenPairs> p_access_types;
};

#endif // ECUSEEDKEYDLL_H
20 changes: 20 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QGuiApplication app(argc, argv);

QQmlApplicationEngine engine;
const QUrl url(QStringLiteral("qrc:/main.qml"));
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);

return app.exec();
}
20 changes: 20 additions & 0 deletions main.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow
{
id: window

width: 780
height: 420
visible: true
title: qsTr("Stack")


StackView
{
id: stackView
initialItem: "MainPage.qml"
anchors.fill: parent
}
}
30 changes: 30 additions & 0 deletions mbseedkey.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
QT += quick

CONFIG += c++11

# 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

SOURCES += \
ecuseedkeydll.cpp \
main.cpp

HEADERS += \
ecuseedkeydll.h

RESOURCES += qml.qrc

TRANSLATIONS += \
mbseedkey_en.ts

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
3 changes: 3 additions & 0 deletions mbseedkey_en.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="mbseedkey_en"></TS>
7 changes: 7 additions & 0 deletions qml.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>qtquickcontrols2.conf</file>
<file>MainPage.qml</file>
</qresource>
</RCC>
12 changes: 12 additions & 0 deletions qtquickcontrols2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
; This file can be edited to change the style of the application
; Read "Qt Quick Controls 2 Configuration File" for details:
; http://doc.qt.io/qt-5/qtquickcontrols2-configuration.html

[Controls]
Style=Universal

[Universal]
Theme=System
;Accent=Steel
;Foreground=Brown
;Background=Steel

0 comments on commit 1f7a8aa

Please sign in to comment.