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.
# 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/arch/arm32.S
src/main/cpp/trampoline/arch/arm64.S
)
......
......@@ -13,7 +13,6 @@ android {
cmake {
arguments '-DBUILD_TESTING=OFF','-DANDROID_TOOLCHAIN=gcc'
cppFlags "-frtti -fexceptions"
abiFilters 'arm64-v8a'
}
}
}
......
#include <jni.h>
#include <string>
#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
Java_com_swift_sandhook_MainActivity_stringFromJNI(
JNIEnv *env,
......@@ -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 addr2 = size + artMethod1 - BYTE_POINT;
return 0;
return reinterpret_cast<jint>(&t_i);
}
extern "C" void hook_trampoline();
extern "C"
JNIEXPORT void JNICALL
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"
#if defined(__arm__)
FUNCTION_START(hook_trampoline)
adr r0, addr_art_method
adr r0, t_i
adr pc, addr_entry_code
addr_art_method:
.long 0
addr_entry_code:
.long 0
FUNCTION_END(hook_trampoline)
#endif
#include "base.h"
#if defined(__aarch64__)
FUNCTION_START(hook_trampoline)
adr x0, addr_art_method
adr x16, addr_entry_code
......@@ -11,3 +14,5 @@ addr_entry_code:
.long 0
.long 0
FUNCTION_END(hook_trampoline)
#endif
package com.swift.sandhook;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
......@@ -68,8 +69,8 @@ public class MainActivity extends AppCompatActivity {
//
// methods[dexMethodIndex] = artMethod;
SandHook.init();
initHook();
//SandHook.init();
//initHook();
tv.setText("" + calArtSize(method1, method2));
} catch (NoSuchMethodException e) {
......@@ -79,6 +80,16 @@ public class MainActivity extends AppCompatActivity {
} catch (IllegalAccessException e) {
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 {
......
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