From 6a2661d4108a81f00ec65fe1153ea7691e0335b7 Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Thu, 24 Jun 2021 14:57:23 -0700 Subject: [PATCH] moved some files, starting to design how the classes should work... --- include/{ => llodctor}/llodctor_base.hpp | 12 +++- include/llodctor/llodctor_bin.hpp | 0 include/llodctor/llodctor_elf.hpp | 0 include/llodctor/llodctor_lib.hpp | 0 include/llodctor/llodctor_pe.hpp | 17 ++++++ include/llodctor_pe.hpp | 14 ----- .../llodisposition/llodisposition_types.hpp | 29 +++++++++ include/lloiff.hpp | 31 +++++----- include/llosymbol/llosymbol_base.hpp | 37 ++++++++++++ include/llosymbol/llosymbol_data.hpp | 0 include/llosymbol/llosymbol_export.hpp | 0 include/llosymbol/llosymbol_function.hpp | 0 include/llosymbol/llosymbol_import.hpp | 0 include/llosymbol/llosymbol_opaque.hpp | 0 .../llosymbol_loader_base.hpp | 19 ++++++ .../llosymbol_loader/llosymbol_loader_map.hpp | 0 .../llosymbol_loader/llosymbol_loader_pdb.hpp | 0 llo-s1.vcxproj | 16 ++++- llo-s1.vcxproj.filters | 60 +++++++++++++++++-- src/llodctor_pe.cpp | 2 +- src/main.cpp | 30 ++++++---- 21 files changed, 214 insertions(+), 53 deletions(-) rename include/{ => llodctor}/llodctor_base.hpp (65%) create mode 100644 include/llodctor/llodctor_bin.hpp create mode 100644 include/llodctor/llodctor_elf.hpp create mode 100644 include/llodctor/llodctor_lib.hpp create mode 100644 include/llodctor/llodctor_pe.hpp delete mode 100644 include/llodctor_pe.hpp create mode 100644 include/llodisposition/llodisposition_types.hpp create mode 100644 include/llosymbol/llosymbol_base.hpp create mode 100644 include/llosymbol/llosymbol_data.hpp create mode 100644 include/llosymbol/llosymbol_export.hpp create mode 100644 include/llosymbol/llosymbol_function.hpp create mode 100644 include/llosymbol/llosymbol_import.hpp create mode 100644 include/llosymbol/llosymbol_opaque.hpp create mode 100644 include/llosymbol_loader/llosymbol_loader_base.hpp create mode 100644 include/llosymbol_loader/llosymbol_loader_map.hpp create mode 100644 include/llosymbol_loader/llosymbol_loader_pdb.hpp diff --git a/include/llodctor_base.hpp b/include/llodctor/llodctor_base.hpp similarity index 65% rename from include/llodctor_base.hpp rename to include/llodctor/llodctor_base.hpp index ce130e8..9cb6ca8 100644 --- a/include/llodctor_base.hpp +++ b/include/llodctor/llodctor_base.hpp @@ -2,7 +2,8 @@ #include #include -#include "lloiff.hpp" +#include +#include namespace llo::s1 { @@ -16,12 +17,19 @@ namespace llo::s1 /// std::vector< std::uint8_t > raw_img; + /// + /// symbol loader used when generating iff... + /// + llo::s1::symbol_loader_base_t* symbol_loader; + public: /// /// set raw_img to the vector passed by reference... /// /// vector of bytes containing the raw image... - dctor_base_t( std::vector< std::uint8_t > &image ) : raw_img{ image } + explicit dctor_base_t( std::vector< std::uint8_t > &image, + llo::s1::symbol_loader_base_t* symbol_loader = nullptr ) + : raw_img{ image }, symbol_loader{ symbol_loader } { } diff --git a/include/llodctor/llodctor_bin.hpp b/include/llodctor/llodctor_bin.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llodctor/llodctor_elf.hpp b/include/llodctor/llodctor_elf.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llodctor/llodctor_lib.hpp b/include/llodctor/llodctor_lib.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llodctor/llodctor_pe.hpp b/include/llodctor/llodctor_pe.hpp new file mode 100644 index 0000000..f58ee81 --- /dev/null +++ b/include/llodctor/llodctor_pe.hpp @@ -0,0 +1,17 @@ +#pragma once +#include + +namespace llo::s1 +{ + class dctor_pe_t : public dctor_base_t + { + public: + explicit dctor_pe_t( std::vector< std::uint8_t > &image, + llo::s1::symbol_loader_base_t *symbol_loader = nullptr ) + : dctor_base_t( image, symbol_loader ) + { + } + + bool generate( lloiff_t &iff ) override; + }; +} // namespace llo::s1 \ No newline at end of file diff --git a/include/llodctor_pe.hpp b/include/llodctor_pe.hpp deleted file mode 100644 index 18bd51d..0000000 --- a/include/llodctor_pe.hpp +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once -#include - -namespace llo::s1 -{ - class dctor_pe_t : public dctor_base_t - { - public: - dctor_pe_t( std::vector< std::uint8_t > &image ) : dctor_base_t( image ) - { - } - bool generate( lloiff_t &iff ) override; - }; -} // namespace llo::s1 \ No newline at end of file diff --git a/include/llodisposition/llodisposition_types.hpp b/include/llodisposition/llodisposition_types.hpp new file mode 100644 index 0000000..c78f5ce --- /dev/null +++ b/include/llodisposition/llodisposition_types.hpp @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +namespace llo +{ + class disposition_t + { + llo::utils::hash_t< std::string > iff_name; + llo::utils::hash_t< std::string > section_name; + std::uint32_t offset; + + public: + explicit disposition_t( llo::utils::hash_t< std::string > &iff_name, + llo::utils::hash_t< std::string > §ion_name, std::uint32_t section_offset ) + : iff_name( iff_name ), section_name( section_name ), offset( offset ) + { + } + + disposition_t( llo::utils::hash_t< std::string > &&iff_name, llo::utils::hash_t< std::string > &§ion_name, + std::uint32_t section_offset ) + : iff_name( iff_name ), section_name( section_name ), offset( offset ) + { + } + + llo::utils::hash_t< std::string > get_section() const; + std::uint32_t get_offset() const; + }; +} // namespace llo \ No newline at end of file diff --git a/include/lloiff.hpp b/include/lloiff.hpp index a412e12..e500ad1 100644 --- a/include/lloiff.hpp +++ b/include/lloiff.hpp @@ -4,36 +4,27 @@ #include #include -#include "lloutils.hpp" +#include +#include namespace llo { class lloiff_t { public: - explicit lloiff_t( std::string &file_name ) : file_name( file_name ) + explicit lloiff_t( std::string &&file_name ) : file_name( file_name ) { } - class section_offset_t + lloiff_t( std::string &file_name ) : file_name( file_name ) { - public: - llo::utils::hash_t< std::string > section_name; - std::uint32_t offset; - }; - - class symbol_t - { - public: - llo::utils::hash_t< std::string > symbol_name; - section_offset_t location; - }; + } class section_t { public: llo::utils::hash_t< std::string > section_name; - std::vector< symbol_t > symbols; + std::vector< llo::symbol::symbol_base_t > symbols; std::vector< std::uint8_t > section_raw; }; @@ -42,6 +33,16 @@ namespace llo return file_name; } + std::vector< section_t > get_sections() const + { + return sections; + } + + void add_section( section_t &§ion ) + { + sections.push_back( section ); + } + private: llo::utils::hash_t< std::string > file_name; std::vector< section_t > sections; diff --git a/include/llosymbol/llosymbol_base.hpp b/include/llosymbol/llosymbol_base.hpp new file mode 100644 index 0000000..60cf30d --- /dev/null +++ b/include/llosymbol/llosymbol_base.hpp @@ -0,0 +1,37 @@ +#pragma once +#include +#include +#include + +namespace llo::symbol +{ + enum class symbol_type_t : std::uint8_t + { + s_invalid, + s_function, + s_data, + s_import, + s_export + }; + + class symbol_base_t + { + disposition_t disposition; + llo::utils::hash_t< std::string > symbol_name; + std::size_t symbol_size; + + public: + explicit symbol_base_t( llo::utils::hash_t< std::string > &&symbol_name, llo::disposition_t &&disposition ) + : disposition( disposition ), symbol_name( symbol_name ) + { + } + + symbol_base_t( llo::utils::hash_t< std::string > &symbol_name, llo::disposition_t &disposition ) + : disposition( disposition ), symbol_name( symbol_name ) + { + } + + virtual symbol_type_t get_type() const; + virtual std::size_t get_size() const; + }; +} // namespace llo::symbol \ No newline at end of file diff --git a/include/llosymbol/llosymbol_data.hpp b/include/llosymbol/llosymbol_data.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol/llosymbol_export.hpp b/include/llosymbol/llosymbol_export.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol/llosymbol_function.hpp b/include/llosymbol/llosymbol_function.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol/llosymbol_import.hpp b/include/llosymbol/llosymbol_import.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol/llosymbol_opaque.hpp b/include/llosymbol/llosymbol_opaque.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol_loader/llosymbol_loader_base.hpp b/include/llosymbol_loader/llosymbol_loader_base.hpp new file mode 100644 index 0000000..8ec0311 --- /dev/null +++ b/include/llosymbol_loader/llosymbol_loader_base.hpp @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace llo::s1 +{ + class symbol_loader_base_t + { + std::string symbols_path; + public: + symbol_loader_base_t( const std::string &&path ) : symbols_path{ path } + { + } + virtual void load( llo::lloiff_t && ) = 0; + }; +} // namespace llo::s1 \ No newline at end of file diff --git a/include/llosymbol_loader/llosymbol_loader_map.hpp b/include/llosymbol_loader/llosymbol_loader_map.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/llosymbol_loader/llosymbol_loader_pdb.hpp b/include/llosymbol_loader/llosymbol_loader_pdb.hpp new file mode 100644 index 0000000..e69de29 diff --git a/llo-s1.vcxproj b/llo-s1.vcxproj index f963414..2ad9a65 100644 --- a/llo-s1.vcxproj +++ b/llo-s1.vcxproj @@ -47,9 +47,21 @@ - - + + + + + + + + + + + + + + diff --git a/llo-s1.vcxproj.filters b/llo-s1.vcxproj.filters index 00bdcd7..4961785 100644 --- a/llo-s1.vcxproj.filters +++ b/llo-s1.vcxproj.filters @@ -15,20 +15,26 @@ {2d5f480f-e425-4a2c-a285-81d679b2250d} + + {acb72df0-efc5-4108-9db8-850ed74acd41} + + + {3c515f99-13ba-45a0-a80e-c7cbff3c5e85} + + + {9e42261f-c0b7-4650-8d5d-4682ee99948e} + + + {3c4da18e-ebe9-4cf0-8edc-025d26da4d13} + - - Header Files - Header Files Header Files - - Header Files - Header Files\fcml @@ -137,6 +143,48 @@ Header Files\fcml + + Header Files\llosymbol + + + Header Files\llosymbol + + + Header Files\llosymbol + + + Header Files\llosymbol + + + Header Files\llosymbol + + + Header Files\llosymbol + + + Header Files\llosymbol_loader + + + Header Files\llosymbol_loader + + + Header Files\llosymbol_loader + + + Header Files\llodctor + + + Header Files\llodctor + + + Header Files\llodctor + + + Header Files\llodctor + + + Header Files\llodisposition + diff --git a/src/llodctor_pe.cpp b/src/llodctor_pe.cpp index 88edb2a..beabb77 100644 --- a/src/llodctor_pe.cpp +++ b/src/llodctor_pe.cpp @@ -1,4 +1,4 @@ -#include "..\include\llodctor_pe.hpp" +#include bool llo::s1::dctor_pe_t::generate( lloiff_t &iff ) { diff --git a/src/main.cpp b/src/main.cpp index 56f7bb2..fc8c77a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,14 @@ #define NOMINMAX -#include -#include -#include +#include #include +#include int __cdecl main( int argc, const char *argv[] ) { + // read the file path in from cli... std::string file_name = "test.exe"; + + // open the image from disk... std::vector< std::uint8_t > image; llo::lloiff_t iff( file_name ); @@ -14,19 +16,21 @@ int __cdecl main( int argc, const char *argv[] ) std::printf( "> iff name = %s, hash = 0x%p\n", iff.get_name().get_data().c_str(), iff.get_name().get_hash() ); - fcml_st_dialect *dialect; - fcml_fn_dialect_init_intel( FCML_INTEL_DIALECT_CF_DEFAULT, &dialect ); - - fcml_st_disassembler *disassembler; - fcml_fn_disassembler_init( dialect, &disassembler ); - - fcml_st_disassembler_result result; - fcml_st_disassembler_context context = { 0 }; - fcml_fn_disassembler_result_prepare( &result ); - if ( !pe_dctor.generate( iff ) ) { std::printf( "> failed to generate iff...\n" ); return -1; } + + const auto &iff_sections = iff.get_sections(); + for ( auto §ion : iff_sections ) + { + std::printf( "> section name = %s, section uq hash = 0x%p\n", section.section_name.get_data().c_str(), + section.section_name.get_unique_hash() ); + + for ( auto &symbol : section.symbols ) + { + std::printf( "> symbol type = %d, symbol size = 0x%x\n", symbol.get_type(), symbol.get_size() ); + } + } } \ No newline at end of file