Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 457 #468

Merged
merged 14 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions deps/elfio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ if(CMAKE_CXX_COMPILER)
endif()

ExternalProject_Add(elfio-project
URL https://github.com/avast-tl/elfio/archive/998374baace397ea98f3b1d768e81c978b4fba41.zip
URL_HASH SHA256=3617770aac77d3bde428c84e8e80bf1da85f37a6741589ece7a84ac7e5a45fb9
URL https://github.com/avast-tl/elfio/archive/87f90a80121384f6933c2e35012f684417f10790.zip
URL_HASH SHA256=7613e90dc07e2e3ac019c7af7c146507cd8acf730a652388addf6f80c1d44544
DOWNLOAD_NAME elfio.zip
CMAKE_ARGS
# This does not work on MSVC, but may be useful on Linux.
Expand Down
1 change: 1 addition & 0 deletions include/retdec/bin2llvmir/providers/names.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Name

private:
void fixPic32Mangling();
void fixPostfix();

private:
std::string _name;
Expand Down
12 changes: 10 additions & 2 deletions include/retdec/fileformat/file_format/elf/elf_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class ElfFormat : public FileFormat
unsigned long long size; ///< size of table
unsigned long long entrySize; ///< size of one entry in table
unsigned long long type; ///< type of relocations (SHT_REL or SHT_RELA)
bool plt = false; ///< associated with Procedure Linkage Table.

RelocationTableInfo();
~RelocationTableInfo();
Expand All @@ -54,17 +55,19 @@ class ElfFormat : public FileFormat
ELFIO::section* addRelocationTable(ELFIO::section *dynamicSection, const RelocationTableInfo &info, ELFIO::section *symbolTable);
ELFIO::section* addRelRelocationTable(ELFIO::section *dynamicSection, const DynamicTable &table, ELFIO::section *symbolTable);
ELFIO::section* addRelaRelocationTable(ELFIO::section *dynamicSection, const DynamicTable &table, ELFIO::section *symbolTable);
ELFIO::section* addPltRelocationTable(ELFIO::section *dynamicSection, const DynamicTable &table, ELFIO::section *symbolTable);
ELFIO::section* addGlobalOffsetTable(ELFIO::section *dynamicSection, const DynamicTable &table);
ELFIO::Elf_Half fixSymbolLink(ELFIO::Elf_Half symbolLink, ELFIO::Elf64_Addr symbolValue);
bool getRelocationMask(unsigned relType, std::vector<std::uint8_t> &mask);
void loadRelocations(const ELFIO::elfio *file, const ELFIO::section *symbolTable, std::unordered_multimap<std::string, unsigned long long> &nameAddressMap);
void loadSymbols(const ELFIO::elfio *file, const ELFIO::symbol_section_accessor *elfSymbolTable, const ELFIO::section *elfSection);
void loadSymbols(const SymbolTable &oldTab, const DynamicTable &dynTab, ELFIO::section &got);
void loadDynamicTable(DynamicTable &table, const ELFIO::dynamic_section_accessor *elfDynamicTable);
void loadDynamicTable(const ELFIO::dynamic_section_accessor *elfDynamicTable);
bool loadDynamicTable(const ELFIO::dynamic_section_accessor *elfDynamicTable, const ELFIO::section *sec);
void loadSections();
void loadSegments();
void loadInfoFromDynamicTables(std::size_t noOfTables);
void loadDynamicSegmentSection();
void loadInfoFromDynamicTables(DynamicTable &dynTab, ELFIO::section *sec);
void loadInfoFromDynamicSegment();
void loadNoteSecSeg(ElfNoteSecSeg &noteSecSegs) const;
void loadNotes();
Expand All @@ -78,6 +81,11 @@ class ElfFormat : public FileFormat
int elfClass; ///< class of input ELF file
ELFIO::elfio reader; ///< parser of input ELF file
ELFIO::elfio writer; ///< parser of auxiliary ELF object which is needed for fixing representation of input file

/// Offsets of already read symbol tables.
std::set<ELFIO::Elf64_Off> symtabOffsets;
/// Addresses of already read symbol tables.
std::set<ELFIO::Elf64_Addr> symtabAddresses;
public:
ElfFormat(std::string pathToFile, LoadFlags loadFlags = LoadFlags::NONE);
ElfFormat(std::istream &inputStream, LoadFlags loadFlags = LoadFlags::NONE);
Expand Down
4 changes: 4 additions & 0 deletions include/retdec/fileformat/types/dynamic_table/dynamic_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class DynamicTable
private:
using dynamicTableIterator = std::vector<DynamicEntry>::const_iterator;
std::vector<DynamicEntry> table; ///< all records in table
/// Name of the section this table was created from.
std::string sectionName;
public:
DynamicTable();
~DynamicTable();
Expand All @@ -31,6 +33,7 @@ class DynamicTable
std::size_t getNumberOfRecords() const;
const DynamicEntry* getRecord(std::size_t recordIndex) const;
const DynamicEntry* getRecordOfType(unsigned long long recordType) const;
const std::string& getSectionName() const;
/// @}

/// @name Iterators
Expand All @@ -45,6 +48,7 @@ class DynamicTable
void addRecord(DynamicEntry &record);
bool hasRecords() const;
bool hasRecordOfType(unsigned long long recordType) const;
void setSectionName(const std::string& name);
void dump(std::string &dumpTable) const;
/// @}
};
Expand Down
22 changes: 21 additions & 1 deletion include/retdec/fileformat/types/import_table/import.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,41 @@ namespace fileformat {
*/
class Import
{
public:
enum class UsageType
{
UNKNOWN,
FUNCTION,
OBJECT,
FILE
};

private:
std::string name; ///< import name
unsigned long long libraryIndex; ///< index of library from which is import imported
unsigned long long address; ///< address of import
unsigned long long ordinalNumber; ///< ordinal number
bool ordinalNumberIsValid; ///< @c true if ordinal number is valid
UsageType usageType; ///< usage of symbol
public:
Import();
~Import();
virtual ~Import();

/// @name Getters
/// @{
std::string getName() const;
unsigned long long getLibraryIndex() const;
unsigned long long getAddress() const;
bool getOrdinalNumber(unsigned long long &importOrdinalNumber) const;
Import::UsageType getUsageType() const;
/// @}

/// @name Usage type queries
/// @{
bool isUnknown() const;
bool isFunction() const;
bool isObject() const;
bool isFile() const;
/// @}

/// @name Setters
Expand All @@ -41,6 +60,7 @@ class Import
void setLibraryIndex(unsigned long long importLibraryIndex);
void setAddress(unsigned long long importAddress);
void setOrdinalNumber(unsigned long long importOrdinalNumber);
void setUsageType(Import::UsageType importUsageType);
/// @}

/// @name Other methods
Expand Down
20 changes: 20 additions & 0 deletions src/bin2llvmir/providers/names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Name::Name(Config* c, const std::string& name, eType type, Lti* lti) :
fixPic32Mangling();
}

fixPostfix();

_inLti = lti->getLtiFunction(_name) != nullptr;
}

Expand Down Expand Up @@ -182,6 +184,24 @@ void Name::fixPic32Mangling()
}
}

/**
* Remove name's postfix.
* TODO: This was done in fileformat, but was removed from there.
* Maybe we should do it only for some types of names (e.g. symbols).
* Probably we should not take care only of GLIBC, there might be more std
* postfixes (e.g. GLIBCXX), or any other postfixes (e.g. NSS).
* Maybe we should keep the postfix somewhere and let the user know this fix
* happened (e.g. add comment to name).
*/
void Name::fixPostfix()
{
const auto pos = _name.find("@@GLIBC_");
if(pos && pos != std::string::npos)
{
_name.erase(pos);
}
}

//
//==============================================================================
// Names
Expand Down
Loading