I'm trying to write a function that will NOP an assembly instruction. Currently I have it NOPing the instruction, but I have to manually enter the instruction size...
It would be nice if I could just feed it the address, and by some magic it's able to calculate the total bytes for that instruction...
For example... In the following OllyDBG assembly line... The instruction is of size 6 (I've bolded the instruction bytes).
02235FF3 3B86 B8020000 CMP EAX,DWORD PTR DS:[ESI+2B8]
This is the function I have now...
void NOP(
DWORD_PTR FromAddress,
const int size)
{
for (int i = 0; i < size; i++)
{
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(FromAddress + i), "\x90", size, NULL);
}
}
I imagine this would transform into something like this....
void NOP(
DWORD_PTR Address)
{
int TotalBytes = MagicFunctionToGetInstructionByteSizeFromAddress(Address);
for (int i = 0; i < TotalBytes; i++)
{
WriteProcessMemory(GetCurrentProcess(), (LPVOID)(FromAddress + i), "\x90", size, NULL);
}
}