38#include <spdlog/spdlog.h>
48namespace fs = std::filesystem;
57int main(
int argc,
char* argv[]) {
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());
142 if (!res.has_value()) {
143 spdlog::error(
"decomposition failed...\n");
147 spdlog::info(
"decomposed {} symbols...", res.value());
149 spdlog::info(
"entry point address: {:X}", entry_pnt);
150 reinterpret_cast<void (*)()
>(entry_pnt)();