Unverified Commit c978ced7 authored by ganyao114's avatar ganyao114 Committed by GitHub

Merge pull request #17 from ganyao114/new_xpcompat

New xpcompat
parents 8f7d1d20 d77a98bd
...@@ -38,7 +38,7 @@ cant hook if lined ...@@ -38,7 +38,7 @@ cant hook if lined
# how to use # how to use
```gradle ```gradle
implementation 'com.swift.sandhook:hooklib:3.1.0' implementation 'com.swift.sandhook:hooklib:4.0.0'
``` ```
## Annotation API ## Annotation API
...@@ -115,7 +115,7 @@ SanHook.public static boolean hook(Member target, Method hook, Method backup) {} ...@@ -115,7 +115,7 @@ SanHook.public static boolean hook(Member target, Method hook, Method backup) {}
if hookers is in plugin(like xposed): if hookers is in plugin(like xposed):
```groovy ```groovy
provided 'com.swift.sandhook:hookannotation:3.1.0' provided 'com.swift.sandhook:hookannotation:4.0.0'
``` ```
in your plugin in your plugin
...@@ -127,18 +127,30 @@ backup method can call itself to avoid be inlining ...@@ -127,18 +127,30 @@ backup method can call itself to avoid be inlining
-------------------------------------------------------------------- --------------------------------------------------------------------
Now you can use Xposed api: Now you can use Xposed api:
We have two different implements:
```groovy ```groovy
implementation 'com.swift.sandhook:xposedcompat:3.1.0' //stable
implementation 'com.swift.sandhook:xposedcompat:4.0.0'
//or
//hook fast first time
implementation 'com.swift.sandhook:xposedcompat_new:4.0.0'
``` ```
```java ```java
//setup for xposed //setup for xposed
//for xposed compat only(no need xposed comapt new)
XposedCompat.cacheDir = getCacheDir(); XposedCompat.cacheDir = getCacheDir();
//for load xp module(sandvxp)
XposedCompat.context = this; XposedCompat.context = this;
XposedCompat.classLoader = getClassLoader(); XposedCompat.classLoader = getClassLoader();
XposedCompat.isFirstApplication= true; XposedCompat.isFirstApplication= true;
//do hook //do hook
XposedHelpers.findAndHookMethod(Activity.class, "onResume", new XC_MethodHook() { XposedHelpers.findAndHookMethod(Activity.class, "onResume", new XC_MethodHook() {
@Override @Override
......
...@@ -27,6 +27,7 @@ dependencies { ...@@ -27,6 +27,7 @@ dependencies {
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') implementation project(':hooklib')
implementation project(':nativehook') //implementation project(':nativehook')
implementation project(':xposedcompat') implementation project(':xposedcompat')
//implementation project(':xposedcompat_new')
} }
...@@ -5,7 +5,6 @@ import android.app.Application; ...@@ -5,7 +5,6 @@ import android.app.Application;
import android.os.Build; import android.os.Build;
import android.util.Log; import android.util.Log;
import com.swift.sandhook.nativehook.NativeHook;
import com.swift.sandhook.test.TestClass; import com.swift.sandhook.test.TestClass;
import com.swift.sandhook.testHookers.ActivityHooker; import com.swift.sandhook.testHookers.ActivityHooker;
import com.swift.sandhook.testHookers.CtrHook; import com.swift.sandhook.testHookers.CtrHook;
...@@ -30,7 +29,6 @@ public class MyApp extends Application { ...@@ -30,7 +29,6 @@ public class MyApp extends Application {
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
NativeHook.test();
SandHookConfig.DEBUG = BuildConfig.DEBUG; SandHookConfig.DEBUG = BuildConfig.DEBUG;
...@@ -58,8 +56,11 @@ public class MyApp extends Application { ...@@ -58,8 +56,11 @@ public class MyApp extends Application {
e.printStackTrace(); e.printStackTrace();
} }
//setup for xposed //for xposed compat(no need xposed comapt new)
XposedCompat.cacheDir = getCacheDir(); XposedCompat.cacheDir = getCacheDir();
//for load xp module(sandvxp)
XposedCompat.context = this; XposedCompat.context = this;
XposedCompat.classLoader = getClassLoader(); XposedCompat.classLoader = getClassLoader();
XposedCompat.isFirstApplication= true; XposedCompat.isFirstApplication= true;
......
...@@ -30,7 +30,7 @@ ext { ...@@ -30,7 +30,7 @@ ext {
userOrg = 'ganyao114' userOrg = 'ganyao114'
groupId = 'com.swift.sandhook' groupId = 'com.swift.sandhook'
repoName = 'SandHook' repoName = 'SandHook'
publishVersion = '3.4.6' publishVersion = '4.0.0'
desc = 'android art hook' desc = 'android art hook'
website = 'https://github.com/ganyao114/SandHook' website = 'https://github.com/ganyao114/SandHook'
licences = ['Apache-2.0'] licences = ['Apache-2.0']
......
...@@ -106,7 +106,7 @@ void* ArtMethod::getQuickCodeEntry() { ...@@ -106,7 +106,7 @@ void* ArtMethod::getQuickCodeEntry() {
} }
void* ArtMethod::getInterpreterCodeEntry() { void* ArtMethod::getInterpreterCodeEntry() {
return CastArtMethod::entryPointFormInterpreter->get(this); return CastArtMethod::entryPointFromInterpreter->get(this);
} }
GCRoot ArtMethod::getDeclaringClass() { GCRoot ArtMethod::getDeclaringClass() {
...@@ -122,10 +122,11 @@ void ArtMethod::setQuickCodeEntry(void *entry) { ...@@ -122,10 +122,11 @@ void ArtMethod::setQuickCodeEntry(void *entry) {
} }
void ArtMethod::setJniCodeEntry(void *entry) { void ArtMethod::setJniCodeEntry(void *entry) {
CastArtMethod::entryPointFromJNI->set(this, entry);
} }
void ArtMethod::setInterpreterCodeEntry(void *entry) { void ArtMethod::setInterpreterCodeEntry(void *entry) {
CastArtMethod::entryPointFormInterpreter->set(this, entry); CastArtMethod::entryPointFromInterpreter->set(this, entry);
} }
void ArtMethod::setDexCacheResolveList(void *list) { void ArtMethod::setDexCacheResolveList(void *list) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "../includes/cast_art_method.h" #include "../includes/cast_art_method.h"
#include "../includes/utils.h" #include "../includes/utils.h"
#include "../includes/never_call.h"
extern int SDK_INT; extern int SDK_INT;
...@@ -90,6 +91,11 @@ namespace SandHook { ...@@ -90,6 +91,11 @@ namespace SandHook {
class CastEntryPointFromJni : public IMember<art::mirror::ArtMethod, void *> { class CastEntryPointFromJni : public IMember<art::mirror::ArtMethod, void *> {
protected: protected:
Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod *p) override { Size calOffset(JNIEnv *jniEnv, art::mirror::ArtMethod *p) override {
Size jniAddr = reinterpret_cast<Size>(Java_com_swift_sandhook_ClassNeverCall_neverCallNative);
int offset = findOffset(p, getParentSize(), 2, jniAddr);
if (offset >= 0) {
return static_cast<Size>(offset);
}
if (SDK_INT >= ANDROID_L2 && SDK_INT <= ANDROID_N) { if (SDK_INT >= ANDROID_L2 && SDK_INT <= ANDROID_N) {
return getParentSize() - 2 * BYTE_POINT; return getParentSize() - 2 * BYTE_POINT;
} else { } else {
...@@ -189,8 +195,8 @@ namespace SandHook { ...@@ -189,8 +195,8 @@ namespace SandHook {
accessFlag = new CastAccessFlag(); accessFlag = new CastAccessFlag();
accessFlag->init(env, m1, size); accessFlag->init(env, m1, size);
entryPointFormInterpreter = new CastEntryPointFormInterpreter(); entryPointFromInterpreter = new CastEntryPointFormInterpreter();
entryPointFormInterpreter->init(env, m1, size); entryPointFromInterpreter->init(env, m1, size);
dexCacheResolvedMethods = new CastDexCacheResolvedMethods(); dexCacheResolvedMethods = new CastDexCacheResolvedMethods();
dexCacheResolvedMethods->init(env, m1, size); dexCacheResolvedMethods->init(env, m1, size);
...@@ -240,6 +246,9 @@ namespace SandHook { ...@@ -240,6 +246,9 @@ namespace SandHook {
genericJniStub = entryPointQuickCompiled->get(neverCallNative); genericJniStub = entryPointQuickCompiled->get(neverCallNative);
} }
entryPointFromJNI = new CastEntryPointFromJni();
entryPointFromJNI->init(env, neverCallNative, size);
art::mirror::ArtMethod *neverCallStatic = reinterpret_cast<art::mirror::ArtMethod *>(env->GetStaticMethodID( art::mirror::ArtMethod *neverCallStatic = reinterpret_cast<art::mirror::ArtMethod *>(env->GetStaticMethodID(
neverCallTestClass, "neverCallStatic", "()V")); neverCallTestClass, "neverCallStatic", "()V"));
staticResolveStub = entryPointQuickCompiled->get(neverCallStatic); staticResolveStub = entryPointQuickCompiled->get(neverCallStatic);
...@@ -252,7 +261,8 @@ namespace SandHook { ...@@ -252,7 +261,8 @@ namespace SandHook {
Size CastArtMethod::size = 0; Size CastArtMethod::size = 0;
IMember<art::mirror::ArtMethod, void *> *CastArtMethod::entryPointQuickCompiled = nullptr; IMember<art::mirror::ArtMethod, void *> *CastArtMethod::entryPointQuickCompiled = nullptr;
IMember<art::mirror::ArtMethod, void *> *CastArtMethod::entryPointFormInterpreter = nullptr; IMember<art::mirror::ArtMethod, void *> *CastArtMethod::entryPointFromInterpreter = nullptr;
IMember<art::mirror::ArtMethod, void *> *CastArtMethod::entryPointFromJNI = nullptr;
ArrayMember<art::mirror::ArtMethod, void *> *CastArtMethod::dexCacheResolvedMethods = nullptr; ArrayMember<art::mirror::ArtMethod, void *> *CastArtMethod::dexCacheResolvedMethods = nullptr;
IMember<art::mirror::ArtMethod, uint32_t> *CastArtMethod::dexMethodIndex = nullptr; IMember<art::mirror::ArtMethod, uint32_t> *CastArtMethod::dexMethodIndex = nullptr;
IMember<art::mirror::ArtMethod, uint32_t> *CastArtMethod::accessFlag = nullptr; IMember<art::mirror::ArtMethod, uint32_t> *CastArtMethod::accessFlag = nullptr;
......
...@@ -14,7 +14,8 @@ namespace SandHook { ...@@ -14,7 +14,8 @@ namespace SandHook {
public: public:
static Size size; static Size size;
static IMember<art::mirror::ArtMethod, void*>* entryPointQuickCompiled; static IMember<art::mirror::ArtMethod, void*>* entryPointQuickCompiled;
static IMember<art::mirror::ArtMethod, void*>* entryPointFormInterpreter; static IMember<art::mirror::ArtMethod, void*>* entryPointFromInterpreter;
static IMember<art::mirror::ArtMethod, void*>* entryPointFromJNI;
static ArrayMember<art::mirror::ArtMethod,void*>* dexCacheResolvedMethods; static ArrayMember<art::mirror::ArtMethod,void*>* dexCacheResolvedMethods;
static IMember<art::mirror::ArtMethod, uint32_t>* dexMethodIndex; static IMember<art::mirror::ArtMethod, uint32_t>* dexMethodIndex;
static IMember<art::mirror::ArtMethod, uint32_t>* accessFlag; static IMember<art::mirror::ArtMethod, uint32_t>* accessFlag;
......
//
// Created by swift on 2019/6/3.
//
#ifndef SANDHOOK_NEVER_CALL_H
#define SANDHOOK_NEVER_CALL_H
#include <jni.h>
extern "C"
JNIEXPORT void JNICALL
Java_com_swift_sandhook_ClassNeverCall_neverCallNative(JNIEnv *env, jobject instance);
#endif //SANDHOOK_NEVER_CALL_H
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include "includes/log.h" #include "includes/log.h"
#include "includes/native_hook.h" #include "includes/native_hook.h"
#include "includes/elf_util.h" #include "includes/elf_util.h"
#include "includes/never_call.h"
#include <jni.h> #include <jni.h>
SandHook::TrampolineManager trampolineManager; SandHook::TrampolineManager trampolineManager;
...@@ -345,6 +345,22 @@ Java_com_swift_sandhook_SandHook_disableDex2oatInline(JNIEnv *env, jclass type, ...@@ -345,6 +345,22 @@ Java_com_swift_sandhook_SandHook_disableDex2oatInline(JNIEnv *env, jclass type,
return static_cast<jboolean>(SandHook::NativeHook::hookDex2oat(disableDex2oat)); return static_cast<jboolean>(SandHook::NativeHook::hookDex2oat(disableDex2oat));
} }
extern "C"
JNIEXPORT jboolean JNICALL
Java_com_swift_sandhook_SandHook_setNativeEntry(JNIEnv *env, jclass type, jobject origin, jobject hook, jlong jniTrampoline) {
if (origin == nullptr || hook == NULL)
return JNI_FALSE;
art::mirror::ArtMethod* hookMethod = reinterpret_cast<art::mirror::ArtMethod *>(env->FromReflectedMethod(hook));
art::mirror::ArtMethod* originMethod = reinterpret_cast<art::mirror::ArtMethod *>(env->FromReflectedMethod(origin));
originMethod->backup(hookMethod);
hookMethod->setNative();
hookMethod->setQuickCodeEntry(SandHook::CastArtMethod::genericJniStub);
hookMethod->setJniCodeEntry(reinterpret_cast<void *>(jniTrampoline));
hookMethod->disableCompilable();
hookMethod->flushCache();
return JNI_TRUE;
}
extern "C" extern "C"
JNIEXPORT void JNICALL JNIEXPORT void JNICALL
Java_com_swift_sandhook_ClassNeverCall_neverCallNative(JNIEnv *env, jobject instance) { Java_com_swift_sandhook_ClassNeverCall_neverCallNative(JNIEnv *env, jobject instance) {
...@@ -456,6 +472,11 @@ static JNINativeMethod jniSandHook[] = { ...@@ -456,6 +472,11 @@ static JNINativeMethod jniSandHook[] = {
"disableDex2oatInline", "disableDex2oatInline",
"(Z)Z", "(Z)Z",
(void *) Java_com_swift_sandhook_SandHook_disableDex2oatInline (void *) Java_com_swift_sandhook_SandHook_disableDex2oatInline
},
{
"setNativeEntry",
"(Ljava/lang/reflect/Member;Ljava/lang/reflect/Member;J)Z",
(void *) Java_com_swift_sandhook_SandHook_setNativeEntry
} }
}; };
......
...@@ -365,6 +365,8 @@ public class SandHook { ...@@ -365,6 +365,8 @@ public class SandHook {
public static native boolean disableDex2oatInline(boolean disableDex2oat); public static native boolean disableDex2oatInline(boolean disableDex2oat);
public static native boolean setNativeEntry(Member origin, Member hook, long nativeEntry);
@FunctionalInterface @FunctionalInterface
public interface HookModeCallBack { public interface HookModeCallBack {
int hookMode(Member originMethod); int hookMode(Member originMethod);
......
...@@ -68,7 +68,7 @@ public class HookWrapper { ...@@ -68,7 +68,7 @@ public class HookWrapper {
if (TextUtils.equals(hookEntity.isCtor() ? "<init>" : hookEntity.target.getName(), hookMethodBackup.value()) && samePars(classLoader, field, hookEntity.pars)) { if (TextUtils.equals(hookEntity.isCtor() ? "<init>" : hookEntity.target.getName(), hookMethodBackup.value()) && samePars(classLoader, field, hookEntity.pars)) {
field.setAccessible(true); field.setAccessible(true);
if (hookEntity.backup == null) { if (hookEntity.backup == null) {
hookEntity.backup = BackupMethodStubs.getStubMethod(); hookEntity.backup = StubMethodsFactory.getStubMethod();
hookEntity.hookIsStub = true; hookEntity.hookIsStub = true;
hookEntity.resolveDexCache = false; hookEntity.resolveDexCache = false;
} }
......
package com.swift.sandhook.wrapper; package com.swift.sandhook.wrapper;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class BackupMethodStubs { public class StubMethodsFactory {
final static int maxStub = 300; final static int maxStub = 300;
private static volatile int curStub = 0; private static volatile int curStub = 0;
private static Method proxyGenClass;
static {
try {
proxyGenClass = Proxy.class.getDeclaredMethod("generateProxy",String.class,Class[].class,ClassLoader.class,Method[].class,Class[][].class);
proxyGenClass.setAccessible(true);
} catch (Throwable e) {
e.printStackTrace();
}
}
public static synchronized Method getStubMethod() { public static synchronized Method getStubMethod() {
while (curStub <= maxStub) { while (curStub <= maxStub) {
try { try {
return BackupMethodStubs.class.getDeclaredMethod("stub" + curStub++); return StubMethodsFactory.class.getDeclaredMethod("stub" + curStub++);
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
} }
} }
return null; try {
curStub++;
Class proxyClass = (Class)proxyGenClass.invoke(null,"SandHookerStubClass_" + curStub, null, StubMethodsFactory.class.getClassLoader(), new Method[]{proxyGenClass}, null);
return proxyClass.getDeclaredMethods()[0];
} catch (Throwable e) {
e.printStackTrace();
return null;
}
} }
public void stub0() {} public void stub0() {}
......
...@@ -39,9 +39,4 @@ android { ...@@ -39,9 +39,4 @@ android {
dependencies { dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar']) implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
} }
package com.swift.sandhook.nativehook;
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.nativehook.test", appContext.getPackageName());
}
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef SANDHOOK_SANDHOOK_NATIVE_H #ifndef SANDHOOK_SANDHOOK_NATIVE_H
#define SANDHOOK_SANDHOOK_NATIVE_H #define SANDHOOK_SANDHOOK_NATIVE_H
#include "hook.h" typedef size_t REG;
#define EXPORT __attribute__ ((visibility ("default"))) #define EXPORT __attribute__ ((visibility ("default")))
......
package com.swift.sandhook.nativehook;
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', ':hooklib', ':hookers', ':annotation', ':xposedcompat', ':nativehook' include ':app', ':hooklib', ':hookers', ':annotation', ':xposedcompat', ':nativehook', ':xposedcompat_new'
...@@ -5,7 +5,7 @@ import android.util.Log; ...@@ -5,7 +5,7 @@ import android.util.Log;
import com.swift.sandhook.SandHook; import com.swift.sandhook.SandHook;
import com.swift.sandhook.SandHookMethodResolver; import com.swift.sandhook.SandHookMethodResolver;
import com.swift.sandhook.utils.ParamWrapper; import com.swift.sandhook.utils.ParamWrapper;
import com.swift.sandhook.wrapper.BackupMethodStubs; import com.swift.sandhook.wrapper.StubMethodsFactory;
import com.swift.sandhook.xposedcompat.XposedCompat; import com.swift.sandhook.xposedcompat.XposedCompat;
import com.swift.sandhook.xposedcompat.utils.DexLog; import com.swift.sandhook.xposedcompat.utils.DexLog;
...@@ -167,13 +167,13 @@ public class HookStubManager { ...@@ -167,13 +167,13 @@ public class HookStubManager {
try { try {
if (is64Bit) { if (is64Bit) {
Method hook = MethodHookerStubs64.class.getDeclaredMethod(getHookMethodName(curUseStubIndex), pars); Method hook = MethodHookerStubs64.class.getDeclaredMethod(getHookMethodName(curUseStubIndex), pars);
Method backup = hasStubBackup ? MethodHookerStubs64.class.getDeclaredMethod(getBackupMethodName(curUseStubIndex), pars) : BackupMethodStubs.getStubMethod(); Method backup = hasStubBackup ? MethodHookerStubs64.class.getDeclaredMethod(getBackupMethodName(curUseStubIndex), pars) : StubMethodsFactory.getStubMethod();
if (hook == null || backup == null) if (hook == null || backup == null)
return null; return null;
return new StubMethodsInfo(stubArgs, curUseStubIndex, hook, backup); return new StubMethodsInfo(stubArgs, curUseStubIndex, hook, backup);
} else { } else {
Method hook = MethodHookerStubs32.class.getDeclaredMethod(getHookMethodName(curUseStubIndex), pars); Method hook = MethodHookerStubs32.class.getDeclaredMethod(getHookMethodName(curUseStubIndex), pars);
Method backup = hasStubBackup ? MethodHookerStubs32.class.getDeclaredMethod(getBackupMethodName(curUseStubIndex), pars) : BackupMethodStubs.getStubMethod(); Method backup = hasStubBackup ? MethodHookerStubs32.class.getDeclaredMethod(getBackupMethodName(curUseStubIndex), pars) : StubMethodsFactory.getStubMethod();
if (hook == null || backup == null) if (hook == null || backup == null)
return null; return null;
return new StubMethodsInfo(stubArgs, curUseStubIndex, hook, backup); return new StubMethodsInfo(stubArgs, curUseStubIndex, hook, backup);
......
# 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)
set(CMAKE_CXX_STANDARD 14)
enable_language(ASM)
SET(CMAKE_ASM_FLAGS "${CFLAGS} -x assembler-with-cpp")
# 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.
if(${CMAKE_ANDROID_ARCH_ABI} STREQUAL "arm64-v8a")
set(OS_DEPENDENDED_SRC
src/main/cpp/libffi/aarch64/ffi_arm64.c
src/main/cpp/libffi/aarch64/sysv_arm64.S)
elseif (${CMAKE_ANDROID_ARCH_ABI} STREQUAL "armeabi-v7a")
set(OS_DEPENDENDED_SRC
src/main/cpp/libffi/arm/ffi_armv7.c
src/main/cpp/libffi/arm/sysv_armv7.S)
endif()
add_library( # Sets the name of the library.
sandhook-xp
# Sets the library as a shared library.
SHARED
src/main/cpp/art_jni_trampoline.cpp
# Provides a relative path to your source file(s).
src/main/cpp/libffi/closures.c
src/main/cpp/libffi/closures.c
src/main/cpp/libffi/debug.c
src/main/cpp/libffi/dlmalloc.c
src/main/cpp/libffi/java_raw_api.c
src/main/cpp/libffi/prep_cif.c
src/main/cpp/libffi/raw_api.c
src/main/cpp/libffi/types.c
src/main/cpp/libffi/ffi_cxx.cc
${OS_DEPENDENDED_SRC})
include_directories(
src/main/cpp
src/main/cpp/libffi
src/main/cpp/libffi/platform_include
../nativehook/src/main/cpp
)
add_library(sandhook-native
SHARED
IMPORTED)
set_target_properties(sandhook-native
PROPERTIES IMPORTED_LOCATION
${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libsandhook-native.so)
# 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.
sandhook-xp
sandhook-native
# Links the target library to the log library
# included in the NDK.
${log-lib})
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'
cppFlags "-frtti -fexceptions -Wpointer-arith"
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compileOnly project(':hooklib')
}
apply plugin: 'com.novoda.bintray-release'
publish {
userOrg = rootProject.userOrg
groupId = rootProject.groupId
artifactId = 'xposedcompat_new'
publishVersion = rootProject.publishVersion
desc = rootProject.desc
website = rootProject.website
licences = rootProject.licences
}
# 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
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.swift.sandhook.xposedcompat" />
This diff is collapsed.
//
// Created by swift on 2019/6/3.
//
#ifndef SANDHOOK_ART_JNI_TRAMPOLINE_H
#define SANDHOOK_ART_JNI_TRAMPOLINE_H
#include <cstdint>
#include <jni.h>
#include <list>
#include <set>
#include "ffi_cxx.h"
jclass java_lang_Object;
JavaVM* javaVM;
jclass bridgeClass;
jmethodID bridgeMethod;
void* (*GetOatQuickMethodHeaderBackup)(void*,uintptr_t) = nullptr;
struct ArtHookParam {
jint slot;
bool is_static_;
char returnShorty;
char* paramsShorty;
};
std::list<ArtHookParam*> hookParams = std::list<ArtHookParam*>();
std::set<void*> hookMethods = std::set<void*>();
template<typename U, typename T>
U ForceCast(T *x) {
return (U) (uintptr_t) x;
}
template<typename U, typename T>
U ForceCast(T &x) {
return *(U *) &x;
}
struct Types {
#define LANG_ClASS(c) static jclass java_lang_##c; static jmethodID java_lang_##c##_init; static jmethodID java_value_##c;
LANG_ClASS(Integer);
LANG_ClASS(Long);
LANG_ClASS(Float);
LANG_ClASS(Double);
LANG_ClASS(Byte);
LANG_ClASS(Short);
LANG_ClASS(Boolean);
LANG_ClASS(Character);
#undef LANG_ClASS
static void Load(JNIEnv *env);
#define LANG_BOX_DEF(c, t) static jobject To##c(JNIEnv *env, t v);
#define LANG_UNBOX_V_DEF(k, c, t) static t From##c(JNIEnv *env, jobject j);
#define LANG_UNBOX_DEF(c, t) LANG_UNBOX_V_DEF(c, c, t)
LANG_BOX_DEF(Object, jobject);
LANG_BOX_DEF(Integer, jint);
LANG_BOX_DEF(Long, jlong);
LANG_BOX_DEF(Float, jfloat);
LANG_BOX_DEF(Double, jdouble);
LANG_BOX_DEF(Byte, jbyte);
LANG_BOX_DEF(Short, jshort);
LANG_BOX_DEF(Boolean, jboolean);
LANG_BOX_DEF(Character, jchar);
LANG_UNBOX_V_DEF(Int, Integer, jint);
LANG_UNBOX_DEF(Object, jobject);
LANG_UNBOX_DEF(Long, jlong);
LANG_UNBOX_DEF(Float, jfloat);
LANG_UNBOX_DEF(Double, jdouble);
LANG_UNBOX_DEF(Byte, jbyte);
LANG_UNBOX_DEF(Short, jshort);
LANG_UNBOX_DEF(Boolean, jboolean);
LANG_UNBOX_V_DEF(Char, Character, jchar);
#undef LANG_BOX_DEF
#undef LANG_UNBOX_V_DEF
#undef LANG_UNBOX_DEF
};
static void UnBoxValue(JNIEnv *env, jvalue *jv, jobject obj, char type) {
switch (type) {
case 'I':
jv->i = Types::FromInteger(env, obj);
break;
case 'Z':
jv->z = Types::FromBoolean(env, obj);
break;
case 'J':
jv->j = Types::FromLong(env, obj);
break;
case 'F':
jv->f = Types::FromFloat(env, obj);
break;
case 'B':
jv->b = Types::FromByte(env, obj);
break;
case 'D':
jv->d = Types::FromDouble(env, obj);
break;
case 'S':
jv->s = Types::FromShort(env, obj);
break;
case 'C':
jv->c = Types::FromCharacter(env, obj);
break;
default:
jv->l = obj;
}
}
class QuickArgumentBuilder {
public:
QuickArgumentBuilder(JNIEnv *env, size_t len) : env_(env), index_(0) {
array_ = env->NewObjectArray(
static_cast<jsize>(len),
java_lang_Object,
nullptr
);
}
#define APPEND_DEF(name, type) \
void Append##name(type value) { \
env_->SetObjectArrayElement(array_, index_++, \
Types::To##name(env_, value)); \
} \
APPEND_DEF(Integer, jint)
APPEND_DEF(Boolean, jboolean)
APPEND_DEF(Byte, jbyte)
APPEND_DEF(Character, jchar)
APPEND_DEF(Short, jshort)
APPEND_DEF(Float, jfloat)
APPEND_DEF(Double, jdouble)
APPEND_DEF(Long, jlong)
APPEND_DEF(Object, jobject)
#undef APPEND_DEF
jobjectArray GetArray() {
return array_;
}
private:
JNIEnv *env_;
jobjectArray array_;
int index_;
};
#endif //SANDHOOK_ART_JNI_TRAMPOLINE_H
This diff is collapsed.
#if defined(__aarch64__) || defined(__arm64__)
/*
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#define AARCH64_RET_VOID 0
#define AARCH64_RET_INT64 1
#define AARCH64_RET_INT128 2
#define AARCH64_RET_UNUSED3 3
#define AARCH64_RET_UNUSED4 4
#define AARCH64_RET_UNUSED5 5
#define AARCH64_RET_UNUSED6 6
#define AARCH64_RET_UNUSED7 7
/* Note that FFI_TYPE_FLOAT == 2, _DOUBLE == 3, _LONGDOUBLE == 4,
so _S4 through _Q1 are layed out as (TYPE * 4) + (4 - COUNT). */
#define AARCH64_RET_S4 8
#define AARCH64_RET_S3 9
#define AARCH64_RET_S2 10
#define AARCH64_RET_S1 11
#define AARCH64_RET_D4 12
#define AARCH64_RET_D3 13
#define AARCH64_RET_D2 14
#define AARCH64_RET_D1 15
#define AARCH64_RET_Q4 16
#define AARCH64_RET_Q3 17
#define AARCH64_RET_Q2 18
#define AARCH64_RET_Q1 19
/* Note that each of the sub-64-bit integers gets two entries. */
#define AARCH64_RET_UINT8 20
#define AARCH64_RET_UINT16 22
#define AARCH64_RET_UINT32 24
#define AARCH64_RET_SINT8 26
#define AARCH64_RET_SINT16 28
#define AARCH64_RET_SINT32 30
#define AARCH64_RET_MASK 31
#define AARCH64_RET_IN_MEM (1 << 5)
#define AARCH64_RET_NEED_COPY (1 << 6)
#define AARCH64_FLAG_ARG_V_BIT 7
#define AARCH64_FLAG_ARG_V (1 << AARCH64_FLAG_ARG_V_BIT)
#define N_X_ARG_REG 8
#define N_V_ARG_REG 8
#define CALL_CONTEXT_SIZE (N_V_ARG_REG * 16 + N_X_ARG_REG * 8)
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#ifdef __arm__
#define ARM_TYPE_VFP_S 0
#define ARM_TYPE_VFP_D 1
#define ARM_TYPE_VFP_N 2
#define ARM_TYPE_INT64 3
#define ARM_TYPE_INT 4
#define ARM_TYPE_VOID 5
#define ARM_TYPE_STRUCT 6
#endif
\ No newline at end of file
#ifdef __arm__
/* -----------------------------------------------------------------------
sysv.S - Copyright (c) 1998, 2008, 2011 Red Hat, Inc.
Copyright (c) 2011 Plausible Labs Cooperative, Inc.
ARM Foreign Function Interface
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------- */
#define LIBFFI_ASM
#include <fficonfig.h>
#include <ffi.h>
#include <ffi_cfi.h>
#include "internal.h"
/* GCC 4.8 provides __ARM_ARCH; construct it otherwise. */
#ifndef __ARM_ARCH
# if defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) \
|| defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) \
|| defined(__ARM_ARCH_7EM__)
# define __ARM_ARCH 7
# elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) \
|| defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) \
|| defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) \
|| defined(__ARM_ARCH_6M__)
# define __ARM_ARCH 6
# elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) \
|| defined(__ARM_ARCH_5E__) || defined(__ARM_ARCH_5TE__) \
|| defined(__ARM_ARCH_5TEJ__)
# define __ARM_ARCH 5
# else
# define __ARM_ARCH 4
# endif
#endif
/* Conditionally compile unwinder directives. */
#ifdef __ARM_EABI__
# define UNWIND(...) __VA_ARGS__
#else
# define UNWIND(...)
#endif
#if defined(HAVE_AS_CFI_PSEUDO_OP) && defined(__ARM_EABI__)
.cfi_sections .debug_frame
#endif
#define CONCAT(a, b) CONCAT2(a, b)
#define CONCAT2(a, b) a ## b
#ifdef __USER_LABEL_PREFIX__
# define CNAME(X) CONCAT (__USER_LABEL_PREFIX__, X)
#else
# define CNAME(X) X
#endif
#ifdef __ELF__
# define SIZE(X) .size CNAME(X), . - CNAME(X)
# define TYPE(X, Y) .type CNAME(X), Y
#else
# define SIZE(X)
# define TYPE(X, Y)
#endif
#define ARM_FUNC_START_LOCAL(name) \
.align 3; \
TYPE(CNAME(name), %function); \
CNAME(name):
#define ARM_FUNC_START(name) \
.globl CNAME(name); \
FFI_HIDDEN(CNAME(name)); \
ARM_FUNC_START_LOCAL(name)
#define ARM_FUNC_END(name) \
SIZE(name)
/* Aid in defining a jump table with 8 bytes between entries. */
/* ??? The clang assembler doesn't handle .if with symbolic expressions. */
#ifdef __clang__
# define E(index)
#else
# define E(index) \
.if . - 0b - 8*index; \
.error "type table out of sync"; \
.endif
#endif
.text
.syntax unified
.arm
#ifndef __clang__
/* We require interworking on LDM, which implies ARMv5T,
which implies the existance of BLX. */
.arch armv5t
#endif
/* Note that we use STC and LDC to encode VFP instructions,
so that we do not need ".fpu vfp", nor get that added to
the object file attributes. These will not be executed
unless the FFI_VFP abi is used. */
@ r0: stack
@ r1: frame
@ r2: fn
@ r3: vfp_used
ARM_FUNC_START(ffi_call_VFP)
UNWIND(.fnstart)
cfi_startproc
cmp r3, #3 @ load only d0 if possible
#ifdef __clang__
vldrle d0, [sp]
vldmgt sp, {d0-d7}
#else
ldcle p11, cr0, [r0] @ vldrle d0, [sp]
ldcgt p11, cr0, [r0], {16} @ vldmgt sp, {d0-d7}
#endif
add r0, r0, #64 @ discard the vfp register args
/* FALLTHRU */
ARM_FUNC_END(ffi_call_VFP)
ARM_FUNC_START(ffi_call_SYSV)
stm r1, {fp, lr}
mov fp, r1
@ This is a bit of a lie wrt the origin of the unwind info, but
@ now we've got the usual frame pointer and two saved registers.
UNWIND(.save {fp,lr})
UNWIND(.setfp fp, sp)
cfi_def_cfa(fp, 8)
cfi_rel_offset(fp, 0)
cfi_rel_offset(lr, 4)
mov sp, r0 @ install the stack pointer
mov lr, r2 @ move the fn pointer out of the way
ldr ip, [fp, #16] @ install the static chain
ldmia sp!, {r0-r3} @ move first 4 parameters in registers.
blx lr @ call fn
@ Load r2 with the pointer to storage for the return value
@ Load r3 with the return type code
ldr r2, [fp, #8]
ldr r3, [fp, #12]
@ Deallocate the stack with the arguments.
mov sp, fp
cfi_def_cfa_register(sp)
@ Store values stored in registers.
.align 3
add pc, pc, r3, lsl #3
nop
0:
E(ARM_TYPE_VFP_S)
#ifdef __clang__
vstr s0, [r2]
#else
stc p10, cr0, [r2] @ vstr s0, [r2]
#endif
pop {fp,pc}
E(ARM_TYPE_VFP_D)
#ifdef __clang__
vstr d0, [r2]
#else
stc p11, cr0, [r2] @ vstr d0, [r2]
#endif
pop {fp,pc}
E(ARM_TYPE_VFP_N)
#ifdef __clang__
vstm r2, {d0-d3}
#else
stc p11, cr0, [r2], {8} @ vstm r2, {d0-d3}
#endif
pop {fp,pc}
E(ARM_TYPE_INT64)
str r1, [r2, #4]
nop
E(ARM_TYPE_INT)
str r0, [r2]
pop {fp,pc}
E(ARM_TYPE_VOID)
pop {fp,pc}
nop
E(ARM_TYPE_STRUCT)
pop {fp,pc}
cfi_endproc
UNWIND(.fnend)
ARM_FUNC_END(ffi_call_SYSV)
/*
int ffi_closure_inner_* (cif, fun, user_data, frame)
*/
ARM_FUNC_START(ffi_go_closure_SYSV)
cfi_startproc
stmdb sp!, {r0-r3} @ save argument regs
cfi_adjust_cfa_offset(16)
ldr r0, [ip, #4] @ load cif
ldr r1, [ip, #8] @ load fun
mov r2, ip @ load user_data
b 0f
cfi_endproc
ARM_FUNC_END(ffi_go_closure_SYSV)
ARM_FUNC_START(ffi_closure_SYSV)
UNWIND(.fnstart)
cfi_startproc
stmdb sp!, {r0-r3} @ save argument regs
cfi_adjust_cfa_offset(16)
#if FFI_EXEC_TRAMPOLINE_TABLE
ldr ip, [ip] @ ip points to the config page, dereference to get the ffi_closure*
#endif
ldr r0, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET] @ load cif
ldr r1, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+4] @ load fun
ldr r2, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+8] @ load user_data
0:
add ip, sp, #16 @ compute entry sp
sub sp, sp, #64+32 @ allocate frame
cfi_adjust_cfa_offset(64+32)
stmdb sp!, {ip,lr}
/* Remember that EABI unwind info only applies at call sites.
We need do nothing except note the save of the stack pointer
and the link registers. */
UNWIND(.save {sp,lr})
cfi_adjust_cfa_offset(8)
cfi_rel_offset(lr, 4)
add r3, sp, #8 @ load frame
bl CNAME(ffi_closure_inner_SYSV)
@ Load values returned in registers.
add r2, sp, #8+64 @ load result
adr r3, CNAME(ffi_closure_ret)
add pc, r3, r0, lsl #3
cfi_endproc
UNWIND(.fnend)
ARM_FUNC_END(ffi_closure_SYSV)
ARM_FUNC_START(ffi_go_closure_VFP)
cfi_startproc
stmdb sp!, {r0-r3} @ save argument regs
cfi_adjust_cfa_offset(16)
ldr r0, [ip, #4] @ load cif
ldr r1, [ip, #8] @ load fun
mov r2, ip @ load user_data
b 0f
cfi_endproc
ARM_FUNC_END(ffi_go_closure_VFP)
ARM_FUNC_START(ffi_closure_VFP)
UNWIND(.fnstart)
cfi_startproc
stmdb sp!, {r0-r3} @ save argument regs
cfi_adjust_cfa_offset(16)
#if FFI_EXEC_TRAMPOLINE_TABLE
ldr ip, [ip] @ ip points to the config page, dereference to get the ffi_closure*
#endif
ldr r0, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET] @ load cif
ldr r1, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+4] @ load fun
ldr r2, [ip, #FFI_TRAMPOLINE_CLOSURE_OFFSET+8] @ load user_data
0:
add ip, sp, #16
sub sp, sp, #64+32 @ allocate frame
cfi_adjust_cfa_offset(64+32)
#ifdef __clang__
vstm sp, {d0-d7}
#else
stc p11, cr0, [sp], {16} @ vstm sp, {d0-d7}
#endif
stmdb sp!, {ip,lr}
/* See above. */
UNWIND(.save {sp,lr})
cfi_adjust_cfa_offset(8)
cfi_rel_offset(lr, 4)
add r3, sp, #8 @ load frame
bl CNAME(ffi_closure_inner_VFP)
@ Load values returned in registers.
add r2, sp, #8+64 @ load result
adr r3, CNAME(ffi_closure_ret)
add pc, r3, r0, lsl #3
cfi_endproc
UNWIND(.fnend)
ARM_FUNC_END(ffi_closure_VFP)
/* Load values returned in registers for both closure entry points.
Note that we use LDM with SP in the register set. This is deprecated
by ARM, but not yet unpredictable. */
ARM_FUNC_START_LOCAL(ffi_closure_ret)
cfi_startproc
cfi_rel_offset(sp, 0)
cfi_rel_offset(lr, 4)
0:
E(ARM_TYPE_VFP_S)
#ifdef __clang__
vldr s0, [r2]
#else
ldc p10, cr0, [r2] @ vldr s0, [r2]
#endif
ldm sp, {sp,pc}
E(ARM_TYPE_VFP_D)
#ifdef __clang__
vldr d0, [r2]
#else
ldc p11, cr0, [r2] @ vldr d0, [r2]
#endif
ldm sp, {sp,pc}
E(ARM_TYPE_VFP_N)
#ifdef __clang__
vldm r2, {d0-d3}
#else
ldc p11, cr0, [r2], {8} @ vldm r2, {d0-d3}
#endif
ldm sp, {sp,pc}
E(ARM_TYPE_INT64)
ldr r1, [r2, #4]
nop
E(ARM_TYPE_INT)
ldr r0, [r2]
ldm sp, {sp,pc}
E(ARM_TYPE_VOID)
ldm sp, {sp,pc}
nop
E(ARM_TYPE_STRUCT)
ldm sp, {sp,pc}
cfi_endproc
ARM_FUNC_END(ffi_closure_ret)
#if FFI_EXEC_TRAMPOLINE_TABLE
#ifdef __MACH__
#include <mach/machine/vm_param.h>
.align PAGE_MAX_SHIFT
ARM_FUNC_START(ffi_closure_trampoline_table_page)
.rept PAGE_MAX_SIZE / FFI_TRAMPOLINE_SIZE
adr ip, #-PAGE_MAX_SIZE @ the config page is PAGE_MAX_SIZE behind the trampoline page
sub ip, #8 @ account for pc bias
ldr pc, [ip, #4] @ jump to ffi_closure_SYSV or ffi_closure_VFP
.endr
ARM_FUNC_END(ffi_closure_trampoline_table_page)
#endif
#else
ARM_FUNC_START(ffi_arm_trampoline)
0: adr ip, 0b
ldr pc, 1f
1: .long 0
ARM_FUNC_END(ffi_arm_trampoline)
#endif /* FFI_EXEC_TRAMPOLINE_TABLE */
#if defined __ELF__ && defined __linux__
.section .note.GNU-stack,"",%progbits
#endif
#endif
\ No newline at end of file
This diff is collapsed.
/* -----------------------------------------------------------------------
debug.c - Copyright (c) 1996 Red Hat, Inc.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
``Software''), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
----------------------------------------------------------------------- */
#include <ffi.h>
#include <ffi_common.h>
#include <stdlib.h>
#include <stdio.h>
/* General debugging routines */
void ffi_stop_here(void)
{
/* This function is only useful for debugging purposes.
Place a breakpoint on ffi_stop_here to be notified of
significant events. */
}
/* This function should only be called via the FFI_ASSERT() macro */
void ffi_assert(char *expr, char *file, int line)
{
fprintf(stderr, "ASSERTION FAILURE: %s at %s:%d\n", expr, file, line);
ffi_stop_here();
abort();
}
/* Perform a sanity check on an ffi_type structure */
void ffi_type_test(ffi_type *a, char *file, int line)
{
FFI_ASSERT_AT(a != NULL, file, line);
FFI_ASSERT_AT(a->type <= FFI_TYPE_LAST, file, line);
FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->size > 0, file, line);
FFI_ASSERT_AT(a->type == FFI_TYPE_VOID || a->alignment > 0, file, line);
FFI_ASSERT_AT((a->type != FFI_TYPE_STRUCT && a->type != FFI_TYPE_COMPLEX)
|| a->elements != NULL, file, line);
FFI_ASSERT_AT(a->type != FFI_TYPE_COMPLEX
|| (a->elements != NULL
&& a->elements[0] != NULL && a->elements[1] == NULL),
file, line);
}
This diff is collapsed.
#ifdef __aarch64__
#include <ffi_arm64.h>
#endif
#ifdef __i386__
#include <ffi_i386.h>
#endif
#ifdef __arm__
#include <ffi_armv7.h>
#endif
#ifdef __x86_64__
#include <ffi_x86_64.h>
#endif
/* -----------------------------------------------------------------------
ffi_cfi.h - Copyright (c) 2014 Red Hat, Inc.
Conditionally assemble cfi directives. Only necessary for building libffi.
----------------------------------------------------------------------- */
#ifndef FFI_CFI_H
#define FFI_CFI_H
#ifdef HAVE_AS_CFI_PSEUDO_OP
# define cfi_startproc .cfi_startproc
# define cfi_endproc .cfi_endproc
# define cfi_def_cfa(reg, off) .cfi_def_cfa reg, off
# define cfi_def_cfa_register(reg) .cfi_def_cfa_register reg
# define cfi_def_cfa_offset(off) .cfi_def_cfa_offset off
# define cfi_adjust_cfa_offset(off) .cfi_adjust_cfa_offset off
# define cfi_offset(reg, off) .cfi_offset reg, off
# define cfi_rel_offset(reg, off) .cfi_rel_offset reg, off
# define cfi_register(r1, r2) .cfi_register r1, r2
# define cfi_return_column(reg) .cfi_return_column reg
# define cfi_restore(reg) .cfi_restore reg
# define cfi_same_value(reg) .cfi_same_value reg
# define cfi_undefined(reg) .cfi_undefined reg
# define cfi_remember_state .cfi_remember_state
# define cfi_restore_state .cfi_restore_state
# define cfi_window_save .cfi_window_save
# define cfi_personality(enc, exp) .cfi_personality enc, exp
# define cfi_lsda(enc, exp) .cfi_lsda enc, exp
# define cfi_escape(...) .cfi_escape __VA_ARGS__
#else
# define cfi_startproc
# define cfi_endproc
# define cfi_def_cfa(reg, off)
# define cfi_def_cfa_register(reg)
# define cfi_def_cfa_offset(off)
# define cfi_adjust_cfa_offset(off)
# define cfi_offset(reg, off)
# define cfi_rel_offset(reg, off)
# define cfi_register(r1, r2)
# define cfi_return_column(reg)
# define cfi_restore(reg)
# define cfi_same_value(reg)
# define cfi_undefined(reg)
# define cfi_remember_state
# define cfi_restore_state
# define cfi_window_save
# define cfi_personality(enc, exp)
# define cfi_lsda(enc, exp)
# define cfi_escape(...)
#endif /* HAVE_AS_CFI_PSEUDO_OP */
#endif /* FFI_CFI_H */
This diff is collapsed.
#include "ffi_cxx.h"
FFICallInterface::~FFICallInterface() {
for (FFIClosure *closure : closures_) {
delete closure;
}
delete cif_;
delete types_;
}
void FFIDispatcher(ffi_cif *cif OPTION, void *ret, void **args, void *userdata) {
FFIClosure *closure = reinterpret_cast<FFIClosure *>(userdata);
FFICallback callback = closure->GetCallback();
callback(closure, ret, args, closure->GetUserData());
}
FFIClosure *FFICallInterface::CreateClosure(void *userdata, FFICallback callback) {
std::lock_guard<std::mutex> guard(lock_);
FFIClosure *closure = new FFIClosure(this, userdata, callback);
ffi_prep_closure_loc(closure->closure_, cif_, FFIDispatcher, closure, closure->code_);
closures_.push_back(closure);
return closure;
}
static ffi_type *FFIGetCType(FFIType type) {
switch (type) {
case FFIType::kFFITypeVoid:
return &ffi_type_void;
case FFIType::kFFITypeU1:
return &ffi_type_uint8;
case FFIType::kFFITypeU2:
return &ffi_type_uint16;
case FFIType::kFFITypeU4:
return &ffi_type_uint32;
case FFIType::kFFITypeU8:
return &ffi_type_uint64;
case FFIType::kFFITypeS1:
return &ffi_type_sint8;
case FFIType::kFFITypeS2:
return &ffi_type_sint16;
case FFIType::kFFITypeS4:
return &ffi_type_sint32;
case FFIType::kFFITypeS8:
return &ffi_type_sint64;
case FFIType::kFFITypePointer:
return &ffi_type_pointer;
case FFIType::kFFITypeFloat:
return &ffi_type_float;
case FFIType::kFFITypeDouble:
return &ffi_type_double;
}
}
FFICallInterface *FFICallInterface::FinalizeCif() {
cif_ = new ffi_cif;
types_ = new ffi_type *[parameters_.size()];
int idx = 0;
for (FFIType type : parameters_) {
types_[idx] = FFIGetCType(type);
idx++;
}
ffi_prep_cif(cif_, FFI_DEFAULT_ABI,
(unsigned int) parameters_.size(), FFIGetCType(return_type_), types_);
return this;
}
This diff is collapsed.
#if defined(__aarch64__) || defined(__arm64__)
#include <fficonfig_arm64.h>
#endif
#ifdef __i386__
#include <fficonfig_i386.h>
#endif
#ifdef __arm__
#include <fficonfig_armv7.h>
#endif
#ifdef __x86_64__
#include <fficonfig_x86_64.h>
#endif
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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