{"id":21820506,"url":"https://github.com/smx-smx/libhooker","last_synced_at":"2025-04-14T03:01:25.137Z","repository":{"id":73708689,"uuid":"195666945","full_name":"smx-smx/libhooker","owner":"smx-smx","description":"Modular binary injection framework","archived":false,"fork":false,"pushed_at":"2020-01-06T21:38:59.000Z","size":881,"stargazers_count":18,"open_issues_count":0,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-27T16:56:06.595Z","etag":null,"topics":["binary","hook","injection","modular","native","shared-library"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smx-smx.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":"2019-07-07T15:24:00.000Z","updated_at":"2023-12-21T22:34:01.000Z","dependencies_parsed_at":"2023-02-28T12:01:00.931Z","dependency_job_id":null,"html_url":"https://github.com/smx-smx/libhooker","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/smx-smx%2Flibhooker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smx-smx%2Flibhooker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smx-smx%2Flibhooker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smx-smx%2Flibhooker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smx-smx","download_url":"https://codeload.github.com/smx-smx/libhooker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248813789,"owners_count":21165633,"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":["binary","hook","injection","modular","native","shared-library"],"created_at":"2024-11-27T16:34:52.035Z","updated_at":"2025-04-14T03:01:25.131Z","avatar_url":"https://github.com/smx-smx.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NOTE\n## libhooker has been simplified and adapted on top of a newly built injector, with a simplified codebase.\n## Follow the new developments here: https://github.com/smx-smx/ezinject\n\n\n\nWhat is libhooker\n-----------------\nThe libhooker project is a multiplatform binary instrumentation framework.\nUsing it you can inject your own code into a running process, hook its\nexisting functions, replacing its functionality, etc.\n\nTo use it, you need to implement your code as an LHM module.\nFor a working example, see modules/sample\n\nUsage\n-----\nCompilation should be as easy as writing make in the root directory of\nthis package.\n\nAfter your module is ready, you can load it into a running process using\nthe needle tool:\n``./bin/needle -v 4 `pidof process_to_inject_to` bin/lhm_sample.so``\n\nAnd thats all.\n\nLHM modules\n-----------\nCreate a dedicated directory in modules for your own module, then you\ncan build it just typing make in the root directory.\n\nTo hook functions, you need to define a hook_settings symbol like this:\n\n```c\nlh_hook_t hook_settings = {\n  // version of the structure. currently supported: 1\n  .version = 1, \n\n  // function to be run at injection time (and before functions were hooked)\n  .autoinit_pre = hooked_autoinit, \n\n  // function to be run after hooking successfully finished\n  .autoinit_post = hooked_autoinit_post,\n\n  // list of functions to be hooked\n  .fn_hooks = {\n\n    {\n          // supported values:\n          //  LHM_FN_HOOK_TRAILING:\n          //    last entry in the array should be specified with this constant\n          //    processing will stop.\n          //  LHM_FN_HOOK_BY_NAME:\n          //    the function to be hooked will be specified\n          //    based on libname and symname fields\n          //  LHM_FN_HOOK_BY_OFFSET: \n          //    when the function to be hooked is not exported,\n          //    you can specify its base address (the absolute\n          //    address will be calculated based on the base\n          //    address of the code section)\n          //  LHM_FN_HOOK_BY_AOBSCAN:\n          //    the function to be hooked will be specified based on a pattern\n          //    the location of the first match is taken as the hook address\n          //    required parameters:\n          //    .aob_size    -\u003e sizeof(pattern)\n          //    .aob_pattern -\u003e { 0xDE, 0xAD, 0xBE, 0xFF } the pattern to look for\n          .hook_kind = LHM_FN_HOOK_BY_NAME,\n\n          // name of the library to be hooked, for example libc.so\n          // if its an empty string, the current executable will\n          // be looked for\n          .libname = \"\",\n\n          // name of the function symbol wanted to be hooked\n          .symname = \"testfunction\",\n\n          // address of the replacement function\n          .hook_fn = (uintptr_t) hooked_testfunction,\n\n          // address where you want to store the address of the\n          // original symbol (so you can call it any time later)\n          .orig_function_ptr = (uintptr_t) \u0026original_test_function,\n\n          // how many opcode bytes you want to restore\n          // it can be automatically determined on x86/x64\n          //\n          // With relative jump we overwrite:\n          //   ARM: 4 bytes\n          //\n          // With absolute jump we overwrite:\n          //   ARM: 8 bytes\n          .opcode_bytes_to_restore = 8\n    },\n    {\n\n          .hook_kind = LHM_FN_HOOK_TRAILING\n    }\n  }\n};\n```\n\nCredits\n-----------------\nBig thanks to `foobaro`, an anonymous guy that wrote the preliminar version of libhooker and handed it to me.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmx-smx%2Flibhooker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmx-smx%2Flibhooker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmx-smx%2Flibhooker/lists"}