两个副本来存储值

逆向工程 艾达 反汇编者
2021-07-09 07:19:54

我有这段代码,反汇编的DX:

.text:004386D3                 push    ecx
.text:004386D4                 fld1
.text:004386D6                 fstp    [esp+26Ch+var_26C] ;load 1.0 value texture coords
.text:004386D9                 push    ecx
.text:004386DA                 fld1
.text:004386DC                 fstp    [esp+270h+var_270] ;load 1.0 value texture coords
.text:004386DF                 push    ecx
.text:004386E0                 fld     ds:__real@c1700000
.text:004386E6                 fstp    [esp+274h+var_274] ;load -15.0 value x vertex
.text:004386E9                 push    ecx
.text:004386EA                 fld     ds:__real@c1700000
.text:004386F0                 fstp    [esp+278h+var_278] ;load -15.0 value y vertex
.text:004386F3                 push    ecx
.text:004386F4                 fld     ds:__real@c1700000
.text:004386FA                 fstp    [esp+27Ch+var_27C] ;load -15.0 value z vertex
.text:004386FD                 lea     ecx, [ebp+var_22C] ;this pointer
.text:00438703                 call    j_D3DVERTEX__D3DVERTEX ;fills structure with values
.text:00438708                 mov     ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func
.text:0043870B                 mov     edx, [eax]
.text:0043870D                 mov     [ecx], edx
.text:0043870F                 mov     edx, [eax+4]
.text:00438712                 mov     [ecx+4], edx
.text:00438715                 mov     edx, [eax+8]
.text:00438718                 mov     [ecx+8], edx
.text:0043871B                 mov     edx, [eax+0Ch]
.text:0043871E                 mov     [ecx+0Ch], edx
.text:00438721                 mov     eax, [eax+10h]
.text:00438724                 mov     [ecx+10h], eax

这段代码用值填充了一个顶点结构:

-15.000000,-15.000000,-15.000000, 1.0,1.0

似乎值存储为两个副本。此值的第一个副本相对存储在 ebp+var_22C 中,并通过此指针传入 ecx:

.text:004386FD                 lea     ecx, [ebp+var_22C] ; ecx has pointer this to store values
.text:00438703                 call    j_D3DVERTEX__D3DVERTEX ;fills structure with values

在调用 j_D3DVERTEX__D3DVERTEX 之后,第二次复制这个值存储在相对 ebp+var_8 中:

.text:00438708                 mov     ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func

即完全它看起来像:

.text:004386FD                 lea     ecx, [ebp+var_22C] ; ecx has pointer this to store values
.text:00438703                 call    j_D3DVERTEX__D3DVERTEX ;store values into structure
.text:00438708                 mov     ecx, [ebp+var_8] ;var_8 pointer returned by Lock() buffer func

如果我理解正确 - 为什么需要这个顶点值的两个副本?也许使用 D3DPOOL_MANAGED 和 D3DUSAGE_WRITEONLY 参数创建的顶点缓冲区很重要。

1个回答

在 D3DVERTEX__D3DVERTEX [ebp+var_334] 中,即 ecx 传递给变量 [ebp+var_4] 并在函数 [ebp+var_4] 的结尾传递给 eax 作为返回:

.text:00439440 D3DVERTEX__D3DVERTEX proc near          ; CODE XREF: j_D3DVERTEX__D3DVERTEXj
.text:00439440
.text:00439440 var_5C          = dword ptr -5Ch
.text:00439440 var_58          = dword ptr -58h
.text:00439440 var_54          = dword ptr -54h
.text:00439440 var_4           = dword ptr -4
.text:00439440 arg_0           = dword ptr  8
.text:00439440 arg_4           = dword ptr  0Ch
.text:00439440 arg_8           = dword ptr  10h
.text:00439440 arg_C           = dword ptr  14h
.text:00439440 arg_10          = dword ptr  18h
.text:00439440
.text:00439440                 push    ebp
.text:00439441                 mov     ebp, esp
.text:00439443                 sub     esp, 44h
.text:00439446                 push    ebx
.text:00439447                 push    esi
.text:00439448                 push    edi
.text:00439449                 mov     [ebp+var_4], ecx

...........
.text:0043947B                 mov     eax, [ebp+var_4]
.text:0043947E                 pop     edi
.text:0043947F                 pop     esi
.text:00439480                 pop     ebx
.text:00439481                 mov     esp, ebp
.text:00439483                 pop     ebp
.text:00439484                 retn    14h
.text:00439484 D3DVERTEX__D3DVERTEX endp

在 D3DVERTEX__D3DVERTEX 之后,这个 eax 用作基础 bointer 用值填充顶点缓冲区的内存:

.text:00438703                 call    j_D3DVERTEX__D3DVERTEX
.text:00438708                 mov     ecx, [ebp+var_8] ;pointer to vertex buffer
.text:0043870B                 mov     edx, [eax] ;eax returned by j_D3DVERTEX__D3DVERTEX

也许 j_D3DVERTEX__D3DVERTEX 用于在调用 j_D3DVERTEX__D3DVERTEX 之后安排和准备顶点值以填充顶点内存?