[quote name='nuclear123' timestamp='1298343078' post='4777353']
im wanting to read my compiled code at a certain point(which i specify) read it into a buffer, and then be able to copy those bytes to a file for viewing...!
That is a more detailed 'what' but you still haven't given a 'why'. If you want to see the 'machine code' just tell your compiler to generate assembly.
[/quote]
Why does it matter WHY he wants this? it's none of your business, he's just asking if it can be done.
It CAN be done, and there are multiple ways of doing it. Without getting into assembly, you could use the function pointer idea (assign a function to a function pointer, which will then point to that funciton's location in memory), but it would have to be offset by some value to get somewhere in the middle of the function. i don't know how to do that without assembly.
With assembly, you would add an assembly section to basically perform a jump and link at the end of the seciton, and be sure and store the return address in a register, and copy it to a variable (I don't know x86 way of doing it). In MIPS, it would be something like this:
void *pvLocation;
if (cond)
{
}
asm {
// store old $ra in $t0
add $to, $ra, $0
b Step1
nop
Step2:
// Address at End is now stored in $ra register, copy it to our variable
// but add 4 1st point at end of instruction at End:
addi $ra, $ra, 4
sw $ra, pvLocation
b End
nop
Step1:
jal Step2
nop
End:
add $ra, $t0, $0
}
// now pvLocation store address of right here
Yes, it's a bit of a hack, but, it is possible. You'll probably want to do this via x86 instructions though.