Hacking Tricks Hooking class

Discussion in 'Ethical Hacking Tricks' started by Muhammad Faiz Bin Adham, Aug 10, 2014.

  1. Muhammad Faiz Bin Adham

    Muhammad Faiz Bin Adham New Member

    Joined:
    Aug 10, 2014
    Messages:
    2
    Likes Received:
    2
    Trophy Points:
    3


    Hook.h
    Code:
    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    class hook
    {
    public:
        DWORD m_Function_Start;
        DWORD m_Offset;
        DWORD m_Hook_Func;
        DWORD m_size;
        DWORD m_ret;
        hook(DWORD Function_Start,DWORD Offset,DWORD Hook_Func,DWORD size);
        hook();
            ~hook();
        void UnHook();
        void ApplyHook();
    private:
        DWORD m_addr;
        BYTE* bOrig;
        BYTE* bHooked;
    };
    hook.cpp
    Code:
    #include "hook.h"
    
    hook::hook(DWORD Function_Start,DWORD Offset,DWORD Hook_Func,DWORD size)
    {
        this->m_size = size;
        this->m_Function_Start = Function_Start;
        this->m_Hook_Func = Hook_Func;
        this->m_Offset = Offset;
        this->bOrig = (BYTE*)malloc(size);
        this->bHooked = (BYTE*)malloc(size);
        this->m_addr = Function_Start+Offset;
        this->m_ret = this->m_addr + this->m_size;
        DWORD dwRelAddr;
        dwRelAddr = (DWORD) (this->m_Hook_Func - this->m_addr) - 5;
        this->bHooked[0] = 0xE9;
        *(DWORD*)(this->bHooked+1) = dwRelAddr;
        for(int x = 5; x < this->m_size; x++)
            *(BYTE*)(this->bHooked+x) = 0x90;
        memcpy(this->bOrig,(void*)this->m_addr,this->m_size);
    }
    hook::hook()
    {
        this->m_size = 0;
        this->m_Function_Start = 0;
        this->m_Hook_Func = 0;
        this->m_Offset = 0;
        this->bOrig = 0;
        this->bHooked = 0;
        this->m_addr = 0;
        this->m_ret = 0;
    }
    void hook::UnHook()
    {
        DWORD dwOldProtect;
        VirtualProtect((LPVOID)this->m_addr, this->m_size, PAGE_EXECUTE_READWRITE, &dwOldProtect);
        memcpy((void*)this->m_addr,this->bOrig,this->m_size);
        VirtualProtect((LPVOID)this->m_addr, this->m_size, dwOldProtect, 0);
    }
    void hook::ApplyHook()
    {
        DWORD dwOldProtect;
        VirtualProtect((LPVOID)this->m_addr, this->m_size, PAGE_EXECUTE_READWRITE, &dwOldProtect);
        memcpy((void*)this->m_addr,this->bHooked,this->m_size);
        VirtualProtect((LPVOID)this->m_addr, this->m_size, dwOldProtect, 0);
    }
    hook::~hook()
    {
        free(bOrig);
        free(bHooked);
    }
    How to use:
    Code:
    __declspec(naked) void nReset()
    {
        _asm{
            pushad
            pushfd
        }
        if(pFont)
            pFont->OnLostDevice();
        hkReset.UnHook(); //Unhook to call orig function without a loop
        _asm{
            mov eax, [ebp+8d]
            push eax
            mov eax, [ebp+12d]
            push eax
            call hkReset.m_Function_Start
        }
        if(pFont)
            pFont->OnResetDevice();
        hkReset.ApplyHook();
        _asm{
            popfd
            popad
            mov edi, edi
            push ebp
            mov ebp, esp
            jmp hkReset.m_ret
        }
    }
    Code:
    hkReset = hook(D3D9_VTABLE[16],0,(DWORD)nReset,5);
        hkReset.ApplyHook();



     
    nikunj chaudhary likes this.


    RELATED POSTS


  2. hackingtosh

    hackingtosh Guest


  3. booblemush

    booblemush Guest



    nice one bro
     

  4. Bibek Shah

    Bibek Shah New Member

    Joined:
    Oct 10, 2014
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6


    thanks for sharing the code
     

  5. AZERTTY

    AZERTTY New Member

    Joined:
    Oct 7, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    8


    thanks for the code
     

  6. AZERTTY

    AZERTTY New Member

    Joined:
    Oct 7, 2014
    Messages:
    14
    Likes Received:
    0
    Trophy Points:
    8


    thanks for the code
     

  7. sundanese

    sundanese Member

    Joined:
    Jul 12, 2014
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    18


    thanks for this share dude, i love this share so much every time every where ............. muuuuuuuuuuuuuuuuuuuuuuuuuaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhh
     

  8. RappaJoy

    RappaJoy Member

    Joined:
    Jul 16, 2014
    Messages:
    56
    Likes Received:
    0
    Trophy Points:
    18


    Nice one thanks for sharing :D
     

  9. vicky

    vicky Member

    Joined:
    Sep 1, 2014
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    16


    thanku 222
     

  10. vvij

    vvij New Member

    Joined:
    Oct 4, 2014
    Messages:
    38
    Likes Received:
    0
    Trophy Points:
    6


    thanks for the codeee
     

  11. sartre

    sartre Member

    Joined:
    Oct 15, 2014
    Messages:
    69
    Likes Received:
    1
    Trophy Points:
    18


    Better goods
     

  12. sajid

    sajid Member

    Joined:
    Oct 11, 2014
    Messages:
    66
    Likes Received:
    0
    Trophy Points:
    18


    kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
     

  13. samuelgangstar

    samuelgangstar Active Member

    Joined:
    Jul 16, 2014
    Messages:
    70
    Likes Received:
    18
    Trophy Points:
    28


    thank you for information
     

Share This Page