首页
社区
课程
招聘
请问 x64下 jmp far 的Opcode 如何计算?
2011-7-13 11:42 20381

请问 x64下 jmp far 的Opcode 如何计算?

2011-7-13 11:42
20381
想了解一下 x64下 jmp far 后面地址的计算方式

看了Intel 的指令集手册
Opcode Instruction Op/
En
64-Bit
Mode
Compat/
Leg Mode
Description
EB cb JMP rel8 A Valid Valid Jump short, RIP = RIP + 8-bi
displacement sign extended
to 64-bits
E9 cw JMP rel16 A N.S. Valid Jump near, relative,
displacement relative to
next instruction. Not
supported in 64-bit mode.
E9 cd JMP rel32 A Valid Valid Jump near, relative, RIP =
RIP + 32-bit displacement
sign extended to 64-bits
FF /4 JMP r/m16 B N.S. Valid Jump near, absolute indirect
address = zero-extended
r/m16. Not supported in 64
bit mode.
FF /4 JMP r/m32 B N.S. Valid Jump near, absolute indirect
address given in r/m32. No
supported in 64-bit mode.
FF /4 JMP r/m64 B Valid N.E. Jump near, absolute indirect
RIP = 64-Bit offset from
register or memory
EA cd JMP ptr16:16 A Inv. Valid Jump far, absolute, address
given in operand
EA cp JMP ptr16:32 A Inv. Valid Jump far, absolute, address
given in operand
FF /5 JMP m16:16 AValid Valid Jump far, absolute indirect,
address given in m16:16
FF /5 JMP m16:32 AValid Valid Jump far, absolute indirect,
address given in m16:32.
REX.W + FF /5 JMP m16:64 A Valid N.E. Jump far, absolute indirect,

没有理解 m16:64  是什么意思
后面的 /5 是如何计算出来的 REX.W 到底是什么意思。。

或者举例说明 jmp far 0x1234567812345678 的Opcode 是什么就行。。。 谢谢

阿里云助力开发者!2核2G 3M带宽不限流量!6.18限时价,开 发者可享99元/年,续费同价!

收藏
点赞0
打赏
分享
最新回复 (10)
雪    币: 250
活跃值: (33)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
XzOsaPl 2 2011-7-13 11:46
2
0
来补充一下问题  我们都知道 x86 架构下 jmp far 可以跳前后 2G的空间
在Windows 下一般是足够使用的

所以 可以直接写  0xE9 0xXXXXXXXX  
然而这种方法到 x64上是不行的,所以想问一下x64下 想跳转到任意一个地址应该如何写Opcode?
雪    币: 2105
活跃值: (424)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
exile 1 2011-7-13 12:47
3
0
push retn???
FF,25?
雪    币: 250
活跃值: (33)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
XzOsaPl 2 2011-7-13 13:48
4
0
问题的关键在于后面跟的64位地址怎么写。。
在GCC的汇编和GDB下面搞的好纠结。。
雪    币: 2105
活跃值: (424)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
exile 1 2011-7-13 13:58
5
0
ff 25 0 0 0 0 1 2 3 4 5 6 7 8
雪    币: 17
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
体验 2011-7-13 14:59
6
0
\5 不是算出来的,是龟腚
REX.W 是64位扩展,说明是64位的
雪    币: 250
活跃值: (33)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
XzOsaPl 2 2011-7-14 10:38
7
0
好吧 这个问题问的没有什么意义了
真相在这里

2.2.1.5  Immediates
In 64-bit mode, the typical size of immediate operands remains 32 bits. When the
operand size is 64 bits, the processor sign-extends all immediates to 64 bits prior to
their use.
Support for 64-bit immediate operands is accomplished by expanding the semantics
of the existing move (MOV reg, imm16/32) instructions. These instructions (opcodes
B8H – BFH) move 16-bits or 32-bits of immediate data (depending on the effective
operand size) into a GPR. When the effective operand size is 64 bits, these instruc-
tions can be used to load an immediate into a GPR. A REX prefix is needed to override
the 32-bit default operand size to a 64-bit operand size.
For example:
48 B8 8877665544332211 MOV RAX,1122334455667788H

Intel指令集手册中给出了答案  说 如果要使用 64位的立即操作数 必须使用寄存器来实现。。


mov rax,1234567812345678h
jmp rax

这个 Opcode 总是好办的
48是REX Prefix,其中 4为固定值 ,8表示启用 64位寄存器扩展
B8是 mov rax,xxxx 的Opcode
剩下来就不解释了。。。
jmp rax的Opcode 为0xFF 0xE0

但是比较杯具的是 这两行代码足足用了12个字节。。。 太纠结了。。
雪    币: 623
活跃值: (40)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
天高 2011-7-14 10:53
8
0
jmp far

是使用 FF /5 opcode,例如以下指令:

jmp far [rax]       ===>  48 FF 28  (仅 3 个 字节)

jmp rax     ===> 这个不是  jmp far,而是 jmp direct
雪    币: 12
活跃值: (21)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
ythalbert 2011-7-14 11:31
9
0
64位程序的32位近跳转和调用还是用,E9 xx xx xx xx,E8 xx xx xx xx,其中xx xx xx xx是两条指令间的相对偏移。
64位程序的64位近跳转和调用是,FF 04 88 77 66 55 44 33 22 11 ,跳转到绝对地址1122334455667788。64位环境FF 04 不支持32位地址,后面都是接64位地址。
64位远跳转指令几乎没有程序使用,别纠结了。
REX.WRXB   + FF /5 JMP m16:64 对应: 0100.1000 11111111 0000 0101 + m16:64
REX=0100
W 1 = 64 Bit Operand Size
R  0 = Extension of the ModR/M reg field
X  0 = Extension of the SIB index field
B  0 = Extension of the ModR/M r/m field, SIB base field, or Opcode reg field
雪    币: 250
活跃值: (33)
能力值: ( LV6,RANK:90 )
在线值:
发帖
回帖
粉丝
XzOsaPl 2 2011-7-19 13:43
10
0
我编译了 FF 04 11 22 33  44 55 66 77 88
结果是:
incl (%rcx,%rdx,1)
and (%rbx),%dh
rex.R push %rbp
data 16
ja 0x100000b34

木有出现传说中的 jmp XX XX XX XX XX XX XX XX
雪    币: 19
活跃值: (25)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
MarvelStu 2013-10-9 17:08
11
0
jmp far 为 段跳转 字节码为 EA (6 byte)   修改cs和ip的值 共7个字节;
jmp far IP:CS  具体记不清楚了!
E9为段内跳转  理论是这么声明  但是 4字节的偏移足够跳很远! 占 5个字节
修改IP的值!
游客
登录 | 注册 方可回帖
返回