Commit 779037e4 authored by swift_gan's avatar swift_gan

tweak project structure

parent 9da3357a
...@@ -4,18 +4,11 @@ android { ...@@ -4,18 +4,11 @@ android {
compileSdkVersion 28 compileSdkVersion 28
defaultConfig { defaultConfig {
applicationId "com.swift.sandhook" applicationId "com.swift.sandhook"
minSdkVersion 15 minSdkVersion 19
targetSdkVersion 28 targetSdkVersion 28
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DBUILD_TESTING=OFF', '-DANDROID_TOOLCHAIN=gcc'
cppFlags "-frtti -fexceptions"
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
} }
buildTypes { buildTypes {
release { release {
...@@ -23,19 +16,15 @@ android { ...@@ -23,19 +16,15 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
} }
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation project(':hooklib')
} }
...@@ -24,7 +24,7 @@ public class ActivityHooker { ...@@ -24,7 +24,7 @@ public class ActivityHooker {
@HookMethod("onCreate") @HookMethod("onCreate")
@MethodParams(Bundle.class) @MethodParams(Bundle.class)
public static void onCreate(Activity thiz, Bundle bundle) { public static void onCreate(Activity thiz, Bundle bundle) {
Log.e("ActivityHooker", "hooked onCreate success " + thiz.hashCode()); Log.e("ActivityHooker", "hooked onCreate success " + thiz);
onCreateBackup(thiz, bundle); onCreateBackup(thiz, bundle);
} }
...@@ -37,7 +37,7 @@ public class ActivityHooker { ...@@ -37,7 +37,7 @@ public class ActivityHooker {
@HookMethod("onPause") @HookMethod("onPause")
public static void onPause(Activity thiz) { public static void onPause(Activity thiz) {
Log.e("ActivityHooker", "hooked onPause success " + thiz.hashCode()); Log.e("ActivityHooker", "hooked onPause success " + thiz);
onPauseBackup(thiz); onPauseBackup(thiz);
} }
......
...@@ -20,7 +20,7 @@ public class LogHooker { ...@@ -20,7 +20,7 @@ public class LogHooker {
@HookMethodBackup("w") @HookMethodBackup("w")
@MethodParams({String.class, String.class}) @MethodParams({String.class, String.class})
public static int onCreateBackup(String tag, String msg) { public static int onCreateBackup(String tag, String msg) {
return 0; return onCreateBackup(tag, msg);
} }
} }
...@@ -17,7 +17,7 @@ public class ObjectHooker { ...@@ -17,7 +17,7 @@ public class ObjectHooker {
@HookMethodBackup("toString") @HookMethodBackup("toString")
public static String toStrBackup(Object thiz) { public static String toStrBackup(Object thiz) {
return null; return toStrBackup(thiz);
} }
} }
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp
src/main/cpp/trampoline/trampoline.cpp
src/main/cpp/trampoline/trampoline_manager.cpp
src/main/cpp/utils/fake_dlfcn.cpp
src/main/cpp/trampoline/arch/arm32.S
src/main/cpp/trampoline/arch/arm64.S
)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
add_definitions(-std=c++11)
ENABLE_LANGUAGE(ASM)
\ No newline at end of file
apply plugin: 'com.android.library'
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
arguments '-DBUILD_TESTING=OFF', '-DANDROID_TOOLCHAIN=gcc'
cppFlags "-frtti -fexceptions"
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
package com.swift.sandhook;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
assertEquals("com.swift.sandhook.test", appContext.getPackageName());
}
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swift.sandhook.lib" />
package com.swift.sandhook; package com.swift.sandhook;
import android.os.Build; import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.swift.sandhook.wrapper.HookErrorException; import com.swift.sandhook.wrapper.HookErrorException;
import com.swift.sandhook.wrapper.HookWrapper; import com.swift.sandhook.wrapper.HookWrapper;
...@@ -49,7 +47,7 @@ public class SandHook { ...@@ -49,7 +47,7 @@ public class SandHook {
HookWrapper.addHookClass(hookWrapperClass); HookWrapper.addHookClass(hookWrapperClass);
} }
public static boolean hook(@NonNull Member target, @NonNull Method hook, @Nullable Method backup) { public static boolean hook(Member target, Method hook, Method backup) {
if (target == null || hook == null) if (target == null || hook == null)
return false; return false;
resolveStaticMethod(target); resolveStaticMethod(target);
......
<resources>
<string name="app_name">hooklib</string>
</resources>
package com.swift.sandhook;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
\ No newline at end of file
include ':app' include ':app', ':hooklib'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment