Skip to main content

A native Cython memory integrity and unhooking library for Windows

Project description

AntiHook Engine

A lightweight, high-performance user-mode memory integrity and unhooking engine for Windows, written in Cython.

It scans the Export Address Table (EAT) of loaded PE modules (e.g., ntdll.dll) to detect instruction redirects (relative, absolute, or indirect jumps) and restores their original .text sections from clean system files on disk.

Features

  • Native PE Parsing: Traverses module exports with zero Python overhead using direct memory pointers.
  • Hook Detection: Identifies standard user-mode hooks (relative, absolute, and indirect jumps).
  • Origin Tracking: Resolves the exact path of the third-party DLL or security product placing the hook.
  • In-Memory Restoration (Perun's Fart): Replaces modified memory bytes with pristine bytes cloned directly from a suspended process's memory space, avoiding suspicious disk I/O.
  • Minimized CRT Dependency: Reduces reliance on the C Runtime (CRT) by utilizing custom-implemented string and memory operations, retaining only essential allocations (malloc and free).

Quick Start

Requirements

  • Operating System: Windows (x64 architecture only)
  • Python: version 3.8 or higher
  • Compiler: Visual Studio C++ Build Tools (MSVC Compiler)

Open the appropriate Visual Studio Native Tools Command Prompt and run:

pip install antihook

2. Usage

import antihook
import ctypes
import json

# Ensure target system DLL is loaded
ctypes.windll.ntdll

# Scan ntdll.dll
scan = antihook.unhook("ntdll.dll", scan_only=True)
print("Scan Results:", json.dumps(scan, indent=4))

# Restore ntdll.dll .text section
restored = antihook.unhook("ntdll.dll", scan_only=False)
print("Unhook Results:", json.dumps(restored, indent=4))

API Reference

unhook(module_name: str, scan_only: bool = False) -> dict

  • module_name: Target DLL name (e.g., "ntdll.dll").
  • scan_only: If True, only reports hooks. If False, performs the full unhooking routine.

Returns:

{
    "status": "success",
    "unhooked": true,
    "detected_hooks": [
        {
            "function": "NtCreateFile",
            "type": "Relative",
            "hook_address": "0x7FFE12345678",
            "hook_module": "C:\\Windows\\System32\\monitor.dll"
        }
    ]
}

Disclaimer

This project is intended strictly for authorized security research, application self-defense, and educational purposes. Modifying execution sections of system libraries in memory can cause instability if handled incorrectly. Use with caution.

License

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

antihook-0.1.8.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

antihook-0.1.8-cp314-cp314-win_amd64.whl (32.0 kB view details)

Uploaded CPython 3.14Windows x86-64

File details

Details for the file antihook-0.1.8.tar.gz.

File metadata

  • Download URL: antihook-0.1.8.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for antihook-0.1.8.tar.gz
Algorithm Hash digest
SHA256 189f6d5fe74d9d2c75a586692ee4c3cefa95cbe0f2e0807597ac8752f81cd4ce
MD5 53423417bc254ca70aa4b907377771a9
BLAKE2b-256 446d9254c9bae34a54dcc76623aef207fdbddcd3f892496c517459e2c5987d23

See more details on using hashes here.

File details

Details for the file antihook-0.1.8-cp314-cp314-win_amd64.whl.

File metadata

  • Download URL: antihook-0.1.8-cp314-cp314-win_amd64.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: CPython 3.14, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for antihook-0.1.8-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 f8065179b869109726ea4e2c04e4666cdd0f19fd161b29b52139e103a7418f83
MD5 19ac5084fed738541b68fec88f9231b6
BLAKE2b-256 accb8c53b4e36051f95719e0cdf75fb230e3d655f15ecd915a63f4bdb04d5ec0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page