xosski

calc.exe

Mar 17th, 2026
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1.  
  2. c
  3. #include
  4. #include
  5.  
  6. // Target function signature (adjust based on actual params)
  7. typedef int (*TargetFunc)(void* rdi, void* rsi, void* rdx, void* rcx, void* r8, void* r9);
  8.  
  9. // Original function pointer
  10. TargetFunc OriginalFunc = NULL;
  11.  
  12. // Our hook implementation
  13. int __fastcall HookFunc(void* rdi, void* rsi, void* rdx, void* rcx, void* r8, void* r9) {
  14. // Log parameters (adjust based on your needs)
  15. printf("[HOOK] Called with rdi: %p, rsi: %p\n", rdi, rsi);
  16.  
  17. // Your custom logic here
  18. // Example: Block certain operations or modify behavior
  19.  
  20. // Call original function
  21. return OriginalFunc(rdi, rsi, rdx, rcx, r8, r9);
  22. }
  23.  
  24. // Installation function
  25. void InstallHook() {
  26. // Find target function address (adjust to your needs)
  27. void* targetAddr = (void*)0x7FFE7B54A816; // Example address
  28.  
  29. // Create trampoline (adjust based on architecture)
  30. BYTE jmp[] = { 0xE9, 0x00, 0x00, 0x00, 0x00 }; // JMP rel32
  31.  
  32. // Calculate relative jump
  33. DWORD offset = (DWORD)((BYTE*)HookFunc - (BYTE*)targetAddr - 5);
  34. memcpy(&jmp[1], &offset, 4);
  35.  
  36. // Save original bytes
  37. DWORD oldProtect;
  38. VirtualProtect(targetAddr, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
  39.  
  40. // Install hook
  41. memcpy(targetAddr, jmp, 5);
  42.  
  43. // Restore protection
  44. VirtualProtect(targetAddr, 5, oldProtect, &oldProtect);
  45.  
  46. // Get original function pointer (adjust based on your needs)
  47. OriginalFunc = (TargetFunc)((BYTE*)targetAddr + 5);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment