{"id":16322265,"url":"https://github.com/p-x9/swift-hook","last_synced_at":"2025-04-10T04:56:07.415Z","repository":{"id":215734012,"uuid":"734966983","full_name":"p-x9/swift-hook","owner":"p-x9","description":"⚓️ A Swift Library for hooking swift methods and functions.","archived":false,"fork":false,"pushed_at":"2025-03-15T04:02:39.000Z","size":66,"stargazers_count":87,"open_issues_count":1,"forks_count":5,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-02T21:48:01.857Z","etag":null,"topics":["interpolation","swizzling"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/p-x9.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":"2023-12-23T07:22:25.000Z","updated_at":"2025-04-01T16:05:18.000Z","dependencies_parsed_at":"2024-01-08T11:01:28.714Z","dependency_job_id":"618e0d36-1d68-4c88-9ad8-77e34c2bd734","html_url":"https://github.com/p-x9/swift-hook","commit_stats":null,"previous_names":["p-x9/swift-hook"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2Fswift-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2Fswift-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2Fswift-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/p-x9%2Fswift-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/p-x9","download_url":"https://codeload.github.com/p-x9/swift-hook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248161261,"owners_count":21057554,"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":["interpolation","swizzling"],"created_at":"2024-10-10T22:50:26.091Z","updated_at":"2025-04-10T04:56:07.390Z","avatar_url":"https://github.com/p-x9.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftHook\n\nA Swift Library for hooking swift methods and functions.\n\n\u003c!-- # Badges --\u003e\n\n[![Github issues](https://img.shields.io/github/issues/p-x9/swift-hook)](https://github.com/p-x9/swift-hook/issues)\n[![Github forks](https://img.shields.io/github/forks/p-x9/swift-hook)](https://github.com/p-x9/swift-hook/network/members)\n[![Github stars](https://img.shields.io/github/stars/p-x9/swift-hook)](https://github.com/p-x9/swift-hook/stargazers)\n[![Github top language](https://img.shields.io/github/languages/top/p-x9/swift-hook)](https://github.com/p-x9/swift-hook/)\n\n## How works\n\n- **Function / Struct Method**\nHook by [facebook/fishhook](https://github.com/facebook/fishhook).\n\n- **Objective-C Class Method**\nSimply, Objective-C runtime is used.\n\n- **Swift Class Method**\nHook by rewriting Vtable.\n\n## Usage\n\n\u003e [!NOTE]\n\u003e To hook a function that exists in your own image, you must specify the following linker flag.\n\u003e `\"-Xlinker -interposable\"`\n\u003e\n\u003e Reference: [johnno1962/SwiftTrace](https://github.com/johnno1962/SwiftTrace)\n\n### Hook\n\n#### Function / Struct Method\n\nThe `targetFunction` implementation is replaced by the `replacementFunction` implementation.\nThe original implementation is moved to `originalFunction`.\n\nIt is possible to call an `originalFunction` within a `replacementFunction`.\n\n```swift\ntry SwiftHook.hookFunction(\n    \"SwiftHookTests.targetFunction() -\u003e Swift.String\",\n    \"SwiftHookTests.replacementFunction() -\u003e Swift.String\",\n    \"SwiftHookTests.originalFunction() -\u003e Swift.String\",\n    isMangled: false\n)\n\n/* using mangled symbol names */\ntry SwiftHook.hookFunction(\n    \"$s14SwiftHookTests14targetFunctionSSyF\",\n    \"$s14SwiftHookTests19replacementFunctionSSyF\",\n    \"$s14SwiftHookTests16originalFunctionSSyF\",\n    isMangled: true\n)\n```\n\n### Exchange Implementation\n\n#### Function / Struct Method\n\n```swift\nSwiftHook.exchangeFuncImplementation(\n    \"SwiftHookTests.StructItem.printA() -\u003e Swift.String\",\n    \"SwiftHookTests.StructItem.printB() -\u003e Swift.String\",\n    isMangled: false\n)\n\n/* using mangled symbol names */\nSwiftHook.exchangeFuncImplementation(\n    \"$s14SwiftHookTests21hook_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_SSAISus6UInt32VtF\",\n    \"$s14SwiftHookTests25XXXXhook_assertionFailure__4file4line5flagss5NeverOs12StaticStringV_A2ISus6UInt32VtF\",\n    isMangled: false\n)\n```\n\n#### Class Method\n\n```swift\n/// Swift Class\ntry SwiftHook.exchangeMethodImplementation(\n    \"SwiftHookTests.SwiftClassItem.mul2(Swift.Int) -\u003e Swift.Int\",\n    \"SwiftHookTests.SwiftClassItem.add2(Swift.Int) -\u003e Swift.Int\",\n    for: SwiftClassItem.self\n)\n\n// Objective-C Class\ntry SwiftHook.exchangeMethodImplementation(\n    \"mul2:\",\n    \"add2:\",\n    for: ObjCClassItem.self\n)\n```\n\n## License\n\nswift-hook is released under the MIT License. See [LICENSE](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-x9%2Fswift-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fp-x9%2Fswift-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fp-x9%2Fswift-hook/lists"}