can anyone help me with this ERROR. i'm basically reading an exe file, decrypt it and copy it to memory and then executing it using createthread() but it seems that i've made some mistake when implementing this method.
unsigned char key[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
AES aes(128);
unsigned char* decipheredBuffer = aes.DecryptECB((unsigned char*)buffer, exeSize, key);
DWORD old_protect;
void* executable_area = VirtualAlloc(0, sizeof(decipheredBuffer), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (executable_area == 0) {
return 0;
}
memcpy(executable_area, decipheredBuffer, sizeof(decipheredBuffer));
//((void(*)())executable_area)();
bool protectTrue = VirtualProtect(executable_area, sizeof(decipheredBuffer), PAGE_EXECUTE_READWRITE, &old_protect);
if(protectTrue){
void* hThread = CreateThread(NULL, sizeof(decipheredBuffer), (LPTHREAD_START_ROUTINE)executable_area, NULL, 0, NULL);
if (hThread != 0) {
WaitForSingleObject(hThread, 0xFFFFFFFF);//acess violation
}
}
VirtualProtect(executable_area, sizeof(decipheredBuffer), old_protect, &old_protect);
VirtualFree(executable_area, 0, MEM_RELEASE);