Dim77
July 13th, 2012, 11:07
I am trying to reverse the code below from ASM to C++. So far it partially works, but there is a problem with the first argument -> *Lrace_vtbl, which supposed to be a reference to this.
It takes the reference to vtbl in the and supposed to pass this to the called function: VtblPtr_proc.
But it looks as if I screwed the references somewhere. It passes the address of Lrace_vtbl to VtblPtr_proc, but inside that function Lrace_vtbl address get's assigned wrong value.
Below are three pieces of code: Original ASM I am trying to reverse, IDA version of the reverse code, my version.
The question is, whether my reversing is correct and what to do with the first argument of the LraceIDInit_proc and VtblPtr_proc to make the reversed code work properly once compiled...
ASM
IDA
My interpretation
It takes the reference to vtbl in the
Code:
*(DWORD *)Lrace_vtbl = off_6E7234;
But it looks as if I screwed the references somewhere. It passes the address of Lrace_vtbl to VtblPtr_proc, but inside that function Lrace_vtbl address get's assigned wrong value.
Below are three pieces of code: Original ASM I am trying to reverse, IDA version of the reverse code, my version.
The question is, whether my reversing is correct and what to do with the first argument of the LraceIDInit_proc and VtblPtr_proc to make the reversed code work properly once compiled...
ASM
Code:
Entry point
CALL <JMP.&MSVCRT._EH_prolog> //Jump to msvcrt._EH_prolog
PUSH ECX
PUSH ESI
MOV ESI,ECX
XOR EAX,EAX
MOV DWORD PTR SS:[EBP-10],ESI
MOV DWORD PTR DS:[ESI+4],EAX
MOV DWORD PTR DS:[ESI+8],EAX
MOV DWORD PTR DS:[ESI+0C],EAX
MOV DWORD PTR DS:[ESI+10],EAX
MOV DWORD PTR DS:[ESI],OFFSET 006E7234
PUSH DWORD PTR DS:[7AB37C] //Arg4 = ASCII "LRace.dbf"
MOV DWORD PTR SS:[EBP-4],EAX
PUSH DWORD PTR SS:[EBP+8] //Arg3 => [ARG.EBP+8]
PUSH DWORD PTR SS:[EBP+0C] //Arg2 => [ARG.EBP+0C]
PUSH ESI //Arg1
CALL 0057ED2E //0057ED2E
IDA
Code:
int __thiscall sub_57EB99(int this, char *Dir, int a3)
{
int v3; // esi@1
v3 = this;
*(_DWORD *)(this + 4) = 0;
*(_DWORD *)(this + 8) = 0;
*(_DWORD *)(this + 12) = 0;
*(_DWORD *)(this + 16) = 0;
*(_DWORD *)this = &off_6E7234;
sub_57ED2E(this, a3, Dir, (char *)off_7AB37C);
return v3;
}
My interpretation
Code:
typedef int(__fastcall * LraceIDInit_proc)(DWORD*, DWORD *, char*, char*);
typedef void(__stdcall * VtblPtrPtr )(DWORD*, int*, char*, char*);
VtblPtrPtr VtblPtr_proc = (VtblPtrPtr)(0x0057ED2E);
DWORD off_6E7234 = (DWORD)(0x006E7234);
extern "C" __declspec(dllexport) int __fastcall LraceIDInit_proc(DWORD *Lrace_vtbl, DWORD *a1, char *Dir, int *some_address)
{
int aLraceId_human = 0;
int aLraceId_dwarf = 0;
int aLraceId_heretic = 0;
int aLraceId_undead =0;
int aLraceId_neutral =0;
int aLraceId_elf =0;
*(DWORD *)Lrace_vtbl = off_6E7234;
VtblPtr_proc(Lrace_vtbl, some_address, Dir, "LRace.dbf";