fnstenv on 64 bit returning wrong value?

2

I'm using fnstenv FPU instruction to get the EIP in a 64 bit shellcode. Running it in GDB everything looks fine:

 0x0000000000400080  ? fldz   
 0x0000000000400082  ? fnstenv [rsp-0xc]

After running these instructions by stepping in with si I get in the stack the right value (0x0000000000400082).

What I miss is this: if I place a breakpoint after the fnstenv and then with continue I execute without a breakpoint between them, I get a wrong value: 0x0000003300400082. The 0x00000033 is the value of CS register...not sure if this is a coincidence or not.

I'm using nasm and ld with the following syntax:

nasm -f elf64 shell.asm -o shell.o
ld shell.o -o sh --omagic
assembly
x86-64
shellcode
x87
asked on Stack Overflow Jul 23, 2020 by cips • edited Jul 24, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0