在 Win32 (MASM) 中使用结构的成员

逆向工程 拆卸 视窗 结构
2021-06-20 00:52:50

由于以下主题, 使用 MASM 在 win32 汇编编程中初始化结构

我试图纠正我的错误,所以我尝试了以下代码:

.386
.model flat,stdcall
option casemap:none

struct1 struct
first db ?
second dd ?
third db ?
struct1 EndS

.data
Initializedstructure struct1 <4,10>

.code
start:
mov eax, struct1.first
mov ebx , struct1.second
mov ecx , struct1.third
;offsets
mov eax , offset struct1.first
mov ebx , offset struct1.second
mov ecx , offset struct1.third
end start

但是在反汇编代码上没有发现任何东西。我添加了每个结构体成员的偏移量以区分两者之间的差异。

.text:00401000 start:
.text:00401000                 mov     eax, 0
.text:00401005                 mov     ebx, 1
.text:0040100A                 mov     ecx, 5
.text:0040100F                 mov     eax, 0
.text:00401014                 mov     ebx, 1
.text:00401019                 mov     ecx, 5

我在网上冲浪,但没有找到任何描述结构体使用的文档,所以我决定自己尝试一下。反汇编的代码似乎包含每个结构成员的大小。

主要问题是如何在代码中使用结构体的成员?

1个回答

在这种情况下,struct1 是这样一个通用结构,应该初始化使用,否则这样的语句:mov eax , struct1.second只是给你struct1从乞讨的偏移量我认为您误解了Initializedstructure指令或其他指令。您可以将其命名为您想要的名称,并使用其名称struct在其余部分中初始化。例如,在 .data 部分中,您将使用:

AAAA struct1 <4,10,60>

因此,在 .code 部分的其余代码中,使用以下语句将起作用, mov eax , AAAA.second并为您提供(在这种情况下)10 并mov eax, offset AAAA.second在运行时提供第二个成员的偏移量。