diff --git a/src/data_format/bound_symbol_list.cpp b/src/data_format/bound_symbol_list.cpp index 0be4a12..0b29b63 100644 --- a/src/data_format/bound_symbol_list.cpp +++ b/src/data_format/bound_symbol_list.cpp @@ -6,7 +6,7 @@ namespace di::data_format { constexpr int BOUND_SYMBOL_LIST_FORMAT_VERSION = 1; -void BoundSymbolList::read(const std::filesystem::path& path) { +void BoundSymbolList::read(const fs::path& path) { std::ifstream ifs(path); if (!ifs) { throw std::runtime_error("Failed to open data path."); @@ -25,7 +25,7 @@ void BoundSymbolList::read(const std::filesystem::path& path) { } } -void BoundSymbolList::write(const std::filesystem::path& path) const { +void BoundSymbolList::write(const fs::path& path) const { std::ofstream ofs(path); if (!ofs) { throw std::runtime_error("Failed to open file!"); @@ -47,7 +47,7 @@ void BoundSymbolList::write(const std::filesystem::path& path) const { void BoundSymbolList::record( std::string_view symbol, - uint64_t rva, + rva_t rva, bool is_function ) { m_entities.emplace(BoundSymbol{std::string(symbol), rva, is_function}); diff --git a/src/data_format/bound_symbol_list.h b/src/data_format/bound_symbol_list.h index c51f3e5..a04f02d 100644 --- a/src/data_format/bound_symbol_list.h +++ b/src/data_format/bound_symbol_list.h @@ -9,10 +9,10 @@ class BoundSymbolList : public IOBase { public: using for_each_callback_t = std::function; - void read(const std::filesystem::path& path) override; - void write(const std::filesystem::path& path) const override; + void read(const fs::path& path) override; + void write(const fs::path& path) const override; - void record(std::string_view symbol, uint64_t rva, bool is_function); + void record(std::string_view symbol, rva_t rva, bool is_function); constexpr void for_each(const for_each_callback_t& callback) const { for (const auto& entity : m_entities) callback(entity); diff --git a/src/data_format/raw_text.cpp b/src/data_format/raw_text.cpp index 6547a32..a5fbf36 100644 --- a/src/data_format/raw_text.cpp +++ b/src/data_format/raw_text.cpp @@ -2,7 +2,7 @@ namespace di::data_format { -void RawText::read(const std::filesystem::path& path) { +void RawText::read(const fs::path& path) { std::ifstream ifs(path); auto size = std::filesystem::file_size(path); @@ -10,7 +10,7 @@ void RawText::read(const std::filesystem::path& path) { m_data.assign(std::istreambuf_iterator(ifs), {}); } -void RawText::write(const std::filesystem::path& path) const { +void RawText::write(const fs::path& path) const { std::ofstream ofs(path); if (!ofs) { throw std::runtime_error("Failed to open save file."); diff --git a/src/data_format/raw_text.h b/src/data_format/raw_text.h index 654a4e1..861a735 100644 --- a/src/data_format/raw_text.h +++ b/src/data_format/raw_text.h @@ -6,8 +6,8 @@ namespace di::data_format { class RawText : public IOBase { public: - void read(const std::filesystem::path& path) override; - void write(const std::filesystem::path& path) const override; + void read(const fs::path& path) override; + void write(const fs::path& path) const override; void record(std::string_view line); diff --git a/src/data_format/raw_type_data.cpp b/src/data_format/raw_type_data.cpp index b3d9b2e..5c9985d 100644 --- a/src/data_format/raw_type_data.cpp +++ b/src/data_format/raw_type_data.cpp @@ -12,7 +12,7 @@ using namespace llvm::pdb; namespace di::data_format { -void RawTypeData::read(const std::filesystem::path& path) { +void RawTypeData::read(const fs::path& path) { std::unique_ptr pdb_session; if (llvm::pdb::loadDataForPDB( PDB_ReaderType::Native, diff --git a/src/data_format/raw_type_data.h b/src/data_format/raw_type_data.h index 09238d0..0623d84 100644 --- a/src/data_format/raw_type_data.h +++ b/src/data_format/raw_type_data.h @@ -15,8 +15,8 @@ public: RawTypeData() : m_storaged_IPI(m_allocator), m_storaged_TPI(m_allocator) {} - void read(const std::filesystem::path& path) override; - void write(const std::filesystem::path& path) const override { + void read(const fs::path& path) override; + void write(const fs::path& path) const override { throw std::runtime_error("Unsupported operation."); } diff --git a/src/data_format/type/bound_symbol.h b/src/data_format/type/bound_symbol.h index 42494fa..fbfd7c0 100644 --- a/src/data_format/type/bound_symbol.h +++ b/src/data_format/type/bound_symbol.h @@ -6,7 +6,7 @@ namespace di { struct BoundSymbol { std::string m_symbol_name; - uint64_t m_rva; + rva_t m_rva; bool m_is_function; bool operator==(const BoundSymbol& other) const { diff --git a/src/data_format/typed_symbol_list.cpp b/src/data_format/typed_symbol_list.cpp index 6c7424e..296559a 100644 --- a/src/data_format/typed_symbol_list.cpp +++ b/src/data_format/typed_symbol_list.cpp @@ -2,7 +2,7 @@ namespace di::data_format { -void TypedSymbolList::read(const std::filesystem::path& path) { +void TypedSymbolList::read(const fs::path& path) { std::ifstream ifs(path); if (!ifs) { throw std::runtime_error("Failed to open symlist file."); @@ -27,7 +27,7 @@ void TypedSymbolList::read(const std::filesystem::path& path) { } } -void TypedSymbolList::write(const std::filesystem::path& path) const { +void TypedSymbolList::write(const fs::path& path) const { std::ofstream ofs(path); for (const auto& [symbol, decl_type] : m_data) { ofs << symbol << ", " << decl_type.string() << "\n"; diff --git a/src/data_format/typed_symbol_list.h b/src/data_format/typed_symbol_list.h index 6c6f004..c7bd58f 100644 --- a/src/data_format/typed_symbol_list.h +++ b/src/data_format/typed_symbol_list.h @@ -13,8 +13,8 @@ public: // this method in this class supports multiple calls (reading multiple // files) - void read(const std::filesystem::path& path) override; - void write(const std::filesystem::path& path) const override; + void read(const fs::path& path) override; + void write(const fs::path& path) const override; void record(const std::string& symbol, DeclType type); diff --git a/src/nonstd.h b/src/nonstd.h index 10f19b2..4c45f79 100644 --- a/src/nonstd.h +++ b/src/nonstd.h @@ -51,3 +51,5 @@ struct hash> { }; } // namespace std + +namespace fs = std::filesystem; diff --git a/src/object_file/coff.cpp b/src/object_file/coff.cpp index 6bcd8ca..0f0f69a 100644 --- a/src/object_file/coff.cpp +++ b/src/object_file/coff.cpp @@ -2,7 +2,7 @@ namespace di::object_file { -COFF::COFF(const std::filesystem::path& path) { +COFF::COFF(const fs::path& path) { using namespace object; auto obj_or_err = ObjectFile::createObjectFile(path.string()); @@ -38,10 +38,10 @@ codeview::PDB70DebugInfo COFF::get_debug_info() const { return debug_info->PDB70; } -size_t COFF::get_section_index(uint64_t offset) const { +size_t COFF::get_section_index(size_t offset) const { using namespace object; - uint64_t current_index = 0; + size_t current_index{}; for (const SectionRef& sec_ref : get_owning_coff().sections()) { const coff_section* section = get_owning_coff().getCOFFSection(sec_ref); if (offset >= section->VirtualAddress diff --git a/src/object_file/coff.h b/src/object_file/coff.h index 35429f6..f3fbdd1 100644 --- a/src/object_file/coff.h +++ b/src/object_file/coff.h @@ -6,11 +6,11 @@ namespace di::object_file { class COFF { public: - explicit COFF(const std::filesystem::path& path); + explicit COFF(const fs::path& path); codeview::PDB70DebugInfo get_debug_info() const; - size_t get_section_index(uint64_t offset) const; + size_t get_section_index(size_t offset) const; object::coff_section* get_section_table(); uint32_t get_number_of_sections() const; diff --git a/src/object_file/pdb.cpp b/src/object_file/pdb.cpp index c597615..dd0de64 100644 --- a/src/object_file/pdb.cpp +++ b/src/object_file/pdb.cpp @@ -12,7 +12,7 @@ using namespace llvm::pdb; namespace di::object_file { PDB::PDB() : m_builder(m_allocator) { - constexpr uint32_t block_size = 4096; + constexpr auto block_size = 4096; if (m_builder.initialize(block_size)) { throw std::runtime_error("Failed to initialize pdb file builder."); } @@ -24,7 +24,7 @@ PDB::PDB() : m_builder(m_allocator) { } } -void PDB::write(const std::filesystem::path& path) { +void PDB::write(const fs::path& path) { build(); codeview::GUID out_guid; diff --git a/src/object_file/pdb.h b/src/object_file/pdb.h index 8843094..94b9fa3 100644 --- a/src/object_file/pdb.h +++ b/src/object_file/pdb.h @@ -30,7 +30,7 @@ public: m_owning_raw_type_data = std::move(raw_type_data); } - void write(const std::filesystem::path& path); + void write(const fs::path& path); private: void build(); @@ -44,7 +44,7 @@ private: owning_symbol_data_t m_owning_symbol_data; owning_type_data_t m_owning_raw_type_data; - uint64_t m_image_base; + addr_t m_image_base; BumpPtrAllocator m_allocator; pdb::PDBFileBuilder m_builder; diff --git a/src/pch.h b/src/pch.h index 9e53107..44a6d82 100644 --- a/src/pch.h +++ b/src/pch.h @@ -27,3 +27,4 @@ using namespace llvm; // Helper #include "nonstd.h" +#include "typedef.h" diff --git a/src/tools/askrva/main.cpp b/src/tools/askrva/main.cpp index 046fc87..3c2f6c5 100644 --- a/src/tools/askrva/main.cpp +++ b/src/tools/askrva/main.cpp @@ -76,7 +76,7 @@ int main(int argc, char* argv[]) try { if (rva) { bound_symbol_list.record( symbol.m_name, - reinterpret_cast(rva), + reinterpret_cast(rva), symbol.m_type.is_function() ); } else { diff --git a/src/tools/extractsym/main.cpp b/src/tools/extractsym/main.cpp index 884f9ef..3e00d2f 100644 --- a/src/tools/extractsym/main.cpp +++ b/src/tools/extractsym/main.cpp @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) try { auto publics_symbols = publics_symbol_stream->getSymbolArray().getUnderlyingStream(); - for (uint32_t offset : publics_stream->getPublicsTable()) { + for (auto offset : publics_stream->getPublicsTable()) { auto cv_symbol = readSymbolFromStream(publics_symbols, offset); auto public_sym32 = SymbolDeserializer::deserializeAs(cv_symbol.get()); diff --git a/src/typedef.h b/src/typedef.h new file mode 100644 index 0000000..15efdb3 --- /dev/null +++ b/src/typedef.h @@ -0,0 +1,10 @@ +#pragma once + +namespace di { + +using rva_t = uint32_t; +using addr_t = uint64_t; + +using hash_t = uint64_t; + +} // namespace di