From b48a82c7e191c6152c4b55343c8f0023ab9010e0 Mon Sep 17 00:00:00 2001
From: Li
Date: Tue, 23 Apr 2024 17:32:04 +1200
Subject: [PATCH] Make it work with VITA licenses
---
jni/default.c | 13 ++++++++++++-
jni/nopsmdrm.c | 20 +++++++++++++++++---
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/jni/default.c b/jni/default.c
index 2d8e840..927a21f 100644
--- a/jni/default.c
+++ b/jni/default.c
@@ -1,5 +1,6 @@
#include
#include
+#include
#include
#include "nopsmdrm.h"
@@ -10,10 +11,20 @@ JNIEXPORT jint JNI_OnLoad(JavaVM* vm, void* reserved) {
LOGFUNCTION();
void* handle = dlopen("/data/data/com.playstation.psstore/lib/libdefault_real.so", RTLD_LAZY);
- LOG("dlopen libdefault_real.so @ %p", handle);
+ LOG("dlopen libdefault_real.so @ %p errno = %x", handle, errno);
+
+ if(handle == NULL) {
+ handle = dlopen("libdefault_real.so", RTLD_LAZY);
+ LOG("fail... trying just the raw name libdefault_real.so @ %p errno = %x", handle, errno);
+ }
JNI_OnLoad_real = dlsym(handle, "JNI_OnLoad");
+ if(JNI_OnLoad_real == NULL) {
+ LOG("Cannot run PSM, JNI_OnLoad_real was nullptr");
+ return 0;
+ }
+
LOG("RUN JNI_OnLoad_real @ %p", JNI_OnLoad_real);
jint res = JNI_OnLoad_real(vm, reserved);
LOG("Install Pathces");
diff --git a/jni/nopsmdrm.c b/jni/nopsmdrm.c
index 2c5fc13..6973107 100644
--- a/jni/nopsmdrm.c
+++ b/jni/nopsmdrm.c
@@ -11,6 +11,7 @@ static void* LIB_DEFAULT_HANDLE = NULL;
int (*scePsmDrmGetKeySet_orig)(ScePsmDrmLicense*, char*, int*, uint64_t*, uint64_t*) = NULL;
void* (*scePsmDrmGetRif_orig)(char*, char*, ScePsmDrmLicense *) = NULL;
+uintptr_t verify_rif_top_part_orig = NULL;
void* get_func_addr(char* function_name) {
@@ -62,7 +63,7 @@ void GetAllLicenses(char* psm_folder) {
struct dirent* ent = NULL;
while((ent = readdir(dfd)) != NULL) {
- snprintf(contentId, sizeof(contentId) - 1, "UM0105-%s-0000000000000000", ent->d_name);
+ snprintf(contentId, sizeof(contentId) - 1, "UM0105-%s_00-0000000000000000", ent->d_name);
LOG("obtaining rif for: %s", contentId);
int res = scePsmDrmGetRif_orig(contentId, psm_folder, &license);
@@ -145,22 +146,35 @@ int scePsmDrmGetRif_patch(char *contentid, char *psm_folder, ScePsmDrmLicense *r
return res;
}
+int verify_rif_top_part_patch() {
+ return 0;
+}
+
int patch_libdefault(void* handle) {
LIB_DEFAULT_HANDLE = handle;
- LOG("Hooking scePsmDrmGetRif");
uintptr_t* scePsmDrmGetRif = get_func_addr("scePsmDrmGetRif");
+ LOG("Hooking scePsmDrmGetRif %p", scePsmDrmGetRif);
+
int res = registerInlineHook((uintptr_t)scePsmDrmGetRif, (uintptr_t)scePsmDrmGetRif_patch, (uintptr_t**)&scePsmDrmGetRif_orig);
if(res == 0)
inlineHook((uintptr_t)scePsmDrmGetRif);
- LOG("Hooking scePsmDrmGetKeySet");
uintptr_t* scePsmDrmGetKeySet = get_func_addr("scePsmDrmGetKeySet");
+ LOG("Hooking scePsmDrmGetKeySet %p", scePsmDrmGetKeySet);
+
res = registerInlineHook((uintptr_t)scePsmDrmGetKeySet, (uintptr_t)scePsmDrmGetKeySet_patch, (uintptr_t**)&scePsmDrmGetKeySet_orig);
if(res == 0)
inlineHook((uintptr_t)scePsmDrmGetKeySet);
+ uintptr_t verify_rif_top_part = get_func_addr("scePsmInitialize") + 0x302EE0;
+ LOG("Hooking verify_rif_top_part %p", verify_rif_top_part);
+
+ res = registerInlineHook((uintptr_t)verify_rif_top_part, (uintptr_t)verify_rif_top_part_patch, (uintptr_t**)&verify_rif_top_part_orig);
+ if(res == 0)
+ inlineHook((uintptr_t)verify_rif_top_part);
+
return 0;
}