From a5004a9a316a00e8d61b409b2a6e3ecf3c44b0be Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Tue, 21 May 2019 05:34:27 +0300 Subject: [PATCH] Start working on titlekeys support --- src/main/java/konogonka/AppPreferences.java | 7 + .../Controllers/NCA/NCAController.java | 1 + .../Settings/SettingsController.java | 9 +- .../konogonka/Settings/SettingsWindow.java | 4 +- .../konogonka/Tools/NCA/NCAContentPFS0.java | 7 +- .../java/konogonka/Tools/NCA/NCAProvider.java | 2 + .../FXML/NCA/NCASectionHeaderBlock.fxml | 4 +- .../FXML/Settings/SettingsLayout.fxml | 425 ++++++++++-------- 8 files changed, 259 insertions(+), 200 deletions(-) diff --git a/src/main/java/konogonka/AppPreferences.java b/src/main/java/konogonka/AppPreferences.java index de2bc90..0820480 100644 --- a/src/main/java/konogonka/AppPreferences.java +++ b/src/main/java/konogonka/AppPreferences.java @@ -98,4 +98,11 @@ public class AppPreferences { public String getSystemKey(int number){ return preferences.get("key_area_key_system_0"+number, "");} public void setSystemKey(int number, String key){ preferences.put("key_area_key_system_0"+number, key); } + public int getTitleKeysCount(){ return preferences.getInt("title_keys_count", 0);} + public void setTitleKeysCount(int number){ preferences.putInt("title_keys_count", number);} + + public String[] getTitleKey(int number){ + return preferences.get(Integer.toString(number), "0 = 0").split(" = ", 2); + } + public void setTitleKey(int number, String name, String value){ preferences.put(Integer.toString(number), name+" = "+value); } } diff --git a/src/main/java/konogonka/Controllers/NCA/NCAController.java b/src/main/java/konogonka/Controllers/NCA/NCAController.java index dd875c2..4f20738 100644 --- a/src/main/java/konogonka/Controllers/NCA/NCAController.java +++ b/src/main/java/konogonka/Controllers/NCA/NCAController.java @@ -80,6 +80,7 @@ public class NCAController implements TabController { keysMap.put("key_area_key_application_0"+i, AppPreferences.getInstance().getApplicationKey(i)); keysMap.put("key_area_key_ocean_0"+i, AppPreferences.getInstance().getOceanKey(i)); keysMap.put("key_area_key_system_0"+i, AppPreferences.getInstance().getSystemKey(i)); + // TODO: Add titlekeys } AnalyzerNCA analyzerNCA = new AnalyzerNCA(file, keysMap); diff --git a/src/main/java/konogonka/Settings/SettingsController.java b/src/main/java/konogonka/Settings/SettingsController.java index 1c3a022..85c152b 100644 --- a/src/main/java/konogonka/Settings/SettingsController.java +++ b/src/main/java/konogonka/Settings/SettingsController.java @@ -5,6 +5,7 @@ import javafx.fxml.Initializable; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.control.TextFormatter; +import javafx.scene.layout.VBox; import javafx.stage.FileChooser; import javafx.stage.Stage; import konogonka.AppPreferences; @@ -17,7 +18,9 @@ import java.util.ResourceBundle; public class SettingsController implements Initializable { @FXML - private Button okBtn, cancelBtn, importBtn; + private Button okBtn, cancelBtn, importKeysBtn, importTitleKeysBtn; + @FXML + private VBox titleKeysVbox; @FXML private TextField xciHdrKeyTF, @@ -103,13 +106,13 @@ public class SettingsController implements Initializable { setTextValidation(keySys6TF); setTextValidation(keySys7TF); - importBtn.setOnAction(e->{ + importKeysBtn.setOnAction(e->{ FileChooser fileChooser = new FileChooser(); fileChooser.setTitle("prod.keys"); fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("prod.keys", "prod.keys")); - File prodKeysFile = fileChooser.showOpenDialog(importBtn.getScene().getWindow()); + File prodKeysFile = fileChooser.showOpenDialog(importKeysBtn.getScene().getWindow()); if (prodKeysFile != null && prodKeysFile.exists()) { HashMap fileMap = new HashMap<>(); diff --git a/src/main/java/konogonka/Settings/SettingsWindow.java b/src/main/java/konogonka/Settings/SettingsWindow.java index eea6b76..58646af 100644 --- a/src/main/java/konogonka/Settings/SettingsWindow.java +++ b/src/main/java/konogonka/Settings/SettingsWindow.java @@ -38,7 +38,9 @@ public class SettingsWindow { new Image(MainFx.class.getResourceAsStream("/res/settings_icon128x128.png")) ); - stageSettings.setScene(new Scene(parentAbout, 570, 500)); + Scene settingsScene = new Scene(parentAbout, 800, 800); + settingsScene.getStylesheets().add("/res/app_light.css"); + stageSettings.setScene(settingsScene); stageSettings.setMinWidth(550.0); stageSettings.setMinHeight(550.0); stageSettings.show(); diff --git a/src/main/java/konogonka/Tools/NCA/NCAContentPFS0.java b/src/main/java/konogonka/Tools/NCA/NCAContentPFS0.java index a586e4b..8e38bd6 100644 --- a/src/main/java/konogonka/Tools/NCA/NCAContentPFS0.java +++ b/src/main/java/konogonka/Tools/NCA/NCAContentPFS0.java @@ -136,7 +136,7 @@ public class NCAContentPFS0 { // IV for CTR == 16 bytes IVarray = new byte[0x10]; // Populate first 8 bytes taken from Header's section Block CTR - System.arraycopy(LoperConverter.flip(sectionCTR), 0x0, IVarray,0x0, 0x8); + System.arraycopy(LoperConverter.flip(sectionCTR), 0x0, IVarray, 0x0, 0x8); } public byte[] dectyptNext(byte[] enctyptedBlock) throws Exception{ @@ -207,9 +207,10 @@ public class NCAContentPFS0 { } // Skip padding and go to PFS0 location if (counter < pfs0offset){ - if ((pfs0offset-counter) != pipedInputStream.skip(pfs0offset-counter)) + long toSkip = pfs0offset-counter; + if (toSkip != pipedInputStream.skip(toSkip)) return; // TODO: fix? - counter += pfs0offset-counter; + counter += toSkip; } //--------------------------------------------------------- byte[] magic = new byte[0x4]; diff --git a/src/main/java/konogonka/Tools/NCA/NCAProvider.java b/src/main/java/konogonka/Tools/NCA/NCAProvider.java index 80057d1..3f3f5c9 100644 --- a/src/main/java/konogonka/Tools/NCA/NCAProvider.java +++ b/src/main/java/konogonka/Tools/NCA/NCAProvider.java @@ -253,6 +253,8 @@ public class NCAProvider { * @param sectionNumber should be 1-4 * */ public NCAContentPFS0 getNCAContentPFS0(int sectionNumber){ + // TODO: provide titleKey if needed + switch (sectionNumber){ case 0: return new NCAContentPFS0(file, offset, sectionBlock0, tableEntry0, decryptedKey2); // TODO: remove decryptedKey2 diff --git a/src/main/resources/FXML/NCA/NCASectionHeaderBlock.fxml b/src/main/resources/FXML/NCA/NCASectionHeaderBlock.fxml index 1b9ed07..1b3c882 100644 --- a/src/main/resources/FXML/NCA/NCASectionHeaderBlock.fxml +++ b/src/main/resources/FXML/NCA/NCASectionHeaderBlock.fxml @@ -12,7 +12,7 @@ - + @@ -228,7 +228,7 @@ -