libdefault_proxy/jni/default.c

55 lines
1.3 KiB
C

#include <jni.h>
#include <string.h>
#include <stdlib.h>
#include <dlfcn.h>
#include <errno.h>
#include "sysinfo.h"
#include "nopsmdrm.h"
#include "freepsm.h"
#define PSM_LIB_PATHS "/data/data/com.playstation.psstore/lib/"
jint (*JNI_OnLoad_real)(JavaVM* vm, void* reserved) = NULL;
JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
LOGFUNCTION();
//sleep(15); gives you time to attach a debugger, (dont do this in production lol)
// clear any previous errno
errno = 0;
void* handle = dlopen(PSM_LIB_PATHS "libdefault_real.so", RTLD_LAZY);
LOG("dlopen libdefault_real.so @ %p errno = %x", handle, errno);
if(handle == NULL) {
LOG("FAILED; %s", dlerror());
handle = dlopen("libdefault_real.so", RTLD_LAZY);
LOG("fail... trying just the raw name libdefault_real.so @ %p errno = %x", handle, errno);
if(handle == NULL) LOG("FAILED; %s", dlerror());
}
JNI_OnLoad_real = dlsym(handle, "JNI_OnLoad");
if(JNI_OnLoad_real == NULL) {
LOG("Cannot run PSM, JNI_OnLoad_real was nullptr");
return 0;
}
// patch psm first
LOG("Install Patches");
set_lib_default_handle(handle);
patch_nopsmdrm();
patch_iap();
// NOW run JNI_OnLoad ...
LOG("RUN JNI_OnLoad_real @ %p", JNI_OnLoad_real);
jint res = JNI_OnLoad_real(vm, reserved);
return res;
}