Anyone know why I am getting an error?
compiler is telling me that modify_this is undefined.
Any help would be GREATLY appreciated!
Thanks ,
Trope
Code:
#include "iostream.h"
#include "windows.h"
char * function_addr;
LPVOID addr;
DWORD prev;
__declspec(naked) int selfmodify()
{
__asm
{
[b]mov dword ptr [addr],offset [modify_this + 1][/b] //get the address of the code
}
VirtualProtect(addr,4,PAGE_READWRITE,&prev); //make the writable
__asm
{
mov ecx, dword ptr [addr]
mov dword ptr [ecx], 12 //set new function return value
}
VirtualProtect(addr,4,PAGE_EXECUTE,&prev); //restore it to executable
__asm
{
modify_this:
mov eax,255 //we are returning 255 but code gets modified here
ret
}
}
int main(int argc, char* argv[])
{
int retval = selfmodify();
cout << "Function returned: " << retval << endl;
return 0;
}
compiler is telling me that modify_this is undefined.
Any help would be GREATLY appreciated!
Thanks ,
Trope