Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read data from absolute address in delphi XE2

Let's say that I want to read from absolute address gs:$30 in 64bit mode, so the asm code looks something like:

asm
  mov   rax, gs:[$30]
end;

...and compiler translate this code to...

  65 48 8B 05 30 00 00 00       mov rax,gs:[rel $00000030]

But I don't want to use relative address (rip + $30). I want the compiler to use absolute address and compile in this way:

  65 48 8B 04 25 30 00 00 00    mov rax,gs:[+$0030]

(It is the same, if I use gs: prefix or not!)

How do I do this?

EDIT:

I know for work-around. I ask if exist any comand to tell compiler to address location as absolute instead relative.

EDIT

So far so good... :)

drhirsch helped me to find the command, and now the compiler translates:

mov   rax, gs:[abs qword ptr $30]
or
mov   rax, gs:[abs $30]

to this:

6548A13000000000000000 mov rax,[qword $0000000000000030]

Which is almost ok :) Because I want short 32bit opcode (look upper opcodes) instlonger long 64bit opcode.

Is there any way to tell compiler to use short 32 bit address opcode instead long?

like image 394
GJ. Avatar asked Dec 15 '11 13:12

GJ.


1 Answers

You need to use the movabs instruction.

movabs  rax, gs:[$30]

Edit: rip relative addressing is the default mode, on some assemblers you may be able to force 32 bit absolute addressing with

mov rax, gs:[dword $30]  #nasm, tasm
mov rax, gs:[abs $30]    #yasm
like image 136
Gunther Piez Avatar answered Oct 25 '22 14:10

Gunther Piez