Click here to Skip to main content
15,884,010 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Well, i want to learn about hooking, but it seems that the tutorials found on the internet won't run.

What i want to do is a jump hook, in C++.

Here's the code :

C++
void DoHook(DWORD* Address, DWORD* Hook, DWORD pid){   

    HANDLE Server = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ , false, pid );
    Address = (DWORD*)Address + 0x18;
    DWORD OldProt;     
    DWORD HookOffset = (DWORD*)Hook-(DWORD*)Address-5;
    std::wcout << "Hook on address" << std::hex << Address<< std::endl;
    std::wcout << "Hook offset is " << std::hex << HookOffset << std::endl;

    if ( ! VirtualProtectEx(Server, (LPVOID) Address, 40,PAGE_EXECUTE_READWRITE, &OldProt) ) {
        ErrorExit(L"VirtualProtectEx");
    };

    char* CharPointer = (char*) Address;
    BYTE newdata[5]={0xE9}; 
    BYTE x;
    int i = 1;
    while ( HookOffset > 0 ) {
        x = HookOffset & 0xff;
        newdata[5-i] = x;
        i++;
        HookOffset >>= 8;
    }
    std::wcout << "Bytes " <<newdata[0] << " " << newdata[1] << " " << newdata[2] << " " << newdata[3] << " " << newdata[4] << std::endl;

    DWORD newdatasize = sizeof(newdata);
    if ( ! WriteProcessMemory(Server,Address,(LPCVOID*)newdata,newdatasize,NULL) ) {
        ErrorExit(L"WriteProcessMemory");
    }

//  VirtualProtect((void*) Address, 40, 0x40, &OldProt);

    return;
}


Here's some output text :
C++
Process ID is 2764 // PID of the app that's being hooked
Function address is 00A81190 // this is the function i'm doing the jump to
Entry point is 00080000 // for the app that's being hooked
Hook on address 00080060 // for the app that's being hooked
Hook offset is 28048e // HookAddress - FunctionAddress - 5
Bytes e9 0 28 4 8e // this is the jump i'm planning to do
Press any key to continue . . .

However, the application doesn't update.
Posted
Comments
pasztorpisti 10-Sep-13 2:18am    
Do you believe that someone can find out what happens on YOUR machine? Use a debugger, noone will be able to answer this.
iDebD 19-Sep-13 6:06am    
debug it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900