|
Wow. I wrote a response and then deleted it because I figured out what you're trying to do.
You're trying to overwrite the return address on the stack with an address to the array, which contains hand-coded op-codes. Right?
Of course, this is very compiler-specific and platform-specific, so you would never do this in a real program. But I realize you are just poking around to try to understand what's going on.
On problem: The size of a pointer is probably 32-bits on a 32-bit machine and 64 bits on a 64-bit machine, but the size of int is probably 32 bits on both machines. So you're only writing half an address. (I say probably because there are no guarantees for compiler-specific details.)
And since you're also using the size of int to navigate the stack, that's likely to be wrong also. I've never investigated this, but gcc may document somewhere what size if pushed on the stack--I would guess sizeof(long *). If it's documented, you could use that type instead of int and at least remove one error.
As for making the op-codes executable, I don't know how you would do that in C. But you could probably use some in-line assembly code.
|