+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 15 of 22

  Click here to go to the first staff post in this thread.   Thread: OpenGL hook + textures recognition

  1. #1
    Join Date
    Nov 2003
    Posts
    249
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Rep Power
    97

    OpenGL hook + textures recognition

    Hi,

    Here is a method to hook OpenGL functions without patching memory ( using pointers ), and filter by texture file path/name:

    PHP Code:
    // Medal of Honor Allied Assault
    #define MOHAA_GLBINDTEXTURE    0x13E3EE4
    #define MOHAA_GLDRAWELEMENTS    0x13E3D04

    // Medal of Honor Spear Head
    #define MOHSH_GLBINDTEXTURE    0x16DCED8
    #define MOHSH_GLDRAWELEMENTS    0x16DCCF8

    // Medal of Honor Break Trough
    #define MOHBT_GLBINDTEXTURE    0x170D00C
    #define MOHBT_GLDRAWELEMENTS    0x170CE38 
    PHP Code:
    char *g_pszTextureName;

    typedef void WINAPI *GLBINDTEXTURE_TYPE )( GLenum iTargetGLuint iTexture );
    DWORD g_dwGlBindTexture NULL;

    void WINAPI glBindTextureHookGLenum iTargetGLuint iTexture )
    {
        
    _asm mov g_pszTextureNameesi;

        
    CASTGLBINDTEXTURE_TYPEg_dwGlBindTexture )( iTargetiTexture );
    }

    typedef void WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices );
    DWORD g_dwGlDrawElements NULL;

    void WINAPI glDrawElementsHookGLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices )
    {
        
    // Here you can filter any textures using g_pszTextureName

        
    CASTGLDRAWELEMENTS_TYPEg_dwGlDrawElements )( iModeiCountiTypepvIndices );

    PHP Code:
    g_dwGlBindTexture = *( DWORD * )MOHAA_GLBINDTEXTURE;
    g_dwGlDrawElements = *( DWORD * )MOHAA_GLDRAWELEMENTS;

    // Redirect
    *( DWORD * )MOHAA_GLBINDTEXTURE PtrToUlongglBindTextureHook );
    *( 
    DWORD * )MOHAA_GLDRAWELEMENTS PtrToUlongglDrawElementsHook );

    // Restore
    *( DWORD * )MOHAA_GLBINDTEXTURE g_dwGlBindTexture;
    *( 
    DWORD * )MOHAA_GLDRAWELEMENTS g_dwGlDrawElements
    Regards.
    Last edited by okidoki; 04-03-2009 at 03:52 PM.

  2. #2
    Join Date
    Aug 2007
    Posts
    220
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Rep Power
    48
    Very nice post OkiDoki well done

  3. #3
    Join Date
    Jan 2006
    Location
    Fort Bragg, NC
    Posts
    768
    Thanks
    1
    Thanked 8 Times in 5 Posts
    Rep Power
    75
    neat, although its been done before ( I believe shard posted a method ).
    Hello
    Haters Gonna Hate and Niggas Gonna Nig. That's life.

  4. #4
    Join Date
    Oct 2003
    Location
    Midlands, UK
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    83
    Yeah it was done a few years ago, I think it was tetuzo who originally discovered it. I don't remember the method ever being posted though.

    I did post a similar method for ET (or CoD?), which is what pingu must be thinking about.

  5. #5
    Join Date
    Dec 2003
    Location
    England
    Posts
    968
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    99
    Basically does the same as a GetProcAddress hook except you are overwriting afterwards. Nice work though.
    [00:17:27] [RunningBon] tis weird i smoked shitlaods and it didnt fefect me
    [00:19:44] [RunningBon] uidunoi lo
    [00:19:53] [RunningBon] is the ts stuill install on our server

    [19:06:47] [flexd] what engine does q3 use?
    [19:06:50] [flexd] unreal engine or something?
    www.cod4hacks.com

  6. #6
    Join Date
    Nov 2007
    Location
    Kangarooland
    Posts
    257
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Rep Power
    56
    Umm just a note, this looks like your modifying the import or export table of a module through static addresses.

    A quick example of what I mean:

    This is from CoD4, a simple reference to a user32.dll function.
    Code:
    0055A19C  |. 8BF0             MOV ESI,EAX
    0055A19E  |. 56               PUSH ESI                                 ; /hWnd
    0055A19F  |. FF15 1C136900    CALL DWORD PTR DS:[<&USER32.GetDC>]      ; \GetDC
    0055A1A5  |. 8BF8             MOV EDI,EAX
    1C136900 from the GetDC call translates to 0x69131C.

    A simple GetDC hook would be like:
    Code:
    void __stdcall PreGetDC ( void )
    {
    	/*Blah*/
    }
    
    unsigned long	GetDCOriginal	= 0;
    __declspec ( naked ) void GetDCHook ( void )
    {
    	_asm pushad
    	_asm call	PreGetDC
    	_asm popad
    	_asm jmp	GetDCOriginal
    }
    
    void InitHook ( void )
    {
    	GetDCOriginal			= *(unsigned long*) 0x69131C;
    	*(unsigned long*) 0x69131C	= (unsigned long) GetDCHook;
    }
    Patrick: we talked for 6 hours today
    Tamimego: yarp
    Patrick: exactly 6 hours
    Patrick: we are like girls
    Tamimego: no
    Tamimego: we are like programmers

  7. #7
    Join Date
    Oct 2003
    Location
    Midlands, UK
    Posts
    57
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    83
    MOHAA gets the GL functions through GetProcAddress and stores them in one block of memory (i.e. MOHAA_GLFUNCTIONS), so it's even simpler than modifying the imports table since you don't have to touch the memory protection. It doesn't matter that he's using static addresses either since there aren't going to be anymore updates to MOHAA.

  8. #8
    Join Date
    Dec 2003
    Location
    England
    Posts
    968
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    99
    Quote Originally Posted by okidoki View Post
    Hi,

    Yes it is 2ci-

    My goal was redirecting functions using pointers only (as I started to do for cge/cgi). Finally I got a full OpenGL and ClientGameXXport access without patching memory.

    Regards.
    Well you are patching memory, just not hooking GetProcAddress. Same result different method

    TLB hook is the best way though since it is static between games and doesn't require direct API hooking ;-)

    Another way is to getprocaddr all the funcs you need then scan the data section memory for the pointers
    [00:17:27] [RunningBon] tis weird i smoked shitlaods and it didnt fefect me
    [00:19:44] [RunningBon] uidunoi lo
    [00:19:53] [RunningBon] is the ts stuill install on our server

    [19:06:47] [flexd] what engine does q3 use?
    [19:06:50] [flexd] unreal engine or something?
    www.cod4hacks.com

  9. #9
    Join Date
    May 2003
    Location
    esreveR tsigolohcysP
    Posts
    316
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    93
    ^^ This is the exact same as in Warsow, which uses qfusion engine. I believe MoHAA uses something very similar.
    Please do not PM me asking how to open the menu. Search the source for "cActivationKey"

  10. #10
    Join Date
    Nov 2007
    Location
    Kangarooland
    Posts
    257
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Rep Power
    56
    Fakk2 Engine iirc
    Patrick: we talked for 6 hours today
    Tamimego: yarp
    Patrick: exactly 6 hours
    Patrick: we are like girls
    Tamimego: no
    Tamimego: we are like programmers

  11. #11
    Join Date
    Dec 2003
    Location
    England
    Posts
    968
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    99
    Same as Q3. That is why you get the "table"

    The "table" is just all the global gl pointers in memory
    [00:17:27] [RunningBon] tis weird i smoked shitlaods and it didnt fefect me
    [00:19:44] [RunningBon] uidunoi lo
    [00:19:53] [RunningBon] is the ts stuill install on our server

    [19:06:47] [flexd] what engine does q3 use?
    [19:06:50] [flexd] unreal engine or something?
    www.cod4hacks.com

  12. #12
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hello okidoki i tryed ur first method of hooking opengl/ game is sof2 so i searched the gldrawelements offset in sof2mp.exe and finded it definded and compiled the code but its not hooking anything here is the code if anyone could help then please answer

    PHP Code:
    #define Client_GLDRAWELEMENTS    0x4E5DA2

    typedef void WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices );

    GLDRAWELEMENTS_TYPE g_dwGlDrawElements NULL;

    void WINAPI glDrawElementsHookGLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices )
    {
      
        
        if(
    iCount==2538||iCount==3108||iCount==2802||iCount==2850||iCount==2634||iCount==2964||iCount==2940||iCount==2838||iCount==2700||iCount==2736||iCount==2724||iCount==2616||iCount==2928)
        {
            
    glDepthRange(-5.50);
        }    
        else
        {
            
    glDepthRange(01);
        }

        
        

        ( 
    g_dwGlDrawElements )( iModeiCountiTypepvIndices );
    }  




       


    bool WINAPI DllMain(HINSTANCE hDllDWORD dwReasonPVOID pvReserved)
    {
        if(
    dwReason == DLL_PROCESS_ATTACH)
        {

         
    g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
            *( 
    DWORD*)Client_GLDRAWELEMENTS PtrToUlong(glDrawElementsHook );    
            
            return 
    true;
        }
        else if(
    dwReason == DLL_PROCESS_DETACH)
        {
        }
        return 
    false;


  13. #13
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    First off thnx for the replay. Well i founded the offset from sof2mp.exe in other words on game executable. Thnx for the tip to check the module (is it loaded or not) OK for checking module im not home(so i couldnt test it) only weekends in home school right now but i think for cheking the module would do that:
    BTW the main idea why i tryed this method is to TRIX the punkbuster because standard hooking with detours and IAT are dedected and hooking pb strings main scan is now also dedected so i tought it can be hided from pb



    PHP Code:
    if( strstrhinstDLL"opengl32.dll" ) )
        {
         
    g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
            *( 
    DWORD*)Client_GLDRAWELEMENTS PtrToUlong(glDrawElementsHook ); 


  14. #14
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    sorry for late replay but im not geting this working i think i dont need to check opengl32.dll because i get the pointer from sof2.exe so mybe needing to wait cgame module like u said but still is this method safe from punkbuster ?

  15. #15
    Join Date
    Dec 2005
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Hello im not getting this working the hook loads into game fine but the wallhack jsut isnt there so i dont know what could cause it very weird. Mybe q3-engine based sof2 just cant be so hooked, or dunno i dont have any ideas ......





    PHP Code:
    #define Client_GLDRAWELEMENTS    0x4E5DA2

    typedef void WINAPI *GLDRAWELEMENTS_TYPE )( GLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices );

    GLDRAWELEMENTS_TYPE g_dwGlDrawElements NULL;


    void WINAPI glDrawElementsHookGLenum iModeGLsizei iCountGLenum iType, const GLvoid *pvIndices )
    {
      
        
        if(
    iCount==2538||iCount==3108||iCount==2802||iCount==2850||iCount==2634||iCount==2964||iCount==2940||iCount==2838||iCount==2700||iCount==2736||iCount==2724||iCount==2616||iCount==2928)    {
            
    glDepthRange(-5.50);
        }    
        else
        {
            
    glDepthRange(01);
        }


        ( 
    g_dwGlDrawElements )( iModeiCountiTypepvIndices );
    }  


    bool WINAPI DllMain(HINSTANCE hDllDWORD dwReasonPVOID pvReserved)
    {
        if(
    dwReason == DLL_PROCESS_ATTACH)
        {

        if(
    GetModuleHandle("opengl32.dll") == NULL)     
        {        
            
    g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
            *( 
    DWORD*)Client_GLDRAWELEMENTS PtrToUlong(glDrawElementsHook );    
        }
        



            if(
    GetModuleHandle("cgamex86.dll") == NULL)     
        {        
            
    g_dwGlDrawElements = *( GLDRAWELEMENTS_TYPE * )Client_GLDRAWELEMENTS;
            *( 
    DWORD*)Client_GLDRAWELEMENTS PtrToUlong(glDrawElementsHook );    
        }

        return 
    true;
        }
        else if(
    dwReason == DLL_PROCESS_DETACH)
        {
        }
        return 
    false;


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Perfect OpenGL models recognition
    By okidoki in forum Medal of Honor
    Replies: 4
    Last Post: 10-15-2009, 07:31 PM
  2. rather old opengl hook
    By pingu in forum Screen Shots
    Replies: 10
    Last Post: 05-07-2008, 10:14 AM
  3. OpenGL Hook v2
    By c0re in forum Public Releases
    Replies: 11
    Last Post: 12-29-2006, 11:14 AM
  4. opengl hook?
    By gfreeman1 in forum Beginner
    Replies: 5
    Last Post: 02-02-2003, 02:44 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts