{"id":23426965,"url":"https://github.com/nanitefactory/gominhook","last_synced_at":"2025-04-12T19:08:14.373Z","repository":{"id":57491814,"uuid":"151430486","full_name":"NaniteFactory/gominhook","owner":"NaniteFactory","description":"MinHook binding for Go (Golang) with support for Windows API.","archived":false,"fork":false,"pushed_at":"2019-07-04T08:17:24.000Z","size":38,"stargazers_count":79,"open_issues_count":2,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-12T19:08:06.478Z","etag":null,"topics":["api-hook","go","golang","hacking","hooking","library","module","win32api","windows"],"latest_commit_sha":null,"homepage":"https://www.youtube.com/watch?v=rMQqD08C3Wc","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NaniteFactory.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}},"created_at":"2018-10-03T14:57:13.000Z","updated_at":"2024-12-25T15:30:18.000Z","dependencies_parsed_at":"2022-08-30T23:21:11.118Z","dependency_job_id":null,"html_url":"https://github.com/NaniteFactory/gominhook","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaniteFactory%2Fgominhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaniteFactory%2Fgominhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaniteFactory%2Fgominhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NaniteFactory%2Fgominhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NaniteFactory","download_url":"https://codeload.github.com/NaniteFactory/gominhook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618276,"owners_count":21134200,"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":["api-hook","go","golang","hacking","hooking","library","module","win32api","windows"],"created_at":"2024-12-23T06:16:05.747Z","updated_at":"2025-04-12T19:08:14.339Z","avatar_url":"https://github.com/NaniteFactory.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gominhook\r\n\r\n`gominhook` is a Golang wrapper of [minhook](https://github.com/TsudaKageyu/minhook).\r\n\r\nThis stuff heavily relies on `cgo`.\r\n\r\n- - -\r\n\r\n### Installation\r\n\r\n1. Install `gominhook`.\r\n    \r\n    `go get -v github.com/nanitefactory/gominhook`\r\n\r\n2. Get `Minhook` library.\r\n\r\n\t---\r\n\r\n\t**For x64 users:**\r\n\r\n\tHave `MinHook.x64.dll` with your project.\r\n\r\n\tYou can get it from either of these sites:\r\n\r\n\t- [gominhook/MinHook_133_bin/bin/MinHook.x64.dll](./MinHook_133_bin/bin)\r\n\r\n\t- https://github.com/TsudaKageyu/minhook/releases\r\n\r\n\t---\r\n\r\n\t**For x86 users:**\r\n\r\n\tYou need `MinHook.gcc.x86.dll`.\r\n\r\n\t- [gominhook/MinHook_133_bin/bin/MinHook.gcc.x86.dll](./MinHook_133_bin/bin)\r\n\r\n\t---\r\n\r\n3. That's it!\r\n\r\n    `import \"github.com/nanitefactory/gominhook\"`\r\n\r\n- - -\r\n\r\n### Exports\r\n\r\nHere is a list of all supported functions \u0026 data by `gominhook`,\r\n\r\n```Go\r\nfunc gominhook.Initialize() error\r\nfunc gominhook.Uninitialize() error\r\n```\r\n\r\n```Go\r\nfunc gominhook.CreateHook(pTarget, pDetour, ppOriginal uintptr) error\r\nfunc gominhook.CreateHookAPI(strModule, strProcName string, pDetour, ppOriginal uintptr) error\r\nfunc gominhook.CreateHookAPIEx(strModule, strProcName string, pDetour, ppOriginal, ppTarget uintptr) error\r\n```\r\n\r\n```Go\r\nfunc gominhook.RemoveHook(pTarget uintptr) error\r\nfunc gominhook.EnableHook(pTarget uintptr) error\r\nfunc gominhook.DisableHook(pTarget uintptr) error\r\n```\r\n\r\n```Go\r\nfunc gominhook.QueueEnableHook(pTarget uintptr) error\r\nfunc gominhook.QueueDisableHook(pTarget uintptr) error\r\nfunc gominhook.ApplyQueued() error\r\n```\r\n\r\n```Go\r\nconst gominhook.AllHooks = NULL\r\nconst gominhook.NULL = 0\r\n```\r\n\r\nwhich is straightforward \u0026 effective enough. xD\r\n\r\n- - -\r\n\r\n### Samples\r\n\r\n- https://github.com/NaniteFactory/hookwin10calc\r\n- https://gist.github.com/NaniteFactory/181ac6be5ac13c200612677f17e3f352\r\n\r\nThis example below tries to hook `user32.MessageBoxW`.\r\n\r\n```Go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"log\"\r\n\t\"syscall\"\r\n\t\"unsafe\"\r\n\r\n\t\"github.com/nanitefactory/gominhook\"\r\n)\r\n\r\n/*\r\n#include \u003cWindows.h\u003e\r\n\r\n// Put C prototypes here\r\n\r\n// Delegate type for calling original MessageBoxW.\r\ntypedef int (WINAPI *MESSAGEBOXW)(HWND, LPCWSTR, LPCWSTR, UINT);\r\n\r\n// (!) This way you can connect/convert a go function to a c function.\r\nint MessageBoxWOverrideHellYeah(HWND hWnd, LPCWSTR lpText, LPCWSTR lpCaption, UINT uType);\r\n*/\r\nimport \"C\"\r\n\r\n// Pointer for calling original MessageBoxW.\r\nvar fpMessageBoxW C.MESSAGEBOXW\r\n\r\n// (!) This way you can connect/convert a go function to a c function.\r\n//export MessageBoxWOverrideHellYeah\r\nfunc MessageBoxWOverrideHellYeah(hWnd C.HWND, lpText C.LPCWSTR, lpCaption C.LPCWSTR, uType C.UINT) C.int {\r\n\tfmt.Println(\" - MessageBoxW Override\")\r\n\tfoo()\r\n\tret, _, _ := syscall.Syscall6(\r\n\t\tuintptr(unsafe.Pointer(fpMessageBoxW)),\r\n\t\t4,\r\n\t\tuintptr(unsafe.Pointer(hWnd)),\r\n\t\tuintptr(unsafe.Pointer(lpText)),\r\n\t\tuintptr(unsafe.Pointer(lpCaption)),\r\n\t\tuintptr(uint(uType)),\r\n\t\t0, 0,\r\n\t)\r\n\treturn C.int(ret)\r\n}\r\n\r\nfunc foo() {\r\n\tfmt.Println(\" - I'm so hooked now.\")\r\n}\r\n\r\nfunc main() {\r\n\t// Initialize minhook\r\n\terr := gominhook.Initialize()\r\n\tif err != nil {\r\n\t\tlog.Fatalln(err)\r\n\t}\r\n\tdefer gominhook.Uninitialize()\r\n\r\n\t// Get procedure user32.MessageBoxW\r\n\tprocedure := syscall.NewLazyDLL(\"user32.dll\").NewProc(\"MessageBoxW\")\r\n\tfmt.Println(\"-- not hooked yet\")\r\n\tprocedure.Call(\r\n\t\t0,\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"Hello1\"))),\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"World1\"))),\r\n\t\t1,\r\n\t)\r\n\tfmt.Println(fmt.Sprintf(\"0x%X\", procedure.Addr()), fmt.Sprintf(\"0x%X\", \u0026fpMessageBoxW), fmt.Sprintf(\"0x%X\", fpMessageBoxW))\r\n\tfmt.Println()\r\n\r\n\t// Create a hook for MessageBoxW.\r\n\terr = gominhook.CreateHook(procedure.Addr(), uintptr(C.MessageBoxWOverrideHellYeah), uintptr(unsafe.Pointer(\u0026fpMessageBoxW)))\r\n\tif err != nil {\r\n\t\tlog.Fatalln(err)\r\n\t}\r\n\r\n\t// Enable the hook for MessageBoxW.\r\n\terr = gominhook.EnableHook(gominhook.AllHooks)\r\n\tif err != nil {\r\n\t\tlog.Fatalln(err)\r\n\t}\r\n\r\n\t// Calling our hooked procedure user32.MessageBoxW.\r\n\tfmt.Println(\"-- after hook\")\r\n\tprocedure.Call(\r\n\t\t0,\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"Hello2\"))),\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"World2\"))),\r\n\t\t1,\r\n\t)\r\n\tfmt.Println(fmt.Sprintf(\"0x%X\", procedure.Addr()), fmt.Sprintf(\"0x%X\", \u0026fpMessageBoxW), fmt.Sprintf(\"0x%X\", fpMessageBoxW))\r\n\tfmt.Println()\r\n\r\n\t// Disable the hook for MessageBoxW.\r\n\terr = gominhook.DisableHook(gominhook.AllHooks)\r\n\tif err != nil {\r\n\t\tlog.Fatalln(err)\r\n\t}\r\n\r\n\t// Calling our unhooked procedure user32.MessageBoxW.\r\n\tfmt.Println(\"-- after unhook\")\r\n\tprocedure.Call(\r\n\t\t0,\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"Hello3\"))),\r\n\t\tuintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(\"World3\"))),\r\n\t\t1,\r\n\t)\r\n\tfmt.Println(fmt.Sprintf(\"0x%X\", procedure.Addr()), fmt.Sprintf(\"0x%X\", \u0026fpMessageBoxW), fmt.Sprintf(\"0x%X\", fpMessageBoxW))\r\n\tfmt.Println()\r\n}\r\n\r\n/* This outputs...\r\n\r\n-- not hooked yet\r\n0x7FFE6CA4EE10 0x578180 0x0\r\n\r\n-- after hook\r\n - MessageBoxW Override\r\n - I'm so hooked now.\r\n0x7FFE6CA4EE10 0x578180 0x\u0026\r\n\r\n-- after unhook\r\n0x7FFE6CA4EE10 0x578180 0x\u0026\r\n\r\n*/\r\n```\r\n\r\n- - -\r\n\r\n### More information\r\n\r\nSee `minhook` ref for C/C++ users.\r\n- https://github.com/TsudaKageyu/minhook\r\n- https://github.com/TsudaKageyu/minhook/blob/master/include/MinHook.h\r\n- https://github.com/TsudaKageyu/minhook/wiki\r\n- https://www.codeproject.com/Articles/44326/MinHook-The-Minimalistic-x-x-API-Hooking-Libra\r\n\r\n- - -\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanitefactory%2Fgominhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnanitefactory%2Fgominhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnanitefactory%2Fgominhook/lists"}