Skip to content

Commit

Permalink
use falsoJNI instead
Browse files Browse the repository at this point in the history
  • Loading branch information
YSaxon committed Jun 14, 2024
1 parent a26a220 commit 414f6a7
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 46 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ parse_address.c
shims.c
exception_handling.c
)
if (ANDROID)
list(APPEND SOURCES FalsoJNI/FalsoJni.c FalsoJNI/FalsoJni_ImplBridge.c FalsoJNI/FalsoJni_Logger.c)
#add header files
include_directories(FalsoJNI)
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down
1 change: 1 addition & 0 deletions FalsoJNI
Submodule FalsoJNI added at 9c0522
101 changes: 55 additions & 46 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -553,54 +553,63 @@ typedef jint(*registerNatives_t)(JNIEnv *env, jclass clazz);

typedef int (*JNI_OnLoadFunc)(void* vm, void* reserved);

int init_jvm(JavaVM **p_vm, JNIEnv **p_env, size_t argc, char** argv) {
JavaVMOption options[argc];
for (size_t i = 0; i < argc; i++) {
options[i].optionString = argv[i];
}

JavaVMInitArgs args;
args.version = JNI_VERSION_1_6;
args.options = options;
args.nOptions = argc;
args.ignoreUnrecognized = JNI_FALSE;

void *libdvm_dso = dlopen("libdvm.so", RTLD_NOW);
void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);

if (!libdvm_dso) {
libdvm_dso = dlopen("libart.so", RTLD_NOW);
}

if (!libdvm_dso || !libandroid_runtime_dso) {
return -1;
}

JNI_CreateJavaVM_t JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
if (!JNI_CreateJavaVM) {
return -2;
}

registerNatives_t registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
if (!registerNatives) {
registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "registerFrameworkNatives");
if (!registerNatives) {
return -3;
}
}

if (JNI_CreateJavaVM(p_vm, p_env, &args)) {
return -4;
}

if (registerNatives(*p_env, 0)) {
return -5;
}

return 0;
// int init_jvm(JavaVM **p_vm, JNIEnv **p_env, size_t argc, char** argv) {
// JavaVMOption options[argc];
// for (size_t i = 0; i < argc; i++) {
// options[i].optionString = argv[i];
// }

// JavaVMInitArgs args;
// args.version = JNI_VERSION_1_6;
// args.options = options;
// args.nOptions = argc;
// args.ignoreUnrecognized = JNI_FALSE;

// void *libdvm_dso = dlopen("libdvm.so", RTLD_NOW);
// void *libandroid_runtime_dso = dlopen("libandroid_runtime.so", RTLD_NOW);

// if (!libdvm_dso) {
// libdvm_dso = dlopen("libart.so", RTLD_NOW);
// }

// if (!libdvm_dso || !libandroid_runtime_dso) {
// return -1;
// }

// JNI_CreateJavaVM_t JNI_CreateJavaVM = (JNI_CreateJavaVM_t) dlsym(libdvm_dso, "JNI_CreateJavaVM");
// if (!JNI_CreateJavaVM) {
// return -2;
// }

// registerNatives_t registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "Java_com_android_internal_util_WithFramework_registerNatives");
// if (!registerNatives) {
// registerNatives = (registerNatives_t) dlsym(libandroid_runtime_dso, "registerFrameworkNatives");
// if (!registerNatives) {
// return -3;
// }
// }

// if (JNI_CreateJavaVM(p_vm, p_env, &args)) {
// return -4;
// }

// if (registerNatives(*p_env, 0)) {
// return -5;
// }

// return 0;
// }

#include "FalsoJNI.h"
int init_jvm(JavaVM **p_vm, JNIEnv **p_env, size_t argc, char** argv){
if (argc > 0) {
printf(" [!] Warning: Arguments are not supported on this faker method\n");
jni_init();
}
*p_vm = jvm;
*p_env = jni;
}


void parseInitJNI(char* initJNICommand) {
int argc;
char** argv;
Expand Down

0 comments on commit 414f6a7

Please sign in to comment.