Assume the filename as library name for ELF libraries without soname field

This commit is contained in:
Martchus 2022-03-03 23:00:16 +01:00
parent 6456273951
commit 8e18b4747f
3 changed files with 15 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include <cstdint>
#include <exception>
#include <filesystem>
#include <fstream>
#include <memory>
@ -185,11 +186,17 @@ void Binary::load(const char *filePath)
case BinaryType::Pe:
name = fileName(filePath);
break;
case BinaryType::Elf:
if (auto ec = std::error_code();
name.empty() && std::string_view(filePath).ends_with(".so") && std::filesystem::is_regular_file(filePath, ec) && !ec) {
name = fileName(filePath);
}
break;
default:;
}
}
void Binary::load(const string &fileContent, const string &fileName)
void Binary::load(const string &fileContent, const string &fileName, bool isRegularFile)
{
stringstream fileStream(ios_base::in | ios_base::out | ios_base::binary);
fileStream.exceptions(ios_base::failbit | ios_base::badbit);
@ -199,6 +206,11 @@ void Binary::load(const string &fileContent, const string &fileName)
case BinaryType::Pe:
name = fileName;
break;
case BinaryType::Elf:
if (name.empty() && isRegularFile && fileName.ends_with(".so")) {
name = fileName;
}
break;
default:;
}
}

View File

@ -83,7 +83,7 @@ inline VirtualAddressMapping::VirtualAddressMapping()
struct LIBPKG_EXPORT Binary {
void load(const char *filePath);
void load(const std::string &fileContent, const std::string &fileName);
void load(const std::string &fileContent, const std::string &fileName, bool isRegularFile = false);
std::string addPrefix(const std::string &dependencyName) const;
BinaryType type = BinaryType::Invalid;

View File

@ -778,7 +778,7 @@ void Package::addDepsAndProvidesFromContainedFile(const ArchiveFile &file, std::
{
try {
Binary binary;
binary.load(file.content, file.name);
binary.load(file.content, file.name, file.type == ArchiveFileType::Regular);
if (!binary.name.empty()) {
if (binary.type == BinaryType::Ar && binary.subType == BinarySubType::WindowsImportLibrary) {
dllsReferencedByImportLibs.emplace(binary.addPrefix(binary.name));