Skip to content

Commit

Permalink
Merge pull request Xplatforms#1 from AcerExtensa/master
Browse files Browse the repository at this point in the history
Load DLL
  • Loading branch information
Xplatforms authored Oct 5, 2020
2 parents 35f83d7 + 0fef77a commit 7f562f4
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
79 changes: 79 additions & 0 deletions ecuseedkeydll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,82 @@ 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),
p_dllHandle(Q_NULLPTR),
p_dllPath(dll_path)
{
if(dll_path.isEmpty())
{
this->setErrorMsg(tr("DLL path is empty!"));
return;
}

QFileInfo info(this->p_dllPath);
if(!info.exists() || !info.isFile() || info.isSymLink())
{
this->setErrorMsg(tr("DLL file doesn't exist or wrong."));
return;
}

this->p_ecu_name = info.baseName();
QString dll_info_str = "[" + info.fileName() + "] ";
qInfo() << dll_info_str << "Loading ...";

this->p_dllHandle = LoadLibraryW(QDir::toNativeSeparators(info.absoluteFilePath()).toStdWString().data());
if(!this->p_dllHandle)
{
auto error_str = GetLastErrorAsString();
this->setErrorMsg(tr("Could not load DLL file. Reason: ")+error_str);
qInfo() << dll_info_str << this->errorMsg();
return;
}
this->loadDllfuncs();
}

ECUSeedKeyDLL::~ECUSeedKeyDLL()
{
if(this->p_dllHandle != Q_NULLPTR)::FreeLibrary(this->p_dllHandle);
}

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

}

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

}

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

}

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

}

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

}

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

}
}
27 changes: 27 additions & 0 deletions ecuseedkeydll.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,33 @@ typedef int (__cdecl * _f_GenerateKeyExOpt )( const unsigned char* ipSeedArray,
unsigned int iMaxKeyArraySize,
unsigned int& oActualKeyArraySize );

class ECUSeedKeyDLL : public QObject
{
Q_OBJECT
public:
explicit ECUSeedKeyDLL(QString dll_path, QObject *parent = nullptr);
~ECUSeedKeyDLL();


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_comment;
};


#endif // ECUSEEDKEYDLL_H

0 comments on commit 7f562f4

Please sign in to comment.