Edit/Upate
So I think what confuses me is that:
LEA ESI, [EBX + 8*EAX + 4]
Loads an address, but:
LEA ESI, [EBX + 4]
Loads the content (value?) and not an address. How is this not dereferencing?
I am also still not sure what
mov [eax+1], ecx
does?
Original Question
I am trying to learn to read assembly, however I am starting to struggle. Sorry if there are typos, I cannot copy from my lab machine. This is from malicious code, so it may not be optimal.
I think I have a flawed understanding somewhere, but I just can't figure this out.
var_30 = byte ptr -30h
lea eax, [ebp+esi+var_30]
My understanding is that a load effective address will become whatever address is calculated from [basepointer-30h+esi]. I don't know what esi or edi is.
lea ecx, [esi+edi]
lea ebx, [esi+6]
So I believe that ebx is the resultant address of esi + 6 bytes?
mov esi, ds:WriteProcessMemory
esi points to the WriteProcessMemory API call
mov byte ptr [eax], 68h
Which I believe puts the instruction PUSH into the address of eax (which is currently [basepointer-30h+esi]
mov [eax+1], ecx
I believe ecx, which is now the address of [esi+edi], contains the argument to give to the PUSH instruction. Does this mean that eax+1 now points to the contents ecx (whatever was in [esi+edi]]?
mov byte ptr [eax+5], 0C3h
This I think puts the instruction RET into the address [eax+5].
lea eax, [epb+var_30]
This essentially moves eax back/forward by whatever esi was, but I am not sure why?
push [ebp+lpBaseAddress]; lpBaseAddress
push 0FFFFFFFFh; hProcess (-1 = this process)
call esi
What confuses me:
ebx is used as the argument for nSize, but why would the length of the content would be stored at the address [esi+6]? I initially thought that it was +6 because that could be the length of 'PUSH arg RET (eax to eax+5)', but it is an address and not a short int. Is the short int (nSize) placed at that address by a previous subroutine?
Why is eax (lpBuffer - the content to write) now at [eax-30h]. Did esi allocate space, but start writing content from the end? Something like:
ebp+var_30+esi (eax, start of buffer address) : PUSH(eax) : arg(eax+1) RET(eax+5) : ebp+var_30 (new eax, end of buffer address)?
I don't think I fully understand what esi or edi are doing, but I don't have the full code to work out what they are.
Thanks
WriteProcessMemory
,lpBaseAddress
,hProcess
and the windows tag. Also it's 32 bit. Your claim that "edi register store the first parameter of function and esi second parameter of function" applies to 64 bit sysv calling convention, not 32 bit windows. – JesterWriteProcessMemory
, would help to understand what's going on better. – Margaret Bloom