Question about reversing C++ calls menu

User Tag List

Results 1 to 5 of 5
  1. #1
    GliderPro's Avatar Member
    Reputation
    -1
    Join Date
    Mar 2009
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question about reversing C++ calls

    I'm trying to figure out the following bit of code.

    Code:
    sub_xxxx proc near
    mov     edx, dword_xxxx
    mov     eax, ds:Foo     ; <<  symbol exported from DLL that points to object
    mov     eax, [eax]
    mov     ecx, [eax]
    push    edi
    push    edx
    push    0Dh
    push    eax
    mov     eax, [ecx+14h]
    call    eax
    test    al, al
    jnz     short loc_xxxx
    Based on this code I've created the following class definition.

    Code:
    class Foo
    {
    public:
      virtual void func00() = 0;
      virtual void func04() = 0;
      virtual void func08() = 0;
      virtual void func0C() = 0;
      virtual void func10() = 0;
      virtual void __cdecl func14(int val) = 0;
    };
    I call this function using this code.

    Code:
    Foo **pFoo = (Foo**)mImports[192];
    
      (*pFoo)->func14(13);
    This results in the following code from the compiler.

    Code:
      (*pFoo)->func14(13);
    00414777  mov         esi,esp 
    00414779  push        0Dh  
    0041477B  mov         eax,dword ptr [pFoo] 
    0041477E  mov         ecx,dword ptr [eax] 
    00414780  mov         edx,dword ptr [pFoo] 
    00414783  mov         eax,dword ptr [edx] 
    00414785  mov         ecx,dword ptr [ecx] 
    00414787  push        eax  
    00414788  mov         edx,dword ptr [ecx+14h] 
    0041478B  call        edx  
    0041478D  add         esp,8 
    00414790  cmp         esi,esp 
    00414792  call        @ILT+4925(__RTC_CheckEsp) (412342h)
    This results in the following runtime error. "Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention."

    I verified that my code calls the same function as the client and the function looks like it was executed based on the log output. I'm guessing that I just messed up the function definition. I'm not well versed on the different calling conventions. Would one of you RE gurus kindly point out what I did wrong?

    Thanks

    Question about reversing C++ calls
  2. #2
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks like the function you're calling is stdcall. Your using cdecl, which is caller cleanup. Try stdcall.

  3. #3
    GliderPro's Avatar Member
    Reputation
    -1
    Join Date
    Mar 2009
    Posts
    93
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried it and I still get the error. Below is the prolog and epilog of the function I'm calling. The function is returning so the stack is not being corrupted. Should I just turn off runtime stack checking and not worry about it?

    Code:
    arg_0= dword ptr  8
    arg_4= word ptr  0Ch
    arg_8= dword ptr  10h
    
    push    ebp
    mov     ebp, esp
    and     esp, 0FFFFFFF8h
    push    0FFFFFFFFh
    push    offset loc_100D9E89
    mov     eax, large fs:0
    push    eax
    sub     esp, 0C8h
    mov     eax, dword_1010602C
    xor     eax, esp
    mov     [esp+0D4h+var_14], eax
    push    ebx
    push    esi
    push    edi
    mov     eax, dword_1010602C
    xor     eax, esp
    push    eax
    lea     eax, [esp+0E4h+var_C]
    mov     large fs:0, eax
    mov     esi, [ebp+arg_0]
    mov     [esp+0E4h+var_D4], esi
    call    sub_1002B490
    test    al, al
    jnz     short loc_1001061A
    Code:
    mov     ecx, [esp+0E4h+var_C]
    mov     large fs:0, ecx
    pop     ecx
    pop     edi
    pop     esi
    pop     ebx
    mov     ecx, [esp+0D4h+var_14]
    xor     ecx, esp
    call    sub_100D1482
    mov     esp, ebp
    pop     ebp
    retn    0Ch
    Last edited by GliderPro; 07-09-2009 at 05:19 PM.

  4. #4
    lanman92's Avatar Active Member
    Reputation
    50
    Join Date
    Mar 2007
    Posts
    1,033
    Thanks G/R
    0/1
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's always an option

  5. #5
    Bobbysing's Avatar Member
    Reputation
    192
    Join Date
    Jan 2009
    Posts
    36
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The "RETN C" tells us that the function actually takes 3 arguments.
    Since that function also is a virtual class-method and passes the this-pointer as first argument ( you can guess that from the way it's being called ) you define it like this:
    Code:
    virtual void __stdcall FuncName( Foo * pThis, DWORD dwValue, DWORD dwSecondArg ) = 0;
    You should never turn RTC off to get rid of errors, they may hunt you later when you can't easily see what is going wrong.
    Last edited by Bobbysing; 07-09-2009 at 07:03 PM. Reason: grammar

Similar Threads

  1. Question about Reversing
    By fudz in forum WoW Memory Editing
    Replies: 11
    Last Post: 05-02-2010, 03:29 AM
  2. Question about calling Blizzard! Help!
    By lowco101 in forum World of Warcraft General
    Replies: 5
    Last Post: 06-09-2009, 12:26 AM
  3. Ok question about registration error config or w.e u wana call it.
    By whatshisface in forum WoW EMU Questions & Requests
    Replies: 14
    Last Post: 09-20-2008, 01:28 PM
  4. Question about MCing - Frostwolf
    By Hydrox in forum World of Warcraft General
    Replies: 0
    Last Post: 07-21-2006, 02:53 AM
  5. questions about model editing
    By Avianar47 in forum World of Warcraft General
    Replies: 2
    Last Post: 07-08-2006, 09:41 PM
All times are GMT -5. The time now is 04:20 PM. Powered by vBulletin® Version 4.2.3
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Google Authenticator verification provided by Two-Factor Authentication (Free) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search