/* * Copyright (C) 2018-2019 QuasarApp. * 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. */ #include "pe.h" #include #include #include #include #include #include namespace peparse { class section; struct importent { VA addr; std::string symbolName; std::string moduleName; }; class reloc; class exportent; class symbol; struct parsed_pe_internal { std::vector
secs; std::vector rsrcs; std::vector imports; std::vector relocs; std::vector exports; std::vector symbols; }; } bool PE::getDep(peparse::parsed_pe_internal * internal, LibInfo &res) const { auto imports = internal->imports; std::set filter; for ( auto &i : imports) { if (!filter.count(i.moduleName)) { filter.insert(i.moduleName); res.addDependncies(QString::fromStdString(i.moduleName)); } } return res.getDependncies().size(); } PE::PE(): IGetLibInfo () { } bool PE::getLibInfo(const QString &lib, LibInfo &info) const { auto parsedPeLib = peparse::ParsePEFromFile(lib.toLatin1()); if (!parsedPeLib) return false; if (static_cast(parsedPeLib->peHeader.nt.OptionalMagic) == RunType::_32bit) { info.setPlatform(Platform::Win32); } else if (static_cast(parsedPeLib->peHeader.nt.OptionalMagic) == RunType::_64bit) { info.setPlatform(Platform::Win64); } else { info.setPlatform(Platform::UnknownPlatform); } info.setName(QFileInfo(lib).fileName()); info.setPath(QFileInfo(lib).absolutePath()); if (!getDep(parsedPeLib->internal, info)) { return false; } peparse::DestructParsedPE(parsedPeLib); return info.isValid(); } PE::~PE(){ }