{"id":16692986,"url":"https://github.com/rdbo/jnihook","last_synced_at":"2025-04-04T23:07:22.722Z","repository":{"id":212169319,"uuid":"730370910","full_name":"rdbo/jnihook","owner":"rdbo","description":"Hook Java methods natively from C/C++","archived":false,"fork":false,"pushed_at":"2024-10-21T19:09:27.000Z","size":184,"stargazers_count":164,"open_issues_count":10,"forks_count":24,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-28T22:11:44.580Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rdbo.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-11T19:23:59.000Z","updated_at":"2025-03-27T19:44:17.000Z","dependencies_parsed_at":"2023-12-30T00:30:49.796Z","dependency_job_id":"c1793904-cc5a-42bc-9a1e-8099a3b99fa7","html_url":"https://github.com/rdbo/jnihook","commit_stats":null,"previous_names":["rdbo/jnihook"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdbo%2Fjnihook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdbo%2Fjnihook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdbo%2Fjnihook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdbo%2Fjnihook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdbo","download_url":"https://codeload.github.com/rdbo/jnihook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247261600,"owners_count":20910108,"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":[],"created_at":"2024-10-12T16:29:02.130Z","updated_at":"2025-04-04T23:07:22.693Z","avatar_url":"https://github.com/rdbo.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JNIHook\n![jnihook-logo](https://raw.githubusercontent.com/rdbo/jnihook/master/LOGO.png)\n\nHook Java methods natively from C/C++\n\n## License\nThis project is licensed under the `GNU AGPL-3.0`. No later version is allowed.\n\nRead the file `LICENSE` for more information.\n\n## Example\nHooking the function `static int myFunction(int mynumber, String name)` from a class `Dummy`:\n```c++\njmethodID originalMethod;\njint hkMyFunction(JNIEnv *env, jclass clazz, jint number, jstring name)\n{\n\t// Print parameters\n\tstd::cout \u003c\u003c \"[*] mynumber value: \" \u003c\u003c mynumber \u003c\u003c std::endl;\n\tstd::cout \u003c\u003c \"[*] name object: \" \u003c\u003c name \u003c\u003c std::endl;\n\n\t// Call the original method with 'mynumber' set to '1337'\n\tenv-\u003eCallStaticIntMethod(dummyClass, originalMethod, 1337, name);\n\n\treturn 42; // Modify the return value to '42'\n}\n\nvoid start(JavaVM *jvm)\n{\n\tjclass dummyClass = env-\u003eFindClass(\"dummy/Dummy\");\n\tjmethodID myFunctionID = env-\u003eGetStaticMethodID(dummyClass, \"myFunction\",\n\t\t\t\t\t\t\t\"(ILjava/lang/String;)I\");\n\n\tJNIHook_Init(jvm);\n\tJNIHook_Attach(myFunctionID, hkMyFunction, \u0026originalMethod);\n}\n```\n\n## Building\nTo build this, you can either compile all the files in `src` into your project, or\nuse CMake to build a static library, which can be compiled into your project.\n\nNOTE: This requires C++17, which is available on newer versions of Visual Studio and GCC.\n\nThe steps ahead are for building a static library with CMake.\n\n\n1. Setup your `JAVA_HOME` environment variable. It will be used for accessing `jni.h`, `jvmti.h`, and linking\nthe `jvm` library. On Linux, it's usually on `/usr/lib/jvm/\u003cjava release\u003e`, and on Windows at `%ProgramFiles%\\Java\\jdk-\u003cversion\u003e`.\n\n---\n\n2. Create a build directory inside the root directory of the repository and enter it:\n\nNOTE: Use the `x64 Native Tools Command Prompt` on Windows.\n```\nmkdir build\ncd build\n```\n\n---\n\n3. Run CMake to setup the project\n\n**Linux/\\*nix**:\n```\ncmake ..\n```\n\n**Windows**:\n```\ncmake .. -G \"NMake Makefiles\" -DCMAKE_CXX_STANDARD=17\n```\n\n---\n\n4. Build using `nmake` (Windows) or `make` (*nix):\n\n**Linux/\\*nix**:\n```\nmake\n```\n\n**Windows**:\n```\nnmake\n```\n\n---\n\nAfter running these commands, you will have `libjnihook.a` or `jnihook.lib` in your `build` directory, which you can compile along with your project.\n\nNOTE: Don't forget to include JNIHook's `include` dir in your project so that you can `#include \u003cjnihook.h\u003e`.\n\n## Acknowledgements\nSpecial thanks to [@Lefraudeur](https://github.com/Lefraudeur) for helping me with information about JVM functionality\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdbo%2Fjnihook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdbo%2Fjnihook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdbo%2Fjnihook/lists"}