Mail Archives: djgpp/1997/10/09/20:06:08
At 01:55 10/8/1997 GMT, Peter Berdeklis wrote:
>On Tue, 7 Oct 1997, Nate Eldredge wrote:
>
>> At 03:03 10/6/1997 GMT, Marsel wrote:
>> >Hi,
>> > Can I get the address of the program counter in a C program ?
>> I don't think there's a good way to do it directly from C, but you can do it
>> with external assembler, I.E. NASM.
>
>Easy to do with inline assembler:
>
> int pc;
>
> asm( "movl %%eip, %0"; "=q" (pc) );
>
>(Untested, but I don't think that it violates any protection.)
The problem is deeper than any protection. You cannot use the eip register
explicitly with any 386 instruction such as MOV. The only way to modify it
is with JMP or CALL, and the only way to look at it is to issue a CALL and
see what value was pushed on the stack (my approach).
Nate Eldredge
eldredge AT ap DOT net
- Raw text -