出于某种原因,我无法正确地将其中的结构放入fasm中。这是问题所在,假设我有这样的结构:
struct IMAGE_SECTION_HEADER
_Name db IMAGE_SIZEOF_SHORT_NAME dup (?)
union
PhysicalAddress dd ?
VirtualSize dd ?
ends
VirtualAddress dd ?
SizeOfRawData dd ?
PointerToRawData dd ?
PointerToRelocations dd ?
PointerToLinenumbers dd ?
NumberOfRelocations dw ?
NumberOfLinenumbers dw ?
Characteristics dd ?
ends
据我所知,要在堆栈中声明这个,我需要写这样的东西:
start:
virtual at esp+N
section IMAGE_SECTION_HEADER
end virtual
lea eax, [section]
其中N应该是结构的大小,但我怎样才能得到结构尺寸?据我所知,没有sizeof,我是否需要手动计算每个结构大小以在堆栈内存中声明它?另外,我如何使用宏在堆栈框架内声明它?
你不需要这个N,结构从esp开始,长度为N个字节。你只需要在堆栈上分配这个结构,所以这应该工作:
start:
virtual at esp
@@:
section IMAGE_SECTION_HEADER
IMAGE_SECTION_HEADER_SIZE = $ - @b
end virtual
sub esp, IMAGE_SECTION_HEADER_SIZE ;allocate local buffer
lea eax, [section]
...
add esp, IMAGE_SECTION_HEADER_SIZE ;;free local buffer