example usage of how to interface with theo. please refer to the source code of this function for details.
62 std::ifstream f(argv[1], std::ios::binary);
63 auto fsize = fs::file_size(fs::path(argv[1]));
64 std::vector<std::uint8_t> fdata;
66 f.read((
char*)fdata.data(), fsize);
68 LoadLibraryA(
"user32.dll");
69 LoadLibraryA(
"win32u.dll");
75 [&](std::uint32_t size,
76 coff::section_characteristics_t section_type) -> std::uintptr_t {
77 return reinterpret_cast<std::uintptr_t
>(VirtualAlloc(
78 NULL, size, MEM_COMMIT | MEM_RESERVE,
79 section_type.mem_execute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE));
84 std::memcpy((
void*)ptr, buff, size);
88 auto loaded_modules = std::make_unique<HMODULE[]>(64);
89 std::uintptr_t result = 0u, loaded_module_sz = 0u;
90 if (!EnumProcessModules(GetCurrentProcess(), loaded_modules.get(), 512,
91 (PDWORD)&loaded_module_sz))
94 for (
auto i = 0u; i < loaded_module_sz / 8u; i++) {
95 wchar_t file_name[MAX_PATH] = L
"";
96 if (!GetModuleFileNameExW(GetCurrentProcess(), loaded_modules.get()[i],
97 file_name, _countof(file_name)))
100 if ((result =
reinterpret_cast<std::uintptr_t
>(
101 GetProcAddress(LoadLibraryW(file_name), sym.c_str()))))
127 std::string entry_name;
128 std::cout <<
"enter the name of the entry point: ";
129 std::cin >> entry_name;
134 theo::theo_t t(fdata, {allocator, copier, resolver}, entry_name.data());
140 auto res = t.decompose();
142 if (!res.has_value()) {
143 spdlog::error(
"decomposition failed...\n");
147 spdlog::info(
"decomposed {} symbols...", res.value());
148 auto entry_pnt = t.compose();
149 spdlog::info(
"entry point address: {:X}", entry_pnt);
150 reinterpret_cast<void (*)()
>(entry_pnt)();
static engine_t * get()
get the singleton object of this class.
Definition: engine.cpp:34
static hello_world_pass_t * get()
Definition: hello_world_pass.hpp:45
static jcc_rewrite_pass_t * get()
Definition: jcc_rewrite_pass.cpp:35
static next_inst_pass_t * get()
Definition: next_inst_pass.cpp:34
the main class which encapsulates a symbol table, decomp, and recomp objects. This class is a bridge ...
Definition: theo.hpp:70
std::function< void(std::uintptr_t, void *, std::uint32_t)> copier_t
a function which is called by recomp_t to copy symbols into memory.
Definition: recomp.hpp:49
std::function< std::uintptr_t(std::string)> resolver_t
a function which is called by recomp_t to resolve external symbols
Definition: recomp.hpp:44
std::function< std::uintptr_t(std::uint32_t, coff::section_characteristics_t)> allocator_t
a function which is called to allocate space for a symbol.
Definition: recomp.hpp:59