Commit 2c6f4305 authored by swift_gan's avatar swift_gan Committed by swift_gan

add

parent 27782e47
...@@ -19,6 +19,7 @@ add_library( # Sets the name of the library. ...@@ -19,6 +19,7 @@ add_library( # Sets the name of the library.
# Provides a relative path to your source file(s). # Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp src/main/cpp/native-lib.cpp
src/main/cpp/trampoline/trampoline.cpp src/main/cpp/trampoline/trampoline.cpp
src/main/cpp/trampoline/arch/arm32.S
src/main/cpp/trampoline/arch/arm64.S src/main/cpp/trampoline/arch/arm64.S
) )
......
...@@ -13,7 +13,6 @@ android { ...@@ -13,7 +13,6 @@ android {
cmake { cmake {
arguments '-DBUILD_TESTING=OFF','-DANDROID_TOOLCHAIN=gcc' arguments '-DBUILD_TESTING=OFF','-DANDROID_TOOLCHAIN=gcc'
cppFlags "-frtti -fexceptions" cppFlags "-frtti -fexceptions"
abiFilters 'arm64-v8a'
} }
} }
} }
......
#include <jni.h> #include <jni.h>
#include <string> #include <string>
#include "casts/cast_art_method.h" #include "casts/cast_art_method.h"
#include "./trampoline/trampoline.h"
extern "C" JNIEXPORT jstring
extern static thread_local int t_i = 0;
extern "C" JNIEXPORT jstring
JNICALL JNICALL
Java_com_swift_sandhook_MainActivity_stringFromJNI( Java_com_swift_sandhook_MainActivity_stringFromJNI(
JNIEnv *env, JNIEnv *env,
...@@ -29,17 +30,14 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j ...@@ -29,17 +30,14 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j
// Size addr1 = reinterpret_cast<size_t>(&methodTest->ptr_sized_fields_.entry_point_from_quick_compiled_code_); // Size addr1 = reinterpret_cast<size_t>(&methodTest->ptr_sized_fields_.entry_point_from_quick_compiled_code_);
// Size addr2 = size + artMethod1 - BYTE_POINT; // Size addr2 = size + artMethod1 - BYTE_POINT;
return 0; return reinterpret_cast<jint>(&t_i);
} }
extern "C" void hook_trampoline();
extern "C" extern "C"
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_swift_sandhook_MainActivity_initHook(JNIEnv *env, jobject instance) { Java_com_swift_sandhook_MainActivity_initHook(JNIEnv *env, jobject instance) {
hook_trampoline();
SandHook::cast_art_method::init(env);
} }
\ No newline at end of file
#include "base.h" #include "base.h"
#if defined(__arm__)
FUNCTION_START(hook_trampoline) FUNCTION_START(hook_trampoline)
adr r0, addr_art_method adr r0, t_i
adr pc, addr_entry_code adr pc, addr_entry_code
addr_art_method: addr_art_method:
.long 0 .long 0
addr_entry_code: addr_entry_code:
.long 0 .long 0
FUNCTION_END(hook_trampoline) FUNCTION_END(hook_trampoline)
#endif
#include "base.h" #include "base.h"
#if defined(__aarch64__)
FUNCTION_START(hook_trampoline) FUNCTION_START(hook_trampoline)
adr x0, addr_art_method adr x0, addr_art_method
adr x16, addr_entry_code adr x16, addr_entry_code
...@@ -11,3 +14,5 @@ addr_entry_code: ...@@ -11,3 +14,5 @@ addr_entry_code:
.long 0 .long 0
.long 0 .long 0
FUNCTION_END(hook_trampoline) FUNCTION_END(hook_trampoline)
#endif
package com.swift.sandhook; package com.swift.sandhook;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log;
import android.widget.TextView; import android.widget.TextView;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
...@@ -68,8 +69,8 @@ public class MainActivity extends AppCompatActivity { ...@@ -68,8 +69,8 @@ public class MainActivity extends AppCompatActivity {
// //
// methods[dexMethodIndex] = artMethod; // methods[dexMethodIndex] = artMethod;
SandHook.init(); //SandHook.init();
initHook(); //initHook();
tv.setText("" + calArtSize(method1, method2)); tv.setText("" + calArtSize(method1, method2));
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
...@@ -79,6 +80,16 @@ public class MainActivity extends AppCompatActivity { ...@@ -79,6 +80,16 @@ public class MainActivity extends AppCompatActivity {
} catch (IllegalAccessException e) { } catch (IllegalAccessException e) {
e.printStackTrace(); e.printStackTrace();
} }
for (int i= 0;i < 10;i++) {
new Thread(new Runnable() {
@Override
public void run() {
Log.e("Thread_Local", "thread_local_i = " + calArtSize(null, null));
}
}).start();
}
} }
public static Field getField(Class topClass, String fieldName) throws NoSuchFieldException { public static Field getField(Class topClass, String fieldName) throws NoSuchFieldException {
......
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