Start working on titlekeys support

This commit is contained in:
Dmitry Isaenko 2019-05-21 05:34:27 +03:00
parent f925b9c8e1
commit a5004a9a31
8 changed files with 259 additions and 200 deletions

View file

@ -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); }
}

View file

@ -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);

View file

@ -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<String, String > fileMap = new HashMap<>();

View file

@ -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();

View file

@ -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];

View file

@ -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

View file

@ -12,7 +12,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<GridPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Controllers.NCA.NCASectionHeaderBlockController">
<GridPane xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Controllers.NCA.NCASectionHeaderBlockController">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="60.0" minWidth="55.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="75.0" minWidth="60.0" />
@ -228,7 +228,7 @@
</AnchorPane>
<AnchorPane styleClass="customGrid" GridPane.columnIndex="2" GridPane.rowIndex="4">
<children>
<Label text="Crypto type. 0 and &gt;4 are invalid. 1 = none(plaintext from raw NCA). 2 = other crypto. 3 = regular crypto. 4 = unknown." AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<Label text="Crypto type. 0 and &gt;4 are invalid, 1 = None, 2 = AesCtrOld, 3 = AesCtr, 4 = AesCtrEx" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<padding>
<Insets left="5.0" right="5.0" />
</padding>

View file

@ -6,207 +6,250 @@
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.control.Separator?>
<?import javafx.scene.control.Tab?>
<?import javafx.scene.control.TabPane?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.shape.SVGPath?>
<AnchorPane prefHeight="600.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.SettingsController">
<VBox minHeight="600.0" minWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Settings.SettingsController">
<children>
<VBox AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<ScrollPane fitToWidth="true" VBox.vgrow="ALWAYS">
<TabPane side="LEFT" tabClosingPolicy="UNAVAILABLE" tabMaxHeight="100.0" tabMaxWidth="80.0" tabMinHeight="80.0" tabMinWidth="50.0" VBox.vgrow="ALWAYS">
<tabs>
<Tab closable="false">
<content>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0">
<children>
<Label text="Used for XCI" />
<HBox alignment="CENTER_LEFT" spacing="5.0">
<ScrollPane fitToWidth="true">
<content>
<VBox prefHeight="200.0" prefWidth="100.0" spacing="5.0">
<children>
<Label text="xci_header_key" wrapText="true" />
<TextField HBox.hgrow="ALWAYS" fx:id="xciHdrKeyTF" />
<Label text="Used for XCI" />
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="xci_header_key" wrapText="true" />
<TextField HBox.hgrow="ALWAYS" fx:id="xciHdrKeyTF" />
</children>
</HBox>
<Label disable="true" text="Length should be 32 symbols" wrapText="true" />
<Separator prefWidth="200.0" />
<Label text="Used for NCA" />
<Button fx:id="importKeysBtn" contentDisplay="TOP" mnemonicParsing="false" text="Import from prod.keys">
<graphic>
<SVGPath content="M1,12H10.76L8.26,9.5L9.67,8.08L14.59,13L9.67,17.92L8.26,16.5L10.76,14H1V12M19,3C20.11,3 21,3.9 21,5V19A2,2 0 0,1 19,21H5C3.89,21 3,20.1 3,19V16H5V19H19V7H5V10H3V5A2,2 0 0,1 5,3H19Z" />
</graphic>
</Button>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="header_key" wrapText="true" />
<TextField fx:id="hdrKeyTF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<Label disable="true" text="Length should be 64 symbols" wrapText="true" />
<Pane VBox.vgrow="ALWAYS" />
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_00" />
<TextField fx:id="keyApp0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_01" />
<TextField fx:id="keyApp1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_02" />
<TextField fx:id="keyApp2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_03" />
<TextField fx:id="keyApp3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_04" />
<TextField fx:id="keyApp4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_05" />
<TextField fx:id="keyApp5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_06" />
<TextField fx:id="keyApp6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_07" />
<TextField fx:id="keyApp7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_00" />
<TextField fx:id="keyOcean0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_01" />
<TextField fx:id="keyOcean1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_02" />
<TextField fx:id="keyOcean2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_03" />
<TextField fx:id="keyOcean3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_04" />
<TextField fx:id="keyOcean4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_05" />
<TextField fx:id="keyOcean5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_06" />
<TextField fx:id="keyOcean6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_07" />
<TextField fx:id="keyOcean7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_00" />
<TextField fx:id="keySys0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_01" />
<TextField fx:id="keySys1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_02" />
<TextField fx:id="keySys2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_03" />
<TextField fx:id="keySys3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_04" />
<TextField fx:id="keySys4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_05" />
<TextField fx:id="keySys5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_06" />
<TextField fx:id="keySys6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_07" />
<TextField fx:id="keySys7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<Separator prefWidth="200.0" />
</children>
</HBox>
<Label disable="true" text="Length should be 32 symbols" wrapText="true" />
<Separator prefWidth="200.0" />
<Label text="Used for NCA" />
<Button fx:id="importBtn" contentDisplay="TOP" mnemonicParsing="false" text="Import from prod.keys">
<graphic>
<SVGPath content="M1,12H10.76L8.26,9.5L9.67,8.08L14.59,13L9.67,17.92L8.26,16.5L10.76,14H1V12M19,3C20.11,3 21,3.9 21,5V19A2,2 0 0,1 19,21H5C3.89,21 3,20.1 3,19V16H5V19H19V7H5V10H3V5A2,2 0 0,1 5,3H19Z" />
</graphic>
</Button>
<HBox alignment="CENTER_LEFT" spacing="5.0">
<children>
<Label text="header_key" wrapText="true" />
<TextField fx:id="hdrKeyTF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<Label disable="true" text="Length should be 64 symbols" wrapText="true" />
<Pane VBox.vgrow="ALWAYS" />
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_00" />
<TextField fx:id="keyApp0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_01" />
<TextField fx:id="keyApp1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_02" />
<TextField fx:id="keyApp2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_03" />
<TextField fx:id="keyApp3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_04" />
<TextField fx:id="keyApp4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_05" />
<TextField fx:id="keyApp5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_06" />
<TextField fx:id="keyApp6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_application_07" />
<TextField fx:id="keyApp7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_00" />
<TextField fx:id="keyOcean0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_01" />
<TextField fx:id="keyOcean1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_02" />
<TextField fx:id="keyOcean2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_03" />
<TextField fx:id="keyOcean3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_04" />
<TextField fx:id="keyOcean4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_05" />
<TextField fx:id="keyOcean5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_06" />
<TextField fx:id="keyOcean6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_ocean_07" />
<TextField fx:id="keyOcean7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_00" />
<TextField fx:id="keySys0TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_01" />
<TextField fx:id="keySys1TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_02" />
<TextField fx:id="keySys2TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_03" />
<TextField fx:id="keySys3TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_04" />
<TextField fx:id="keySys4TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_05" />
<TextField fx:id="keySys5TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_06" />
<TextField fx:id="keySys6TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<HBox spacing="5.0">
<children>
<Label text="key_area_key_system_07" />
<TextField fx:id="keySys7TF" HBox.hgrow="ALWAYS" />
</children>
</HBox>
<Separator prefWidth="200.0" />
</children>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</VBox>
</content>
</ScrollPane>
</content>
</ScrollPane>
<ButtonBar>
<buttons>
<graphic>
<VBox alignment="TOP_CENTER" spacing="5.0">
<children>
<SVGPath content="M6.5,2C8.46,2 10.13,3.25 10.74,5H22V8H18V11H15V8H10.74C10.13,9.75 8.46,11 6.5,11C4,11 2,9 2,6.5C2,4 4,2 6.5,2M6.5,5A1.5,1.5 0 0,0 5,6.5A1.5,1.5 0 0,0 6.5,8A1.5,1.5 0 0,0 8,6.5A1.5,1.5 0 0,0 6.5,5M6.5,13C8.46,13 10.13,14.25 10.74,16H22V19H20V22H18V19H16V22H13V19H10.74C10.13,20.75 8.46,22 6.5,22C4,22 2,20 2,17.5C2,15 4,13 6.5,13M6.5,16A1.5,1.5 0 0,0 5,17.5A1.5,1.5 0 0,0 6.5,19A1.5,1.5 0 0,0 8,17.5A1.5,1.5 0 0,0 6.5,16Z" />
<Label text="prod.keys" />
</children>
</VBox>
</graphic>
</Tab>
<Tab closable="false">
<content>
<ScrollPane fitToWidth="true">
<content>
<VBox spacing="5.0">
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
<children>
<Label text="Title Keys" />
<Button fx:id="importTitleKeysBtn" contentDisplay="TOP" mnemonicParsing="false" text="Import from title.keys">
<graphic>
<SVGPath content="M1,12H10.76L8.26,9.5L9.67,8.08L14.59,13L9.67,17.92L8.26,16.5L10.76,14H1V12M19,3C20.11,3 21,3.9 21,5V19A2,2 0 0,1 19,21H5C3.89,21 3,20.1 3,19V16H5V19H19V7H5V10H3V5A2,2 0 0,1 5,3H19Z" />
</graphic>
</Button>
<VBox fx:id="titleKeysVbox" spacing="5.0" />
</children>
</VBox>
</content>
</ScrollPane>
</content>
<graphic>
<VBox alignment="TOP_CENTER" spacing="5.0">
<children>
<SVGPath content="M22,18V22H18V19H15V16H12L9.74,13.74C9.19,13.91 8.61,14 8,14A6,6 0 0,1 2,8A6,6 0 0,1 8,2A6,6 0 0,1 14,8C14,8.61 13.91,9.19 13.74,9.74L22,18M7,5A2,2 0 0,0 5,7A2,2 0 0,0 7,9A2,2 0 0,0 9,7A2,2 0 0,0 7,5Z" />
<Label text="title.keys" />
</children>
</VBox>
</graphic>
</Tab>
</tabs>
</TabPane>
<ButtonBar>
<buttons>
<Button fx:id="okBtn" mnemonicParsing="false" text="Ok" />
<Button fx:id="cancelBtn" mnemonicParsing="false" text="Cancel" />
</buttons>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</ButtonBar>
</children>
</VBox>
<Button fx:id="cancelBtn" mnemonicParsing="false" text="Cancel" />
</buttons>
<padding>
<Insets bottom="5.0" left="5.0" right="5.0" top="5.0" />
</padding>
</ButtonBar>
</children>
</AnchorPane>
</VBox>