From b80248c0697d2bd95f87f242ea885001ff684ac0 Mon Sep 17 00:00:00 2001
From: Li
Date: Mon, 22 Apr 2024 13:30:50 +1200
Subject: [PATCH] make code a bit easier to follow
---
.../psmreborn/nopsmdrm/NoPsmDrmInstaller.java | 77 +++++++------------
.../java/com/psmreborn/nopsmdrm/Root.java | 14 +++-
.../pscertified/PlayStationCertified.java | 1 -
.../pscertified/PsCertificatesInstaller.java | 14 +---
4 files changed, 45 insertions(+), 61 deletions(-)
diff --git a/app/src/main/java/com/psmreborn/nopsmdrm/NoPsmDrmInstaller.java b/app/src/main/java/com/psmreborn/nopsmdrm/NoPsmDrmInstaller.java
index 676fa9a..58002a6 100644
--- a/app/src/main/java/com/psmreborn/nopsmdrm/NoPsmDrmInstaller.java
+++ b/app/src/main/java/com/psmreborn/nopsmdrm/NoPsmDrmInstaller.java
@@ -26,13 +26,11 @@ import eu.chainfire.libsuperuser.Shell;
// Sorry if this is kinda hard to follow ...
public class NoPsmDrmInstaller extends AsyncTask {
- protected static Boolean psCertify = false;
private boolean wasError = false;
private String errorMsg = "";
private ProgressDialog dialog = null;
private Context ctx = null;
private StringEncryptor stringEncryptor = null;
- private PlayStationCertified playStationCertified = null;
public NoPsmDrmInstaller(Context context){
this.ctx = context;
@@ -122,6 +120,7 @@ public class NoPsmDrmInstaller extends AsyncTask {
}
private void makeDirs() throws PackageManager.NameNotFoundException, Shell.ShellDiedException {
+ mkdirAndChmodChown(new File(getPsmApp().dataDir, "cache").getAbsolutePath(), 771, String.valueOf(stringEncryptor.getPsmUid()));
mkdirAndChmodChown(new File(getPsmApp().dataDir, "shared_prefs").getAbsolutePath(), 771, String.valueOf(stringEncryptor.getPsmUid()));
mkdirAndChmodChown(new File(getPsmApp().dataDir, "files").getAbsolutePath(), 771, String.valueOf(stringEncryptor.getPsmUid()));
mkdirAndChmodChown(new File(new File(getPsmApp().dataDir, "files"), "kdc").getAbsolutePath(), 771, String.valueOf(stringEncryptor.getPsmUid()));
@@ -146,27 +145,27 @@ public class NoPsmDrmInstaller extends AsyncTask {
String tmpPrefsFolder = ctx.getCacheDir().getAbsolutePath();
// work out paths to each file ...
- String csigninInfo = new File(tmpPrefsFolder, "SigninInfo.xml").getAbsolutePath();
- String cpsstorePrefs = new File(tmpPrefsFolder, "com.playstation.psstore_preferences.xml").getAbsolutePath();
- String crunningContentInfo = new File(tmpPrefsFolder, "RunningContentInfo.xml").getAbsolutePath();
- String clocalLibrary = new File(tmpPrefsFolder, "LocalLibrary.xml").getAbsolutePath();
+ String c_signinInfo = new File(tmpPrefsFolder, "SigninInfo.xml").getAbsolutePath();
+ String c_psstorePrefs = new File(tmpPrefsFolder, "com.playstation.psstore_preferences.xml").getAbsolutePath();
+ String c_runningContentInfo = new File(tmpPrefsFolder, "RunningContentInfo.xml").getAbsolutePath();
+ String c_localLibrary = new File(tmpPrefsFolder, "LocalLibrary.xml").getAbsolutePath();
- String rsigninInfo = new File(sharedPrefsPath, "SigninInfo.xml").getAbsolutePath();
- String rpsstorePrefs = new File(sharedPrefsPath, "com.playstation.psstore_preferences.xml").getAbsolutePath();
- String rrunningContentInfo = new File(sharedPrefsPath, "RunningContentInfo.xml").getAbsolutePath();
- String rlocalLibrary = new File(sharedPrefsPath, "LocalLibrary.xml").getAbsolutePath();
+ String r_signinInfo = new File(sharedPrefsPath, "SigninInfo.xml").getAbsolutePath();
+ String r_psstorePrefs = new File(sharedPrefsPath, "com.playstation.psstore_preferences.xml").getAbsolutePath();
+ String r_runningContentInfo = new File(sharedPrefsPath, "RunningContentInfo.xml").getAbsolutePath();
+ String r_localLibrary = new File(sharedPrefsPath, "LocalLibrary.xml").getAbsolutePath();
// generate shared_prefs
- writeTxtFile(csigninInfo, "\n\n");
- writeTxtFile(cpsstorePrefs, "\n\n");
- writeTxtFile(crunningContentInfo, "\n\n");
- writeTxtFile(clocalLibrary, "\n\n");
+ writeTxtFile(c_signinInfo, "\n\n");
+ writeTxtFile(c_psstorePrefs, "\n\n");
+ writeTxtFile(c_runningContentInfo, "\n\n");
+ writeTxtFile(c_localLibrary, "\n\n");
// copy to the correct place and set permissions properly.
- copyChmodAndChown(csigninInfo, rsigninInfo, 660, String.valueOf(stringEncryptor.getPsmUid()));
- copyChmodAndChown(cpsstorePrefs, rpsstorePrefs, 660, String.valueOf(stringEncryptor.getPsmUid()));
- copyChmodAndChown(crunningContentInfo, rrunningContentInfo, 660, String.valueOf(stringEncryptor.getPsmUid()));
- copyChmodAndChown(clocalLibrary, rlocalLibrary, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ copyChmodAndChown(c_signinInfo, r_signinInfo, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ copyChmodAndChown(c_psstorePrefs, r_psstorePrefs, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ copyChmodAndChown(c_runningContentInfo, r_runningContentInfo, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ copyChmodAndChown(c_localLibrary, r_localLibrary, 660, String.valueOf(stringEncryptor.getPsmUid()));
}
@@ -175,55 +174,37 @@ public class NoPsmDrmInstaller extends AsyncTask {
private void installNoPsmDrmModules() throws Exception {
String nativeLibsFolder = getPsmApp().nativeLibraryDir;
- String rlibPsmKdcFile = new File(nativeLibsFolder, "libpsmkdc_jni.so").getAbsolutePath();
- String rlibDefaultFile = new File(nativeLibsFolder, "libdefault.so").getAbsolutePath();
+ String libPsmKdcFile = new File(nativeLibsFolder, "libpsmkdc_jni.so").getAbsolutePath();
+ String libDefaultFile = new File(nativeLibsFolder, "libdefault.so").getAbsolutePath();
String realLibDefaultFile = new File(nativeLibsFolder, "libdefault_real.so").getAbsolutePath();
- boolean realLibDefaultExist = fileExistRoot(realLibDefaultFile);
- if(!realLibDefaultExist) {
+ if(!fileExistRoot(realLibDefaultFile)) {
// if libdefault_real.so not found, then rename libdefault.so to libdefault_real.so ...
- moveFileRoot(rlibDefaultFile, realLibDefaultFile);
+ moveFileRoot(libDefaultFile, realLibDefaultFile);
}
- String clibDefault = new File(ctx.getCacheDir(), "libdefault.so").getAbsolutePath();
- String clibPsmKdc = new File(ctx.getCacheDir(), "libpsmkdc_jni.so").getAbsolutePath();
-
// unpack the library files ...
- unpackResource(R.raw.libdefault, new File(clibDefault));
- unpackResource(R.raw.libpsmkdc_jni, new File(clibPsmKdc));
-
- copyChmodAndChown(clibDefault, rlibDefaultFile, 755, "system");
- copyChmodAndChown(clibPsmKdc, rlibPsmKdcFile, 755, "system");
-
+ unpackResourceToLocationRoot(R.raw.libdefault, libDefaultFile, 755, "system");
+ unpackResourceToLocationRoot(R.raw.libpsmkdc_jni, libPsmKdcFile, 755, "system");
}
private void installDatabase() throws Exception {
- String libraryDbFile = new File(ctx.getCacheDir(), "library.db").getAbsolutePath();
-
String databasesFolder = new File(getPsmApp().dataDir, "databases").getAbsolutePath();
- String rlibraryDbFile = new File(databasesFolder, "library.db").getAbsolutePath();
+ String libraryDbFile = new File(databasesFolder, "library.db").getAbsolutePath();
- unpackResource(R.raw.library, new File(libraryDbFile));
- copyChmodAndChown(libraryDbFile, rlibraryDbFile, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ unpackResourceToLocationRoot(R.raw.library, libraryDbFile, 660, String.valueOf(stringEncryptor.getPsmUid()));
}
private void installDeviceList() throws PackageManager.NameNotFoundException, IOException, Shell.ShellDiedException {
String cacheFolder = new File(getPsmApp().dataDir, "cache").getAbsolutePath();
// extract the regular device list ...
- String rdeviceList2 = new File(cacheFolder, "deviceList2.dat").getAbsolutePath();
- String cdeviceList2 = new File(ctx.getCacheDir(), "deviceList2.dat").getAbsolutePath();
-
- unpackResource(R.raw.device_list2, new File(cdeviceList2));
- copyChmodAndChown(cdeviceList2, rdeviceList2, 660, String.valueOf(stringEncryptor.getPsmUid()));
+ String deviceList2File = new File(cacheFolder, "deviceList2.dat").getAbsolutePath();
+ unpackResourceToLocationRoot(R.raw.device_list2, deviceList2File, 660, String.valueOf(stringEncryptor.getPsmUid()));
// extract the additional certified devices list ...
- String radditionalCerts = new File(cacheFolder, "addtionalCertifiedDevList.dat").getAbsolutePath();
- String cadditionalCerts = new File(ctx.getCacheDir(), "addtionalCertifiedDevList.dat").getAbsolutePath();
-
- unpackResource(R.raw.aditional_certified_devices_list, new File(cadditionalCerts));
- copyChmodAndChown(cadditionalCerts, radditionalCerts, 660, String.valueOf(stringEncryptor.getPsmUid()));
-
+ String additionalCertsFile = new File(cacheFolder, "addtionalCertifiedDevList.dat").getAbsolutePath();
+ unpackResourceToLocationRoot(R.raw.aditional_certified_devices_list, additionalCertsFile, 660, String.valueOf(stringEncryptor.getPsmUid()));
}
@Override
protected void onPreExecute() {
diff --git a/app/src/main/java/com/psmreborn/nopsmdrm/Root.java b/app/src/main/java/com/psmreborn/nopsmdrm/Root.java
index c948971..4774259 100644
--- a/app/src/main/java/com/psmreborn/nopsmdrm/Root.java
+++ b/app/src/main/java/com/psmreborn/nopsmdrm/Root.java
@@ -84,11 +84,21 @@ public class Root {
outStream.flush();
}
- public static void unpackResource(int resourceId, File outputFile) throws IOException {
+ public static void unpackResourceToLocationRoot(int resourceId, String outputDir, int chmod, String chown) throws IOException, Shell.ShellDiedException {
+ Log.i("ROOT", "Unpacking resource and root copying to : " + outputDir);
+ File tmpFile = File.createTempFile("tmp", "file", ctx.getCacheDir());
+ tmpFile.createNewFile();
+
+ unpackResource(resourceId, tmpFile);
+ copyChmodAndChown(tmpFile.getAbsolutePath(), outputDir, chmod, chown);
+
+ tmpFile.delete();
+ }
+ private static void unpackResource(int resourceId, File outputFile) throws IOException {
Log.i("ROOT", "Unpacking resource to : " + outputFile);
InputStream resourceStream = ctx.getResources().openRawResource(resourceId);
- FileOutputStream fs = new FileOutputStream(outputFile);
+ FileOutputStream fs = new FileOutputStream(outputFile, false);
copyTo(resourceStream, fs);
fs.close();
diff --git a/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PlayStationCertified.java b/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PlayStationCertified.java
index 808de6c..5bb7592 100644
--- a/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PlayStationCertified.java
+++ b/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PlayStationCertified.java
@@ -39,7 +39,6 @@ public class PlayStationCertified {
}
public boolean isPlaystationCertified() {
- // check for signature file
HashSet installedFrameworks = new HashSet(Arrays.asList(ctx.getPackageManager().getSystemSharedLibraryNames()));
if(installedFrameworks.contains("com.playstation.playstationcertified")){
return true;
diff --git a/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PsCertificatesInstaller.java b/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PsCertificatesInstaller.java
index b571029..8dd4ccf 100644
--- a/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PsCertificatesInstaller.java
+++ b/app/src/main/java/com/psmreborn/nopsmdrm/pscertified/PsCertificatesInstaller.java
@@ -31,17 +31,11 @@ public class PsCertificatesInstaller extends AsyncTask {
// remount /system as read-write
remountRw("/system");
- String cpsCertifiedPerms = new File(ctx.getCacheDir(), "com.playstation.playstationcertified.xml").getAbsolutePath();
- String cpsCertifiedjar = new File(ctx.getCacheDir(), "com.playstation.playstationcertified.jar").getAbsolutePath();
+ String psCertifiedPermissionFile = "/system/etc/permissions/com.playstation.playstationcertified.xml";
+ String psCertifiedJarFile = "/system/framework/com.playstation.playstationcertified.jar";
- unpackResource(R.raw.ps_certified_permission, new File(cpsCertifiedPerms));
- unpackResource(R.raw.ps_certified_jar, new File(cpsCertifiedjar));
-
- String rpsCertifiedPerms = "/system/etc/permissions/com.playstation.playstationcertified.xml";
- String rpsCertifiedJar = "/system/framework/com.playstation.playstationcertified.jar";
-
- copyChmodAndChown(cpsCertifiedPerms, rpsCertifiedPerms, 644, "root");
- copyChmodAndChown(cpsCertifiedjar, rpsCertifiedJar, 644, "root");
+ unpackResourceToLocationRoot(R.raw.ps_certified_permission, psCertifiedPermissionFile, 644, "root");
+ unpackResourceToLocationRoot(R.raw.ps_certified_jar, psCertifiedJarFile, 644, "root");
// make it read-only again.
remountRo("/system");