fix #91 added elf and pe readers

This commit is contained in:
Andrei Yankovich 2019-03-23 23:13:52 +03:00
parent 9976120671
commit 67c38112e8
8 changed files with 75 additions and 14 deletions

View File

@ -46,7 +46,9 @@ SOURCES += \
pe.cpp \
igetlibinfo.cpp \
structs.cpp \
dependenciesscanner.cpp
dependenciesscanner.cpp \
../qtTools/src/windeployqt/elfreader.cpp \
elf.cpp
HEADERS += \
deploy.h \
@ -55,4 +57,6 @@ HEADERS += \
pe.h \
igetlibinfo.h \
structs.h \
dependenciesscanner.h
dependenciesscanner.h \
../qtTools/src/windeployqt/elfreader.h \
elf.h

View File

@ -33,12 +33,15 @@ PrivateScaner DependenciesScanner::getScaner(const QString &lib) const {
bool DependenciesScanner::fillLibInfo(LibInfo &info, const QString &file) {
info.clear();
auto scaner = getScaner(file);
switch (scaner) {
case PrivateScaner::PE: {
return _peScaner.getLibInfo(file, info);
}
case PrivateScaner::ELF:
return _elfScaner.getLibInfo(file, info);
default: return false;
}

View File

@ -13,6 +13,7 @@
#include "deploy_global.h"
#include "structs.h"
#include "pe.h"
#include "elf.h"
enum class PrivateScaner: unsigned char {
UNKNOWN,
@ -28,6 +29,7 @@ private:
QMap<QString, QString> _EnvLibs;
PE _peScaner;
ELF _elfScaner;
PrivateScaner getScaner(const QString& lib) const;

32
Deploy/elf.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "elf.h"
#include <QFileInfo>
ELF::ELF()
{
}
bool ELF::getLibInfo(const QString &lib, LibInfo &info) {
ElfReader reader(lib);
auto headers = reader.readHeaders();
if (headers.elfclass == ElfClass::Elf_ELFCLASS32) {
info.platform = Unix32;
} else if (headers.elfclass == ElfClass::Elf_ELFCLASS64) {
info.platform = Unix64;
} else {
info.platform = UnknownPlatform;
return false;
}
info.name = QFileInfo(lib).fileName();
info.path = QFileInfo(lib).absolutePath();
for (auto &i : reader.dependencies()) {
info.dependncies.push_back(i);
}
return true;
}

17
Deploy/elf.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef ELF_H
#define ELF_H
#include "../qtTools/src/windeployqt/elfreader.h"
#include "igetlibinfo.h"
class ELF : public IGetLibInfo
{
public:
ELF();
bool getLibInfo(const QString &lib, LibInfo &info);
};
#endif // ELF_H

View File

@ -9,6 +9,13 @@ QString LibInfo::fullPath() {
return path + "/" + name;
}
void LibInfo::clear() {
path = "";
name = "";
platform = Platform::UnknownPlatform;
dependncies.clear();
}
bool LibInfo::isValid() const {
return platform != Platform::UnknownPlatform &&
name.size() && path.size();

View File

@ -8,7 +8,8 @@ enum Platform {
UnknownPlatform = 0x0,
Win32,
Win64,
Unix
Unix32,
Unix64
};
struct LibInfo {
@ -21,6 +22,8 @@ struct LibInfo {
QString fullPath();
void clear();
bool isValid() const;
};

View File

@ -42,13 +42,8 @@ void LibCreator::initLinux64() {
"libstdc++.so.6",
"libgcc_s.so.1",
"libc.so.6",
"libgcc_s.so.1",
"libQt5Core.so.5",
"libc.so.6",
"libQt5Network.so.5",
"libstdc++.so.6:",
},
Platform::Unix);
Platform::Unix64);
createLib(":/linux64.so", {
"libQt5Core.so.5",
"libpthread.so.0",
@ -56,11 +51,9 @@ void LibCreator::initLinux64() {
"libm.so.6",
"libgcc_s.so.1",
"libc.so.6",
"libSignalProcessorCommon.so.1",
"libc.so.6",
"libQt5Core.so.5",
},
Platform::Unix);
Platform::Unix64);
}
@ -176,7 +169,7 @@ LibCreator::LibCreator(const QString &path) {
this->path = path;
initWin32();
initWin64();
//initLinux64();
initLinux64();
}
const QStringList &LibCreator::getLibs() const {