Commit 08fe90f5 authored by swift_gan's avatar swift_gan

done s

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,7 @@ android { ...@@ -13,7 +13,7 @@ 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' abiFilters 'armeabi-v7a', '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" #include "./trampoline/arch/base.h"
extern "C" JNIEXPORT jstring extern "C" JNIEXPORT jstring
...@@ -32,13 +32,13 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j ...@@ -32,13 +32,13 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j
return 0; return 0;
} }
extern "C" void hook_trampoline(); extern "C" void INLINE_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(); INLINE_HOOK_TRAMPOLINE();
SandHook::cast_art_method::init(env); SandHook::cast_art_method::init(env);
......
#include "base.h" #include "base.h"
FUNCTION_START(hook_trampoline) #if defined(__arm__)
adr r0, addr_art_method
adr pc, addr_entry_code FUNCTION_START(REPLACEMENT_HOOK_TRAMPOLINE)
ldr r0, addr_art_method
ldr r12, offset_entry_code
add r12, r0, r12
ldr pc, [r12]
addr_art_method: addr_art_method:
.long 0 .long 0
addr_entry_code: offset_entry_code:
.long 0
FUNCTION_END(REPLACEMENT_HOOK_TRAMPOLINE)
FUNCTION_START(DIRECT_JUMP_TRAMPOLINE)
ldr pc, addr_target
addr_target:
.long 0 .long 0
FUNCTION_END(hook_trampoline) FUNCTION_END(DIRECT_JUMP_TRAMPOLINE)
FUNCTION_START(INLINE_HOOK_TRAMPOLINE)
FUNCTION_END(INLINE_HOOK_TRAMPOLINE)
#endif
\ No newline at end of file
#include "base.h" #include "base.h"
FUNCTION_START(hook_trampoline)
adr x0, addr_art_method #if defined(__aarch64__)
adr x16, addr_entry_code
FUNCTION_START(REPLACEMENT_HOOK_TRAMPOLINE)
ldr x0, addr_art_method
ldr x16, offset_entry_code
add x16, x0, x16
ldr x16, [x16]
br x16 br x16
addr_art_method: addr_art_method:
.long 0 .long 0
.long 0 .long 0
addr_entry_code: offset_entry_code:
.long 0
.long 0
FUNCTION_END(REPLACEMENT_HOOK_TRAMPOLINE)
FUNCTION_START(DIRECT_JUMP_TRAMPOLINE)
ldr x16, addr_target
br x16
addr_target:
.long 0
.long 0
FUNCTION_END(DIRECT_JUMP_TRAMPOLINE)
FUNCTION_START(INLINE_HOOK_TRAMPOLINE)
ldr x17, addr_origin_art_method
cmp x0, x17
bne go_to_origin_code
ldr x16, addr_hook_art_method
ldr x17, offset_entry_code2
add x17, x16, x17
ldr x17, [x17]
br x17
go_to_origin_code:
mov x0, x17
b origin_code
addr_origin_art_method:
.long 0
.long 0
origin_code:
.long 0
.long 0
.long 0
.long 0 .long 0
ldr x17, offset_entry_code2
add x17, x0, x17
ldr x17, [x17]
br x17
offset_entry_code2:
.long 0 .long 0
FUNCTION_END(hook_trampoline) .long 0
addr_hook_art_method:
.long 0
.long 0
FUNCTION_END(INLINE_HOOK_TRAMPOLINE)
#endif
...@@ -13,4 +13,8 @@ x: \ ...@@ -13,4 +13,8 @@ x: \
#define FUNCTION_END(x) .size x, .-x #define FUNCTION_END(x) .size x, .-x
#define REPLACEMENT_HOOK_TRAMPOLINE replacement_hook_trampoline
#define INLINE_HOOK_TRAMPOLINE inline_hook_trampoline
#define DIRECT_JUMP_TRAMPOLINE direct_jump_trampoline
#endif //SANDHOOK_BASE_H #endif //SANDHOOK_BASE_H
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Created by SwiftGan on 2019/1/17. // Created by SwiftGan on 2019/1/17.
// //
#include "trampoline.h" #include "trampoline.h"
#include "stdlib.h"
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