Commit 56125250 authored by swift_gan's avatar swift_gan

add arm64.s

parent e4af8592
...@@ -18,6 +18,8 @@ add_library( # Sets the name of the library. ...@@ -18,6 +18,8 @@ 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/arch/arm64.S
) )
# Searches for a specified prebuilt library and stores the path as a # Searches for a specified prebuilt library and stores the path as a
...@@ -45,4 +47,6 @@ target_link_libraries( # Specifies the target library. ...@@ -45,4 +47,6 @@ target_link_libraries( # Specifies the target library.
${log-lib} ) ${log-lib} )
add_definitions(-std=c++11) add_definitions(-std=c++11)
\ No newline at end of file
ENABLE_LANGUAGE(ASM)
\ No newline at end of file
...@@ -12,6 +12,7 @@ android { ...@@ -12,6 +12,7 @@ android {
externalNativeBuild { externalNativeBuild {
cmake { cmake {
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 "C" JNIEXPORT jstring
...@@ -29,10 +30,15 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j ...@@ -29,10 +30,15 @@ Java_com_swift_sandhook_MainActivity_calArtSize(JNIEnv *env, jobject instance, j
// Size addr2 = size + artMethod1 - BYTE_POINT; // Size addr2 = size + artMethod1 - BYTE_POINT;
return 0; return 0;
}extern "C" }
extern void hook_trampoline();
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) {
void(*fp)() = hook_trampoline;
SandHook::cast_art_method::init(env); SandHook::cast_art_method::init(env);
......
#include <base.h> #include "base.h"
.align 4
.global hook_trampoline
hook_trampoline:
ldr x0, addr_art_method
ldr x16, addr_entry_code
br x16
addr_art_method:
.long 0
.long 0
addr_entry_code:
.long 0
.long 0
\ No newline at end of file
...@@ -5,7 +5,15 @@ ...@@ -5,7 +5,15 @@
#ifndef SANDHOOK_BASE_H #ifndef SANDHOOK_BASE_H
#define SANDHOOK_BASE_H #define SANDHOOK_BASE_H
#define FUNCTION_START(x) .global x; x: #if defined(__WIN32__) || defined(__APPLE__)
#define FUNCTION_END(x) . - x #define cdecl(s) s
#else
#define cdecl(s) s
#endif
#define FUNCTION_START(x) .globl cdecl(x) \
cdecl(x):
#define FUNCTION_END(x) .x:
#endif //SANDHOOK_BASE_H #endif //SANDHOOK_BASE_H
//
// Created by SwiftGan on 2019/1/17.
//
#include "trampoline.h"
...@@ -5,4 +5,25 @@ ...@@ -5,4 +5,25 @@
#ifndef SANDHOOK_TRAMPOLINE_H #ifndef SANDHOOK_TRAMPOLINE_H
#define SANDHOOK_TRAMPOLINE_H #define SANDHOOK_TRAMPOLINE_H
extern void hook_trampoline();
#if defined(__i386__)
#define SIZE_TRAMPOLINE = 4 * 7
#define OFFSET_ADDR_ART_METHOD 4 * 3
#define OFFSET_ADDR_ENTRY_CODE 4 * 5
#elif defined(__x86_64__)
#define SIZE_TRAMPOLINE = 4 * 7
#define OFFSET_ADDR_ART_METHOD 4 * 3
#define OFFSET_ADDR_ENTRY_CODE 4 * 5
#elif defined(__arm__)
#define SIZE_TRAMPOLINE = 4 * 7
#define OFFSET_ADDR_ART_METHOD 4 * 3
#define OFFSET_ADDR_ENTRY_CODE 4 * 5
#elif defined(__aarch64__)
#define SIZE_TRAMPOLINE = 4 * 7
#define OFFSET_ADDR_ART_METHOD 4 * 3
#define OFFSET_ADDR_ENTRY_CODE 4 * 5
#endif
#endif //SANDHOOK_TRAMPOLINE_H #endif //SANDHOOK_TRAMPOLINE_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