Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Hooking pr_write problem

Hooking pr_write problem

Scheduled Pinned Locked Moved C / C++ / MFC
help
1 Posts 1 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cd0c
    wrote on last edited by
    #1

    Trying to hook pr_write in ff. I'm injecting dll to a process, process is not crashing but hooked proc in not calling. Help plz to find error in code.

    typedef int (*PR_Write)(void* fd, const void* buf, int amount);
    PR_Write old = (PR_Write)(ProcAddress);

    int HookedPR_Write(void* fd, char* buf, int amount) {

    MessageBoxA(NULL,"hooked func","",MB\_OK);   
    return old(fd, buf, amount);
    

    }

    BYTE* Trampoline(BYTE* src, BYTE* dst, int len) {
    BYTE patch[5];
    BYTE* addr = (BYTE*)VirtualAlloc(NULL, len, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    SIZE_T written;
    memcpy_s(addr, len, src, len);
    uintptr_t gatewayrelative = src - addr - 5;

    memcpy\_s(patch, 1, "\\xE9", 1);
    
    \*(uintptr\_t\*)(patch + 1) = gatewayrelative;
    
    if (!WriteProcessMemory(GetCurrentProcess(), addr + len, patch, 5, &written))
        MessageBoxA(NULL, "WriteProcessMemory error", "", MB\_OK);
    Detour(src, dst, len);
    return addr;
    

    }

    void Detour(BYTE* src, BYTE* dst, int len) {
    BYTE patch[11];
    SIZE_T written;

    uintptr\_t relative\_addr = dst - src - 5;
    memcpy\_s(patch, 1, "\\xE9", 1);
    \*(uintptr\_t\*)(patch + 1) = relative\_addr;
    memset(patch + 5, 0x90, len - 5);
    if (!WriteProcessMemory(GetCurrentProcess(), ProcAddress, patch, sizeof(patch), &written))
        MessageBoxA(NULL, "WriteProcessMemory detour error", "Caption", MB\_OK); 
    

    }

    BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
    {
    ProcAddress = (void*)GetProcAddress(LoadLibraryA("nss3.dll"), "PR_Write");
    int stopSize = 0;
    while (*((BYTE*)ProcAddress + stopSize) != 0xFF) {
    stopSize++;
    }
    if (ul_reason_for_call == DLL_PROCESS_ATTACH)
    {
    if (ProcAddress != NULL) {
    old = (PR_Write)Trampoline((BYTE*)ProcAddress, (BYTE*)HookedPR_Write, stopSize);
    }
    }
    return TRUE;
    }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups