tags:

views:

66

answers:

2

Not used memcpy much but here's my code that doesn't work.

memcpy((PVOID)(enginebase+0x74C9D),(void *)0xEB,2);

(enginebase+0x74C9D) is a pointer location to the address of the bytes that I want to patch.

(void *)0xEB is the op code for the kind of jmp that I want.

Only problem is that this crashes the instant that the line tries to run, I don't know what I'm doing wrong, any incite?

A: 

memcpy() expect two pointers for the source and destination buffers. Your second argument is not a pointer but rather the data itself (it is the opcode of jnz, as you described it). If I understand correctly what you are trying to do, you should set an array with the opcode as its contetns, and provide memcpy() with the pointer to that array.

The program crashes b/c you try to reference a memory location out of your assigned space (address 0xEB).

ysap
+1  A: 

The argument (void*)0xEB is saying to copy memory from address 0xEB; presumably you want something more like

unsigned char x = 0xEB;
memcpy((void*)(enginebase+0x74c9d), (void*)&x, 2);

in order to properly copy the value 0xEB to the destination. BTW, is 2 the right value to copy a single byte to program memory? Looks like it should be 1, since you're copying 1 byte. I'm also under the assumption that you can't just do

((char*)enginebase)[0x74c9d] = 0xEB; 

for some reason? (I don't have any experience overwriting program memory intentionally)

Mark Rushakoff