15 IMAGE_RESOURCE_DIRECTORY_ENTRY *root_dir,
16 const IMAGE_RESOURCE_DIRECTORY *upper_dir,
17 IMAGE_RESOURCE_DIRECTORY_ENTRY* entry,
20 if (!entry->DataIsDirectory) {
22 std::cout <<
"Entry is NOT a directory\n";
24 DWORD offset = entry->OffsetToData;
26 std::cout <<
"Offset: " << offset << std::endl;
28 IMAGE_RESOURCE_DATA_ENTRY *data_entry = (IMAGE_RESOURCE_DATA_ENTRY*)(offset + (ULONGLONG)upper_dir);
29 if (!
peconv::validate_ptr(modulePtr, moduleSize, data_entry,
sizeof(IMAGE_RESOURCE_DATA_ENTRY))) {
33 std::cout <<
"Data Offset: " << data_entry->OffsetToData <<
" : " << data_entry->Size << std::endl;
35 BYTE* data_ptr = (BYTE*)((ULONGLONG)modulePtr + data_entry->OffsetToData);
39 on_entry(modulePtr, root_dir, data_entry);
43 std::cout <<
"Entry is a directory\n";
46 DWORD offset = entry->OffsetToDirectory;
48 std::cout <<
"Offset: " << offset << std::endl;
50 IMAGE_RESOURCE_DIRECTORY *next_dir = (IMAGE_RESOURCE_DIRECTORY*)(offset + (ULONGLONG)upper_dir);
54 return parse_resource_dir(modulePtr, moduleSize, root_dir, upper_dir, next_dir, on_entry);
58 IMAGE_RESOURCE_DIRECTORY_ENTRY *root_dir,
59 const IMAGE_RESOURCE_DIRECTORY *upper_dir,
60 IMAGE_RESOURCE_DIRECTORY* curr_dir,
63 size_t total_entries = curr_dir->NumberOfIdEntries + curr_dir->NumberOfNamedEntries;
64 IMAGE_RESOURCE_DIRECTORY_ENTRY* first_entry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)((ULONGLONG)&curr_dir->NumberOfIdEntries +
sizeof(WORD));
65 for (
size_t i = 0; i < total_entries; i++) {
66 IMAGE_RESOURCE_DIRECTORY_ENTRY* entry = &first_entry[i];
68 std::cout <<
"Entry:" << std::hex << i <<
" ; " <<
"Id: " << entry->Id <<
" ; dataOffset:" << entry->OffsetToData <<
"\n";
70 if (root_dir ==
nullptr) {
82 if (!dir || dir->VirtualAddress == 0 || dir->Size == 0) {
85 IMAGE_RESOURCE_DIRECTORY *res_dir = (IMAGE_RESOURCE_DIRECTORY*)(dir->VirtualAddress + (ULONGLONG)modulePtr);
89 return parse_resource_dir(modulePtr, module_size,
nullptr, res_dir, res_dir, on_entry);
bool parse_resource_entry(BYTE *modulePtr, const size_t moduleSize, IMAGE_RESOURCE_DIRECTORY_ENTRY *root_dir, const IMAGE_RESOURCE_DIRECTORY *upper_dir, IMAGE_RESOURCE_DIRECTORY_ENTRY *entry, peconv::t_on_res_entry_found on_entry)
bool parse_resource_dir(BYTE *modulePtr, const size_t moduleSize, IMAGE_RESOURCE_DIRECTORY_ENTRY *root_dir, const IMAGE_RESOURCE_DIRECTORY *upper_dir, IMAGE_RESOURCE_DIRECTORY *curr_dir, peconv::t_on_res_entry_found on_entry)