CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Apr 2014
    Posts
    61

    Question How restore inline hooks?

    I'm needing restore one inline hook in a app made by a third party program.

    I alredy know that firstly is need to load the target module for reading and calculate the offset to the target API:

    Code:
    // Get the module handle and function address.. 
    auto modGdi32 = GetModuleHandle("GDI32.dll"); 
    auto funcBitBlt = GetProcAddress(modGdi32, "BitBlt"); 
    
    // Calculate the function offset.. 
    auto offBitBlt = (uintptr_t)funcBitBlt - (uintptr_t)modGdi32;
    So, now that i know the offset to the function, how i can use that to calculate and read the original function data directly from the file loaded to get the original data and then restore it to the loaded module data?

    Eg:

    if any third party software make something like this in my app:

    Code:
      DWORD NtHookInstall(LPVOID lpTargetAddress,LPVOID lpCallbackAddress)
        {
          if(lpTargetAddress == 0 || lpCallbackAddress == 0) return 0; 
    
              DWORD dwOldProtection = 0;
                if(VirtualProtect(lpTargetAddress,7,PAGE_EXECUTE_READWRITE,&dwOldProtection) == 0) return 0;
    
                  *(BYTE*)(lpTargetAddress)= 0xE9;  
                  *(long*)((LPBYTE)lpTargetAddress+1) = ((DWORD)lpCallbackAddress - ((DWORD)lpTargetAddress + 5));
                   VirtualProtect(lpTargetAddress,7,dwOldProtection,&dwOldProtection); 
                 return 1; 
        }
    
    void Callback()
    {
    
    SetLastError(5);
    
    }
    
    // Usage:
    
    NtHookInstall(GetProcAddress(GetModuleHandleW(L"ntdll.dll"),"ZwOpenProcess"), (LPVOID) Callback);
    Then, how revert any inline hook, independent how was coded, like is made by PC Hunter software:



    Any suggestion or help will welcome.
    Last edited by FL4SHC0D3R; January 30th, 2017 at 12:33 AM.

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
  •  





Click Here to Expand Forum to Full Width

Featured