{"id":15033625,"url":"https://github.com/aslody/sandhook","last_synced_at":"2025-05-15T12:02:11.927Z","repository":{"id":37723149,"uuid":"165422092","full_name":"asLody/SandHook","owner":"asLody","description":"Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat","archived":false,"fork":false,"pushed_at":"2023-01-19T07:04:46.000Z","size":24211,"stargazers_count":2104,"open_issues_count":45,"forks_count":451,"subscribers_count":75,"default_branch":"master","last_synced_at":"2025-04-14T18:17:03.926Z","etag":null,"topics":["android","aop","art","hook","inline-hook","java-hook","xposed"],"latest_commit_sha":null,"homepage":"","language":"Java","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/asLody.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-12T18:32:08.000Z","updated_at":"2025-04-14T05:19:07.000Z","dependencies_parsed_at":"2023-02-10T21:01:07.753Z","dependency_job_id":null,"html_url":"https://github.com/asLody/SandHook","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asLody%2FSandHook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asLody%2FSandHook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asLody%2FSandHook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asLody%2FSandHook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asLody","download_url":"https://codeload.github.com/asLody/SandHook/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248933345,"owners_count":21185460,"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":["android","aop","art","hook","inline-hook","java-hook","xposed"],"created_at":"2024-09-24T20:22:01.348Z","updated_at":"2025-04-14T18:17:13.714Z","avatar_url":"https://github.com/asLody.png","language":"Java","readme":"# SandHook\n- Android ART Hook\n- Native Inline Hook\n## Version \n\n[ ![Version](https://api.bintray.com/packages/ganyao114/maven/hooklib/images/download.svg) ](https://bintray.com/ganyao114/maven/hooklib/_latestVersion)\n\n## Chinese\n\n[中文文档以及实现](https://github.com/ganyao114/SandHook/blob/master/doc/doc.md)\n\n[中文 Blog](https://blog.csdn.net/ganyao939543405/article/details/86661040)  \n\n与 VirtualApp 相关的商业合作请联系微信：10890\n\n# arch support \n\n- ARM64\n- ARM32(no tested)\n- Thumb-2\n\n# OS\n\n4.4(ART Runtime) - 11.0 dev-preview-1\n\n# Project Struct\n\n- annotation\u003cbr/\u003e\nannotation api\n- hooklib\u003cbr/\u003e\ncore lib of art hook\n- nativehook\u003cbr/\u003e\nlib of native hook\n- xposedcompat\u003cbr/\u003e\nstable implement of xposed api compat for sandhook\n- xposedcompat_new\u003cbr/\u003e\nannother implement of xposed api compat for sandhook(hook more fast first time)\n- hookers\u003cbr/\u003e\nhook plugin demo for annotation api\n\n# how to use\n\n```gradle\nimplementation 'com.swift.sandhook:hooklib:4.2.0'\n// need for android 11\nimplementation 'com.swift.sandhook:nativehook:4.2.0'\n```\n\n## Annotation API\n\n--------------------------------------------------------------------\n\n- hook method must be a static method\n- first par must be this if method is not static\n- method description must \"same\"(can be isAssignableFrom) with origin method\n- backup method same with above\n\n```java\n@HookClass(Activity.class)\n//@HookReflectClass(\"android.app.Activity\")\npublic class ActivityHooker {\n\n    @HookMethodBackup(\"onCreate\")\n    @MethodParams(Bundle.class)\n    static Method onCreateBackup;\n\n    @HookMethodBackup(\"onPause\")\n    static HookWrapper.HookEntity onPauseBackup;\n\n    @HookMethod(\"onCreate\")\n    @MethodParams(Bundle.class)\n    public static void onCreate(Activity thiz, Bundle bundle) throws Throwable {\n        Log.e(\"ActivityHooker\", \"hooked onCreate success \" + thiz);\n        SandHook.callOriginByBackup(onCreateBackup, thiz, bundle);\n    }\n\n    @HookMethod(\"onPause\")\n    public static void onPause(@ThisObject Activity thiz) throws Throwable {\n        Log.e(\"ActivityHooker\", \"hooked onPause success \" + thiz);\n        onPauseBackup.callOrigin(thiz);\n    }\n\n}\n\n\n\n//or like this:\n\n@HookClass(TestClass.class)\npublic class NewAnnotationApiHooker {\n\n    @HookMethod(\"testNewHookApi\")\n    public static void onTestNewHookApi(@ThisObject TestClass thiz, @Param(\"com.swift.sandhook.MainActivity\") Activity activity, int a) {\n        Log.e(\"TestClassHook\", \"testNewHookApi been hooked\");\n        onTestNewHookApiBackup(thiz, activity, a);\n    }\n\n    @HookMethodBackup(\"testNewHookApi\")\n    public static void onTestNewHookApiBackup(@ThisObject TestClass thiz, @Param(\"com.swift.sandhook.MainActivity\") Activity activity, int a) {\n        onTestNewHookApiBackup(thiz, activity, a);\n    }\n\n}\n\n\n\n//first set debuggable\nSandHookConfig.DEBUG = BuildConfig.DEBUG;\n\nand\n\n//add hookers\nSandHook.addHookClass(CtrHook.class, LogHooker.class, CustmizeHooker.class, ActivityHooker.class, ObjectHooker.class);\n\nyou can also use:\nSanHook.public static boolean hook(Member target, Method hook, Method backup) {}\n\n```\n\nif hookers is in plugin(like xposed):  \n\n```groovy\nprovided 'com.swift.sandhook:hookannotation:4.2.0'\n```\n  \nin your plugin\n\nif OS \u003c= 5.1 \nbackup method can call itself to avoid be inlining\n\n## Xposed API\n\n--------------------------------------------------------------------\n\nNow you can use Xposed api:\n\nWe have two different implements:\n```groovy\n//stable\nimplementation 'com.swift.sandhook:xposedcompat:4.2.0'\n\n//or\n\n//hook fast first time\nimplementation 'com.swift.sandhook:xposedcompat_new:4.2.0'\n```\n\n```java\n\n//setup for xposed\n//for xposed compat only(no need xposed comapt new)\nXposedCompat.cacheDir = getCacheDir();\n\n//for load xp module(sandvxp)\nXposedCompat.context = this;\nXposedCompat.classLoader = getClassLoader();\nXposedCompat.isFirstApplication= true;\n\n//do hook\nXposedHelpers.findAndHookMethod(Activity.class, \"onResume\", new XC_MethodHook() {\n      @Override\n      protected void beforeHookedMethod(MethodHookParam param) throws Throwable {\n          super.beforeHookedMethod(param);\n          Log.e(\"XposedCompat\", \"beforeHookedMethod: \" + param.method.getName());\n      }\n\n      @Override\n      protected void afterHookedMethod(MethodHookParam param) throws Throwable {\n          super.afterHookedMethod(param);\n          Log.e(\"XposedCompat\", \"afterHookedMethod: \" + param.method.getName());\n      }\n});\n\n```\n\n# Notice\n\n## Disable Inline\n\n### JIT inline\n\nWe can do nothing to prevent some methods been inlined before app start, but we can try to disable VM Jit Inline after launch.\n\nif you will hook some method that could be inlined, please call SandHook.disableVMInline()(OS \u003e= 7.0) in Application.OnCreate()\n\n### Inline by dex2oat\n\n#### Background dex2oat\n\nSandHook.tryDisableProfile(getPackageName());\n\n#### dex2oat by DexClassLoader\n\nSandHook.disableDex2oatInline(fullyDisableDex2oat);\n\nor\n\nArtDexOptimizer.dexoatAndDisableInline to dex2oat manuly \n\n### Deoptimize(Boot Image)\n\nYou can also deoptimize a caller that inlined your hook method by SandHook.deCompile(caller), just implement \u003e= 7.0\n\n## Hidden API\n\nSandHook.passApiCheck();\n\nTo bypass hidden api on P \u0026 Q\n\n## Debuggable\n\nYou must set debuggble of the target hook process before init when OS \u003e= 8.0.  \n\nSandHookConfig.DEBUG = \u003cDebuggable of target process\u003e  \n\n# Native Hook\n\n## simple hook(no backup)\n#include \"includes/sandhook.h\"  \n\nbool nativeHookNoBackup(void* origin, void* hook);\n\n## need backup origin method\n#include \"sandhook_native.h\"  \n\nvoid* SandInlineHook(void* origin, void* replace);  \n\nvoid* SandInlineHookSym(const char* so, const char* symb, void* replace);  \n\n\nreturn is backup method\n\n## break point\n\nyou can insert a break point in body of method(not only start of method), so you can read/write registers in break point.  \n\n\nbool SandBreakPoint(void* origin, void (*callback)(REG[]));  \n\nbool SandSingleInstBreakPoint(void *origin, BreakCallback(callback));\n\n## short method \n\n#include \"sandhook_native.h\"  \n\nvoid* SandSingleInstHook(void* origin, void* replace);  \n\nvoid* SandSingleInstHookSym(const char* so, const char* symb, void* replace);  \n\nuse it when your method is \u003c= 16bytes(64bit)/8bytes(32bit)  \n\nSandSingleInstHook only need 4bytes length\n\n\n## more\n\n- disassembler (only implement important instructions)\n- assembler (only implement important instructions)\n\n# Demo\n\n## SandVXPosed\n\nnon-Root Xposed Environment Demo (VirtualApp with SandHook):\n\nhttps://github.com/ganyao114/SandVXposed\n\n## EdXposed(SandHook Brunch)\n\nUnofficial xposed framework \u003e= 8.0\n\nSee release above\n\nhttps://github.com/ElderDrivers/EdXposed\n\n# Android Q(10.0)\n\nin MyApp.java\n\n//if you want test Android Q, please set true, because SDK_INT of Android Q is still 28\npublic final static boolean testAndroidQ = false;\n \n\n# References\n\n- Epic:https://github.com/tiann/epic\n- Yahfa:https://github.com/rk700/YAHFA\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faslody%2Fsandhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faslody%2Fsandhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faslody%2Fsandhook/lists"}