flat assembler
Message board for the users of flat assembler.

Index > Windows > jmp in binary

Author
Thread Post new topic Reply to topic
mario29



Joined: 07 Sep 2010
Posts: 5
mario29 08 Jan 2011, 02:25
I need to create a jmp to an absolute address determined at runtime. I know the absolute address I need to jump to, but how do I build the jmp in binary code?

In fasm I tested:
Code:
use32
jmp 0x12345678
    


The result was:
Code:
E9 73 56 34 12
    


So the jmp instruction is E9, but I have no idea what format the bytes after are in (why is it not 12345678)? Can anyone please help me how to encode a known address into jmp format?
Post 08 Jan 2011, 02:25
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 08 Jan 2011, 05:15
Opcode E9 uses a relative offset - specifically in the example above this offset is 0x12345673 (stored least byte first). As you might imagine this offset is from the instruction end address - which is at address 0x00000005 above.

5 + 0x12345673 = 0x12345678 (as expected)
Post 08 Jan 2011, 05:15
View user's profile Send private message Visit poster's website Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler 08 Jan 2011, 07:13
Why not just jmp reg32?
Post 08 Jan 2011, 07:13
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung 09 Jan 2011, 00:58
To understand why 0x12345678==78 56 34 12 visit http://en.wikipedia.org/wiki/Endianness

if you want to jmp memory use:
jmp dwod[0x12345678] ; 32bit
jmp word[0x1234] ; 16 bit
Post 09 Jan 2011, 00:58
View user's profile Send private message Yahoo Messenger Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 09 Jan 2011, 06:39
use little endian, most significant byte last.
calculate it by substracting instruction following your jmp from destination.
Post 09 Jan 2011, 06:39
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 09 Jan 2011, 11:45
b1528932
dude, watch its 73 56 34 12
maybe author posted wrong ?
Post 09 Jan 2011, 11:45
View user's profile Send private message Reply with quote
b1528932



Joined: 21 May 2010
Posts: 287
b1528932 09 Jan 2011, 22:19
dest = 12345678
src = 0

operand = destination - source+sizeof(jmp) = 12345678 - (0 + 5) = 12345673
Post 09 Jan 2011, 22:19
View user's profile Send private message Reply with quote
MinhHung



Joined: 10 Sep 2010
Posts: 51
Location: Viet Nam
MinhHung 11 Jan 2011, 02:08
i'm said:
Quote:

if you want to jmp memory use:
jmp dwod[0x12345678] ; 32bit
jmp word[0x1234] ; 16 bit

i'm fail
it jmp to address store in $12345678
ex:
Code:
include 'win32ax.inc' ; you can simply switch between win32ax, win32wx, win64ax and win64wx here
aa dd ?
.code

  start:
        invoke  MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",invoke GetCommandLine,MB_OK
        mov     [aa],b
        jmp     [aa]
  a:
        invoke  MessageBox,HWND_DESKTOP,"a program!",invoke GetCommandLine,MB_OK
        jmp     e
  b:
        invoke  MessageBox,HWND_DESKTOP,"b program!",invoke GetCommandLine,MB_OK
        mov     [aa],a
        jmp     [aa]
   e:
        invoke  ExitProcess,0

.end start      

b1528932

i think it only true if jmp short


Code:
address        code         disassembly
12345678         ED  01           jmp   1234567B

    

jmp(instruction)+8bit displacement(singed byte)+2(because jmp short have 2 byte)
destination=address+2(size of jmp short)+singed byte
1234567B=12345678+2+01

if you jmp Overflowz true

_________________
sorry for my english
Post 11 Jan 2011, 02:08
View user's profile Send private message Yahoo Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.