13 BYTE* dimps_table = (BYTE*)((ULONGLONG) modulePtr + d_imps_dir->VirtualAddress);
15 if (d_imps_dir->Size < min_size) {
21 dir_size = d_imps_dir->Size;
27 const ULONGLONG img_base,
29 const T_FIELD ordinal_flag,
36 if (iat_addr > img_base) iat_addr -= img_base;
39 if (thunk_addr > img_base) thunk_addr -= img_base;
41 T_FIELD* record_va = (T_FIELD*)((ULONGLONG)modulePtr + iat_addr);
42 T_IMAGE_THUNK_DATA* thunk_va = (T_IMAGE_THUNK_DATA*)((ULONGLONG)modulePtr + thunk_addr);
44 for (; *record_va != NULL && thunk_va != NULL; record_va++, thunk_va++) {
52 T_FIELD iat_va = *record_va;
53 ULONGLONG iat_rva = (ULONGLONG)iat_va;
54 if (iat_va > img_base) iat_rva -= img_base;
56 std::cout << std::hex << iat_rva <<
" : ";
58 T_FIELD* iat_record_ptr = (T_FIELD*)((ULONGLONG)modulePtr + iat_rva);
62 FARPROC hProc =
nullptr;
63 if (thunk_va->u1.Ordinal & ordinal_flag) {
64 T_FIELD raw_ordinal = thunk_va->u1.Ordinal & (~ordinal_flag);
66 std::cout << std::hex <<
"ord: " << raw_ordinal <<
" ";
68 hProc = func_resolver->
resolve_func(lib_name, MAKEINTRESOURCEA(raw_ordinal));
71 ULONGLONG name_rva = thunk_va->u1.AddressOfData;
72 if (name_rva > img_base) {
75 PIMAGE_IMPORT_BY_NAME by_name = (PIMAGE_IMPORT_BY_NAME)((ULONGLONG)modulePtr + name_rva);
76 LPSTR func_name =
reinterpret_cast<LPSTR
>(by_name->Name);
81 std::cout << func_name <<
" ";
83 hProc = func_resolver->
resolve_func(lib_name, func_name);
87 *record_va = (T_FIELD) hProc;
89 std::cout <<
"[OK]\n";
94 std::cout <<
"[NOPE]\n";
107 bool is_loader64 =
false;
111 if (is_64bit != is_loader64) {
112 std::cerr <<
"[ERROR] Loader/Payload bitness mismatch.\n";
118 if (!func_resolver) {
121 size_t table_size = 0;
127 std::cout <<
"OK, table_size = " << table_size << std::endl;
131 for (
size_t i = 0; i < max_count; i++) {
138 if (dll_name_rva > moduleBase) {
139 dll_name_rva -= moduleBase;
141 char* dll_name = (
char*)((ULONGLONG) modulePtr + dll_name_rva);
142 if (!
validate_ptr(modulePtr, module_size, dll_name,
sizeof(
char)))
continue;
144 std::cout << dll_name << std::endl;
bool parse_delayed_desc(BYTE *modulePtr, const size_t moduleSize, const ULONGLONG img_base, LPSTR lib_name, const T_FIELD ordinal_flag, IMAGE_DELAYLOAD_DESCRIPTOR *desc, peconv::t_function_resolver *func_resolver)