├── .gitattributes ├── .gitignore ├── README.md ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── libs │ └── substrate-api.jar ├── lint.xml └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ ├── cydiasubstrate │ │ └── hooktools │ │ │ ├── Initialize.java │ │ │ ├── MainActivity.java │ │ │ └── MyApplication.java │ ├── hook │ │ ├── android │ │ │ ├── build.java │ │ │ ├── smsManager.java │ │ │ └── telephonyManager.java │ │ └── java │ │ │ ├── cipher.java │ │ │ └── stringBuilder.java │ └── tools │ │ ├── file.java │ │ └── statckTrace.java │ ├── jni │ ├── Android.mk │ ├── Application.mk │ ├── TKHooklib.h │ ├── cydiasubstrate_nativehooktools.cpp │ └── substrate.h │ ├── prebuildSo │ ├── libTKHooklib.so │ ├── libsubstrate-dvm.so │ └── libsubstrate.so │ └── res │ ├── drawable │ └── ic_launcher.png │ ├── layout │ └── activity_main.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── dimens.xml │ └── strings.xml ├── build.gradle ├── cydiasubstrate_hooktools.iml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── import-summary.txt ├── local.properties └── settings.gradle /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | build 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | cydiasubstrate_hooktools 2 | An android hook tools based on cydia substrate 3 | 4 | QQgroup:456853837 5 | 6 | Change eclipse project to Android Studio project 7 | and add a launch Activity. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | build -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.model.application' 2 | 3 | model { 4 | repositories { 5 | libs(PrebuiltLibraries) { 6 | Substrate { 7 | binaries.withType(SharedLibraryBinary) { 8 | sharedLibraryFile = file("src/main/prebuildSo/libsubstrate.so") 9 | } 10 | } 11 | SubstrateDvm { 12 | binaries.withType(SharedLibraryBinary) { 13 | sharedLibraryFile = file("src/main/prebuildSo/libsubstrate-dvm.so") 14 | } 15 | } 16 | TKHook { 17 | binaries.withType(SharedLibraryBinary) { 18 | sharedLibraryFile = file("src/main/prebuildSo/libTKHooklib.so") 19 | } 20 | } 21 | } 22 | } 23 | 24 | android.sources { 25 | main { 26 | jni { 27 | dependencies { 28 | library "Substrate" 29 | library "SubstrateDvm" 30 | library "TKHook" 31 | } 32 | } 33 | } 34 | } 35 | 36 | android { 37 | compileSdkVersion 23 38 | buildToolsVersion "23.0.2" 39 | 40 | defaultConfig { 41 | applicationId "cydiasubstrate.hooktools" 42 | minSdkVersion.apiLevel 16 43 | targetSdkVersion.apiLevel 19 44 | 45 | 46 | } 47 | 48 | ndk { 49 | moduleName "substrate-dvm" 50 | ldLibs.addAll(["log", "dl"]) 51 | cppFlags.addAll(["-Wpointer-arith", "-fpermissive", "-Wformat"]) 52 | } 53 | 54 | productFlavors { 55 | create("f8") { 56 | ndk.abiFilters.add("armeabi") 57 | } 58 | } 59 | 60 | buildTypes { 61 | release { 62 | minifyEnabled false 63 | proguardFiles.add(file("proguard-rules.pro")) 64 | } 65 | } 66 | } 67 | } 68 | 69 | 70 | dependencies { 71 | compile files('libs/substrate-api.jar') 72 | compile 'com.android.support:appcompat-v7:19.1.0' 73 | } 74 | -------------------------------------------------------------------------------- /app/libs/substrate-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/app/libs/substrate-api.jar -------------------------------------------------------------------------------- /app/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 21 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/java/cydiasubstrate/hooktools/Initialize.java: -------------------------------------------------------------------------------- 1 | package cydiasubstrate.hooktools; 2 | 3 | import android.util.Log; 4 | 5 | public class Initialize { 6 | public static void initialize() { 7 | Log.v("Fhook", "java_hook start!"); 8 | //com.tencent.mm.app.MMApplication 9 | MyApplication.hook("com.tencent.mm.app.MMApplication"); 10 | Log.v("Fhook", "java_hook end!"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/cydiasubstrate/hooktools/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cydiasubstrate.hooktools; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | public class MainActivity extends Activity { 7 | 8 | @Override 9 | protected void onCreate(Bundle savedInstanceState) { 10 | super.onCreate(savedInstanceState); 11 | setContentView(R.layout.activity_main); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/java/cydiasubstrate/hooktools/MyApplication.java: -------------------------------------------------------------------------------- 1 | package cydiasubstrate.hooktools; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import android.util.Log; 6 | import hook.android.build; 7 | import hook.android.smsManager; 8 | import hook.android.telephonyManager; 9 | import hook.java.cipher; 10 | import hook.java.stringBuilder; 11 | 12 | import com.saurik.substrate.MS; 13 | 14 | public class MyApplication implements MS.ClassLoadHook { 15 | private static MyApplication MyApplication_Instance; 16 | 17 | public MyApplication() { 18 | super(); 19 | } 20 | public static void hook(String application) 21 | { 22 | MS.hookClassLoad( application, new MyApplication() ); 23 | } 24 | 25 | 26 | @SuppressWarnings("unchecked") 27 | public void classLoaded(Class MyApplication) { 28 | Log.i("Fhook", "hook_Application start!"); 29 | cipher.hook(); 30 | stringBuilder.hook(); 31 | build.hook(); 32 | smsManager.hook(); 33 | telephonyManager.hook(); 34 | Log.i("Fhook", "hook_Application end!"); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /app/src/main/java/hook/android/build.java: -------------------------------------------------------------------------------- 1 | package hook.android; 2 | 3 | import java.lang.reflect.Field; 4 | 5 | public class build { 6 | 7 | public static void hook(){ 8 | setBRAND("wm_qd"); 9 | setMODEL("QQgroup_456853837"); 10 | } 11 | 12 | 13 | public static void setBRAND(String brand){ 14 | setStaticObjectField( "android.os.Build","BRAND",brand); 15 | } 16 | public static void setMODEL(String model){ 17 | setStaticObjectField( "android.os.Build","MODEL",model); 18 | } 19 | 20 | public static boolean setStaticObjectField(String className, String fieldName, Object data ) 21 | { 22 | try 23 | { 24 | Class c = Class.forName( className ); 25 | Field f = c.getDeclaredField( fieldName ); 26 | f.setAccessible( true ); 27 | f.set( className, data ); 28 | } 29 | catch (Exception e ) 30 | { 31 | e.printStackTrace( ); 32 | return false; 33 | } 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/hook/android/smsManager.java: -------------------------------------------------------------------------------- 1 | package hook.android; 2 | 3 | import java.lang.reflect.Method; 4 | import java.util.Arrays; 5 | 6 | import javax.crypto.SecretKey; 7 | import javax.crypto.spec.IvParameterSpec; 8 | 9 | import android.R.integer; 10 | import android.app.PendingIntent; 11 | import android.util.Log; 12 | import tools.statckTrace; 13 | 14 | import com.saurik.substrate.MS; 15 | 16 | //hook 短信内容 17 | public class smsManager implements MS.ClassLoadHook 18 | { 19 | 20 | private static smsManager SmsManager_Instance; 21 | public smsManager( ) 22 | { 23 | super( ); 24 | } 25 | 26 | public static void hook(){ 27 | MS.hookClassLoad("android.telephony.SmsManager", getInstance()); 28 | } 29 | 30 | public static smsManager getInstance( ) 31 | { 32 | if ( SmsManager_Instance == null ) 33 | { 34 | SmsManager_Instance = new smsManager( ); 35 | } 36 | return SmsManager_Instance; 37 | } 38 | 39 | @SuppressWarnings( { "unchecked", "rawtypes" } ) 40 | public void classLoaded( Class< ? > SmsManager ) 41 | { 42 | Method sendTextMessage = null; 43 | try 44 | { 45 | sendTextMessage = SmsManager.getMethod( "sendTextMessage", new Class[] { String.class, String.class, String.class, PendingIntent.class, PendingIntent.class } ); 46 | } 47 | catch ( Exception e ) 48 | { 49 | sendTextMessage =null; 50 | e.printStackTrace(); 51 | } 52 | if(sendTextMessage!=null){ 53 | final MS.MethodPointer sendTextMessageold = new MS.MethodPointer( ); 54 | MS.hookMethod( SmsManager, sendTextMessage, new MS.MethodHook( ) 55 | { 56 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 57 | { 58 | Log.i("Fhook", "hook_smsT_destination" + (String) arg1[ 0 ] ); 59 | Log.i("Fhook", "hook_smsT_text" + (String) arg1[ 2 ] ); 60 | statckTrace.LogStatckTrace("hook_smsT_StatckTrace"); 61 | return sendTextMessageold.invoke( arg0, arg1 ); 62 | } 63 | }, sendTextMessageold ); 64 | } 65 | Method sendDataMessage = null; 66 | try 67 | { 68 | sendDataMessage = SmsManager.getMethod( "sendDataMessage", new Class[] { String.class, String.class, short.class,byte[].class, PendingIntent.class, PendingIntent.class } ); 69 | 70 | } 71 | catch ( Exception e ) 72 | { 73 | sendDataMessage = null; 74 | e.printStackTrace(); 75 | } 76 | 77 | if(sendDataMessage!=null){ 78 | final MS.MethodPointer sendDataMessageold = new MS.MethodPointer( ); 79 | MS.hookMethod( SmsManager, sendDataMessage, new MS.MethodHook( ) 80 | { 81 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 82 | { 83 | Log.i("Fhook", "hook_smsD_destination" + (String) arg1[ 0 ] ); 84 | Log.i("Fhook", "hook_smsD_port" + String.valueOf( (Short)arg1[ 2 ] ) ); 85 | Log.i("Fhook", "hook_smsD_array" + Arrays.toString((byte[]) arg1[ 3 ]) ); 86 | statckTrace.LogStatckTrace("hook_smsD_StatckTrace"); 87 | return sendDataMessageold.invoke( arg0, arg1 ); 88 | } 89 | }, sendDataMessageold ); 90 | } 91 | } 92 | } -------------------------------------------------------------------------------- /app/src/main/java/hook/android/telephonyManager.java: -------------------------------------------------------------------------------- 1 | package hook.android; 2 | 3 | 4 | import java.lang.reflect.Method; 5 | import android.util.Log; 6 | import tools.statckTrace; 7 | 8 | import com.saurik.substrate.MS; 9 | 10 | public class telephonyManager implements MS.ClassLoadHook 11 | { 12 | private static telephonyManager TelephonyManager_Instance; 13 | 14 | public telephonyManager( ) 15 | { 16 | super( ); 17 | } 18 | 19 | public static void hook(){ 20 | MS.hookClassLoad( "android.telephony.TelephonyManager",getInstance()); 21 | } 22 | 23 | public static telephonyManager getInstance( ) 24 | { 25 | if ( TelephonyManager_Instance == null ) 26 | { 27 | TelephonyManager_Instance = new telephonyManager( ); 28 | } 29 | return TelephonyManager_Instance; 30 | } 31 | 32 | @SuppressWarnings( "unchecked" ) 33 | public void classLoaded( Class< ? > arg0 ) 34 | { 35 | Method hookimei; 36 | try 37 | { 38 | hookimei = arg0.getMethod( "getDeviceId", null ); 39 | } 40 | catch (Exception e ) 41 | { 42 | hookimei = null; 43 | e.printStackTrace( ); 44 | } 45 | if ( hookimei != null ) 46 | { 47 | final MS.MethodPointer old = new MS.MethodPointer( ); 48 | MS.hookMethod( arg0, hookimei, new MS.MethodHook( ) 49 | { 50 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 51 | { 52 | String imei = ""; 53 | imei = ( String ) old.invoke( arg0, arg1 ); 54 | // imei = "352621061639586"; 55 | Log.i( "hook_imei", imei ); 56 | statckTrace.LogStatckTrace("hook_imsi_StatckTrace"); 57 | return imei; 58 | } 59 | }, old ); 60 | } 61 | Method hookimsi; 62 | try 63 | { 64 | hookimsi = arg0.getMethod( "getSubscriberId", null ); 65 | } 66 | catch (Exception e ) 67 | { 68 | hookimsi = null; 69 | e.printStackTrace( ); 70 | } 71 | if ( hookimsi != null ) 72 | { 73 | final MS.MethodPointer old = new MS.MethodPointer( ); 74 | MS.hookMethod( arg0, hookimsi, new MS.MethodHook( ) 75 | { 76 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 77 | { 78 | String imsi = ""; 79 | imsi = ( String ) old.invoke( arg0, arg1 ); 80 | Log.i( "hook_imsi", imsi ); 81 | statckTrace.LogStatckTrace("hook_imsi_StatckTrace"); 82 | return imsi; 83 | } 84 | }, old ); 85 | } 86 | 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/hook/java/cipher.java: -------------------------------------------------------------------------------- 1 | package hook.java; 2 | 3 | import java.lang.reflect.Method; 4 | import java.security.Key; 5 | import java.security.spec.AlgorithmParameterSpec; 6 | import java.util.Arrays; 7 | 8 | import javax.crypto.SecretKey; 9 | import javax.crypto.spec.IvParameterSpec; 10 | 11 | import android.util.Log; 12 | import tools.statckTrace; 13 | 14 | import com.saurik.substrate.MS; 15 | 16 | public class cipher implements MS.ClassLoadHook 17 | { 18 | private static cipher Cipher_Instance; 19 | 20 | public cipher( ) 21 | { 22 | super( ); 23 | } 24 | 25 | public static void hook() 26 | { 27 | MS.hookClassLoad("javax.crypto.Cipher", Cipher_Instance.getInstance()); 28 | } 29 | 30 | public static cipher getInstance( ) 31 | { 32 | if ( Cipher_Instance == null ) 33 | { 34 | Cipher_Instance = new cipher( ); 35 | } 36 | return Cipher_Instance; 37 | } 38 | 39 | @SuppressWarnings( "unchecked" ) 40 | public void classLoaded( Class< ? > clazz ) 41 | { 42 | //------------------------------------------------------------------------------init 43 | Method init=null; 44 | try 45 | { 46 | init = clazz.getMethod( "init", new Class[]{int.class,Key.class,AlgorithmParameterSpec.class} ); 47 | } 48 | catch ( Exception e ) 49 | { 50 | init = null; 51 | e.printStackTrace( ); 52 | } 53 | if ( init != null ) 54 | { 55 | final MS.MethodPointer initold = new MS.MethodPointer( ); 56 | MS.hookMethod( clazz, init, new MS.MethodHook( ) 57 | { 58 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 59 | { 60 | byte[] key = ((SecretKey)arg1[1]).getEncoded() ; 61 | byte[] iv = ((IvParameterSpec)arg1[2]).getIV(); 62 | Log.i("Fhook", "hook_Cipher_doFinal_key" + Arrays.toString((byte[])key) ); 63 | Log.i("Fhook", "hook_Cipher_doFinal_iv" + Arrays.toString((byte[])iv) ); 64 | statckTrace.LogStatckTrace("hook_Cipher_StatckTrace"); 65 | return initold.invoke( arg0, arg1 ); 66 | } 67 | }, initold ); 68 | } 69 | //------------------------------------------------------------------------------doFinal 70 | Method doFinal; 71 | try 72 | { 73 | doFinal = clazz.getMethod( "doFinal", new Class[]{byte[].class} ); 74 | } 75 | catch ( Exception e ) 76 | { 77 | doFinal = null; 78 | e.printStackTrace( ); 79 | } 80 | if(doFinal != null){ 81 | final MS.MethodPointer doFinalold = new MS.MethodPointer( ); 82 | MS.hookMethod( clazz, doFinal, new MS.MethodHook( ) 83 | { 84 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 85 | { 86 | byte[] result = (byte[]) doFinalold.invoke( arg0, arg1 ); 87 | Log.i("Fhook", "hook_Cipher_doFinal_data" + Arrays.toString((byte[])arg1[0]) ); 88 | Log.i("Fhook", "hook_Cipher_doFinal_result" + Arrays.toString(result) ); 89 | statckTrace.LogStatckTrace("hook_Cipher_StatckTrace"); 90 | return result; 91 | } 92 | }, doFinalold ); 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/hook/java/stringBuilder.java: -------------------------------------------------------------------------------- 1 | package hook.java; 2 | 3 | import java.lang.reflect.Method; 4 | 5 | import android.util.Log; 6 | 7 | import com.saurik.substrate.MS; 8 | 9 | public class stringBuilder implements MS.ClassLoadHook 10 | { 11 | private static stringBuilder StringBuilder_Instance = null; 12 | 13 | public stringBuilder( ) 14 | { 15 | super( ); 16 | } 17 | 18 | public static void hook(){ 19 | MS.hookClassLoad( "java.lang.StringBuilder",getInstance( )); 20 | } 21 | 22 | public static stringBuilder getInstance( ) 23 | { 24 | if ( StringBuilder_Instance == null ) 25 | { 26 | StringBuilder_Instance = new stringBuilder( ); 27 | } 28 | return StringBuilder_Instance; 29 | } 30 | 31 | @SuppressWarnings( "unchecked" ) 32 | public void classLoaded( Class< ? > StringBuilder_class ) 33 | { 34 | Method hookstring; 35 | try 36 | { 37 | hookstring = StringBuilder_class.getMethod( "toString", null ); 38 | } 39 | catch ( Exception e ) 40 | { 41 | hookstring = null; 42 | e.printStackTrace( ); 43 | } 44 | if ( hookstring != null ) 45 | { 46 | final MS.MethodPointer old = new MS.MethodPointer( ); 47 | MS.hookMethod( StringBuilder_class, hookstring, new MS.MethodHook( ) 48 | { 49 | public Object invoked( Object arg0, Object... arg1 ) throws Throwable 50 | { 51 | String str = ( String ) old.invoke( arg0, arg1 ); 52 | if(str.length()<1023){ 53 | Log.i( "Fhook", "hook_StringBuilder_toString" + str ); 54 | }else{ 55 | Log.i("Fhook", "hook_StringBuilder_toString_Multi-section" + "start" ); 56 | int length= 1023; 57 | int i = 0; 58 | for(;i 2 | #include "substrate.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | 23 | #ifndef __ASM_SH_LOCAL_H 24 | #define __ASM_SH_LOCAL_H 25 | #endif 26 | 27 | MSConfig(MSFilterExecutable, "/system/bin/app_process") 28 | 29 | //MSConfig(MSFilterLibrary,"/system/lib/libc.so") 30 | 31 | #define GETLR(store_lr) \ 32 | __asm__ __volatile__( \ 33 | "mov %0, lr\n\t" \ 34 | : "=r"(store_lr) \ 35 | ) 36 | 37 | 38 | #define SOINFO_NAME_LEN 128 39 | 40 | #define HOOK_SUCCESS 0 41 | #define HOOK_FAILED -1 42 | 43 | #define TK_INLINEHOOK(addr) TK_InlineHookFunction((void*)(baseAdd + 0x ## addr),(void*)&my_ ## addr,(void **)&old_ ## addr); 44 | 45 | #define TK_ARM_INLINEHOOK(addr) TK_InlineHookFunction((void*)((unsigned int)baseAdd + 0x ## addr -1),(void*)&my_ ## addr,(void **)&old_ ## addr); 46 | 47 | /*----全局-----*/ 48 | static void* baseAdd = 0; 49 | /*----变量-----*/ 50 | 51 | typedef struct _HookStruct{ 52 | char SOName[SOINFO_NAME_LEN]; 53 | char FunctionName[SOINFO_NAME_LEN]; 54 | void *NewFunc; 55 | void *OldFunc; 56 | void *occPlace; 57 | }HookStruct; 58 | 59 | int (*TK_HookImportFunction)(HookStruct *pHookStruct); 60 | int (*TK_HookExportFunction)(HookStruct *pHookStruct); 61 | int (*TK_InlineHookFunction)(void *TargetFunc, void *NewFunc, void** OldFunc); 62 | 63 | int init_TKHookFunc() 64 | { 65 | void * handle = dlopen("/data/data/cydiasubstrate.hooktools/lib/libTKHooklib.so",RTLD_NOW); 66 | if(handle!=NULL) 67 | { 68 | TK_HookExportFunction = dlsym(handle,"TK_HookExportFunction"); 69 | // if(TK_HookExportFunction!=NULL) 70 | 71 | TK_InlineHookFunction = dlsym(handle,"TK_InlineHookFunction"); 72 | // if(TK_InlineHookFunction!=NULL) 73 | 74 | TK_HookImportFunction = dlsym(handle,"TK_HookImportFunction"); 75 | if(TK_HookImportFunction!=NULL) 76 | return 1; 77 | } 78 | return 0; 79 | } 80 | 81 | /* dump mem 82 | START 83 | */ 84 | void dump(unsigned int baseAddr, int size, char* s) 85 | { 86 | char filename[1024]; 87 | memset(filename,0,1024); 88 | sprintf(filename,"/sdcard/dump/char_%s_0x%x",s,baseAdd); 89 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strlen","filename:%s", filename); 90 | int fd = open(filename, O_CREAT | O_WRONLY);//创建 只写 91 | int n = write(fd,baseAddr -1,size); 92 | close(fd); 93 | } 94 | /* 95 | END 96 | */ 97 | 98 | 99 | int (* oldstrlen)(const char *str); 100 | int mystrlen(const char *str) 101 | { 102 | unsigned lr; 103 | GETLR(lr); 104 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strlen","str[0x%x]:%s [0x%x]", str, str, lr); 105 | return oldstrlen(str); 106 | } 107 | 108 | void* (* oldmemset)(void* s, int ch, size_t n); 109 | void* mymemset(void* s, int ch, size_t n) 110 | { 111 | unsigned lr; 112 | GETLR(lr); 113 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_memset","s:%p ch:[0x%x] size_t:%d [0x%x]",s ,ch, n, lr); 114 | return oldmemset(s, ch, n); 115 | } 116 | 117 | int (* oldlstat)(const char *path, struct stat *buf); 118 | int mylstat(const char *path, struct stat *buf) 119 | { 120 | unsigned lr; 121 | GETLR(lr); 122 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_lstat","path[0x%x]:%s buf:%s [0x%x]",path, path, buf, lr); 123 | return oldlstat(path,buf); 124 | } 125 | 126 | int (* oldremove)(const char * filepath); 127 | int myremove(const char * filepath) 128 | { 129 | unsigned lr; 130 | GETLR(lr); 131 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_remove","path[0x%x]:%s [0x%x]", filepath, filepath, lr); 132 | return oldremove(filepath); 133 | } 134 | 135 | int (* oldopen)(const char* path, int mode, __va_list ap ); 136 | int myopen(const char* path, int mode, __va_list ap ) 137 | { 138 | unsigned lr; 139 | GETLR(lr); 140 | int fd = oldopen(path, mode, ap); 141 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_open","path[0x%x]:%s fd:%d [0x%x]", path, path, fd, lr); 142 | return fd; 143 | } 144 | 145 | FILE * (* oldfopen)(const char* path, const char * mode); 146 | FILE * myfopen(const char* path, const char * mode) 147 | { 148 | unsigned lr; 149 | GETLR(lr); 150 | FILE * f = oldfopen(path,mode); 151 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fopen","File:0x%x path[0x%x]:%s mode:%s [0x%x]",(unsigned int)f, path, path, mode, lr); 152 | return f; 153 | } 154 | 155 | char *(* oldstrcpy)(char* dest, const char *src); 156 | char *mystrcpy(char* dest, const char *src) 157 | { 158 | unsigned lr; 159 | GETLR(lr); 160 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strcpy","dest[0x%x]:%s src[0x%x]:%s [0x%x]",dest,dest,src,src,lr); 161 | return oldstrcpy(dest,src); 162 | } 163 | 164 | char *(* oldstrncpy)(char* dest,char* src, size_t n); 165 | char *mystrncpy(char* dest,char* src, size_t n) 166 | { 167 | unsigned lr; 168 | GETLR(lr); 169 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strncpy","dest[0x%x]:%.*s src[0x%x]:%.*s size:n [0x%x]", dest,n,dest,src,n,src,n,lr); 170 | return oldstrncpy(dest,src,n); 171 | } 172 | 173 | void (*oldfree)(void *ptr); 174 | void myfree(void *ptr) 175 | { 176 | unsigned lr; 177 | GETLR(lr); 178 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_free","free[0x%x]:%s [0x%x]", ptr, ptr, lr); 179 | return oldfree(ptr); 180 | } 181 | 182 | char *(* oldstrcat)(char *dest,char *src); 183 | char *mystrcat(char *dest,char *src) 184 | { 185 | unsigned lr; 186 | GETLR(lr); 187 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strcat","[0x%x] dest[0x%x]:%s src[0x%x]:%s ", lr,dest,dest,src,src); 188 | return oldstrcat(dest, src); 189 | } 190 | 191 | void *(* oldmemcpy)(void *dest, const void *src, size_t n); 192 | void *mymemcpy(void *dest, const void *src, size_t n) 193 | { 194 | unsigned lr; 195 | GETLR(lr); 196 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_memcpy","dest[0x%x] src[0x%x]:%.*s size:%d [0x%x]", dest , src , n , src,n,lr); 197 | return oldmemcpy(dest, src, n); 198 | } 199 | 200 | int (* oldgettimeofday)(struct timeval*tv, struct timezone *tz); 201 | int mygettimeofday(struct timeval*tv, struct timezone *tz) 202 | { 203 | unsigned lr; 204 | GETLR(lr); 205 | int ret = oldgettimeofday(tv,tz); 206 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_gettimeofday","tv_sec:%ld,tv_usec:%ld,[0x%x]",tv->tv_sec,tv->tv_usec,lr); 207 | return ret; 208 | 209 | 210 | } 211 | 212 | void* (* oldmalloc)(unsigned int num_bytes); 213 | void* mymalloc(unsigned int num_bytes) 214 | { 215 | unsigned lr; 216 | GETLR(lr); 217 | void* tmp = oldmalloc(num_bytes); 218 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_malloc","malloc[0x%x] num_bytes:%u [0x%x]", tmp, num_bytes, lr); 219 | 220 | return tmp; 221 | } 222 | 223 | int (* oldread)(int handle, void *buf, int nbyte); 224 | int myread(int handle, void *buf, int nbyte) 225 | { 226 | unsigned lr; 227 | GETLR(lr); 228 | int read = oldread(handle, buf, nbyte); 229 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_read","handle:%d buf[0x%x]:%.*s nbyte:%u [0x%x]", handle, buf,read, buf, nbyte, lr); 230 | return read; 231 | 232 | 233 | } 234 | 235 | int (* oldwrite) (int fd,const void * buf,size_t count); 236 | int mywrite (int fd,const void * buf,size_t count) 237 | { 238 | unsigned lr; 239 | GETLR(lr); 240 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_write","fd:%d buf[0x%x]:%.*s count:%d [0x%x]", fd, buf,count,buf, count, lr); 241 | return oldwrite(fd, buf, count); 242 | } 243 | 244 | void (* oldexit)(int ret); 245 | void myexit(int ret) 246 | { 247 | unsigned lr; 248 | GETLR(lr); 249 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_exit","ret:%d [0x%x]",ret,lr); 250 | return oldexit(ret); 251 | } 252 | 253 | char *(* oldstrdup)(char *s); 254 | char *mystrdup(char *s) 255 | { 256 | unsigned lr; 257 | GETLR(lr); 258 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strdup","char[0x%x]:%s [0x%x]",s,s,lr); 259 | return oldstrdup(s); 260 | } 261 | 262 | void * (* oldcalloc)(size_t n, size_t size); 263 | void *mycalloc(size_t n, size_t size) 264 | { 265 | unsigned lr; 266 | GETLR(lr); 267 | void *v = oldcalloc(n,size); 268 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_calloc","calloc[0x%x] size:%d [0x%x]",v,n,lr); 269 | return v; 270 | } 271 | 272 | int (* oldaccess)(const char *filenpath, int mode); 273 | int myaccess(const char *filenpath, int mode) 274 | { 275 | unsigned lr; 276 | GETLR(lr); 277 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_access","filenpath[0x%x]:%s mode:%d [0x%x]",filenpath,filenpath,mode,lr); 278 | return oldaccess(filenpath,mode); 279 | } 280 | 281 | char (* olddirname) ( char* path ); 282 | char mydirname ( char* path ) 283 | { 284 | unsigned lr; 285 | GETLR(lr); 286 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_dirname","path[0x%x]:%s [0x%x]",path,path,lr); 287 | return olddirname(path); 288 | } 289 | 290 | char *(* oldstrtok)(char* s,char *delim); 291 | char *mystrtok(char* s,char *delim) 292 | { 293 | unsigned lr; 294 | GETLR(lr); 295 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strtok","s[0x%x]:%s delim:%s [0x%x]",s,s,delim,lr); 296 | return oldstrtok(s,delim); 297 | } 298 | 299 | int (* oldatoi)(const char *nptr); 300 | int myatoi(const char *nptr) 301 | { 302 | unsigned lr; 303 | GETLR(lr); 304 | int n = oldatoi(nptr); 305 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_atoi","nptr:%s return:%d [0x%x]",nptr,n,lr); 306 | return n; 307 | } 308 | 309 | void *(* oldrealloc)(void *mem_address, unsigned int newsize); 310 | void *myrealloc(void *mem_address, unsigned int newsize) 311 | { 312 | unsigned lr; 313 | GETLR(lr); 314 | void *v = oldrealloc(mem_address, newsize); 315 | if (v != NULL) { 316 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_realloc","realloc[0x%x] mem_ad[0x%x] newsize:%u [0x%x]",v,mem_address, newsize, lr); 317 | } 318 | return v; 319 | } 320 | 321 | int (* oldgetpriority)(int which,int who); 322 | int mygetpriority(int which,int who) 323 | { 324 | unsigned lr; 325 | GETLR(lr); 326 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getpriority","which:%d who:%d [0x%x]", which, who, lr); 327 | return oldgetpriority(which, who); 328 | } 329 | 330 | void (* oldusleep)(int micro_seconds); 331 | void myusleep(int micro_seconds) 332 | { 333 | unsigned lr; 334 | GETLR(lr); 335 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_usleep","micro_seconds:%d [0x%x]", micro_seconds, lr); 336 | return oldusleep(micro_seconds); 337 | } 338 | 339 | char *(* oldfgets)(char *buf, int bufsize, FILE *stream); 340 | char *myfgets(char *buf, int bufsize, FILE *stream) 341 | { 342 | unsigned lr; 343 | GETLR(lr); 344 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fgets","buf[0x%x]:%s bufsize:%d [0x%x]", buf, bufsize, lr); 345 | return oldfgets(buf, bufsize, stream); 346 | } 347 | 348 | int (* oldpthread_create)(void* tidp, void* attr, void* start_rtn, void* arg); 349 | int mypthread_create(void* tidp, void *attr,void* start_rtn , void* arg) 350 | { 351 | unsigned lr; 352 | GETLR(lr); 353 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_create","tidp:[%p] start_rtn:[%p] [0x%x]", tidp, start_rtn, lr); 354 | return oldpthread_create(tidp, attr, start_rtn, arg); 355 | } 356 | 357 | int (* oldpthread_cond_init)(void *cond, void *cond_attr); 358 | int mypthread_cond_init(void *cond, void *cond_attr) 359 | { 360 | unsigned lr; 361 | GETLR(lr); 362 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_cond_init"," cond[0x%x] cond_attr[0x%x] [0x%x]", cond , cond_attr, lr); 363 | return oldpthread_cond_init(cond, cond_attr); 364 | } 365 | 366 | int (* oldpthread_cond_wait)(void *cond, void *mutex); 367 | int mypthread_cond_wait(void *cond, void *mutex) 368 | { 369 | unsigned lr; 370 | GETLR(lr); 371 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_cond_wait"," cond[0x%x] mutex[0x%x] [0x%x]",cond, mutex, lr); 372 | return oldpthread_cond_wait(cond, mutex); 373 | } 374 | 375 | int (* oldpthread_cond_timedwait)(void *cond, void *mutex, const struct timespec *abstime); 376 | int mypthread_cond_timedwait(void *cond, void *mutex, const struct timespec *abstime) 377 | { 378 | unsigned lr; 379 | GETLR(lr); 380 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_cond_timedwait"," cond[0x%x] mutex[0x%x] abstime:%d [0x%x]",cond, mutex, abstime, lr); 381 | return oldpthread_cond_timedwait(cond, mutex, abstime); 382 | } 383 | 384 | int (* oldpthread_cond_signal)(void *cond); 385 | int mypthread_cond_signal(void *cond) 386 | { 387 | unsigned lr; 388 | GETLR(lr); 389 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_cond_signal"," cond[0x%x] [0x%x]",cond,lr); 390 | return oldpthread_cond_signal(cond); 391 | } 392 | 393 | int (* oldpthread_kill)(void* thread, int sig); 394 | int mypthread_kill(void* thread, int sig) 395 | { 396 | unsigned lr; 397 | GETLR(lr); 398 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_kill","thread[0x%x], sig:%d [0x%x]",thread, sig, lr); 399 | return oldpthread_kill(thread, sig); 400 | } 401 | 402 | int (* oldpthread_mutex_lock)(void *mutex); 403 | int mypthread_mutex_lock(void *mutex) 404 | { 405 | unsigned lr; 406 | GETLR(lr); 407 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_mutex_lock","mutex[0x%x] [0x%x]",mutex,lr); 408 | return oldpthread_mutex_lock(mutex); 409 | } 410 | 411 | int (* oldpthread_mutex_unlock)(void *mutex); 412 | int mypthread_mutex_unlock(void *mutex) 413 | { 414 | unsigned lr; 415 | GETLR(lr); 416 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_mutex_unlock","mutex[0x%x] [0x%x]",mutex,lr); 417 | return oldpthread_mutex_unlock(mutex); 418 | } 419 | 420 | int (* oldpthread_mutex_init)(void *mutex,void *attr); 421 | int mypthread_mutex_init(void *mutex,void *attr) 422 | { 423 | unsigned lr; 424 | GETLR(lr); 425 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_mutex_init","mutex[0x%x] attr[0x%x] [0x%x]", mutex, attr, lr); 426 | return oldpthread_mutex_init(mutex, attr); 427 | } 428 | 429 | int (* oldpthread_mutex_destroy)(void * mutex,void * attr); 430 | int mypthread_mutex_destroy(void * mutex,void * attr) 431 | { 432 | unsigned lr; 433 | GETLR(lr); 434 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_mutex_destroy","mutex[0x%x] attr[0x%x] [0x%x]", mutex, attr, lr); 435 | return oldpthread_mutex_destroy(mutex, attr); 436 | } 437 | 438 | int (* oldmprotect)(const void *addr, size_t len, int prot); 439 | int mymprotect(const void *addr, size_t len, int prot) 440 | { 441 | unsigned lr; 442 | GETLR(lr); 443 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_mprotect","addr[0x%x] size:%d [0x%x]", addr, len, lr); 444 | return oldmprotect(addr, len, prot); 445 | } 446 | 447 | int (* oldptrace)(int request, int pid, int addr, int data); 448 | int myptrace(int request, int pid, int addr, int data) 449 | { 450 | unsigned lr; 451 | GETLR(lr); 452 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_ptrace","request:%d pid:%d addr[0x%x] data:%d [0x%x]", request, pid, addr, data, lr); 453 | return oldptrace(request, pid, addr, data); 454 | } 455 | 456 | int (* oldsetenv)(const char *name,const char * value,int overwrite); 457 | int mysetenv(const char *name,const char * value,int overwrite) 458 | { 459 | unsigned lr; 460 | GETLR(lr); 461 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_setenv","name[0x%x]:%s value[0x%x]:s overwrite:%d [0x%x]", name, name, value, value, lr); 462 | return oldsetenv(name, value, overwrite); 463 | } 464 | 465 | int (* oldvsprintf)(char *string, char *format, va_list param); 466 | int myvsprintf(char *string, char *format, va_list param) 467 | { 468 | unsigned lr; 469 | GETLR(lr); 470 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_vsprintf","string[0x%x]:%s format[0x%x]:%s [0x%x]",string,string,format,format,lr); 471 | return oldvsprintf(string, format, param); 472 | } 473 | 474 | int (* oldvprintf)(char *format, va_list param); 475 | int myvprintf(char *format, va_list param) 476 | { 477 | unsigned lr; 478 | GETLR(lr); 479 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_vprintf","format[0x%x]:%s [0x%x]",format,format,lr); 480 | return oldvprintf(format, param); 481 | } 482 | 483 | int (* oldvfprintf)(FILE *stream, char *format, va_list param); 484 | int myvfprintf(FILE *stream, char *format, va_list param) 485 | { 486 | unsigned lr; 487 | GETLR(lr); 488 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_vsprintf","format[0x%x]:%s [0x%x]",format,format,lr); 489 | return oldvfprintf(stream, format, param); 490 | } 491 | 492 | long (* oldtime)(long *tloc); 493 | long mytime(long *tloc) 494 | { 495 | unsigned lr; 496 | GETLR(lr); 497 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_time","time:%f [0x%x]",tloc,lr); 498 | return oldtime(tloc); 499 | } 500 | 501 | int (* oldtolower)(int c); 502 | int mytolower(int c) 503 | { 504 | unsigned lr; 505 | GETLR(lr); 506 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_tolower","c:%d [0x%x]",c,lr); 507 | return oldtolower(c); 508 | } 509 | 510 | long (* oldstrtoul)(const char *nptr,char **endptr,int base); 511 | long mystrtoul(const char *nptr,char **endptr,int base) 512 | { 513 | unsigned lr; 514 | GETLR(lr); 515 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strtoul","nptr[0x%x]:%s [0x%x]",nptr,nptr,lr); 516 | return oldstrtoul(nptr, endptr, base); 517 | } 518 | 519 | int (* oldstrtol)(const char *nptr,char **endptr,int base); 520 | int mystrtol(const char *nptr,char **endptr,int base) 521 | { 522 | unsigned lr; 523 | GETLR(lr); 524 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strtol","nptr[0x%x]:%s [0x%x]",nptr,nptr,lr); 525 | return oldstrtol(nptr, endptr, base); 526 | } 527 | 528 | char *(* oldstrstr)(char *str1, const char *str2); 529 | char * mystrstr(char *str1, const char *str2) 530 | { 531 | unsigned lr; 532 | GETLR(lr); 533 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strstr","str1[0x%x]:%s str2[0x%x]:%s [0x%x]",str1,str1,str2,str2,lr); 534 | return oldstrstr(str1, str2); 535 | } 536 | 537 | char *(* oldstrsep)(char **stringp, const char *delim); 538 | char * mystrsep(char **stringp, const char *delim) 539 | { 540 | unsigned lr; 541 | GETLR(lr); 542 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strsep","stringp[0x%x]:%s delim[0x%x]:%s [0x%x]", *stringp, *stringp, delim, delim, lr); 543 | return oldstrsep(stringp, delim); 544 | } 545 | 546 | char *(* oldstrrchr)(const char *str, char c); 547 | char * mystrrchr(const char *str, char c) 548 | { 549 | unsigned lr; 550 | GETLR(lr); 551 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strrchr","str[0x%x]:%s c[0x%x]:%s [0x%x]", str, str, c, c, lr); 552 | return oldstrrchr(str, c); 553 | } 554 | 555 | char *(* oldstrpbrk)(const char *s1, const char *s2); 556 | char * mystrpbrk(const char * s1,const char * s2) 557 | { 558 | unsigned lr; 559 | GETLR(lr); 560 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strpbrk","str1[0x%x]:%s str2[0x%x]:%s [0x%x]",s1,s1,s2,s2,lr); 561 | return oldstrpbrk(s1, s2); 562 | } 563 | 564 | int (* oldstrncmp) ( const char * str1, const char * str2, size_t num ); 565 | int mystrncmp ( const char * str1, const char * str2, size_t num ) 566 | { 567 | unsigned lr; 568 | GETLR(lr); 569 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strncmp","str1[0x%x]:%s str2[0x%x]:%s size:%d [0x%x]",str1,str1,str2,str2,num,lr); 570 | return oldstrncmp(str1, str2, num); 571 | } 572 | 573 | int (* oldstrncasecmp)(const char *s1, const char *s2, size_t n); 574 | int mystrncasecmp(const char *s1, const char *s2, size_t n) 575 | { 576 | unsigned lr; 577 | GETLR(lr); 578 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strncasecmp","str1[0x%x]:%s str2[0x%x]:%s size:%d [0x%x]",s1,s1,s2,s2,n,lr); 579 | return oldstrncmp(s1, s2, n); 580 | } 581 | 582 | int (* oldstrcmp)(const char *s1,const char *s2); 583 | int mystrcmp(const char *s1,const char *s2) 584 | { 585 | unsigned lr; 586 | GETLR(lr); 587 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strcmp","str1[0x%x]:%s str2[0x%x]:%s [0x%x]",s1,s1,s2,s2,lr); 588 | return oldstrcmp(s1, s2); 589 | } 590 | 591 | void (* oldsleep)(int i); 592 | void mysleep(int i) 593 | { 594 | unsigned lr; 595 | GETLR(lr); 596 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_sleep","i:%d [0x%x]",i,lr); 597 | return oldsleep(i); 598 | } 599 | 600 | int (* oldsetpriority)(int which,int who, int prio); 601 | int mysetpriority(int which,int who, int prio) 602 | { 603 | unsigned lr; 604 | GETLR(lr); 605 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_setpriority","which:%d who:%d prio:%d [0x%x]", which, who, prio, lr); 606 | return oldsetpriority(which,who,prio); 607 | } 608 | 609 | void (* oldsend) (int s,const void *msg,size_t len,int flags); 610 | void mysend (int s,const void *msg,size_t len,int flags) 611 | { 612 | unsigned lr; 613 | GETLR(lr); 614 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_send","s:%d msg[0x%x]:%s size:%d flags:%d [0x%x]",s, msg, msg, len, flags, lr); 615 | return oldsend(s,msg,len,flags); 616 | } 617 | 618 | int (* oldrmdir)( const char *dirname ); 619 | int myrmdir( const char *dirname ) 620 | { 621 | unsigned lr; 622 | GETLR(lr); 623 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_rmdir","dirname:%s [0x%x]",dirname, lr); 624 | return oldrmdir(dirname); 625 | } 626 | 627 | void (* oldreadlink)(const char *path, char *buf, size_t bufsiz); 628 | void myreadlink(const char *path, char *buf, size_t bufsiz) 629 | { 630 | unsigned lr; 631 | GETLR(lr); 632 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_readlink","path[0x%x]:%s buf[0x%x]:%s size:%d [0x%x]",path, path, buf, buf, bufsiz, lr); 633 | return oldreadlink(path, buf, bufsiz); 634 | } 635 | 636 | int (* oldraise)(int sig); 637 | int myraise(int sig) 638 | { 639 | unsigned lr; 640 | GETLR(lr); 641 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_raise","sig:%d [0x%x]", sig, lr); 642 | return oldraise(sig); 643 | } 644 | 645 | int (* oldpthread_cond_destroy)(void *cond); 646 | int mypthread_cond_destroy(void *cond) 647 | { 648 | unsigned lr; 649 | GETLR(lr); 650 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_cond_destroy","cond:[0x%x] [0x%x]", cond, lr); 651 | return oldpthread_cond_destroy(cond); 652 | } 653 | 654 | int (* oldpthread_attr_init)(void *attr); 655 | int mypthread_attr_init(void *attr) 656 | { 657 | unsigned lr; 658 | GETLR(lr); 659 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_attr_init","attr:[0x%x] [0x%x]", attr, lr); 660 | return oldpthread_attr_init(attr); 661 | } 662 | 663 | int (* oldpthread_attr_setdetachstate)(void *attr, int detachstate); 664 | int mypthread_attr_setdetachstate(void *attr, int detachstate) 665 | { 666 | unsigned lr; 667 | GETLR(lr); 668 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_setdetachstate","attr:[0x%x] detachstate:%d [0x%x]", attr, detachstate, lr); 669 | return oldpthread_attr_setdetachstate(attr, detachstate); 670 | } 671 | 672 | void (* oldperror)(const char *s); 673 | void myperror(const char *s) 674 | { 675 | unsigned lr; 676 | GETLR(lr); 677 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_perror","s[0x%x]:%s [0x%x]", s, s, lr); 678 | return oldperror(s); 679 | } 680 | 681 | void* (* oldmmap)(void* start,size_t length,int prot,int flags,int fd,off_t offset); 682 | void* mymmap(void* start,size_t length,int prot,int flags,int fd,off_t offset) 683 | { 684 | unsigned lr; 685 | GETLR(lr); 686 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_mmap","start:%d length:%d prot:%d flags:%d fd:%d offset:%d [0x%x]", start, length, prot, flags, fd, offset, lr); 687 | return oldmmap(start,length,prot,flags,fd,offset); 688 | } 689 | 690 | int (* oldmkdir)( const char *dirname ); 691 | int mymkdir( const char *dirname ) 692 | { 693 | unsigned lr; 694 | GETLR(lr); 695 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_mkdir","dirname:%s [0x%x]", dirname, lr); 696 | return oldmkdir(dirname); 697 | } 698 | 699 | void *(* oldmemmove)( void* dest, const void* src, size_t count ); 700 | void *mymemmove( void* dest, const void* src, size_t count ) 701 | { 702 | unsigned lr; 703 | GETLR(lr); 704 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_memmove","dest[0x%x]:%.*s src[0x%x]:%.*s count:%d [0x%x]", dest, count, dest, src, count, src, count, lr); 705 | return oldmemmove(dest, src, count); 706 | } 707 | 708 | int (* oldmemcmp)(const void *buf1, const void *buf2, unsigned int count); 709 | int mymemcmp(const void *buf1, const void *buf2, unsigned int count) 710 | { 711 | unsigned lr; 712 | GETLR(lr); 713 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_memcmp","buf1[0x%x]:%.*s buf2[0x%x]:%.*s count:%d [0x%x]", buf1,count, buf1, buf2,count, buf2, count, lr); 714 | return oldmemcmp(buf1, buf2, count); 715 | } 716 | 717 | int (* oldlrand48)(); 718 | int mylrand48() 719 | { 720 | int i = oldlrand48(); 721 | unsigned lr; 722 | GETLR(lr); 723 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_lrand48","lrand48:%d [0x%x]", i, lr); 724 | return i; 725 | } 726 | 727 | int (* oldgetppid)(); 728 | int mygetppid() 729 | { 730 | unsigned lr; 731 | GETLR(lr); 732 | int i = oldgetppid(); 733 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getppid","getppid():%d [0x%x]", i, lr); 734 | return i; 735 | } 736 | 737 | int (* oldgetpid)(); 738 | int mygetpid() 739 | { 740 | unsigned lr; 741 | GETLR(lr); 742 | int i = oldgetpid(); 743 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getpid","getpid():%d [0x%x]", i, lr); 744 | return i; 745 | } 746 | 747 | int (* oldgeteuid)(); 748 | int mygeteuid() 749 | { 750 | unsigned lr; 751 | GETLR(lr); 752 | int i = oldgeteuid(); 753 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_geteuid","oldgeteuid():%d [0x%x]", i, lr); 754 | return i; 755 | } 756 | 757 | int (* oldgetsockname)( void* s, void* name, int namelen); 758 | int mygetsockname( void* s, void* name, int namelen) 759 | { 760 | unsigned lr; 761 | GETLR(lr); 762 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getsockname","s[0x%x]:%s name[0x%x]:%s namelen:%d [0x%x]", s, s, name, name, namelen, lr); 763 | return oldgetsockname( s, name, namelen); 764 | } 765 | 766 | int (* oldgetpeername)( void* s, void* name, int namelen); 767 | int mygetpeername( void* s, void* name, int namelen) 768 | { 769 | unsigned lr; 770 | GETLR(lr); 771 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getpeername","s[0x%x]:%s name[0x%x]:%s namelen:%d [0x%x]", s, s, name, name, namelen, lr); 772 | return oldgetpeername( s, name, namelen); 773 | } 774 | 775 | char *(* oldgetenv)(char *envvar); 776 | char *mygetenv(char *envvar) 777 | { 778 | unsigned lr; 779 | GETLR(lr); 780 | char* c = oldgetenv(envvar); 781 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_getenv","envvar[0x%x]:%s getenv:%s [0x%x]", envvar, envvar, c, lr); 782 | return c; 783 | } 784 | 785 | int (* oldfwrite)(const void* buffer, size_t size, size_t count, void* stream); 786 | int myfwrite(const void* buffer, size_t size, size_t count, void* stream) 787 | { 788 | unsigned lr; 789 | GETLR(lr); 790 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fwrite"," FILE:0x%x buffer[0x%x]:%.*s size:%d count:%d [0x%x]",stream, buffer, size, buffer, size, count, lr); 791 | return oldfwrite(buffer,size,count,stream); 792 | } 793 | 794 | long (* oldftell)(void *stream); 795 | long myftell(void *stream) 796 | { 797 | unsigned lr; 798 | GETLR(lr); 799 | long l = oldftell(stream); 800 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_ftell","FILE:0x%x l:%ld [0x%x]", stream,l, lr); 801 | return l; 802 | } 803 | 804 | int (* oldfstat)(int fildes,struct stat *buf); 805 | int myfstat(int fildes,struct stat *buf) 806 | { 807 | unsigned lr; 808 | GETLR(lr); 809 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fstat","fildes:%d [0x%x]", fildes, lr); 810 | return oldfstat(fildes,buf); 811 | } 812 | 813 | int (* oldfseek)(FILE *stream, long offset, int fromwhere); 814 | int myfseek(FILE *stream, long offset, int fromwhere) 815 | { 816 | unsigned lr; 817 | GETLR(lr); 818 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fseek","FILE:0x%x offset:%ld fromwhere:%d [0x%x]", (unsigned int)stream, offset, fromwhere ,lr); 819 | return oldfseek(stream,offset,fromwhere); 820 | } 821 | 822 | size_t (* oldfread) ( void *buffer, size_t size, size_t count, FILE *stream); 823 | size_t myfread ( void *buffer, size_t size, size_t count, FILE *stream) 824 | { 825 | unsigned lr; 826 | GETLR(lr); 827 | size_t result = oldfread(buffer,size,count,stream); 828 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fread","FILE:0x%x buffer[0x%x]:%.*s size:%d count:%d result:%d [0x%x]",(unsigned int)stream, buffer, result,(char*)buffer, size, count,result, lr); 829 | return result; 830 | } 831 | 832 | pid_t (* oldfork)(); 833 | pid_t myfork() 834 | { 835 | unsigned lr; 836 | GETLR(lr); 837 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fork","fork() ---- [0x%x]", lr); 838 | return oldfork(); 839 | } 840 | 841 | void (* oldfnmatch)(void* pattern,char* string,int flags); 842 | void myfnmatch(void* pattern,char* string,int flags) 843 | { 844 | unsigned lr; 845 | GETLR(lr); 846 | // __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fnmatch","string[0x%x]:%s flags:%d [0x%x]",string,string,flags, lr); 847 | return oldfnmatch(pattern,string,flags); 848 | }//LOG引起闪退 849 | 850 | int (* oldfflush)(FILE *stream); 851 | int myfflush(FILE *stream) 852 | { 853 | unsigned lr; 854 | GETLR(lr); 855 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fflush","FILE:0x%x [0x%x]",stream, lr); 856 | return oldfflush(stream); 857 | } 858 | 859 | int (* oldfclose)(FILE *stream); 860 | int myfclose(FILE *stream) 861 | { 862 | unsigned lr; 863 | GETLR(lr); 864 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fclose","FILE:0x%x [0x%x]",stream, lr); 865 | return oldfclose(stream); 866 | } 867 | 868 | char *(* oldstrchr)(const char *s,char c); 869 | char *mystrchr(const char *s,char c) 870 | { 871 | unsigned lr; 872 | GETLR(lr); 873 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strchr","s[0x%x]:%s c[0x%x]:%c [0x%x]",s,s,c,c, lr); 874 | return oldstrchr(s,c); 875 | } 876 | 877 | int (* oldclosedir)(void *dir); 878 | int myclosedir(void *dir) 879 | { 880 | unsigned lr; 881 | GETLR(lr); 882 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_closedir","dir[0x%x]:%s [0x%x]",dir,dir, lr); 883 | return oldclosedir(dir); 884 | } 885 | 886 | int (* oldclose)(int fd); 887 | int myclose(int fd) 888 | { 889 | unsigned lr; 890 | GETLR(lr); 891 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_close","fd:%d [0x%x]",fd, lr); 892 | return oldclose(fd); 893 | } 894 | 895 | char* (* oldbasename) ( char* path , char* suffix ); 896 | char* mybasename ( char* path , char* suffix ) 897 | { 898 | unsigned lr; 899 | GETLR(lr); 900 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_basename","path:%s suffix:%s [0x%x]",path,suffix, lr); 901 | return oldbasename(path,suffix); 902 | } 903 | 904 | void (* oldabort)(); 905 | void myabort() 906 | { 907 | unsigned lr; 908 | GETLR(lr); 909 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_abort","abort() ---- [0x%x]", lr); 910 | return oldabort(); 911 | } 912 | 913 | int (* oldkill)(pid_t pid, int sig); 914 | int mykill(pid_t pid, int sig) 915 | { 916 | unsigned lr; 917 | GETLR(lr); 918 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_kill","pid:%d sig:%d [0x%x]",pid,sig, lr); 919 | return oldkill(pid,sig); 920 | } 921 | 922 | char* (* oldstrncat)(char *dest,char *src,int n); 923 | char* mystrncat(char *dest,char *src,int n) 924 | { 925 | unsigned lr; 926 | GETLR(lr); 927 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strncat","dest[0x%x]:%s src[0x%x]:%s size:%d [0x%x]",dest,dest,src,src,n, lr); 928 | return oldstrncat(dest,src,n); 929 | } 930 | 931 | char * (* oldstrerror)(int errnum); 932 | char * mystrerror(int errnum) 933 | { 934 | unsigned lr; 935 | GETLR(lr); 936 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_strerror","errnum:%d [0x%x]",errnum, lr); 937 | return oldstrerror(errnum); 938 | } 939 | 940 | int (* oldstat)(const char *file_name, struct stat *buf); 941 | int mystat(const char *file_name, struct stat *buf) 942 | { 943 | unsigned lr; 944 | GETLR(lr); 945 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_stat","file_name[0x%x]:%s [0x%x]",file_name,file_name, lr); 946 | return oldstat(file_name,buf); 947 | } 948 | 949 | int (* oldsocket)(int domain, int type, int protocol); 950 | int mysocket(int domain, int type, int protocol) 951 | { 952 | unsigned lr; 953 | GETLR(lr); 954 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_socket","domain:%d type:%d protocol:%d [0x%x]", domain, type, protocol, lr); 955 | return oldsocket(domain,type,protocol); 956 | } 957 | 958 | int (* oldselect)(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval*timeout); 959 | int myselect(int maxfdp,fd_set *readfds,fd_set *writefds,fd_set *errorfds,struct timeval*timeout) 960 | { 961 | unsigned lr; 962 | GETLR(lr); 963 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_select","maxfdp:%d readfds:%d writefds:%d errorfds:%d timeout:%d [0x%x]", maxfdp, readfds, writefds, errorfds, timeout, lr); 964 | return oldselect(maxfdp,readfds,writefds,errorfds,timeout); 965 | } 966 | 967 | int (* oldrecvmsg)(int s, struct msghdr *msg, unsigned int flags); 968 | int myrecvmsg(int s, struct msghdr *msg, unsigned int flags) 969 | { 970 | unsigned lr; 971 | GETLR(lr); 972 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_recvmsg","s:%d msg:%s flags:%d [0x%x]", s, msg, flags, lr); 973 | return oldrecvmsg(s,msg,flags); 974 | } 975 | 976 | struct dirent * (* oldreaddir)(void * dir); 977 | struct dirent * myreaddir(void * dir) 978 | { 979 | unsigned lr; 980 | GETLR(lr); 981 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_readdir","dir:%s [0x%x]", dir, lr); 982 | return oldreaddir(dir); 983 | } 984 | 985 | int (* oldpthread_self)(); 986 | int mypthread_self() 987 | { 988 | int pthreadself = oldpthread_self(); 989 | unsigned lr; 990 | GETLR(lr); 991 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pthread_self","pthreadself:%d [0x%x]", pthreadself, lr); 992 | return pthreadself; 993 | } 994 | 995 | int (* oldpipe)(int fd[2]); 996 | int mypipe(int fd[2]) 997 | { 998 | unsigned lr; 999 | GETLR(lr); 1000 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_pipe","fd:%d fd:%d fd:%d [0x%x]", fd[0], fd[1], fd[2], lr); 1001 | return oldpipe(fd); 1002 | } 1003 | 1004 | void* (* oldopendir) (const char * path ); 1005 | void* myopendir (const char * path ) 1006 | { 1007 | unsigned lr; 1008 | GETLR(lr); 1009 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_opendir","path[0x%x]:%s [0x%x]", path, path, lr); 1010 | return oldopendir(path); 1011 | } 1012 | 1013 | void (* oldlseek)(int fildes,off_t offset ,int whence); 1014 | void mylseek(int fildes,off_t offset ,int whence) 1015 | { 1016 | unsigned lr; 1017 | GETLR(lr); 1018 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_lseek","fildes:%d offset:%d whence:%d [0x%x]", fildes, offset, whence, lr); 1019 | return oldlseek(fildes, offset, whence); 1020 | } 1021 | 1022 | int (* oldfcnt1)(int fd, int cmd, struct flock *lock); 1023 | int myfcnt1(int fd, int cmd, struct flock *lock) 1024 | { 1025 | unsigned lr; 1026 | GETLR(lr); 1027 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_fcnt1","fd:%d cmd:%d lock:%d [0x%x]", fd, cmd, lock, lr); 1028 | return oldfcnt1(fd, cmd, lock); 1029 | } 1030 | 1031 | // int (* oldinflateInit2_)(void* z,int w, const char* version,int stream_size); 1032 | // int myinflateInit2_(void* z,int w, const char* version,int stream_size) 1033 | // { 1034 | // unsigned lr; 1035 | // GETLR(lr); 1036 | // __android_log_print(ANDROID_LOG_INFO,"native_hook_c_inflateInit2_","stream_size:%d version[0x%x]:%s [0x%x]",stream_size,version,version, lr); 1037 | // return oldinflateInit2_(z,w,version,stream_size); 1038 | // } 1039 | 1040 | int (* oldprintf)(const char *format,...); 1041 | int myprintf(const char *format, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7, void* arg8, void* arg9, void* arg10, void* arg11, void* arg12, void* arg13, void* arg14, void* arg15, void* arg16, void* arg17, void* arg18, void* arg19, void* arg20, void* arg21, void* arg22, void* arg23, void* arg24) 1042 | { 1043 | unsigned lr; 1044 | GETLR(lr); 1045 | int ret = oldprintf(format,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24); 1046 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_printf","format[0x%x]:%s [0x%x]",format,format,lr); 1047 | return ret; 1048 | } 1049 | 1050 | int (* oldsprintf)(char *str, const char *fmt, ...); 1051 | int mysprintf(char *str, const char *fmt, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7, void* arg8, void* arg9, void* arg10, void* arg11, void* arg12, void* arg13, void* arg14, void* arg15, void* arg16, void* arg17, void* arg18, void* arg19, void* arg20, void* arg21, void* arg22, void* arg23, void* arg24) 1052 | { 1053 | unsigned lr; 1054 | GETLR(lr); 1055 | int ret = oldsprintf(str, fmt,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24); 1056 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_sprintf","fmt[0x%x]:%s str[0x%x]:%s [0x%x]",fmt,fmt,str,str,lr); 1057 | 1058 | return ret; 1059 | } 1060 | 1061 | int (* oldsnprintf)(char *str, size_t size, const char *format, ...); 1062 | int mysnprintf(char *str, size_t size, const char *format, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7, void* arg8, void* arg9, void* arg10, void* arg11, void* arg12, void* arg13, void* arg14, void* arg15, void* arg16, void* arg17, void* arg18, void* arg19, void* arg20, void* arg21, void* arg22, void* arg23, void* arg24) 1063 | { 1064 | unsigned lr; 1065 | GETLR(lr); 1066 | int ret = oldsnprintf(str, size, format,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24); 1067 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_snprintf_format","format[0x%x]:%s str[0x%x]:%s len[%d] [0x%x]",format,format,str,str,size,lr); 1068 | return ret; 1069 | 1070 | } 1071 | 1072 | int (* oldsscanf)( const char *buffer, const char *format, ...); 1073 | int mysscanf( const char *buffer, const char *format, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7, void* arg8, void* arg9, void* arg10, void* arg11, void* arg12, void* arg13, void* arg14, void* arg15, void* arg16, void* arg17, void* arg18, void* arg19, void* arg20, void* arg21, void* arg22, void* arg23, void* arg24) 1074 | { 1075 | unsigned lr; 1076 | GETLR(lr); 1077 | int ret = oldsscanf(buffer, format,arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,arg10,arg11,arg12,arg13, arg14, arg15, arg16, arg17, arg18, arg19, arg20, arg21, arg22, arg23, arg24); 1078 | __android_log_print(ANDROID_LOG_INFO,"native_hook_c_sscanf_format","format[0x%x]:%s buffer[0x%x]:%s [0x%x]",format,format,buffer,buffer,lr); 1079 | return ret; 1080 | } 1081 | 1082 | static void HookFunction(const char* FunctionName, void* myfunction, void** oldfunction, int mode, HookStruct* entity, MSImageRef image){ 1083 | switch(mode) 1084 | { 1085 | case 1: 1086 | { 1087 | strcpy(entity->FunctionName, FunctionName); 1088 | entity->NewFunc = (void*)myfunction; 1089 | if(!TK_HookExportFunction(entity)){ 1090 | *oldfunction = entity->OldFunc; 1091 | goto success; 1092 | }else{ 1093 | goto failed; 1094 | } 1095 | } 1096 | break; 1097 | case 2: 1098 | { 1099 | void * Function=MSFindSymbol(image,FunctionName); 1100 | if(Function!=NULL){ 1101 | MSHookFunction(Function,(void*)&myfunction,(void **)oldfunction); 1102 | goto success; 1103 | }else{ 1104 | goto failed; 1105 | } 1106 | } 1107 | break; 1108 | } 1109 | success: 1110 | __android_log_print(ANDROID_LOG_ERROR, "native_hook_HookFunction", "hook %s,mode %d, success",FunctionName,mode); 1111 | return; 1112 | failed: 1113 | __android_log_print(ANDROID_LOG_ERROR, "native_hook_HookFunction", "hook %s,mode %d, failed",FunctionName,mode); 1114 | return; 1115 | } 1116 | #define MODE_EXPORT 1 1117 | #define MODE_INLINE 2 1118 | #define MODE_IMPORT 3 1119 | #define HOOKEXPORT(FUNCNAME,MODE) {#FUNCNAME,(void*)my ## FUNCNAME,(void**)&old ## FUNCNAME ,MODE} 1120 | 1121 | typedef struct 1122 | { 1123 | const char* FunctionName; 1124 | void* myfunction; 1125 | void** oldfunction; 1126 | int data; 1127 | }myHookStruct; 1128 | myHookStruct myHookLibc[] = 1129 | { 1130 | // HOOKEXPORT(access,MODE_EXPORT), 1131 | // HOOKEXPORT(open,MODE_EXPORT), 1132 | // HOOKEXPORT(write,MODE_EXPORT), 1133 | // HOOKEXPORT(read,MODE_EXPORT), 1134 | // HOOKEXPORT(close,MODE_EXPORT), 1135 | // HOOKEXPORT(remove,MODE_EXPORT), 1136 | 1137 | // HOOKEXPORT(stat,MODE_EXPORT), 1138 | // HOOKEXPORT(lseek,MODE_EXPORT), 1139 | // HOOKEXPORT(lstat,MODE_EXPORT), 1140 | 1141 | 1142 | // HOOKEXPORT(fopen,MODE_EXPORT), 1143 | //HOOKEXPORT(fstat,MODE_EXPORT), 1144 | //HOOKEXPORT(fread,MODE_EXPORT), 1145 | //HOOKEXPORT(fwrite,MODE_EXPORT), 1146 | //HOOKEXPORT(fseek,MODE_EXPORT), 1147 | //HOOKEXPORT(ftell,MODE_EXPORT), 1148 | // HOOKEXPORT(fflush,MODE_EXPORT), 1149 | // HOOKEXPORT(fclose,MODE_EXPORT), 1150 | 1151 | // HOOKEXPORT(opendir,MODE_EXPORT), 1152 | // HOOKEXPORT(closedir,MODE_EXPORT), 1153 | // HOOKEXPORT(readdir,MODE_EXPORT), 1154 | // HOOKEXPORT(rmdir,MODE_EXPORT), 1155 | 1156 | 1157 | 1158 | // HOOKEXPORT(exit,MODE_EXPORT), 1159 | // HOOKEXPORT(kill,MODE_EXPORT), 1160 | 1161 | HOOKEXPORT(sprintf,MODE_EXPORT), 1162 | // HOOKEXPORT(printf,MODE_EXPORT), 1163 | // HOOKEXPORT(vprintf,MODE_EXPORT), 1164 | // HOOKEXPORT(sscanf,MODE_EXPORT), 1165 | HOOKEXPORT(snprintf,MODE_EXPORT), 1166 | 1167 | // HOOKEXPORT(malloc,MODE_EXPORT), 1168 | // HOOKEXPORT(realloc,MODE_EXPORT), 1169 | HOOKEXPORT(free,MODE_EXPORT), 1170 | // HOOKEXPORT(mprotect,MODE_EXPORT), 1171 | // HOOKEXPORT(mmap,MODE_EXPORT), 1172 | 1173 | // HOOKEXPORT(memmove,MODE_EXPORT), 1174 | // HOOKEXPORT(memset,MODE_EXPORT), 1175 | //HOOKEXPORT(memcpy,MODE_EXPORT), 1176 | // HOOKEXPORT(memcmp,MODE_EXPORT), 1177 | 1178 | // HOOKEXPORT(socket,MODE_EXPORT), 1179 | // HOOKEXPORT(select,MODE_EXPORT), 1180 | // HOOKEXPORT(recvmsg,MODE_EXPORT), 1181 | // HOOKEXPORT(pipe,MODE_EXPORT), 1182 | // HOOKEXPORT(getpriority,MODE_EXPORT), 1183 | // HOOKEXPORT(basename,MODE_EXPORT), 1184 | // HOOKEXPORT(fork,MODE_EXPORT), 1185 | // HOOKEXPORT(setpriority,MODE_EXPORT), 1186 | // HOOKEXPORT(send,MODE_EXPORT), 1187 | 1188 | // HOOKEXPORT(ptrace,MODE_EXPORT), 1189 | // HOOKEXPORT(perror,MODE_EXPORT), 1190 | // HOOKEXPORT(usleep,MODE_EXPORT), 1191 | // HOOKEXPORT(tolower,MODE_EXPORT), 1192 | //HOOKEXPORT(lrand48,MODE_EXPORT), 1193 | 1194 | // HOOKEXPORT(getsockname,MODE_EXPORT), 1195 | // HOOKEXPORT(getppid,MODE_EXPORT), 1196 | // HOOKEXPORT(getpid,MODE_EXPORT), 1197 | // HOOKEXPORT(geteuid,MODE_EXPORT), 1198 | //HOOKEXPORT(getenv,MODE_EXPORT), 1199 | //HOOKEXPORT(setenv,MODE_EXPORT), 1200 | 1201 | // HOOKEXPORT(time,MODE_EXPORT), 1202 | // HOOKEXPORT(gettimeofday,MODE_EXPORT), 1203 | 1204 | 1205 | HOOKEXPORT(strlen,MODE_EXPORT), 1206 | // HOOKEXPORT(strtol,MODE_EXPORT), 1207 | // HOOKEXPORT(strstr,MODE_EXPORT), 1208 | // HOOKEXPORT(strdup,MODE_EXPORT), 1209 | HOOKEXPORT(strcpy,MODE_EXPORT), 1210 | // HOOKEXPORT(strcmp,MODE_EXPORT), 1211 | HOOKEXPORT(strncpy,MODE_EXPORT), 1212 | HOOKEXPORT(strncat,MODE_EXPORT), 1213 | HOOKEXPORT(strcat,MODE_EXPORT), 1214 | // HOOKEXPORT(strtok,MODE_EXPORT), 1215 | // HOOKEXPORT(strerror,MODE_EXPORT), 1216 | 1217 | // HOOKEXPORT(pthread_self,MODE_EXPORT), 1218 | // HOOKEXPORT(pthread_kill,MODE_EXPORT), 1219 | // HOOKEXPORT(pthread_create,MODE_EXPORT), 1220 | // HOOKEXPORT(pthread_attr_init,MODE_EXPORT), 1221 | // HOOKEXPORT(pthread_attr_setdetachstate,MODE_EXPORT), 1222 | //HOOKEXPORT(pthread_mutex_init,MODE_EXPORT), 1223 | // HOOKEXPORT(pthread_mutex_destroy,MODE_EXPORT), 1224 | //HOOKEXPORT(pthread_mutex_unlock,MODE_EXPORT), 1225 | //HOOKEXPORT(pthread_mutex_lock,MODE_EXPORT), 1226 | //HOOKEXPORT(pthread_cond_init,MODE_EXPORT), 1227 | //HOOKEXPORT(pthread_cond_wait,MODE_EXPORT), 1228 | // HOOKEXPORT(pthread_cond_timedwait,MODE_EXPORT), 1229 | //HOOKEXPORT(pthread_cond_signal,MODE_EXPORT), 1230 | 1231 | /*无法hook*/ 1232 | // HOOKEXPORT(fcnt1,MODE_EXPORT), NULL 1233 | // HOOKEXPORT(strrchr,MODE_EXPORT), p 1234 | // HOOKEXPORT(strpbrk,MODE_EXPORT), p 1235 | // HOOKEXPORT(strncasecmp,MODE_EXPORT), P 1236 | // HOOKEXPORT(strchr,MODE_EXPORT), //无LOG 1237 | // HOOKEXPORT(fnmatch,MODE_EXPORT), //LOG停止运行 1238 | // HOOKEXPORT(fgets,MODE_EXPORT), P 1239 | // HOOKEXPORT(crc32,MODE_EXPORT), NULL 1240 | // HOOKEXPORT(calloc,MODE_EXPORT), P 1241 | // HOOKEXPORT(adler32,MODE_EXPORT), NULL 1242 | // HOOKEXPORT(abort,MODE_EXPORT), //无LOG 1243 | // HOOKEXPORT(inflateInit2_,MODE_EXPORT), NULL 1244 | // HOOKEXPORT(mkdir,MODE_EXPORT), 第一次登陆闪退 1245 | }; 1246 | 1247 | jclass* (*oldFindClass)(JNIEnv* env, char* className); 1248 | jclass* myFindClass(JNIEnv* env, char* className){ 1249 | unsigned lr; 1250 | GETLR(lr); 1251 | jclass* clazz = oldFindClass(env, className); 1252 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_FindClass","class[0x%x]%s [0x%x]", clazz,className,lr); 1253 | return clazz; 1254 | } 1255 | 1256 | jmethodID* (*oldGetMethodID)(JNIEnv* env, jclass clazz, char* methodName, char* params); 1257 | jmethodID* myGetMethodID(JNIEnv* env, jclass clazz, char* methodName, char* params){ 1258 | unsigned lr; 1259 | GETLR(lr); 1260 | jmethodID* methodID = oldGetMethodID(env, clazz, methodName, params); 1261 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_GetMethodID","class[0x%x],method[0x%x]%s%s [0x%x]",clazz,methodID,methodName,params,lr); 1262 | return methodID; 1263 | } 1264 | 1265 | jmethodID* (*oldGetStaticMethodID)(JNIEnv* env, jclass clazz, char* methodName, char* params); 1266 | jmethodID* myGetStaticMethodID(JNIEnv* env, jclass clazz, char* methodName, char* params){ 1267 | unsigned lr; 1268 | GETLR(lr); 1269 | jmethodID* methodID = oldGetStaticMethodID(env, clazz, methodName, params); 1270 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_GetStaticMethodID","class[0x%x],method[0x%x]%s%s [0x%x]",clazz,methodID,methodName,params,lr); 1271 | return methodID; 1272 | } 1273 | 1274 | void* (*oldSetByteArrayRegion)(JNIEnv* env, jbyteArray buf, int size, int size2, char* byte); 1275 | void* mySetByteArrayRegion(JNIEnv* env, jbyteArray buf, int size, int size2, char* byte){ 1276 | unsigned lr; 1277 | GETLR(lr); 1278 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_SetByteArrayRegion","sieze[%d-%d],byte[0x%x] [0x%x]",size, size2,byte,lr); 1279 | void* ret = oldSetByteArrayRegion(env, buf, size, size2, byte); 1280 | return ret; 1281 | } 1282 | 1283 | 1284 | // 2A0 GetStringUTFLength jsize (*)( JNIEnv*, jstring ) 1285 | // 2A4 GetStringUTFChars (*)( JNIEnv*, jstring, jboolean* ) 1286 | 1287 | const char* (*oldGetStringUTFChars)(JNIEnv* env, jstring jstr, jboolean* b); 1288 | const char* myGetStringUTFChars(JNIEnv* env, jstring jstr, jboolean* b){ 1289 | unsigned lr; 1290 | GETLR(lr); 1291 | char * result = oldGetStringUTFChars(env,jstr,b); 1292 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_GetStringUTFChars","jstr[0x%x] str[0x%x]:%s [0x%x]",jstr,result,result, lr); 1293 | return result; 1294 | } 1295 | 1296 | //29C NewStringUTF jstring (*)( JNIEnv*, const char* ) 1297 | 1298 | jstring (* oldNewStringUTF)(JNIEnv* env, const char* str); 1299 | jstring myNewStringUTF(JNIEnv* env, const char* str){ 1300 | unsigned lr; 1301 | GETLR(lr); 1302 | jstring result = oldNewStringUTF(env,str); 1303 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_NewStringUTF","jstr[0x%x] str[0x%x]:%s [0x%x]",result,str,str,lr); 1304 | return result; 1305 | } 1306 | 1307 | //35C RegisterNatives jint (*)( JNIEnv*, jclass, const JNINativeMethod*, jint ) 1308 | 1309 | //static JNINativeMethod s_methods[] = { {"callCustomClass", "(LMyJavaClass;)V", (void*)callCustomClass}, }; 1310 | // typedef struct { 1311 | // const char* name; 1312 | // const char* signature; 1313 | // void* fnPtr; 1314 | // } JNINativeMethod; 1315 | 1316 | jint (* oldRegisterNatives)( JNIEnv* env, jclass c, const JNINativeMethod* m, jint n); 1317 | jint myRegisterNatives( JNIEnv* env, jclass c, const JNINativeMethod* m, jint n){ 1318 | unsigned lr; 1319 | GETLR(lr); 1320 | __android_log_print(ANDROID_LOG_INFO, "native_hook_j_RegisterNatives","start! jclass[0x%x] methods[0x%x]%d [0x%x]",c,m,n,lr); 1321 | for(int i=0;i. 19 | **/ 20 | /* }}} */ 21 | 22 | #ifndef SUBSTRATE_H_ 23 | #define SUBSTRATE_H_ 24 | 25 | #ifdef __APPLE__ 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | #include 30 | #ifdef __cplusplus 31 | } 32 | #endif 33 | 34 | #include 35 | #include 36 | #endif 37 | 38 | #include 39 | #include 40 | 41 | #define _finline \ 42 | inline __attribute__((__always_inline__)) 43 | #define _disused \ 44 | __attribute__((__unused__)) 45 | 46 | #ifdef __cplusplus 47 | #define _default(value) = value 48 | #else 49 | #define _default(value) 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | extern "C" { 54 | #endif 55 | 56 | bool MSHookProcess(pid_t pid, const char *library); 57 | 58 | typedef const void *MSImageRef; 59 | 60 | MSImageRef MSGetImageByName(const char *file); 61 | void *MSFindSymbol(MSImageRef image, const char *name); 62 | 63 | void MSHookFunction(void *symbol, void *replace, void **result); 64 | 65 | #ifdef __APPLE__ 66 | #ifdef __arm__ 67 | __attribute__((__deprecated__)) 68 | IMP MSHookMessage(Class _class, SEL sel, IMP imp, const char *prefix _default(NULL)); 69 | #endif 70 | void MSHookMessageEx(Class _class, SEL sel, IMP imp, IMP *result); 71 | #endif 72 | 73 | #ifdef __ANDROID__ 74 | #include 75 | void MSJavaHookClassLoad(JNIEnv *jni, const char *name, void (*callback)(JNIEnv *, jclass, void *), void *data _default(NULL)); 76 | void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID methodID, void *function, void **result); 77 | void MSJavaBlessClassLoader(JNIEnv *jni, jobject loader); 78 | 79 | typedef struct MSJavaObjectKey_ *MSJavaObjectKey; 80 | MSJavaObjectKey MSJavaCreateObjectKey(); 81 | void MSJavaReleaseObjectKey(MSJavaObjectKey key); 82 | void *MSJavaGetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key); 83 | void MSJavaSetObjectKey(JNIEnv *jni, jobject object, MSJavaObjectKey key, void *value, void (*clean)(void *, JNIEnv *, void *) _default(NULL), void *data _default(NULL)); 84 | #endif 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #ifdef __cplusplus 91 | 92 | #ifdef __APPLE__ 93 | 94 | namespace etl { 95 | 96 | template 97 | struct Case { 98 | static char value[Case_ + 1]; 99 | }; 100 | 101 | typedef Case Yes; 102 | typedef Case No; 103 | 104 | namespace be { 105 | template 106 | static Yes CheckClass_(void (Checked_::*)()); 107 | 108 | template 109 | static No CheckClass_(...); 110 | } 111 | 112 | template 113 | struct IsClass { 114 | void gcc32(); 115 | 116 | static const bool value = (sizeof(be::CheckClass_(0).value) == sizeof(Yes::value)); 117 | }; 118 | 119 | } 120 | 121 | #ifdef __arm__ 122 | template 123 | __attribute__((__deprecated__)) 124 | static inline Type_ *MSHookMessage(Class _class, SEL sel, Type_ *imp, const char *prefix = NULL) { 125 | return reinterpret_cast(MSHookMessage(_class, sel, reinterpret_cast(imp), prefix)); 126 | } 127 | #endif 128 | 129 | template 130 | static inline void MSHookMessage(Class _class, SEL sel, Type_ *imp, Type_ **result) { 131 | return MSHookMessageEx(_class, sel, reinterpret_cast(imp), reinterpret_cast(result)); 132 | } 133 | 134 | template 135 | static inline Type_ &MSHookIvar(id self, const char *name) { 136 | Ivar ivar(class_getInstanceVariable(object_getClass(self), name)); 137 | void *pointer(ivar == NULL ? NULL : reinterpret_cast(self) + ivar_getOffset(ivar)); 138 | return *reinterpret_cast(pointer); 139 | } 140 | 141 | #define MSAddMessage0(_class, type, arg0) \ 142 | class_addMethod($ ## _class, @selector(arg0), (IMP) &$ ## _class ## $ ## arg0, type); 143 | #define MSAddMessage1(_class, type, arg0) \ 144 | class_addMethod($ ## _class, @selector(arg0:), (IMP) &$ ## _class ## $ ## arg0 ## $, type); 145 | #define MSAddMessage2(_class, type, arg0, arg1) \ 146 | class_addMethod($ ## _class, @selector(arg0:arg1:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $, type); 147 | #define MSAddMessage3(_class, type, arg0, arg1, arg2) \ 148 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $, type); 149 | #define MSAddMessage4(_class, type, arg0, arg1, arg2, arg3) \ 150 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $, type); 151 | #define MSAddMessage5(_class, type, arg0, arg1, arg2, arg3, arg4) \ 152 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $, type); 153 | #define MSAddMessage6(_class, type, arg0, arg1, arg2, arg3, arg4, arg5) \ 154 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $, type); 155 | #define MSAddMessage7(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 156 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $, type); 157 | #define MSAddMessage8(_class, type, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 158 | class_addMethod($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), (IMP) &$ ## _class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ $$ arg6 ## $ ## arg7 ## $, type); 159 | 160 | #define MSHookMessage0(_class, arg0) \ 161 | MSHookMessage($ ## _class, @selector(arg0), MSHake(_class ## $ ## arg0)) 162 | #define MSHookMessage1(_class, arg0) \ 163 | MSHookMessage($ ## _class, @selector(arg0:), MSHake(_class ## $ ## arg0 ## $)) 164 | #define MSHookMessage2(_class, arg0, arg1) \ 165 | MSHookMessage($ ## _class, @selector(arg0:arg1:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $)) 166 | #define MSHookMessage3(_class, arg0, arg1, arg2) \ 167 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $)) 168 | #define MSHookMessage4(_class, arg0, arg1, arg2, arg3) \ 169 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $)) 170 | #define MSHookMessage5(_class, arg0, arg1, arg2, arg3, arg4) \ 171 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $)) 172 | #define MSHookMessage6(_class, arg0, arg1, arg2, arg3, arg4, arg5) \ 173 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $)) 174 | #define MSHookMessage7(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6) \ 175 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $)) 176 | #define MSHookMessage8(_class, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7) \ 177 | MSHookMessage($ ## _class, @selector(arg0:arg1:arg2:arg3:arg4:arg5:arg6:arg7:), MSHake(_class ## $ ## arg0 ## $ ## arg1 ## $ ## arg2 ## $ ## arg3 ## $ ## arg4 ## $ ## arg5 ## $ ## arg6 ## $ ## arg7 ## $)) 178 | 179 | #define MSRegister_(name, dollar, colon) \ 180 | namespace { static class C_$ ## name ## $ ## dollar { public: _finline C_$ ## name ## $ ##dollar() { \ 181 | MSHookMessage($ ## name, @selector(colon), MSHake(name ## $ ## dollar)); \ 182 | } } V_$ ## name ## $ ## dollar; } \ 183 | 184 | #define MSIgnore_(name, dollar, colon) 185 | 186 | #define MSMessage_(extra, type, _class, name, dollar, colon, call, args...) \ 187 | static type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args); \ 188 | MSHook(type, name ## $ ## dollar, _class self, SEL _cmd, ## args) { \ 189 | Class const _cls($ ## name); \ 190 | type (* const _old)(_class, SEL, ## args, ...) = reinterpret_cast(_ ## name ## $ ## dollar); \ 191 | typedef type (*msgSendSuper_t)(struct objc_super *, SEL, ## args, ...); \ 192 | msgSendSuper_t const _spr(::etl::IsClass::value ? reinterpret_cast(&objc_msgSendSuper_stret) : reinterpret_cast(&objc_msgSendSuper)); \ 193 | return _$ ## name ## $ ## dollar call; \ 194 | } \ 195 | extra(name, dollar, colon) \ 196 | static _finline type _$ ## name ## $ ## dollar(Class _cls, type (*_old)(_class, SEL, ## args, ...), type (*_spr)(struct objc_super *, SEL, ## args, ...), _class self, SEL _cmd, ## args) 197 | 198 | /* for((x=1;x!=7;++x)){ echo -n "#define MSMessage${x}_(extra, type, _class, name";for((y=0;y!=x;++y));do echo -n ", sel$y";done;for((y=0;y!=x;++y));do echo -n ", type$y, arg$y";done;echo ") \\";echo -n " MSMessage_(extra, type, _class, name,";for((y=0;y!=x;++y));do if [[ $y -ne 0 ]];then echo -n " ##";fi;echo -n " sel$y ## $";done;echo -n ", ";for((y=0;y!=x;++y));do echo -n "sel$y:";done;echo -n ", (_cls, _old, _spr, self, _cmd";for((y=0;y!=x;++y));do echo -n ", arg$y";done;echo -n ")";for((y=0;y!=x;++y));do echo -n ", type$y arg$y";done;echo ")";} */ 199 | 200 | #define MSMessage0_(extra, type, _class, name, sel0) \ 201 | MSMessage_(extra, type, _class, name, sel0, sel0, (_cls, _old, _spr, self, _cmd)) 202 | #define MSMessage1_(extra, type, _class, name, sel0, type0, arg0) \ 203 | MSMessage_(extra, type, _class, name, sel0 ## $, sel0:, (_cls, _old, _spr, self, _cmd, arg0), type0 arg0) 204 | #define MSMessage2_(extra, type, _class, name, sel0, sel1, type0, arg0, type1, arg1) \ 205 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $, sel0:sel1:, (_cls, _old, _spr, self, _cmd, arg0, arg1), type0 arg0, type1 arg1) 206 | #define MSMessage3_(extra, type, _class, name, sel0, sel1, sel2, type0, arg0, type1, arg1, type2, arg2) \ 207 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $, sel0:sel1:sel2:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2), type0 arg0, type1 arg1, type2 arg2) 208 | #define MSMessage4_(extra, type, _class, name, sel0, sel1, sel2, sel3, type0, arg0, type1, arg1, type2, arg2, type3, arg3) \ 209 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $, sel0:sel1:sel2:sel3:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3), type0 arg0, type1 arg1, type2 arg2, type3 arg3) 210 | #define MSMessage5_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4) \ 211 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $, sel0:sel1:sel2:sel3:sel4:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4) 212 | #define MSMessage6_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5) \ 213 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $, sel0:sel1:sel2:sel3:sel4:sel5:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5) 214 | #define MSMessage7_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6) \ 215 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6) 216 | #define MSMessage8_(extra, type, _class, name, sel0, sel1, sel2, sel3, sel4, sel5, sel6, sel7, type0, arg0, type1, arg1, type2, arg2, type3, arg3, type4, arg4, type5, arg5, type6, arg6, type7, arg7) \ 217 | MSMessage_(extra, type, _class, name, sel0 ## $ ## sel1 ## $ ## sel2 ## $ ## sel3 ## $ ## sel4 ## $ ## sel5 ## $ ## sel6 ## $ ## sel7 ## $, sel0:sel1:sel2:sel3:sel4:sel5:sel6:sel7:, (_cls, _old, _spr, self, _cmd, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7), type0 arg0, type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5, type6 arg6, type7 arg7) 218 | 219 | #define MSInstanceMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, _class *, _class, ## args) 220 | #define MSInstanceMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, _class *, _class, ## args) 221 | #define MSInstanceMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, _class *, _class, ## args) 222 | #define MSInstanceMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, _class *, _class, ## args) 223 | #define MSInstanceMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, _class *, _class, ## args) 224 | #define MSInstanceMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, _class *, _class, ## args) 225 | #define MSInstanceMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, _class *, _class, ## args) 226 | #define MSInstanceMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, _class *, _class, ## args) 227 | #define MSInstanceMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, _class *, _class, ## args) 228 | 229 | #define MSClassMessage0(type, _class, args...) MSMessage0_(MSIgnore_, type, Class, $ ## _class, ## args) 230 | #define MSClassMessage1(type, _class, args...) MSMessage1_(MSIgnore_, type, Class, $ ## _class, ## args) 231 | #define MSClassMessage2(type, _class, args...) MSMessage2_(MSIgnore_, type, Class, $ ## _class, ## args) 232 | #define MSClassMessage3(type, _class, args...) MSMessage3_(MSIgnore_, type, Class, $ ## _class, ## args) 233 | #define MSClassMessage4(type, _class, args...) MSMessage4_(MSIgnore_, type, Class, $ ## _class, ## args) 234 | #define MSClassMessage5(type, _class, args...) MSMessage5_(MSIgnore_, type, Class, $ ## _class, ## args) 235 | #define MSClassMessage6(type, _class, args...) MSMessage6_(MSIgnore_, type, Class, $ ## _class, ## args) 236 | #define MSClassMessage7(type, _class, args...) MSMessage7_(MSIgnore_, type, Class, $ ## _class, ## args) 237 | #define MSClassMessage8(type, _class, args...) MSMessage8_(MSIgnore_, type, Class, $ ## _class, ## args) 238 | 239 | #define MSInstanceMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, _class *, _class, ## args) 240 | #define MSInstanceMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, _class *, _class, ## args) 241 | #define MSInstanceMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, _class *, _class, ## args) 242 | #define MSInstanceMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, _class *, _class, ## args) 243 | #define MSInstanceMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, _class *, _class, ## args) 244 | #define MSInstanceMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, _class *, _class, ## args) 245 | #define MSInstanceMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, _class *, _class, ## args) 246 | #define MSInstanceMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, _class *, _class, ## args) 247 | #define MSInstanceMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, _class *, _class, ## args) 248 | 249 | #define MSClassMessageHook0(type, _class, args...) MSMessage0_(MSRegister_, type, Class, $ ## _class, ## args) 250 | #define MSClassMessageHook1(type, _class, args...) MSMessage1_(MSRegister_, type, Class, $ ## _class, ## args) 251 | #define MSClassMessageHook2(type, _class, args...) MSMessage2_(MSRegister_, type, Class, $ ## _class, ## args) 252 | #define MSClassMessageHook3(type, _class, args...) MSMessage3_(MSRegister_, type, Class, $ ## _class, ## args) 253 | #define MSClassMessageHook4(type, _class, args...) MSMessage4_(MSRegister_, type, Class, $ ## _class, ## args) 254 | #define MSClassMessageHook5(type, _class, args...) MSMessage5_(MSRegister_, type, Class, $ ## _class, ## args) 255 | #define MSClassMessageHook6(type, _class, args...) MSMessage6_(MSRegister_, type, Class, $ ## _class, ## args) 256 | #define MSClassMessageHook7(type, _class, args...) MSMessage7_(MSRegister_, type, Class, $ ## _class, ## args) 257 | #define MSClassMessageHook8(type, _class, args...) MSMessage8_(MSRegister_, type, Class, $ ## _class, ## args) 258 | 259 | #define MSOldCall(args...) \ 260 | _old(self, _cmd, ## args) 261 | #define MSSuperCall(args...) \ 262 | _spr(& (struct objc_super) {self, class_getSuperclass(_cls)}, _cmd, ## args) 263 | 264 | #define MSIvarHook(type, name) \ 265 | type &name(MSHookIvar(self, #name)) 266 | 267 | #define MSClassHook(name) \ 268 | @class name; \ 269 | static Class $ ## name = objc_getClass(#name); 270 | #define MSMetaClassHook(name) \ 271 | @class name; \ 272 | static Class $$ ## name = object_getClass($ ## name); 273 | 274 | #endif/*__APPLE__*/ 275 | 276 | template 277 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace, Type_ **result) { 278 | return MSHookFunction( 279 | reinterpret_cast(symbol), 280 | reinterpret_cast(replace), 281 | reinterpret_cast(result) 282 | ); 283 | } 284 | 285 | template 286 | static inline void MSHookFunction(Type_ *symbol, Type_ *replace) { 287 | return MSHookFunction(symbol, replace, reinterpret_cast(NULL)); 288 | } 289 | 290 | template 291 | static inline void MSHookSymbol(Type_ *&value, const char *name, MSImageRef image = NULL) { 292 | value = reinterpret_cast(MSFindSymbol(image, name)); 293 | } 294 | 295 | template 296 | static inline void MSHookFunction(const char *name, Type_ *replace, Type_ **result = NULL) { 297 | Type_ *symbol; 298 | MSHookSymbol(symbol, name); 299 | return MSHookFunction(symbol, replace, result); 300 | } 301 | 302 | template 303 | static inline void MSHookFunction(MSImageRef image, const char *name, Type_ *replace, Type_ **result = NULL) { 304 | Type_ *symbol; 305 | MSHookSymbol(symbol, name, image); 306 | return MSHookFunction(symbol, replace, result); 307 | } 308 | 309 | #endif 310 | 311 | #ifdef __ANDROID__ 312 | 313 | #ifdef __cplusplus 314 | 315 | template 316 | static inline void MSJavaHookMethod(JNIEnv *jni, jclass _class, jmethodID method, Type_ (*replace)(JNIEnv *, Kind_, Args_...), Type_ (**result)(JNIEnv *, Kind_, ...)) { 317 | return MSJavaHookMethod( 318 | jni, _class, method, 319 | reinterpret_cast(replace), 320 | reinterpret_cast(result) 321 | ); 322 | } 323 | 324 | #endif 325 | 326 | static inline void MSAndroidGetPackage(JNIEnv *jni, jobject global, const char *name, jobject &local, jobject &loader) { 327 | jclass Context(jni->FindClass("android/content/Context")); 328 | jmethodID Context$createPackageContext(jni->GetMethodID(Context, "createPackageContext", "(Ljava/lang/String;I)Landroid/content/Context;")); 329 | jmethodID Context$getClassLoader(jni->GetMethodID(Context, "getClassLoader", "()Ljava/lang/ClassLoader;")); 330 | 331 | jstring string(jni->NewStringUTF(name)); 332 | local = jni->CallObjectMethod(global, Context$createPackageContext, string, 3); 333 | loader = jni->CallObjectMethod(local, Context$getClassLoader); 334 | } 335 | 336 | static inline jclass MSJavaFindClass(JNIEnv *jni, jobject loader, const char *name) { 337 | jclass Class(jni->FindClass("java/lang/Class")); 338 | jmethodID Class$forName(jni->GetStaticMethodID(Class, "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;")); 339 | 340 | jstring string(jni->NewStringUTF(name)); 341 | jobject _class(jni->CallStaticObjectMethod(Class, Class$forName, string, JNI_TRUE, loader)); 342 | if (jni->ExceptionCheck()) 343 | return NULL; 344 | 345 | return reinterpret_cast(_class); 346 | } 347 | 348 | _disused static void MSJavaCleanWeak(void *data, JNIEnv *jni, void *value) { 349 | jni->DeleteWeakGlobalRef(reinterpret_cast(value)); 350 | } 351 | 352 | #endif 353 | 354 | #define MSHook(type, name, args...) \ 355 | _disused static type (*_ ## name)(args); \ 356 | static type $ ## name(args) 357 | 358 | #define MSJavaHook(type, name, arg0, args...) \ 359 | _disused static type (*_ ## name)(JNIEnv *jni, arg0, ...); \ 360 | static type $ ## name(JNIEnv *jni, arg0, ## args) 361 | 362 | #ifdef __cplusplus 363 | #define MSHake(name) \ 364 | &$ ## name, &_ ## name 365 | #else 366 | #define MSHake(name) \ 367 | &$ ## name, (void **) &_ ## name 368 | #endif 369 | 370 | #define SubstrateConcat_(lhs, rhs) \ 371 | lhs ## rhs 372 | #define SubstrateConcat(lhs, rhs) \ 373 | SubstrateConcat_(lhs, rhs) 374 | 375 | #ifdef __APPLE__ 376 | #define SubstrateSection \ 377 | __attribute__((__section__("__TEXT, __substrate"))) 378 | #else 379 | #define SubstrateSection \ 380 | __attribute__((__section__(".substrate"))) 381 | #endif 382 | 383 | #ifdef __APPLE__ 384 | #define MSFilterCFBundleID "Filter:CFBundleID" 385 | #define MSFilterObjC_Class "Filter:ObjC.Class" 386 | #endif 387 | 388 | #define MSFilterLibrary "Filter:Library" 389 | #define MSFilterExecutable "Filter:Executable" 390 | 391 | #define MSConfig(name, value) \ 392 | extern const char SubstrateConcat(_substrate_, __LINE__)[] SubstrateSection = name "=" value; 393 | 394 | #ifdef __cplusplus 395 | #define MSInitialize \ 396 | static void _MSInitialize(void); \ 397 | namespace { static class $MSInitialize { public: _finline $MSInitialize() { \ 398 | _MSInitialize(); \ 399 | } } $MSInitialize; } \ 400 | static void _MSInitialize() 401 | #else 402 | #define MSInitialize \ 403 | __attribute__((__constructor__)) static void _MSInitialize(void) 404 | #endif 405 | 406 | #define Foundation_f "/System/Library/Frameworks/Foundation.framework/Foundation" 407 | #define UIKit_f "/System/Library/Frameworks/UIKit.framework/UIKit" 408 | #define JavaScriptCore_f "/System/Library/PrivateFrameworks/JavaScriptCore.framework/JavaScriptCore" 409 | #define IOKit_f "/System/Library/Frameworks/IOKit.framework/IOKit" 410 | 411 | #endif//SUBSTRATE_H_ 412 | -------------------------------------------------------------------------------- /app/src/main/prebuildSo/libTKHooklib.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/app/src/main/prebuildSo/libTKHooklib.so -------------------------------------------------------------------------------- /app/src/main/prebuildSo/libsubstrate-dvm.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/app/src/main/prebuildSo/libsubstrate-dvm.so -------------------------------------------------------------------------------- /app/src/main/prebuildSo/libsubstrate.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/app/src/main/prebuildSo/libsubstrate.so -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/app/src/main/res/drawable/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | buildscript { 3 | repositories { 4 | jcenter() 5 | } 6 | dependencies { 7 | classpath 'com.android.tools.build:gradle-experimental:0.7.0-rc1' 8 | } 9 | } 10 | 11 | allprojects { 12 | repositories { 13 | jcenter() 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /cydiasubstrate_hooktools.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ## Project-wide Gradle settings. 2 | # 3 | # For more details on how to configure your build environment visit 4 | # http://www.gradle.org/docs/current/userguide/build_environment.html 5 | # 6 | # Specifies the JVM arguments used for the daemon process. 7 | # The setting is particularly useful for tweaking memory settings. 8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 10 | # 11 | # When configured, Gradle will run in incubating parallel mode. 12 | # This option should only be used with decoupled projects. More details, visit 13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 14 | # org.gradle.parallel=true 15 | #Sat Apr 30 10:12:38 CST 2016 16 | android.useDeprecatedNdk=true 17 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/F8LEFT/cydiasubstrate_hooktools/4570869d8dfb4a88437d85379f932ada2d8be109/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Dec 28 10:00:20 PST 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /import-summary.txt: -------------------------------------------------------------------------------- 1 | ECLIPSE ANDROID PROJECT IMPORT SUMMARY 2 | ====================================== 3 | 4 | Ignored Files: 5 | -------------- 6 | The following files were *not* copied into the new Gradle project; you 7 | should evaluate whether these are still needed in your project and if 8 | so manually move them: 9 | 10 | * .externalToolBuilders\ 11 | * .externalToolBuilders\ndk_Builder.launch 12 | * ic_launcher-web.png 13 | * proguard-project.txt 14 | 15 | Moved Files: 16 | ------------ 17 | Android Gradle projects use a different directory structure than ADT 18 | Eclipse projects. Here's how the projects were restructured: 19 | 20 | * AndroidManifest.xml => app\src\main\AndroidManifest.xml 21 | * assets\ => app\src\main\assets 22 | * jni\ => app\src\main\jni\ 23 | * libs\substrate-api.jar => app\libs\substrate-api.jar 24 | * lint.xml => app\lint.xml 25 | * res\ => app\src\main\res\ 26 | * src\ => app\src\main\java\ 27 | 28 | Next Steps: 29 | ----------- 30 | You can now build the project. The Gradle project needs network 31 | connectivity to download dependencies. 32 | 33 | Bugs: 34 | ----- 35 | If for some reason your project does not build, and you determine that 36 | it is due to a bug or limitation of the Eclipse to Gradle importer, 37 | please file a bug at http://b.android.com with category 38 | Component-Tools. 39 | 40 | (This import summary is for your information only, and can be deleted 41 | after import once you are satisfied with the results.) 42 | -------------------------------------------------------------------------------- /local.properties: -------------------------------------------------------------------------------- 1 | ## This file is automatically generated by Android Studio. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must *NOT* be checked into Version Control Systems, 5 | # as it contains information specific to your local configuration. 6 | # 7 | # Location of the SDK. This is only used by Gradle. 8 | # For customization when using a Version Control System, please read the 9 | # header note. 10 | #Sat Apr 30 10:12:15 CST 2016 11 | ndk.dir=D\:\\environment\\AndroidSDK\\ndk-bundle 12 | sdk.dir=D\:\\environment\\AndroidSDK 13 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------