Change pe_find_section interface

This commit is contained in:
mkrsym1 2023-08-04 00:28:53 +03:00
parent 5e2b015cc0
commit dcb482ab8e
3 changed files with 9 additions and 5 deletions

Binary file not shown.

View File

@ -2,5 +2,10 @@
#include <windows.h>
void pe_find_section(HMODULE module, const char *section, MEMORY_BASIC_INFORMATION *buf);
struct pe_section_info {
void *base_address;
size_t initialized_size;
};
void pe_find_section(HMODULE module, const char *section, struct pe_section_info *buf);
void *pe_find_entry_point(HMODULE module);

View File

@ -1,6 +1,6 @@
#include <pe.h>
void pe_find_section(HMODULE module, const char *section, MEMORY_BASIC_INFORMATION *buf) {
void pe_find_section(HMODULE module, const char *section, struct pe_section_info *buf) {
char *cModule = (char*)module;
IMAGE_DOS_HEADER* dosHeader = (IMAGE_DOS_HEADER*)module;
@ -9,17 +9,16 @@ void pe_find_section(HMODULE module, const char *section, MEMORY_BASIC_INFORMATI
WORD sectionCount = ntHeaders->FileHeader.NumberOfSections;
IMAGE_SECTION_HEADER* sectionHeader = (IMAGE_SECTION_HEADER*)(ntHeaders + 1);
void* targetAddress = 0x0;
for (WORD i = 0; i < sectionCount; i++) {
if (strncmp((char*)sectionHeader->Name, section, 8) == 0) {
targetAddress = (void*)(cModule + sectionHeader->VirtualAddress);
break;
}
sectionHeader++;
}
VirtualQuery(targetAddress, buf, sizeof(MEMORY_BASIC_INFORMATION));
buf->base_address = cModule + sectionHeader->VirtualAddress;
buf->initialized_size = sectionHeader->SizeOfRawData;
}
void *pe_find_entry_point(HMODULE module) {