Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dvm环境兼容 #39

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake
/node_modules
package.json
package-lock.json
20 changes: 15 additions & 5 deletions whale/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,27 @@ set(WHALE_DARWIN_SOURCES
src/dbi/darwin/macho_import_hook.cc
)

set(WHALE_ANDROID_COMMON
src/android/native_on_load.cc
src/android/java_types.cc
src/android/well_known_classes.cc
src/android/scoped_thread_state_change.cc
)

set(WHALE_ANDROID_ART
src/android/art/native_on_load.cc
src/android/art/art_runtime.cc
src/android/art/art_symbol_resolver.cc
src/android/art/java_types.cc
src/android/art/well_known_classes.cc
src/android/art/art_method.cc
src/android/art/scoped_thread_state_change.cc
src/android/art/art_jni_trampoline.cc
)

set(WHALE_ANDROID_DVM
src/android/dvm/dvm_runtime.cc
src/android/dvm/dvm_symbol_resolver.cc
src/android/dvm/dvm_method.cc
src/android/dvm/dvm_jni_trampoline.cc
)

set(WHALE_AARCH32
src/dbi/arm/decoder_arm.cc
src/dbi/arm/decoder_thumb.cc
Expand Down Expand Up @@ -151,7 +161,7 @@ endif ()

if (PLATFORM STREQUAL "Android")

set(WHALE_SOURCES ${WHALE_SOURCES} ${WHALE_ANDROID_ART})
set(WHALE_SOURCES ${WHALE_SOURCES} ${WHALE_ANDROID_ART} ${WHALE_ANDROID_DVM} ${WHALE_ANDROID_COMMON})

if (CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")

Expand Down
22 changes: 21 additions & 1 deletion whale/src/android/android_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <cstdint>
#include <cstdlib>
#include <sys/system_properties.h>
#include <jni.h>
#include "base/logging.h"


#define ANDROID_ICE_CREAM_SANDWICH 14
#define ANDROID_ICE_CREAM_SANDWICH_MR1 15
Expand All @@ -21,10 +24,27 @@
#define ANDROID_O_MR1 27
#define ANDROID_P 28



extern bool g_isArt;

static inline int32_t GetAndroidApiLevel() {
char prop_value[PROP_VALUE_MAX];
char prop_value[PROP_VALUE_MAX] = {0x0};
__system_property_get("ro.build.version.sdk", prop_value);
return atoi(prop_value);
}

static inline bool isArt(JNIEnv *env) {
jclass System = env->FindClass("java/lang/System");
jmethodID System_getProperty = env->GetStaticMethodID(System, "getProperty", "(Ljava/lang/String;)Ljava/lang/String;");

jstring vm_version_name = env->NewStringUTF("java.vm.version");
jstring vm_version_value = (jstring)(env->CallStaticObjectMethod(System, System_getProperty, vm_version_name));

char *cvm_version_value = (char *)env->GetStringUTFChars(vm_version_value, NULL);
LOG(ERROR)<<"[ArtRuntime::OnLoad] cvm_version_value=" << cvm_version_value;
double version = atof(cvm_version_value);
g_isArt = version >= 2 ? true : false;
return g_isArt;
}
#endif // WHALE_ANDROID_ANDROID_BUILD_H_
4 changes: 2 additions & 2 deletions whale/src/android/art/art_jni_trampoline.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include <cstdarg>
#include <jni.h>
#include "android/art/art_jni_trampoline.h"
#include "android/art/java_types.h"
#include "android/art/well_known_classes.h"
#include "android/java_types.h"
#include "android/well_known_classes.h"
#include "android/art/art_runtime.h"
#include "platform/memory.h"
#include "base/macros.h"
Expand Down
2 changes: 1 addition & 1 deletion whale/src/android/art/art_method.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "android/art/art_method.h"
#include "well_known_classes.h"
#include "android/well_known_classes.h"

namespace whale {
namespace art {
Expand Down
4 changes: 2 additions & 2 deletions whale/src/android/art/art_method.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <jni.h>
#include <android/android_build.h>
#include "android/art/art_runtime.h"
#include "android/art/modifiers.h"
#include "android/modifiers.h"
#include "base/cxx_helper.h"
#include "base/primitive_types.h"

Expand Down Expand Up @@ -135,7 +135,7 @@ class ArtMethod final {
jmethodID jni_method_;
// Convenient for quick invocation
ArtMethodOffsets *offset_;
ResolvedSymbols *symbols_;
ArtResolvedSymbols *symbols_;
};


Expand Down
18 changes: 10 additions & 8 deletions whale/src/android/art/art_runtime.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#include "whale.h"
#include "android/android_build.h"
#include "android/art/art_runtime.h"
#include "android/art/modifiers.h"
#include "android/art/native_on_load.h"
#include "android/modifiers.h"
#include "android/native_on_load.h"
#include "android/art/art_method.h"
#include "android/art/art_symbol_resolver.h"
#include "android/art/scoped_thread_state_change.h"
#include "android/scoped_thread_state_change.h"
#include "android/art/art_jni_trampoline.h"
#include "android/art/well_known_classes.h"
#include "android/art/java_types.h"
#include "android/well_known_classes.h"
#include "android/java_types.h"
#include "platform/memory.h"
#include "base/logging.h"
#include "base/singleton.h"
Expand All @@ -36,6 +36,7 @@ bool ArtRuntime::OnLoad(JavaVM *vm, JNIEnv *env, jclass java_class) {
LOG(ERROR) << "Failed to find " #field "."; \
return false; \
}
LOG(ERROR)<<"[ArtRuntime::OnLoad] start call ArtRuntime::OnLoad";
if ((kRuntimeISA == InstructionSet::kArm
|| kRuntimeISA == InstructionSet::kArm64)
&& IsFileInMemory("libhoudini.so")) {
Expand All @@ -60,6 +61,7 @@ bool ArtRuntime::OnLoad(JavaVM *vm, JNIEnv *env, jclass java_class) {
LOG(ERROR) << "Unable to read data from libart.so.";
return false;
}
LOG(ERROR)<<"[ArtRuntime::OnLoad] start call art_symbol_resolver_.Resolve";
if (!art_symbol_resolver_.Resolve(art_elf_image_, api_level_)) {
// The log will all output from ArtSymbolResolver.
return false;
Expand Down Expand Up @@ -210,7 +212,7 @@ ArtRuntime::HookMethod(JNIEnv *env, jclass decl_class, jobject hooked_java_metho
param->origin_access_flags = hooked_method.GetAccessFlags();
jobject origin_java_method = hooked_method.Clone(env, param->origin_access_flags);

ResolvedSymbols *symbols = GetSymbols();
ArtResolvedSymbols *symbols = GetSymbols();
if (symbols->ProfileSaver_ForceProcessProfiles) {
symbols->ProfileSaver_ForceProcessProfiles();
}
Expand Down Expand Up @@ -374,7 +376,7 @@ void ArtRuntime::SetObjectClassUnsafe(JNIEnv *env, jobject obj, jclass cl) {
}

jobject ArtRuntime::CloneToSubclass(JNIEnv *env, jobject obj, jclass sub_class) {
ResolvedSymbols *symbols = GetSymbols();
ArtResolvedSymbols *symbols = GetSymbols();
ArtThread *thread = GetCurrentArtThread();
ptr_t art_object = symbols->Thread_DecodeJObject(thread, obj);
ptr_t art_clone_object = CloneArtObject(art_object);
Expand Down Expand Up @@ -461,7 +463,7 @@ ALWAYS_INLINE bool ArtRuntime::EnforceDisableHiddenAPIPolicyImpl() {
}

ptr_t ArtRuntime::CloneArtObject(ptr_t art_object) {
ResolvedSymbols *symbols = GetSymbols();
ArtResolvedSymbols *symbols = GetSymbols();
if (symbols->Object_Clone) {
return symbols->Object_Clone(art_object, GetCurrentArtThread());
}
Expand Down
18 changes: 3 additions & 15 deletions whale/src/android/art/art_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,6 @@
#include "base/macros.h"
#include "base/primitive_types.h"

#if defined(__LP64__)
static constexpr const char *kAndroidLibDir = "/system/lib64/";
static constexpr const char *kLibNativeBridgePath = "/system/lib64/libnativebridge.so";
static constexpr const char *kLibArtPath = "/system/lib64/libart.so";
static constexpr const char *kLibAocPath = "/system/lib64/libaoc.so";
static constexpr const char *kLibHoudiniArtPath = "/system/lib64/arm64/libart.so";
#else
static constexpr const char *kAndroidLibDir = "/system/lib/";
static constexpr const char *kLibArtPath = "/system/lib/libart.so";
static constexpr const char *kLibAocPath = "/system/lib/libaoc.so";
static constexpr const char *kLibHoudiniArtPath = "/system/lib/arm/libart.so";
#endif


namespace whale {
namespace art {

Expand Down Expand Up @@ -60,6 +46,8 @@ class ArtRuntime final {
public:
friend class ArtMethod;

bool isArt = false;

static ArtRuntime *Get();

ArtRuntime() {}
Expand Down Expand Up @@ -89,7 +77,7 @@ class ArtRuntime final {
return &class_linker_objects_;
}

ResolvedSymbols *GetSymbols() {
ArtResolvedSymbols *GetSymbols() {
return art_symbol_resolver_.GetSymbols();
}

Expand Down
6 changes: 3 additions & 3 deletions whale/src/android/art/art_symbol_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace whale {
namespace art {

struct ResolvedSymbols {
struct ArtResolvedSymbols {
const char *(*Art_GetMethodShorty)(JNIEnv *, jmethodID);

void (*Dbg_SuspendVM)();
Expand Down Expand Up @@ -40,12 +40,12 @@ class ArtSymbolResolver {

bool Resolve(void *elf_image, s4 api_level);

ResolvedSymbols *GetSymbols() {
ArtResolvedSymbols *GetSymbols() {
return &symbols_;
};

private:
ResolvedSymbols symbols_;
ArtResolvedSymbols symbols_;
};

} // namespace art
Expand Down
28 changes: 28 additions & 0 deletions whale/src/android/dvm/dvm_hook_param.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef WHALE_ANDROID_DVM_INTERCEPT_PARAM_H_
#define WHALE_ANDROID_DVM_INTERCEPT_PARAM_H_

#include <jni.h>
#include "base/primitive_types.h"
#include "ffi_cxx.h"

namespace whale {
namespace dvm {

struct DvmHookParam final {
bool is_static_; //标志位,标志函数是否为静态函数
const char *shorty_; //函数描述符缩写
jobject addition_info_;
u4 origin_access_flags;
jobject origin_method_;
jobject hooked_method_;
volatile ptr_t decl_class_;
jobject class_Loader_; //
jmethodID hooked_native_method_;
jmethodID origin_native_method_;
FFIClosure *jni_closure_;
};

} // namespace dvm
} // namespace whale

#endif // WHALE_ANDROID_DVM_INTERCEPT_PARAM_H_
Loading