Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix a bug in PerformBaseRelocation
  • Loading branch information
H4ckF0rFun committed Jan 3, 2024
commit dabd353bbeac1db15199d75b7712c49940e544e0
8 changes: 7 additions & 1 deletion MemoryModule.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,18 +382,24 @@ static BOOL
PerformBaseRelocation(PMEMORYMODULE module, ptrdiff_t delta)
{
unsigned char *codeBase = module->codeBase;
DWORD relocation_size;
PIMAGE_BASE_RELOCATION relocation;

PIMAGE_DATA_DIRECTORY directory = GET_HEADER_DICTIONARY(module, IMAGE_DIRECTORY_ENTRY_BASERELOC);
if (directory->Size == 0) {
return (delta == 0);
}

relocation_size = directory->Size;
relocation = (PIMAGE_BASE_RELOCATION) (codeBase + directory->VirtualAddress);
for (; relocation->VirtualAddress > 0; ) {

for (;relocation_size; ) {
DWORD i;
unsigned char *dest = codeBase + relocation->VirtualAddress;
unsigned short *relInfo = (unsigned short*) OffsetPointer(relocation, IMAGE_SIZEOF_BASE_RELOCATION);

relocation_size -= relocation->SizeOfBlock;

for (i=0; i<((relocation->SizeOfBlock-IMAGE_SIZEOF_BASE_RELOCATION) / 2); i++, relInfo++) {
// the upper 4 bits define the type of relocation
int type = *relInfo >> 12;
Expand Down