All Projects → ganyao114 → Sandhook

ganyao114 / Sandhook

Licence: other
Android ART Hook/Native Inline Hook/Single Instruction Hook - support 4.4 - 11.0 32/64 bit - Xposed API Compat

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Sandhook

Epic
Dynamic java method AOP hook for Android(continution of Dexposed on ART), Supporting 5.0~11
Stars: ✭ 3,434 (+193%)
Mutual labels:  hook, art, xposed, aop
Pine
Dynamic java method hook framework on ART.
Stars: ✭ 171 (-85.41%)
Mutual labels:  hook, art, xposed, aop
Virtualxposed
A simple app to use Xposed without root, unlock the bootloader or modify system image, etc.
Stars: ✭ 12,648 (+979.18%)
Mutual labels:  hook, xposed, aop
Qujing
曲境是一个xposed模块,可实现在PC浏览器上动态监控(hook)函数调用和查看堆栈信息,及反射调用(invoke)等功能。
Stars: ✭ 197 (-83.19%)
Mutual labels:  hook, xposed
Easyrouter
A simple android framework used to route activity or action with url.
Stars: ✭ 164 (-86.01%)
Mutual labels:  hook, aop
Headwolf
Scaffolding for agile development based on Xposed and Sekiro/基于Xposed和Sekiro搭建的敏捷开发的脚手架🎁献给懒汉们的小礼物😘只需四步!部署完一个Hook项目!👋👋新版本只需两步!!!
Stars: ✭ 182 (-84.47%)
Mutual labels:  hook, xposed
Swifthook
A library to hook methods in Swift and Objective-C.
Stars: ✭ 93 (-92.06%)
Mutual labels:  hook, aop
Beike AspectD
Flutter AOP framework.(Flutter面向切面库, 最新适配Flutter v2.5.3, null-safety)
Stars: ✭ 39 (-96.67%)
Mutual labels:  hook, aop
SandVXposed
Xposed environment without root (OS 5.0 - 10.0)
Stars: ✭ 832 (-29.01%)
Mutual labels:  hook, xposed
SandVXposed
Xposed environment without root (OS 5.0 - 12.0)
Stars: ✭ 241 (-79.44%)
Mutual labels:  hook, xposed
X Apm
应用管理 Xposed
Stars: ✭ 482 (-58.87%)
Mutual labels:  hook, xposed
Androididchanger
Xposed Module for Changing Android Device Info
Stars: ✭ 394 (-66.38%)
Mutual labels:  hook, xposed
Sandvxposed
Xposed environment without root (OS 5.0 - 10.0)
Stars: ✭ 604 (-48.46%)
Mutual labels:  hook, xposed
Hookwormforandroid
一个基于Magisk&Riru的Module,可以助你用超低成本开发各种Hook插件,无须Xposed
Stars: ✭ 136 (-88.4%)
Mutual labels:  hook, xposed
Easyprotector
一行代码检测XP/调试/多开/模拟器/root
Stars: ✭ 1,732 (+47.78%)
Mutual labels:  hook, xposed
aspectgo
Aspect-Oriented Programming framework for Go
Stars: ✭ 62 (-94.71%)
Mutual labels:  hook, aop
Xposednavigationbar
Xposed导航栏功能拓展模块
Stars: ✭ 42 (-96.42%)
Mutual labels:  hook, xposed
Stinger
Stinger is a high-efficiency library with great compatibility, for aop in Objective-C, using libffi instead of Objective-C message forwarding. It is 20+ times faster than the Aspects, from message-sending to Aspect-oriented code ends.
Stars: ✭ 845 (-27.9%)
Mutual labels:  hook, aop
Xpatch
免Root实现app加载Xposed插件工具。This is a tool to repackage apk file, then the apk can load any xposed modules installed in the device. It is another way to hook an app without root device.
Stars: ✭ 1,054 (-10.07%)
Mutual labels:  hook, xposed
Responsivedevices.css
Responsive CSS Device frames for your landing pages
Stars: ✭ 59 (-94.97%)
Mutual labels:  art

SandHook

  • Android ART Hook
  • Native Inline Hook

Version

Version

Chinese

中文文档以及实现

中文 Blog

QQ Group:756071167

与 VirtualApp 相关的商业合作请联系 QQ939543405

arch support

  • ARM64
  • ARM32(no tested)
  • Thumb-2

OS

4.4(ART Runtime) - 11.0 dev-preview-1

Project Struct

  • annotation
    annotation api
  • hooklib
    core lib of art hook
  • nativehook
    lib of native hook
  • xposedcompat
    stable implement of xposed api compat for sandhook
  • xposedcompat_new
    annother implement of xposed api compat for sandhook(hook more fast first time)
  • hookers
    hook plugin demo for annotation api

how to use

implementation 'com.swift.sandhook:hooklib:4.2.0'
// need for android 11
implementation 'com.swift.sandhook:nativehook:4.2.0'

Annotation API


  • hook method must be a static method
  • first par must be this if method is not static
  • method description must "same"(can be isAssignableFrom) with origin method
  • backup method same with above
@HookClass(Activity.class)
//@HookReflectClass("android.app.Activity")
public class ActivityHooker {

    @HookMethodBackup("onCreate")
    @MethodParams(Bundle.class)
    static Method onCreateBackup;

    @HookMethodBackup("onPause")
    static HookWrapper.HookEntity onPauseBackup;

    @HookMethod("onCreate")
    @MethodParams(Bundle.class)
    public static void onCreate(Activity thiz, Bundle bundle) throws Throwable {
        Log.e("ActivityHooker", "hooked onCreate success " + thiz);
        SandHook.callOriginByBackup(onCreateBackup, thiz, bundle);
    }

    @HookMethod("onPause")
    public static void onPause(@ThisObject Activity thiz) throws Throwable {
        Log.e("ActivityHooker", "hooked onPause success " + thiz);
        onPauseBackup.callOrigin(thiz);
    }

}



//or like this:

@HookClass(TestClass.class)
public class NewAnnotationApiHooker {

    @HookMethod("testNewHookApi")
    public static void onTestNewHookApi(@ThisObject TestClass thiz, @Param("com.swift.sandhook.MainActivity") Activity activity, int a) {
        Log.e("TestClassHook", "testNewHookApi been hooked");
        onTestNewHookApiBackup(thiz, activity, a);
    }

    @HookMethodBackup("testNewHookApi")
    public static void onTestNewHookApiBackup(@ThisObject TestClass thiz, @Param("com.swift.sandhook.MainActivity") Activity activity, int a) {
        onTestNewHookApiBackup(thiz, activity, a);
    }

}



//first set debuggable
SandHookConfig.DEBUG = BuildConfig.DEBUG;

and

//add hookers
SandHook.addHookClass(CtrHook.class, LogHooker.class, CustmizeHooker.class, ActivityHooker.class, ObjectHooker.class);

you can also use:
SanHook.public static boolean hook(Member target, Method hook, Method backup) {}

if hookers is in plugin(like xposed):

provided 'com.swift.sandhook:hookannotation:4.2.0'

in your plugin

if OS <= 5.1 backup method can call itself to avoid be inlining

Xposed API


Now you can use Xposed api:

We have two different implements:

//stable
implementation 'com.swift.sandhook:xposedcompat:4.2.0'

//or

//hook fast first time
implementation 'com.swift.sandhook:xposedcompat_new:4.2.0'
//setup for xposed
//for xposed compat only(no need xposed comapt new)
XposedCompat.cacheDir = getCacheDir();

//for load xp module(sandvxp)
XposedCompat.context = this;
XposedCompat.classLoader = getClassLoader();
XposedCompat.isFirstApplication= true;

//do hook
XposedHelpers.findAndHookMethod(Activity.class, "onResume", new XC_MethodHook() {
      @Override
      protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
          super.beforeHookedMethod(param);
          Log.e("XposedCompat", "beforeHookedMethod: " + param.method.getName());
      }

      @Override
      protected void afterHookedMethod(MethodHookParam param) throws Throwable {
          super.afterHookedMethod(param);
          Log.e("XposedCompat", "afterHookedMethod: " + param.method.getName());
      }
});

Notice

Disable Inline

JIT inline

We can do nothing to prevent some methods been inlined before app start, but we can try to disable VM Jit Inline after launch.

if you will hook some method that could be inlined, please call SandHook.disableVMInline()(OS >= 7.0) in Application.OnCreate()

Inline by dex2oat

Background dex2oat

SandHook.tryDisableProfile(getPackageName());

dex2oat by DexClassLoader

SandHook.disableDex2oatInline(fullyDisableDex2oat);

or

ArtDexOptimizer.dexoatAndDisableInline to dex2oat manuly

Deoptimize(Boot Image)

You can also deoptimize a caller that inlined your hook method by SandHook.deCompile(caller), just implement >= 7.0

Hidden API

SandHook.passApiCheck();

To bypass hidden api on P & Q

Debuggable

You must set debuggble of the target hook process before init when OS >= 8.0.

SandHookConfig.DEBUG =

Native Hook

simple hook(no backup)

#include "includes/sandhook.h"

bool nativeHookNoBackup(void* origin, void* hook);

need backup origin method

#include "sandhook_native.h"

void* SandInlineHook(void* origin, void* replace);

void* SandInlineHookSym(const char* so, const char* symb, void* replace);

return is backup method

break point

you can insert a break point in body of method(not only start of method), so you can read/write registers in break point.

bool SandBreakPoint(void* origin, void (*callback)(REG[]));

bool SandSingleInstBreakPoint(void *origin, BreakCallback(callback));

short method

#include "sandhook_native.h"

void* SandSingleInstHook(void* origin, void* replace);

void* SandSingleInstHookSym(const char* so, const char* symb, void* replace);

use it when your method is <= 16bytes(64bit)/8bytes(32bit)

SandSingleInstHook only need 4bytes length

more

  • disassembler (only implement important instructions)
  • assembler (only implement important instructions)

Demo

SandVXPosed

non-Root Xposed Environment Demo (VirtualApp with SandHook):

https://github.com/ganyao114/SandVXposed

EdXposed(SandHook Brunch)

Unofficial xposed framework >= 8.0

See release above

https://github.com/ElderDrivers/EdXposed

Android Q(10.0)

in MyApp.java

//if you want test Android Q, please set true, because SDK_INT of Android Q is still 28 public final static boolean testAndroidQ = false;

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].