Skip to content

Error if allocated memory spans over the address 0x100000000 (4GB) #63

@tobias-loew

Description

@tobias-loew

FinalizeSections will fail if the allocated memory spans over the address 0x100000000 (4GB) since the addresses in the IMAGE_SECTION_HEADER are only 32-bit values.
I could fix it by putting the following code after the allocation of the variable "code":

#ifdef _WIN64
// check that memory-block does not span over the 4GB border
if(code < (LPVOID)0x100000000 && code + alignedImageSize >= (LPVOID)0x100000000)
{
auto old_code = code;
code = (unsigned char *)allocMemory(NULL,
alignedImageSize,
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE,
userdata);
freeMemory(old_code, 0, MEM_RELEASE, userdata);
if(code == NULL) {
SetLastError(ERROR_OUTOFMEMORY);
return NULL;
}
}
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions