Recently, i learn how to C by making a program by peeking to another public source code and i got stopped working error whenever i run it.
I got "Access violation writing location" from debuger.
Code:
VOID LoadSection(HMODULE hModule, PUINT8 oBinary, IMAGE_SECTION_HEADER *section)
{
LPVOID targetAddress = (uint8_t*)((PUINT8)hModule + section->VirtualAddress);
LPVOID sourceAddress = oBinary + section->PointerToRawData;
if ((uintptr_t)targetAddress >= 0x140000000 + 0x60000000)
{
return;
}
if (section->SizeOfRawData > 0)
{
size_t sizeOfData = min(section->SizeOfRawData, section->Misc.VirtualSize);
memcpy(targetAddress, sourceAddress, sizeOfData);
// When i removed this memcpy line, i got no error on runtime.
DWORD oldProtect;
VirtualProtect(targetAddress, sizeOfData, PAGE_EXECUTE_READWRITE, &oldProtect);
}
}