93 lines
2.1 KiB
C++
Raw Normal View History

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();
for (auto &sectionHeader : headers.sectionHeaders) {
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();
if (headers.elfclass == ElfClass::Elf_ELFCLASS32) {
2019-04-05 14:23:42 +03:00
info.setPlatform(Unix32);
2019-03-23 23:13:52 +03:00
} else if (headers.elfclass == ElfClass::Elf_ELFCLASS64) {
2019-04-05 14:23:42 +03:00
info.setPlatform(Unix64);
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;
}
2019-11-14 17:35:21 +03:00
if (!QuasarAppUtils::Params::isEndable("noAutoCheckQmake")) {
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();
for (auto &i : dep) {
info.addDependncies(i.toUpper());
2019-03-23 23:13:52 +03:00
}
return true;
}