From 78f2b39b71995c38bb72fd238a03250a55248e10 Mon Sep 17 00:00:00 2001 From: _xeroxz Date: Wed, 6 Apr 2022 19:40:56 -0700 Subject: [PATCH] refactored the code so that there are 3 main namespaces: decomp, obf, and recomp... --- CMakeLists.txt | 50 +++++++++---------- include/decomp/decomp.hpp | 11 ++-- include/decomp/symbol.hpp | 8 +-- include/{comp => }/obf/engine.hpp | 4 +- include/{comp => }/obf/pass.hpp | 2 +- .../obf/passes/jcc_rewrite_pass.hpp | 4 +- .../{comp => }/obf/passes/next_inst_pass.hpp | 4 +- .../obf/passes/reloc_transform_pass.hpp | 4 +- include/{comp => }/obf/transform/add_op.hpp | 8 +-- include/{comp => }/obf/transform/and_op.hpp | 0 .../{comp => }/obf/transform/operation.hpp | 4 +- include/{comp => }/obf/transform/or_op.hpp | 0 include/{comp => }/obf/transform/rol_op.hpp | 0 include/{comp => }/obf/transform/ror_op.hpp | 0 include/{comp => }/obf/transform/sub_op.hpp | 0 .../{comp => }/obf/transform/transform.hpp | 3 +- include/{comp => }/obf/transform/xor_op.hpp | 0 include/{comp/comp.hpp => recomp/recomp.hpp} | 12 ++--- include/{comp => recomp}/reloc.hpp | 2 +- include/{comp => recomp}/symbol_table.hpp | 2 +- include/theo.hpp | 17 ++++--- src/tests/demo/main.cpp | 6 +-- src/theo/decomp/decomp.cpp | 6 +-- src/theo/decomp/routine.cpp | 14 +++--- src/theo/decomp/symbol.cpp | 4 +- src/theo/{comp => }/obf/engine.cpp | 4 +- .../obf/passes/jcc_rewrite_pass.cpp | 0 .../{comp => }/obf/passes/next_inst_pass.cpp | 0 .../obf/passes/reloc_transform_pass.cpp | 11 ++-- src/theo/{comp => }/obf/transform/add_op.cpp | 4 +- src/theo/{comp => }/obf/transform/sub_op.cpp | 0 src/theo/{comp/comp.cpp => recomp/recomp.cpp} | 22 ++++---- src/theo/{comp => recomp}/symbol_table.cpp | 4 +- src/theo/theo.cpp | 26 +++++----- 34 files changed, 120 insertions(+), 116 deletions(-) rename include/{comp => }/obf/engine.hpp (73%) rename include/{comp => }/obf/pass.hpp (87%) rename include/{comp => }/obf/passes/jcc_rewrite_pass.hpp (75%) rename include/{comp => }/obf/passes/next_inst_pass.hpp (75%) rename include/{comp => }/obf/passes/reloc_transform_pass.hpp (76%) rename include/{comp => }/obf/transform/add_op.hpp (66%) rename include/{comp => }/obf/transform/and_op.hpp (100%) rename include/{comp => }/obf/transform/operation.hpp (91%) rename include/{comp => }/obf/transform/or_op.hpp (100%) rename include/{comp => }/obf/transform/rol_op.hpp (100%) rename include/{comp => }/obf/transform/ror_op.hpp (100%) rename include/{comp => }/obf/transform/sub_op.hpp (100%) rename include/{comp => }/obf/transform/transform.hpp (61%) rename include/{comp => }/obf/transform/xor_op.hpp (100%) rename include/{comp/comp.hpp => recomp/recomp.hpp} (78%) rename include/{comp => recomp}/reloc.hpp (90%) rename include/{comp => recomp}/symbol_table.hpp (93%) rename src/theo/{comp => }/obf/engine.cpp (78%) rename src/theo/{comp => }/obf/passes/jcc_rewrite_pass.cpp (100%) rename src/theo/{comp => }/obf/passes/next_inst_pass.cpp (100%) rename src/theo/{comp => }/obf/passes/reloc_transform_pass.cpp (80%) rename src/theo/{comp => }/obf/transform/add_op.cpp (66%) rename src/theo/{comp => }/obf/transform/sub_op.cpp (100%) rename src/theo/{comp/comp.cpp => recomp/recomp.cpp} (89%) rename src/theo/{comp => recomp}/symbol_table.cpp (94%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 811da43..c96d53e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,38 +54,38 @@ set(CMKR_TARGET Theodosius) set(Theodosius_SOURCES "") list(APPEND Theodosius_SOURCES - "include/comp/comp.hpp" - "include/comp/obf/engine.hpp" - "include/comp/obf/pass.hpp" - "include/comp/obf/passes/jcc_rewrite_pass.hpp" - "include/comp/obf/passes/next_inst_pass.hpp" - "include/comp/obf/passes/reloc_transform_pass.hpp" - "include/comp/obf/transform/add_op.hpp" - "include/comp/obf/transform/and_op.hpp" - "include/comp/obf/transform/operation.hpp" - "include/comp/obf/transform/or_op.hpp" - "include/comp/obf/transform/rol_op.hpp" - "include/comp/obf/transform/ror_op.hpp" - "include/comp/obf/transform/sub_op.hpp" - "include/comp/obf/transform/transform.hpp" - "include/comp/obf/transform/xor_op.hpp" - "include/comp/reloc.hpp" - "include/comp/symbol_table.hpp" "include/decomp/decomp.hpp" "include/decomp/routine.hpp" "include/decomp/symbol.hpp" + "include/obf/engine.hpp" + "include/obf/pass.hpp" + "include/obf/passes/jcc_rewrite_pass.hpp" + "include/obf/passes/next_inst_pass.hpp" + "include/obf/passes/reloc_transform_pass.hpp" + "include/obf/transform/add_op.hpp" + "include/obf/transform/and_op.hpp" + "include/obf/transform/operation.hpp" + "include/obf/transform/or_op.hpp" + "include/obf/transform/rol_op.hpp" + "include/obf/transform/ror_op.hpp" + "include/obf/transform/sub_op.hpp" + "include/obf/transform/transform.hpp" + "include/obf/transform/xor_op.hpp" + "include/recomp/recomp.hpp" + "include/recomp/reloc.hpp" + "include/recomp/symbol_table.hpp" "include/theo.hpp" - "src/theo/comp/comp.cpp" - "src/theo/comp/obf/engine.cpp" - "src/theo/comp/obf/passes/jcc_rewrite_pass.cpp" - "src/theo/comp/obf/passes/next_inst_pass.cpp" - "src/theo/comp/obf/passes/reloc_transform_pass.cpp" - "src/theo/comp/obf/transform/add_op.cpp" - "src/theo/comp/obf/transform/sub_op.cpp" - "src/theo/comp/symbol_table.cpp" "src/theo/decomp/decomp.cpp" "src/theo/decomp/routine.cpp" "src/theo/decomp/symbol.cpp" + "src/theo/obf/engine.cpp" + "src/theo/obf/passes/jcc_rewrite_pass.cpp" + "src/theo/obf/passes/next_inst_pass.cpp" + "src/theo/obf/passes/reloc_transform_pass.cpp" + "src/theo/obf/transform/add_op.cpp" + "src/theo/obf/transform/sub_op.cpp" + "src/theo/recomp/recomp.cpp" + "src/theo/recomp/symbol_table.cpp" "src/theo/theo.cpp" ) diff --git a/include/decomp/decomp.hpp b/include/decomp/decomp.hpp index 79e29c1..1330684 100644 --- a/include/decomp/decomp.hpp +++ b/include/decomp/decomp.hpp @@ -5,8 +5,8 @@ #include #include -#include #include +#include #include #include @@ -14,20 +14,21 @@ namespace theo::decomp { class decomp_t { public: - explicit decomp_t(std::vector& lib, comp::symbol_table_t* syms); + explicit decomp_t(std::vector& lib, + recomp::symbol_table_t* syms); std::vector rtns(); std::vector lib(); std::vector objs(); - comp::symbol_table_t* syms(); + recomp::symbol_table_t* syms(); std::map& scn_hash_tbl(); - std::optional decompose(); + std::optional decompose(); private: const std::vector m_lib; std::vector m_objs; std::vector m_rtns; std::map m_scn_hash_tbl; - comp::symbol_table_t* m_syms; + recomp::symbol_table_t* m_syms; }; } // namespace theo::decomp \ No newline at end of file diff --git a/include/decomp/symbol.hpp b/include/decomp/symbol.hpp index 7f1ccd9..07ae9e0 100644 --- a/include/decomp/symbol.hpp +++ b/include/decomp/symbol.hpp @@ -1,6 +1,6 @@ #pragma once #include -#include +#include #include #include #include @@ -15,7 +15,7 @@ class symbol_t { std::vector data, coff::section_header_t* scn = {}, coff::symbol_t* sym = {}, - std::vector relocs = {}, + std::vector relocs = {}, sym_type_t dcmp_type = {}); std::string name() const; @@ -26,7 +26,7 @@ class symbol_t { std::vector& data(); coff::symbol_t* sym() const; sym_type_t type() const; - std::vector& relocs(); + std::vector& relocs(); void allocated_at(std::uintptr_t allocated_at); std::size_t hash(); @@ -37,7 +37,7 @@ class symbol_t { std::uintptr_t m_offset, m_allocated_at; std::vector m_data; coff::section_header_t* m_scn; - std::vector m_relocs; + std::vector m_relocs; sym_type_t m_sym_type; coff::symbol_t* m_sym; }; diff --git a/include/comp/obf/engine.hpp b/include/obf/engine.hpp similarity index 73% rename from include/comp/obf/engine.hpp rename to include/obf/engine.hpp index 40ca1e6..7c3e590 100644 --- a/include/comp/obf/engine.hpp +++ b/include/obf/engine.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include +#include #include -namespace theo::comp::obf { +namespace theo::obf { class engine_t { explicit engine_t(){}; diff --git a/include/comp/obf/pass.hpp b/include/obf/pass.hpp similarity index 87% rename from include/comp/obf/pass.hpp rename to include/obf/pass.hpp index 29b95b3..dd5b422 100644 --- a/include/comp/obf/pass.hpp +++ b/include/obf/pass.hpp @@ -8,7 +8,7 @@ extern "C" { #include } -namespace theo::comp::obf { +namespace theo::obf { class pass_t { public: explicit pass_t(decomp::sym_type_t sym_type) : m_sym_type(sym_type){}; diff --git a/include/comp/obf/passes/jcc_rewrite_pass.hpp b/include/obf/passes/jcc_rewrite_pass.hpp similarity index 75% rename from include/comp/obf/passes/jcc_rewrite_pass.hpp rename to include/obf/passes/jcc_rewrite_pass.hpp index b5b1ecd..31fc665 100644 --- a/include/comp/obf/passes/jcc_rewrite_pass.hpp +++ b/include/obf/passes/jcc_rewrite_pass.hpp @@ -1,7 +1,7 @@ #pragma once -#include +#include -namespace theo::comp::obf { +namespace theo::obf { class jcc_rewrite_pass_t : public pass_t { explicit jcc_rewrite_pass_t() : pass_t(decomp::sym_type_t::inst_split){}; diff --git a/include/comp/obf/passes/next_inst_pass.hpp b/include/obf/passes/next_inst_pass.hpp similarity index 75% rename from include/comp/obf/passes/next_inst_pass.hpp rename to include/obf/passes/next_inst_pass.hpp index 594efbc..5590f55 100644 --- a/include/comp/obf/passes/next_inst_pass.hpp +++ b/include/obf/passes/next_inst_pass.hpp @@ -1,7 +1,7 @@ #pragma once -#include +#include -namespace theo::comp::obf { +namespace theo::obf { class next_inst_pass_t : public pass_t { explicit next_inst_pass_t() : pass_t(decomp::sym_type_t::inst_split){}; diff --git a/include/comp/obf/passes/reloc_transform_pass.hpp b/include/obf/passes/reloc_transform_pass.hpp similarity index 76% rename from include/comp/obf/passes/reloc_transform_pass.hpp rename to include/obf/passes/reloc_transform_pass.hpp index e3f00d0..651c202 100644 --- a/include/comp/obf/passes/reloc_transform_pass.hpp +++ b/include/obf/passes/reloc_transform_pass.hpp @@ -1,7 +1,7 @@ #pragma once -#include +#include -namespace theo::comp::obf { +namespace theo::obf { class reloc_transform_pass_t : public pass_t { explicit reloc_transform_pass_t() : pass_t(decomp::sym_type_t::inst_split){}; diff --git a/include/comp/obf/transform/add_op.hpp b/include/obf/transform/add_op.hpp similarity index 66% rename from include/comp/obf/transform/add_op.hpp rename to include/obf/transform/add_op.hpp index a01a1ae..f8cd965 100644 --- a/include/comp/obf/transform/add_op.hpp +++ b/include/obf/transform/add_op.hpp @@ -1,8 +1,8 @@ #pragma once -#include +#include -namespace theo::comp::obf::transform { -class add_op_t : operation_t { +namespace theo::obf::transform { +class add_op_t : public operation_t { explicit add_op_t() : operation_t([&](std::size_t val, std::size_t imm) -> std::size_t { return val + imm; }, @@ -12,4 +12,4 @@ class add_op_t : operation_t { static add_op_t* get(); std::vector native(xed_inst_t* inst, std::size_t imm); }; -} // namespace theo::comp::obf::transform \ No newline at end of file +} // namespace theo::obf::transform \ No newline at end of file diff --git a/include/comp/obf/transform/and_op.hpp b/include/obf/transform/and_op.hpp similarity index 100% rename from include/comp/obf/transform/and_op.hpp rename to include/obf/transform/and_op.hpp diff --git a/include/comp/obf/transform/operation.hpp b/include/obf/transform/operation.hpp similarity index 91% rename from include/comp/obf/transform/operation.hpp rename to include/obf/transform/operation.hpp index ae6fbe1..1c4b31b 100644 --- a/include/comp/obf/transform/operation.hpp +++ b/include/obf/transform/operation.hpp @@ -8,7 +8,7 @@ extern "C" { #include } -namespace theo::comp::obf::transform { +namespace theo::obf::transform { using transform_t = std::function; class operation_t { @@ -33,4 +33,4 @@ class operation_t { {rol_op, ror_op}, {ror_op, rol_op}, {xor_op, xor_op}}; }; -} // namespace theo::comp::obf::transform \ No newline at end of file +} // namespace theo::obf::transform \ No newline at end of file diff --git a/include/comp/obf/transform/or_op.hpp b/include/obf/transform/or_op.hpp similarity index 100% rename from include/comp/obf/transform/or_op.hpp rename to include/obf/transform/or_op.hpp diff --git a/include/comp/obf/transform/rol_op.hpp b/include/obf/transform/rol_op.hpp similarity index 100% rename from include/comp/obf/transform/rol_op.hpp rename to include/obf/transform/rol_op.hpp diff --git a/include/comp/obf/transform/ror_op.hpp b/include/obf/transform/ror_op.hpp similarity index 100% rename from include/comp/obf/transform/ror_op.hpp rename to include/obf/transform/ror_op.hpp diff --git a/include/comp/obf/transform/sub_op.hpp b/include/obf/transform/sub_op.hpp similarity index 100% rename from include/comp/obf/transform/sub_op.hpp rename to include/obf/transform/sub_op.hpp diff --git a/include/comp/obf/transform/transform.hpp b/include/obf/transform/transform.hpp similarity index 61% rename from include/comp/obf/transform/transform.hpp rename to include/obf/transform/transform.hpp index 5bc0f41..26b9960 100644 --- a/include/comp/obf/transform/transform.hpp +++ b/include/obf/transform/transform.hpp @@ -4,5 +4,6 @@ #include namespace theo::comp::obf::transform { -std::map operations; +std::map operations = { + {operation_t::type_t::add_op, add_op_t::get()}}; } \ No newline at end of file diff --git a/include/comp/obf/transform/xor_op.hpp b/include/obf/transform/xor_op.hpp similarity index 100% rename from include/comp/obf/transform/xor_op.hpp rename to include/obf/transform/xor_op.hpp diff --git a/include/comp/comp.hpp b/include/recomp/recomp.hpp similarity index 78% rename from include/comp/comp.hpp rename to include/recomp/recomp.hpp index 4924c9f..3416509 100644 --- a/include/comp/comp.hpp +++ b/include/recomp/recomp.hpp @@ -1,19 +1,19 @@ #pragma once -#include -#include +#include +#include #include -namespace theo::comp { +namespace theo::recomp { using resolver_t = std::function; using copier_t = std::function; using allocator_t = std::function; -class comp_t { +class recomp_t { public: - explicit comp_t(decomp::decomp_t* dcmp); - explicit comp_t(decomp::decomp_t* dcmp, + explicit recomp_t(decomp::decomp_t* dcmp); + explicit recomp_t(decomp::decomp_t* dcmp, allocator_t alloc, copier_t copy, resolver_t resolve); diff --git a/include/comp/reloc.hpp b/include/recomp/reloc.hpp similarity index 90% rename from include/comp/reloc.hpp rename to include/recomp/reloc.hpp index 0d3949d..3b0c4f4 100644 --- a/include/comp/reloc.hpp +++ b/include/recomp/reloc.hpp @@ -2,7 +2,7 @@ #include #include -namespace theo::comp { +namespace theo::recomp { class reloc_t { public: explicit reloc_t(std::uint16_t offset, diff --git a/include/comp/symbol_table.hpp b/include/recomp/symbol_table.hpp similarity index 93% rename from include/comp/symbol_table.hpp rename to include/recomp/symbol_table.hpp index e7f5cb7..1449652 100644 --- a/include/comp/symbol_table.hpp +++ b/include/recomp/symbol_table.hpp @@ -7,7 +7,7 @@ #include -namespace theo::comp { +namespace theo::recomp { class symbol_table_t { public: symbol_table_t() {} diff --git a/include/theo.hpp b/include/theo.hpp index a5337ae..d243c66 100644 --- a/include/theo.hpp +++ b/include/theo.hpp @@ -1,12 +1,13 @@ #pragma once #include -#include -#include #include +#include +#include +#include -#include -#include -#include +#include +#include +#include #include #include @@ -20,7 +21,7 @@ extern "C" { namespace theo { using lnk_fns_t = - std::tuple; + std::tuple; class theo_t { public: @@ -32,7 +33,7 @@ class theo_t { private: decomp::decomp_t m_dcmp; - comp::comp_t m_cmp; - comp::symbol_table_t m_sym_tbl; + recomp::recomp_t m_recmp; + recomp::symbol_table_t m_sym_tbl; }; } // namespace theo \ No newline at end of file diff --git a/src/tests/demo/main.cpp b/src/tests/demo/main.cpp index 671770c..924ceb4 100644 --- a/src/tests/demo/main.cpp +++ b/src/tests/demo/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char* argv[]) { fdata.resize(fsize); f.read((char*)fdata.data(), fsize); - theo::comp::allocator_t allocator = + theo::recomp::allocator_t allocator = [&](std::uint32_t size, coff::section_characteristics_t section_type) -> std::uintptr_t { return reinterpret_cast(VirtualAlloc( @@ -26,12 +26,12 @@ int main(int argc, char* argv[]) { section_type.mem_execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE)); }; - theo::comp::copier_t copier = [&](std::uintptr_t ptr, void* buff, + theo::recomp::copier_t copier = [&](std::uintptr_t ptr, void* buff, std::uint32_t size) { std::memcpy((void*)ptr, buff, size); }; - theo::comp::resolver_t resolver = [&](std::string sym) -> std::uintptr_t { + theo::recomp::resolver_t resolver = [&](std::string sym) -> std::uintptr_t { return reinterpret_cast( GetProcAddress(LoadLibraryA("user32.dll"), sym.data())); }; diff --git a/src/theo/decomp/decomp.cpp b/src/theo/decomp/decomp.cpp index e066c74..ad5c47e 100644 --- a/src/theo/decomp/decomp.cpp +++ b/src/theo/decomp/decomp.cpp @@ -1,10 +1,10 @@ #include namespace theo::decomp { -decomp_t::decomp_t(std::vector& lib, comp::symbol_table_t* syms) +decomp_t::decomp_t(std::vector& lib, recomp::symbol_table_t* syms) : m_lib(lib), m_syms(syms) {} -std::optional decomp_t::decompose() { +std::optional decomp_t::decompose() { // extract obj files from the archive file... // ar::view lib(m_lib.data(), m_lib.size()); @@ -148,7 +148,7 @@ std::vector decomp_t::objs() { return m_objs; } -comp::symbol_table_t* decomp_t::syms() { +recomp::symbol_table_t* decomp_t::syms() { return m_syms; } diff --git a/src/theo/decomp/routine.cpp b/src/theo/decomp/routine.cpp index 0831932..c5dfd26 100644 --- a/src/theo/decomp/routine.cpp +++ b/src/theo/decomp/routine.cpp @@ -13,7 +13,7 @@ std::vector routine_t::decompose() { switch (m_dcmp_type) { case function: { - std::vector relocs; + std::vector relocs; auto scn_relocs = reinterpret_cast( m_scn->ptr_relocs + reinterpret_cast(m_img)); @@ -27,7 +27,7 @@ std::vector routine_t::decompose() { m_sym->name.to_string(m_img->get_strings()), sym_name, sym_hash, scn_reloc->virtual_address); - relocs.push_back(comp::reloc_t(scn_reloc->virtual_address, sym_hash, + relocs.push_back(recomp::reloc_t(scn_reloc->virtual_address, sym_hash, sym_name.data())); } @@ -58,7 +58,7 @@ std::vector routine_t::decompose() { if (offset) new_sym_name.append("@").append(std::to_string(offset)); - std::vector relocs; + std::vector relocs; auto scn_relocs = reinterpret_cast( m_scn->ptr_relocs + reinterpret_cast(m_img)); @@ -85,7 +85,7 @@ std::vector routine_t::decompose() { reloc_offset); relocs.push_back( - comp::reloc_t(reloc_offset, sym_hash, sym_name.data())); + recomp::reloc_t(reloc_offset, sym_hash, sym_name.data())); } // add a reloc to the next instruction... @@ -98,7 +98,7 @@ std::vector routine_t::decompose() { .append(std::to_string(offset + xed_decoded_inst_get_length(&instr))); - relocs.push_back(comp::reloc_t(0, decomp::symbol_t::hash(next_inst_sym), + relocs.push_back(recomp::reloc_t(0, decomp::symbol_t::hash(next_inst_sym), next_inst_sym.data())); // get the instructions bytes @@ -126,8 +126,8 @@ std::vector routine_t::decompose() { // remove the relocation to the next symbol from the last instruction // - auto last_inst = result.back(); - auto last_inst_relocs = last_inst.relocs(); + auto& last_inst = result.back(); + auto& last_inst_relocs = last_inst.relocs(); last_inst_relocs.erase(last_inst_relocs.end() - 1); break; } diff --git a/src/theo/decomp/symbol.cpp b/src/theo/decomp/symbol.cpp index b4cf624..37eaf36 100644 --- a/src/theo/decomp/symbol.cpp +++ b/src/theo/decomp/symbol.cpp @@ -6,7 +6,7 @@ symbol_t::symbol_t(std::string name, std::vector data, coff::section_header_t* scn, coff::symbol_t* sym, - std::vector relocs, + std::vector relocs, sym_type_t dcmp_type) : m_name(name), m_offset(offset), @@ -57,7 +57,7 @@ coff::symbol_t* symbol_t::sym() const { return m_sym; } -std::vector& symbol_t::relocs() { +std::vector& symbol_t::relocs() { return m_relocs; } diff --git a/src/theo/comp/obf/engine.cpp b/src/theo/obf/engine.cpp similarity index 78% rename from src/theo/comp/obf/engine.cpp rename to src/theo/obf/engine.cpp index d3c1d15..dbe69b8 100644 --- a/src/theo/comp/obf/engine.cpp +++ b/src/theo/obf/engine.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace theo::comp::obf { +namespace theo::obf { engine_t* engine_t::get() { static engine_t obj; return &obj; diff --git a/src/theo/comp/obf/passes/jcc_rewrite_pass.cpp b/src/theo/obf/passes/jcc_rewrite_pass.cpp similarity index 100% rename from src/theo/comp/obf/passes/jcc_rewrite_pass.cpp rename to src/theo/obf/passes/jcc_rewrite_pass.cpp diff --git a/src/theo/comp/obf/passes/next_inst_pass.cpp b/src/theo/obf/passes/next_inst_pass.cpp similarity index 100% rename from src/theo/comp/obf/passes/next_inst_pass.cpp rename to src/theo/obf/passes/next_inst_pass.cpp diff --git a/src/theo/comp/obf/passes/reloc_transform_pass.cpp b/src/theo/obf/passes/reloc_transform_pass.cpp similarity index 80% rename from src/theo/comp/obf/passes/reloc_transform_pass.cpp rename to src/theo/obf/passes/reloc_transform_pass.cpp index e40449a..cbf7dba 100644 --- a/src/theo/comp/obf/passes/reloc_transform_pass.cpp +++ b/src/theo/obf/passes/reloc_transform_pass.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace theo::comp::obf { +namespace theo::obf { reloc_transform_pass_t* reloc_transform_pass_t::get() { static reloc_transform_pass_t obj; return &obj; @@ -31,9 +31,10 @@ bool reloc_transform_pass_t::has_legit_reloc(decomp::symbol_t* sym) { auto res = // see if there are any relocations with offset not equal to // zero... relocations with zero mean its a relocation to the next // instruction... - std::find_if(sym->relocs().begin(), sym->relocs().end(), - [&](reloc_t& reloc) -> bool { return reloc.offset(); }); + std::find_if( + sym->relocs().begin(), sym->relocs().end(), + [&](recomp::reloc_t& reloc) -> bool { return reloc.offset(); }); return res != sym->relocs().end(); } -} // namespace theo::comp::obf \ No newline at end of file +} // namespace theo::obf \ No newline at end of file diff --git a/src/theo/comp/obf/transform/add_op.cpp b/src/theo/obf/transform/add_op.cpp similarity index 66% rename from src/theo/comp/obf/transform/add_op.cpp rename to src/theo/obf/transform/add_op.cpp index 7cb1d31..c9d3a69 100644 --- a/src/theo/comp/obf/transform/add_op.cpp +++ b/src/theo/obf/transform/add_op.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace theo::comp::obf::transform { +namespace theo::obf::transform { add_op_t* add_op_t::get() { static add_op_t obj; return &obj; diff --git a/src/theo/comp/obf/transform/sub_op.cpp b/src/theo/obf/transform/sub_op.cpp similarity index 100% rename from src/theo/comp/obf/transform/sub_op.cpp rename to src/theo/obf/transform/sub_op.cpp diff --git a/src/theo/comp/comp.cpp b/src/theo/recomp/recomp.cpp similarity index 89% rename from src/theo/comp/comp.cpp rename to src/theo/recomp/recomp.cpp index acf3dee..a8b204e 100644 --- a/src/theo/comp/comp.cpp +++ b/src/theo/recomp/recomp.cpp @@ -1,14 +1,14 @@ -#include +#include -namespace theo::comp { -comp_t::comp_t(decomp::decomp_t* dcmp) : m_dcmp(dcmp) {} -comp_t::comp_t(decomp::decomp_t* dcmp, +namespace theo::recomp { +recomp_t::recomp_t(decomp::decomp_t* dcmp) : m_dcmp(dcmp) {} +recomp_t::recomp_t(decomp::decomp_t* dcmp, allocator_t alloc, copier_t copy, resolver_t resolve) : m_dcmp(dcmp), m_allocator(alloc), m_copier(copy), m_resolver(resolve) {} -void comp_t::allocate() { +void recomp_t::allocate() { // map code & data/rdata/bss sections first... // m_dcmp->syms()->for_each([&](theo::decomp::symbol_t& sym) { @@ -60,7 +60,7 @@ void comp_t::allocate() { }); } -void comp_t::resolve() { +void recomp_t::resolve() { // resolve relocations in all symbols... // m_dcmp->syms()->for_each([&](theo::decomp::symbol_t& sym) { @@ -109,7 +109,7 @@ void comp_t::resolve() { }); } -void comp_t::copy_syms() { +void recomp_t::copy_syms() { // copy symbols into memory using the copier supplied... // m_dcmp->syms()->for_each([&](theo::decomp::symbol_t& sym) { @@ -117,19 +117,19 @@ void comp_t::copy_syms() { }); } -void comp_t::allocator(allocator_t alloc) { +void recomp_t::allocator(allocator_t alloc) { m_allocator = alloc; } -void comp_t::copier(copier_t copy) { +void recomp_t::copier(copier_t copy) { m_copier = copy; } -void comp_t::resolver(resolver_t resolve) { +void recomp_t::resolver(resolver_t resolve) { m_resolver = resolve; } -std::uintptr_t comp_t::resolve(const std::string&& sym) { +std::uintptr_t recomp_t::resolve(const std::string&& sym) { auto res = m_dcmp->syms()->sym_from_hash(decomp::symbol_t::hash(sym)); return res.has_value() ? res->allocated_at() : 0; } diff --git a/src/theo/comp/symbol_table.cpp b/src/theo/recomp/symbol_table.cpp similarity index 94% rename from src/theo/comp/symbol_table.cpp rename to src/theo/recomp/symbol_table.cpp index 828e53c..bf4fd53 100644 --- a/src/theo/comp/symbol_table.cpp +++ b/src/theo/recomp/symbol_table.cpp @@ -1,6 +1,6 @@ -#include +#include -namespace theo::comp { +namespace theo::recomp { symbol_table_t::symbol_table_t(const std::vector&& syms) { std::for_each(syms.begin(), syms.end(), [&](decomp::symbol_t sym) { m_table.insert({sym.hash(), sym}); diff --git a/src/theo/theo.cpp b/src/theo/theo.cpp index a0682c0..c5890cf 100644 --- a/src/theo/theo.cpp +++ b/src/theo/theo.cpp @@ -2,7 +2,7 @@ namespace theo { theo_t::theo_t(std::vector& lib, lnk_fns_t lnkr_fns) - : m_dcmp(lib, &m_sym_tbl), m_cmp(&m_dcmp) { + : m_dcmp(lib, &m_sym_tbl), m_recmp(&m_dcmp) { // init enc/dec tables only once... add obfuscation passes to the engine... // if (static std::atomic_bool v = true; v.exchange(false)) { @@ -11,15 +11,15 @@ theo_t::theo_t(std::vector& lib, lnk_fns_t lnkr_fns) // order matters, the order in which the pass is added is the order they // will be executed! // - auto engine = comp::obf::engine_t::get(); - engine->add_pass(comp::obf::reloc_transform_pass_t::get()); - engine->add_pass(comp::obf::next_inst_pass_t::get()); - engine->add_pass(comp::obf::jcc_rewrite_pass_t::get()); + auto engine = obf::engine_t::get(); + engine->add_pass(obf::reloc_transform_pass_t::get()); + engine->add_pass(obf::next_inst_pass_t::get()); + engine->add_pass(obf::jcc_rewrite_pass_t::get()); } - m_cmp.allocator(std::get<0>(lnkr_fns)); - m_cmp.copier(std::get<1>(lnkr_fns)); - m_cmp.resolver(std::get<2>(lnkr_fns)); + m_recmp.allocator(std::get<0>(lnkr_fns)); + m_recmp.copier(std::get<1>(lnkr_fns)); + m_recmp.resolver(std::get<2>(lnkr_fns)); } std::optional theo_t::decompose() { @@ -39,12 +39,12 @@ std::optional theo_t::decompose() { std::uintptr_t theo_t::compose(const std::string&& entry_sym) { // run obfuscation engine on all symbols... // - auto engine = comp::obf::engine_t::get(); + auto engine = obf::engine_t::get(); m_sym_tbl.for_each([&](decomp::symbol_t& sym) { engine->run(&sym); }); - m_cmp.allocate(); - m_cmp.resolve(); - m_cmp.copy_syms(); - return m_cmp.resolve(entry_sym.data()); + m_recmp.allocate(); + m_recmp.resolve(); + m_recmp.copy_syms(); + return m_recmp.resolve(entry_sym.data()); } } // namespace theo \ No newline at end of file