{"id":24600792,"url":"https://github.com/cursey/safetyhook","last_synced_at":"2025-12-24T11:33:06.665Z","repository":{"id":53744612,"uuid":"442640898","full_name":"cursey/safetyhook","owner":"cursey","description":"C++23 procedure hooking library.","archived":false,"fork":false,"pushed_at":"2025-01-04T01:17:58.000Z","size":257,"stargazers_count":426,"open_issues_count":11,"forks_count":53,"subscribers_count":12,"default_branch":"main","last_synced_at":"2025-01-17T05:44:10.060Z","etag":null,"topics":["cmkr","detour","detours","hook","hooking","hooks"],"latest_commit_sha":null,"homepage":"https://cursey.dev/safetyhook","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsl-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cursey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-29T02:43:18.000Z","updated_at":"2025-01-16T17:04:25.000Z","dependencies_parsed_at":"2023-10-04T11:02:26.411Z","dependency_job_id":"b4f14f15-ecdc-45bb-bd47-8112dd1f31b9","html_url":"https://github.com/cursey/safetyhook","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cursey%2Fsafetyhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cursey%2Fsafetyhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cursey%2Fsafetyhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cursey%2Fsafetyhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cursey","download_url":"https://codeload.github.com/cursey/safetyhook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235448520,"owners_count":18991891,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cmkr","detour","detours","hook","hooking","hooks"],"created_at":"2025-01-24T14:01:33.505Z","updated_at":"2025-10-05T21:32:01.421Z","avatar_url":"https://github.com/cursey.png","language":"C++","funding_links":[],"categories":["Miscellaneous","Recently Updated","C++"],"sub_categories":["[Who Wants to Be a Millionare](https://www.boardgamecapital.com/who-wants-to-be-a-millionaire-rules.htm)"],"readme":"# SafetyHook\n\nSafetyHook is a **C++23** procedure hooking library for Windows x86 and x86_64 systems. It aims to make runtime procedure hooking as safe as possible while maintaining simplicity of its implementation. To that end it currently does:\n\n* Stops all other threads when creating or deleting hooks\n* Fixes the IP of threads that may be affected by the creation or deletion of hooks\n* Fixes IP relative displacements of relocated instructions (eg. `lea rax, [rip + 0x1234]`)\n* Fixes relative offsets of relocated instructions (eg. `jmp 0x1234`)\n* Widens short branches into near branches\n* Handles short branches that land within the trampoline\n* Uses a modern disassembler engine that supports the latest instructions\n* Has a carefully designed API that is hard to misuse\n\n## Installation\n\nSafetyHook can be added via CMake's `FetchContent`, git submodules, or copied directly into your project using the amalgamated builds. SafetyHook requires [Zydis](https://github.com/zyantific/zydis) to function.\n\n### Amalgamated builds\n\nThis is the easiest way to use safety hook. You can find amalgamated builds on the releases page. Simply download the ZIP file containing [Zydis](https://github.com/zyantific/zydis) (or without [Zydis](https://github.com/zyantific/zydis) if you already have it in your project) and copy the files into your project.\n\nYou may need to define `ZYDIS_STATIC_BUILD` if you're using the build with [Zydis](https://github.com/zyantific/zydis) included.\n\n### CMake FetchContent\n\n```CMake\ninclude(FetchContent)\n\n# Safetyhook\nFetchContent_Declare(\n    safetyhook\n    GIT_REPOSITORY \"https://github.com/cursey/safetyhook.git\"\n    GIT_TAG \"origin/main\"\n)\nFetchContent_MakeAvailable(safetyhook)\n```\n\nIf you want SafetyHook to fetch [Zydis](https://github.com/zyantific/zydis) you must enable the CMake option `-DSAFETYHOOK_FETCH_ZYDIS=ON`.\n\n## Usage\n\n```C++\n#include \u003ciostream\u003e\n\n#include \u003csafetyhook.hpp\u003e\n\n__declspec(noinline) int add(int x, int y) {\n    return x + y;\n}\n\nSafetyHookInline g_add_hook{};\n\nint hook_add(int x, int y) {\n    return g_add_hook.call\u003cint\u003e(x * 2, y * 2);\n}\n\nint main() {\n    std::cout \u003c\u003c \"unhooked add(2, 3) = \" \u003c\u003c add(2, 3) \u003c\u003c \"\\n\";\n\n    // Create a hook on add (This uses SafetyHook's easy API).\n    g_add_hook = safetyhook::create_inline(reinterpret_cast\u003cvoid*\u003e(add), reinterpret_cast\u003cvoid*\u003e(hook_add));\n\n    std::cout \u003c\u003c \"hooked add(3, 4) = \" \u003c\u003c add(3, 4) \u003c\u003c \"\\n\";\n\n    g_add_hook = {};\n\n    std::cout \u003c\u003c \"unhooked add(5, 6) = \" \u003c\u003c add(5, 6) \u003c\u003c \"\\n\";\n\n    return 0;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcursey%2Fsafetyhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcursey%2Fsafetyhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcursey%2Fsafetyhook/lists"}