首页
社区
课程
招聘
[原创] MASM伪指令Offset的使用问题
2020-10-23 19:15 2622

[原创] MASM伪指令Offset的使用问题

2020-10-23 19:15
2622

伪指令Offset指令使用问题

定义

大致讲:使用该伪指令将获取expression相对于当前段的偏移.
offset

一个例子 demo.asm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
.386
.model flat, stdcall
option casemap  :none           ;forces your labels to be case sensitive, which means Hello and hello are treated differently.
 
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\masm32.inc
 
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib
 
.data
    HelloWorld db "Hello, World!", 0
 
.code
start:
    mov eax, offset CC_Position
    invoke StdOut, addr HelloWorld
    invoke ExitProcess, 0
 
CC_Position:
    int 3
    int 3
    int 3
    int 3
end start

编译 & 运行

1
2
ml /c /Zd /coff demo.asm
link /subsystem:console demo.obj

问题

offset返回一个偏移,但链接之后的exe程序中使用的却是一个有效地址地址

 

如下图:
offset

如何在运行时获取标号的偏移呢,即CC_Position相对.code的偏移


[培训]二进制漏洞攻防(第3期);满10人开班;模糊测试与工具使用二次开发;网络协议漏洞挖掘;Linux内核漏洞挖掘与利用;AOSP漏洞挖掘与利用;代码审计。

最后于 2020-10-23 19:16 被baolongshou编辑 ,原因:
收藏
点赞0
打赏
分享
最新回复 (1)
雪    币: 897
活跃值: (5917)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
Alfik 2020-10-24 19:17
2
0
https://c9x.me/x86/html/file_module_x86_id_176.html

codestart0:
   jmp codestart1

someVar dd 0

codestart1:
  mov eax,[rip+($-someVar)]

Position-Independent Code
https://www.oreilly.com/library/view/practical-malware-analysis/9781593272906/ch20s02.html

How RIP/EIP relative addressing works in 32-bit mode
http://www.codegurus.be/Programming/riprelativeaddressing_en.htm#Mode32
游客
登录 | 注册 方可回帖
返回