Results 1 to 6 of 6
  1. #1
    trojan.win128's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Nix Olympica, Mars
    Posts
    58
    Reputation
    10
    Thanks
    90

    Remove Detour/Unhook

    Here is the DetourFunction (in injected DLL):
    Code:
    int initHook(void)
    {
    	DWORD *vTable;
    	HMODULE hMod;
    
    	do{
    		hMod = GetModuleHandleA("d3d9.dll");
    		Sleep(50);
    	}while(!hMod);
    
    	DWORD addy = dwFindPattern((DWORD)hMod,0x128000,(PBYTE)"\xC7\x06\x00\x00\x00\x00\x89\x86\x00\x00\x00\x00\x89\x86","xx????xx????xx");
    	if(addy)
    	{
    		memcpy(&vTable,(void *)(addy +0x2),4);
    		EndScene_orig = (EndSceneType)DetourFunction((PBYTE)vTable[42],(PBYTE)EndSceneDetour);
    	}
    	return true;
    }
    I tried doing this:
    Code:
    DetourRemove((PBYTE)EndScene_orig, (PBYTE)EndSceneDetour);
    But for some reason, the game crashes when I unload the DLL.

    Any help is appreciated!
    Successful trades with:
    Dark21890 (Genuine Trader)

  2. #2
    Pingo's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    687
    Reputation
    24
    Thanks
    865
    My Mood
    Blah
    My guess is you're not writing the original bytes back to the EndScene address.
    So it tries to jump to some deallocated memory and crashes.
    Just a guess..

  3. The Following User Says Thank You to Pingo For This Useful Post:

    trojan.win128 (05-13-2013)

  4. #3
    trojan.win128's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Nix Olympica, Mars
    Posts
    58
    Reputation
    10
    Thanks
    90
    Quote Originally Posted by Pingo View Post
    My guess is you're not writing the original bytes back to the EndScene address.
    So it tries to jump to some deallocated memory and crashes.
    Just a guess..
    Any suggestions on how I should reset it back to normal?
    Should I create a copy of the default memory before hooking?

    EDIT:
    Nevermind, the DetourRemove function is working like a charm now. Had problems with some EndScene codes.
    Last edited by trojan.win128; 05-13-2013 at 10:02 AM.
    Successful trades with:
    Dark21890 (Genuine Trader)

  5. #4
    Pingo's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Posts
    687
    Reputation
    24
    Thanks
    865
    My Mood
    Blah
    Quote Originally Posted by trojan.win128 View Post
    Any suggestions on how I should reset it back to normal?
    Should I create a copy of the default memory before hooking?
    Yeah copy the first 5 bytes before hooking and store it.
    Write the default bytes back before unloading the dll.
    See if that helps any.

  6. #5
    topblast's Avatar
    Join Date
    Mar 2010
    Gender
    male
    Location
    Far from around you Programmer: C++ | VB | C# | JAVA
    Posts
    3,607
    Reputation
    149
    Thanks
    5,052
    My Mood
    Cool
    I made this,

    Code:
    //Hook
    ReturnPresent = DetourCreate( (PBYTE)dwTable[17], &hkPresent, 7); // hkPresent is the function
    //delete Hook
    datareturn dt = DetourDelete(ReturnPresent);//delete
    // Recreate Hook
    ReturnPresent = DetourCreate(dt.function, &hkPresent, dt.len);
    
    
    typedef struct 
    {
        const INT len;
        PBYTE function;
    } datareturn;
    
    
    template<typename t>
    datareturn dxHook::DetourDelete( t& dst )
    {
        BYTE *jmp = (BYTE *)dst;
        datareturn* dt = (datareturn*)(jmp - sizeof(datareturn));
        auto len = dt->len;
        auto src = dt->function;
        DWORD dwback;
        VirtualProtect(src, len, PAGE_READWRITE, &dwback);
        memcpy(dt->function, jmp, dt->len);
        jmp -= sizeof(datareturn);
        datareturn retdt = {len, src};
    
    
        VirtualProtect(src, len, dwback, &dwback);
        free(jmp);
        dst = NULL;
        return retdt;
    }
    
    
    template<typename t>
    t dxHook::DetourCreate(PBYTE src, t dst, const INT len)
    {
        BYTE *jmp = (BYTE *)malloc(sizeof(datareturn) + len + 5 );            
        datareturn dt = {len, src};
    
    
        memcpy(jmp, &dt, sizeof(datareturn));
        jmp += sizeof(datareturn);
        DWORD dwback;
        VirtualProtect(src, len, PAGE_EXECUTE_READWRITE, &dwback);
        memcpy(jmp, src, len);
        jmp += len;
        jmp[0] = 0xE9;
        *(DWORD *)(jmp + 1) = (DWORD)(src + len - jmp) - 5;            
        src[0] = 0xE9;
        *(DWORD *)(src + 1) = (DWORD)((PBYTE)dst - src) - 5;
        for(INT i = 5; i < len; i++) src[i] = 0x90;
        VirtualProtect(src, len, dwback, &dwback);
    
    
        return(t)(jmp - len);
    }
    Last edited by topblast; 05-13-2013 at 01:40 PM.
    I just like programming, that is all.

    Current Stuff:

    • GPU Programmer (Cuda)
    • Client/Server (Cloud Server)
    • Mobile App Development

  7. The Following User Says Thank You to topblast For This Useful Post:

    trojan.win128 (05-13-2013)

  8. #6
    trojan.win128's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Location
    Nix Olympica, Mars
    Posts
    58
    Reputation
    10
    Thanks
    90
    @topblast Thanks!

    I'll try that in my next projects.
    Successful trades with:
    Dark21890 (Genuine Trader)

Similar Threads

  1. should we REMOVE THE EDIT BUTTON?
    By ace76543 in forum Spammers Corner
    Replies: 12
    Last Post: 02-04-2021, 02:01 PM
  2. [removing word filter] "Fuck" you want
    By analog70 in forum WarRock - International Hacks
    Replies: 3
    Last Post: 03-01-2007, 04:16 PM
  3. Remove MSN Live 8.0 Ads [GUIDE
    By barney in forum Hardware & Software Support
    Replies: 4
    Last Post: 12-15-2006, 05:25 PM
  4. removing the edit button, attempt 2
    By ace76543 in forum Spammers Corner
    Replies: 19
    Last Post: 12-11-2006, 04:49 PM
  5. removing softnyx nprotect!!!
    By terence in forum General Game Hacking
    Replies: 12
    Last Post: 01-08-2006, 12:57 AM