{"id":20662516,"url":"https://github.com/xxdark/reflectionhooks","last_synced_at":"2025-04-19T15:52:54.564Z","repository":{"id":43289546,"uuid":"179298201","full_name":"xxDark/reflectionhooks","owner":"xxDark","description":"Java reflection hooking library","archived":false,"fork":false,"pushed_at":"2022-03-09T21:08:41.000Z","size":68,"stargazers_count":26,"open_issues_count":2,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2023-03-07T14:35:41.319Z","etag":null,"topics":["hooks","invoke-api","java","reflection"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xxDark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-03T13:40:25.000Z","updated_at":"2023-01-15T09:32:22.000Z","dependencies_parsed_at":"2022-08-12T10:21:55.441Z","dependency_job_id":null,"html_url":"https://github.com/xxDark/reflectionhooks","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxDark%2Freflectionhooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxDark%2Freflectionhooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxDark%2Freflectionhooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxDark%2Freflectionhooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xxDark","download_url":"https://codeload.github.com/xxDark/reflectionhooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224958273,"owners_count":17398500,"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":["hooks","invoke-api","java","reflection"],"created_at":"2024-11-16T19:14:26.907Z","updated_at":"2024-11-16T19:14:27.468Z","avatar_url":"https://github.com/xxDark.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# reflectionhooks\nWARNING: java.lang.invoke hooks can only be used if jar is appended into bootstrap class path\n```Java\npublic class Test {\n\n\tprivate static int val = 1;\n\n\tprivate Test(String str) {\n\t\tSystem.err.println(str);\n\t}\n\n\tpublic static void main(String[] a) throws Throwable {\n\t\tHooksFactory factory = new DefaultHooksFactory();\n\t\tHook hook = factory\n\t\t\t\t.createMethodHook(Void.class, Test.class.getDeclaredMethod(\"hi\", String.class),\n\t\t\t\t\t\t(parent, handle, args) -\u003e {\n\t\t\t\t\t\t\tSystem.out\n\t\t\t\t\t\t\t\t\t.println(\"Hello, World!, arg0 is: \"\n\t\t\t\t\t\t\t\t\t\t\t+ args[0] + \" and my instance is \" + handle);\n\t\t\t\t\t\t\tparent.invoke(null, handle, args);\n\t\t\t\t\t\t\treturn null;\n\t\t\t\t\t\t});\n\t\thook.hook();\n\t\tTest.class.getDeclaredMethod(\"hi\", String.class)\n\t\t\t\t.invoke(null, \"Hi!\");\n\n\t\tHook hook1 = factory.createFieldHook(Test.class.getDeclaredField(\"val\"),\n\t\t\t\t(parent, handle) -\u003e {\n\t\t\t\t\tSystem.out.println(\"get called from \" + handle);\n\t\t\t\t\treturn parent.get(null, handle);\n\t\t\t\t}, (parent, handle, value) -\u003e {\n\t\t\t\t\tSystem.out.println(\"set called from \" + handle + \", to \" + value);\n\t\t\t\t\tparent.set(null, handle, value);\n\t\t\t\t});\n\t\thook1.hook();\n\t\tField field = Test.class.getDeclaredField(\"val\");\n\t\tfield.setInt(null, 5);\n\n\t\tHook hook2 = factory\n\t\t\t\t.createConstructorHook(Test.class, Test.class.getDeclaredConstructor(String.class),\n\t\t\t\t\t\t(parent, handle, args) -\u003e {\n\t\t\t\t\t\t\tSystem.err.println(\"Constructor called!\");\n\t\t\t\t\t\t\targs[0] = \"World!\";\n\t\t\t\t\t\t\treturn parent.invoke(null, handle, args);\n\t\t\t\t\t\t});\n\t\thook2.hook();\n\t\tTest.class.getDeclaredConstructor(String.class).newInstance(\"Hello, \");\n\t}\n\n\tpublic static void hi(String str) {\n\t\tSystem.out.println(str);\n\t}\n}\n```\n\n```Java\npublic class Test {\n\n    public static void main(String[] args) throws Throwable {\n        JavaInvokeInjector.inject();\n        HooksFactory factory = new DefaultHooksFactory();\n        factory.createMethodInvokeHook((type, classRef, nameRef, typeRef) -\u003e {\n            System.out.println(\"Call: \" + classRef.get() + ' ' + nameRef.get() + ' ' + typeRef.get());\n            nameRef.set(\"hooked\");\n        });\n        MethodHandles.publicLookup().findStatic(Test.class, \"first\", MethodType.methodType(void.class))\n                .invokeExact();\n    }\n\n    public static void first() {\n        System.out.println(\"Hello, \");\n    }\n\n    public static void hooked() {\n        System.out.println(\"World!\");\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxdark%2Freflectionhooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxxdark%2Freflectionhooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxdark%2Freflectionhooks/lists"}