Ollydbg & #define functions

Results 1 to 2 of 2
  1. #1
    Good Guy George qet123 is offline
    MemberRank
    Apr 2009 Join Date
    DesertLocation
    1,432Posts

    Ollydbg & #define functions

    Well, i looked for older sources for gunz, and i found out that in 2007 they didn't defined "ZGetGame" and "ZGetGameClient" ... like they did in 1.5, in 1.5 they define it in ZGlobal.h which that makes me impossible to find the adress, my question is, does it really impossible to find the "Address" if it's defined as #define?


  2. #2
    Enthusiast ngskRabbit is offline
    MemberRank
    Sep 2012 Join Date
    32Posts

    Re: Ollydbg & #define functions

    In short, possible. #define just makes the function to "strong" inline.

    In long...
    #define is interpreted by a preprocessor (not a compiler), this replaces all of reference to #define's code.

    Example,
    Code:
    #define SOME_MACRO  16
    ...
    int n[SOME_MACRO];
    memset(n, 0, SOME_MACRO * sizeof(int));
    for(int i = 0; i < SOME_MACRO; i++)
    ...
    while compiling, this will be...
    Code:
    ...
    int n[16];
    memset(n, 0, 16 * sizeof(int));
    for(int i = 0; i < 16; i++)
    ...
    Imagined ASM...
    Code:
    ...
    SUB ESP,16 * sizeof(int)
    PUSH 16 * sizeof(int)
    PUSH 0
    LEA EAX,[ESP+8]
    PUSH EAX
    CALL memset
    ADD ESP,12
    PUSH EBX
    XOR EBX,EBX
    Addr1 :
    ...
    INC EBX
    CMP EBX,16
    JL Addr1
    POP EBX
    ...
    ADD ESP,16 * sizeof(int)
    hmm...


    Code:
    void MyOutput(const char *pszMsg)
    {
      ZChatOutput(MCOLOR(255,0,0), pszMsg, ZChat::CL_CURRENT);
    }
    
    ...
      MyOutput("1st.");
      MyOutput("2nd.");
      MyOutput("3rd.");
    ...
    Code:
    MyOutput  :
    PUSH EBP
    MOV EBP,ESP
    PUSH ESI
    MOV ESI,[EBP-12]
    PUSH ZChat::CL_CURRENT
    PUSH ESI
    PUSH MCOLOR(255,0,0)
    CALL ZChatOutput
    ADD ESP,sizeof(MCOLOR) + 8
    POP ESI
    POP EBP
    RETN
    
    ...
    PUSH "1st"
    CALL MyOutput
    PUSH "2nd"
    CALL MyOutput
    PUSH "3rd"
    CALL MyOutput
    ADD ESP,12
    ...
    -------------------------

    Code:
    #define MyOutput(pszMsg)	\
      ZChatOutput(MCOLOR(255,0,0), pszMsg, ZChat::CL_CURRENT)
      
    ...
      MyOutput("1st.");
      MyOutput("2nd.");
      MyOutput("3rd.");
    ...
    Code:
    ...
    PUSH ZChat::CL_CURRENT
    PUSH "1st"
    PUSH MCOLOR(255,0,0)
    CALL ZChatOutput
    ADD ESP,sizeof(MCOLOR) + 8
    PUSH ZChat::CL_CURRENT
    PUSH "2nd"
    PUSH MCOLOR(255,0,0)
    CALL ZChatOutput
    ADD ESP,sizeof(MCOLOR) + 8
    PUSH ZChat::CL_CURRENT
    PUSH "3rd"
    PUSH MCOLOR(255,0,0)
    CALL ZChatOutput
    ADD ESP,sizeof(MCOLOR) + 8
    ...
    NOTE :Wrote in decimal, Also for ASM part I don't have confidence.



Advertisement