2019-09-23 16:46:57 +03:00
|
|
|
//#
|
2019-12-08 13:57:20 +03:00
|
|
|
//# Copyright (C) 2018-2020 QuasarApp.
|
2019-09-23 16:46:57 +03:00
|
|
|
//# Distributed under the lgplv3 software license, see the accompanying
|
|
|
|
//# Everyone is permitted to copy and distribute verbatim copies
|
|
|
|
//# of this license document, but changing it is not allowed.
|
|
|
|
//#
|
|
|
|
|
2019-03-23 23:13:52 +03:00
|
|
|
#include "elf.h"
|
2019-09-22 16:46:07 +03:00
|
|
|
#include <cmath>
|
2019-03-23 23:13:52 +03:00
|
|
|
#include <QFileInfo>
|
2019-11-14 17:35:21 +03:00
|
|
|
#include <quasarapp.h>
|
2019-03-23 23:13:52 +03:00
|
|
|
|
|
|
|
ELF::ELF()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-22 16:46:07 +03:00
|
|
|
QByteArrayList ELF::getDynamicString(ElfReader& reader) const {
|
|
|
|
auto headers = reader.readHeaders();
|
|
|
|
|
2020-01-12 16:43:03 +03:00
|
|
|
for (const auto §ionHeader : headers.sectionHeaders) {
|
2019-09-22 16:46:07 +03:00
|
|
|
if (sectionHeader.name == ".dynstr") {
|
|
|
|
auto arr = reader.readSection(sectionHeader.name).split(0);
|
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
int ELF::getVersionOfTag(const QByteArray& tag, QByteArray& source) const {
|
|
|
|
auto versions = source.replace(tag, "").split('.');
|
|
|
|
|
|
|
|
int step = static_cast<int>(pow(100, 4));
|
|
|
|
int ver = 0;
|
|
|
|
auto it = versions.begin();
|
|
|
|
|
|
|
|
while (it != versions.end()) {
|
|
|
|
bool ok;
|
|
|
|
int curVer = it->toInt(&ok);
|
|
|
|
|
|
|
|
if (!ok) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ver += curVer * step;
|
|
|
|
step /= 100;
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ver;
|
|
|
|
}
|
|
|
|
|
2019-08-31 22:22:26 +03:00
|
|
|
bool ELF::getLibInfo(const QString &lib, LibInfo &info) const {
|
2019-03-23 23:13:52 +03:00
|
|
|
ElfReader reader(lib);
|
|
|
|
|
|
|
|
auto headers = reader.readHeaders();
|
|
|
|
|
2020-07-02 16:00:34 +03:00
|
|
|
if (headers.elfmachine == ElfMachine::Elf_EM_386) {
|
|
|
|
info.setPlatform(Unix_x86_32);
|
|
|
|
} else if (headers.elfmachine == ElfMachine::Elf_EM_X86_64) {
|
|
|
|
info.setPlatform(Unix_x86_64);
|
|
|
|
} else if (headers.elfmachine == ElfMachine::Elf_EM_ARM) {
|
|
|
|
info.setPlatform(Unix_ARM_32);
|
2019-03-23 23:13:52 +03:00
|
|
|
} else {
|
2019-04-05 14:23:42 +03:00
|
|
|
info.setPlatform(UnknownPlatform);
|
2019-03-23 23:13:52 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-01-28 15:25:35 +03:00
|
|
|
if (!QuasarAppUtils::Params::isEndable("noCheckRPATH")) {
|
2019-11-14 17:35:21 +03:00
|
|
|
auto dynStr = getDynamicString(reader);
|
2019-09-22 16:46:07 +03:00
|
|
|
|
2019-11-14 17:35:21 +03:00
|
|
|
for (auto i = dynStr.rbegin(); i != dynStr.rend(); ++i) {
|
2019-09-22 16:46:07 +03:00
|
|
|
|
2019-11-14 17:35:21 +03:00
|
|
|
if (i->contains("end_")) {
|
|
|
|
break;
|
|
|
|
}
|
2019-09-22 16:46:07 +03:00
|
|
|
|
2019-11-14 17:35:21 +03:00
|
|
|
if (QFileInfo(*i).isDir()) {
|
|
|
|
info.setQtPath(*i);
|
|
|
|
}
|
2019-09-22 16:46:07 +03:00
|
|
|
|
2019-11-14 17:35:21 +03:00
|
|
|
}
|
2019-09-22 16:46:07 +03:00
|
|
|
}
|
|
|
|
|
2019-04-05 14:23:42 +03:00
|
|
|
info.setName(QFileInfo(lib).fileName());
|
|
|
|
info.setPath(QFileInfo(lib).absolutePath());
|
2019-03-23 23:13:52 +03:00
|
|
|
|
2019-04-05 16:52:53 +03:00
|
|
|
auto dep = reader.dependencies();
|
2020-01-12 16:43:03 +03:00
|
|
|
for (const auto &i : dep) {
|
2019-04-05 16:52:53 +03:00
|
|
|
info.addDependncies(i.toUpper());
|
2019-03-23 23:13:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|