Bugfix for dumb issue with key_area_key_[all] to support Lockpick dump: hex representation instead of dec %)

master
Dmitry Isaenko 2020-04-08 04:17:45 +03:00
parent 0f49812e5f
commit ce4c5d9870
6 changed files with 104 additions and 108 deletions

View File

@ -77,7 +77,7 @@ public class AppPreferences {
public void setKAKAppCount(int number){
if (this.kakAppCount > number){
for (int i = number; i < this.kakAppCount; i++) {
preferences.remove(String.format("key_area_key_application_%02d", number));
preferences.remove(String.format("key_area_key_application_%02x", number));
}
}
preferences.putInt("key_area_key_application_count", number);
@ -86,7 +86,7 @@ public class AppPreferences {
public void setKAKOceanCount(int number){
if (this.kakOceanCount > number){
for (int i = number; i < this.kakOceanCount; i++) {
preferences.remove(String.format("key_area_key_ocean_%02d", number));
preferences.remove(String.format("key_area_key_ocean_%02x", number));
}
}
preferences.putInt("key_area_key_ocean_count", number);
@ -95,7 +95,7 @@ public class AppPreferences {
public void setKAKSysCount(int number){
if (this.kakSysCount > number){
for (int i = number; i < this.kakSysCount; i++) {
preferences.remove(String.format("key_area_key_system_%02d", number));
preferences.remove(String.format("key_area_key_system_%02x", number));
}
}
preferences.putInt("key_area_key_system_count", number);
@ -105,7 +105,7 @@ public class AppPreferences {
public void setTitleKeksCount(int number){
if (this.titleKeksCount > number){
for (int i = number; i < this.titleKeksCount; i++) {
preferences.remove(String.format("titlekek_%02d", number));
preferences.remove(String.format("titlekek_%02x", number));
}
}
preferences.putInt("titlekek_count", number);
@ -117,17 +117,17 @@ public class AppPreferences {
public int getKAKSysCount(){ return preferences.getInt("key_area_key_system_count", 0); }
public int getTitleKeksCount(){ return preferences.getInt("titlekek_count", 0); }
public String getApplicationKey(int number){ return preferences.get(String.format("key_area_key_application_%02d", number), "");}
public void setApplicationKey(int number, String key){ preferences.put(String.format("key_area_key_application_%02d", number), key); }
public String getApplicationKey(int number){ return preferences.get(String.format("key_area_key_application_%02x", number), "");}
public void setApplicationKey(int number, String key){ preferences.put(String.format("key_area_key_application_%02x", number), key); }
public String getOceanKey(int number){ return preferences.get(String.format("key_area_key_ocean_%02d", number), "");}
public void setOceanKey(int number, String key){ preferences.put(String.format("key_area_key_ocean_%02d", number), key); }
public String getOceanKey(int number){ return preferences.get(String.format("key_area_key_ocean_%02x", number), "");}
public void setOceanKey(int number, String key){ preferences.put(String.format("key_area_key_ocean_%02x", number), key); }
public String getSystemKey(int number){ return preferences.get(String.format("key_area_key_system_%02d", number), "");}
public void setSystemKey(int number, String key){ preferences.put(String.format("key_area_key_system_%02d", number), key); }
public String getSystemKey(int number){ return preferences.get(String.format("key_area_key_system_%02x", number), "");}
public void setSystemKey(int number, String key){ preferences.put(String.format("key_area_key_system_%02x", number), key); }
public String getTitleKek(int number){ return preferences.get(String.format("titlekek_%02d", number), "");}
public void setTitleKek(int number, String key){ preferences.put(String.format("titlekek_%02d", number), key); }
public String getTitleKek(int number){ return preferences.get(String.format("titlekek_%02x", number), "");}
public void setTitleKek(int number, String key){ preferences.put(String.format("titlekek_%02x", number), key); }
// Title keys

View File

@ -101,13 +101,13 @@ public class NCAController implements ITabController {
keysMap.put("header_key", AppPreferences.getInstance().getHeaderKey());
for (int i = 0; i < AppPreferences.getInstance().getKAKAppCount(); i++)
keysMap.put(String.format("key_area_key_application_%02d", i), AppPreferences.getInstance().getApplicationKey(i));
keysMap.put(String.format("key_area_key_application_%02x", i), AppPreferences.getInstance().getApplicationKey(i));
for (int i = 0; i < AppPreferences.getInstance().getKAKOceanCount(); i++)
keysMap.put(String.format("key_area_key_ocean_%02d", i), AppPreferences.getInstance().getOceanKey(i));
keysMap.put(String.format("key_area_key_ocean_%02x", i), AppPreferences.getInstance().getOceanKey(i));
for (int i = 0; i < AppPreferences.getInstance().getKAKSysCount(); i++)
keysMap.put(String.format("key_area_key_system_%02d", i), AppPreferences.getInstance().getSystemKey(i));
keysMap.put(String.format("key_area_key_system_%02x", i), AppPreferences.getInstance().getSystemKey(i));
for (int i = 0; i < AppPreferences.getInstance().getTitleKeksCount(); i++)
keysMap.put(String.format("titlekek_%02d", i), AppPreferences.getInstance().getTitleKek(i));
keysMap.put(String.format("titlekek_%02x", i), AppPreferences.getInstance().getTitleKek(i));
for (int i = 0; i < AppPreferences.getInstance().getTitleKeysCount(); i++){
String[] pair = AppPreferences.getInstance().getTitleKeyPair(i);
if ( ! pair[0].equals("0") && ! pair[1].equals("0"))
@ -180,59 +180,59 @@ public class NCAController implements ITabController {
}
private void populateFields(NCAProvider ncaProvider){
if (ncaProvider != null){
rsa2048oneTF.setText(byteArrToHexString(ncaProvider.getRsa2048one()));
rsa2048twoTF.setText(byteArrToHexString(ncaProvider.getRsa2048two()));
magicnumLbl.setText(ncaProvider.getMagicnum());
systemOrGcIndLbl.setText(Byte.toString(ncaProvider.getSystemOrGcIndicator()));
contentTypeLbl.setText(Byte.toString(ncaProvider.getContentType()));
cryptoType1Lbl.setText(Byte.toString(ncaProvider.getCryptoType1()));
keyIndexLbl.setText(Byte.toString(ncaProvider.getKeyIndex()));
ncaSizeLbl.setText(Long.toString(ncaProvider.getNcaSize()));
titleIdLbl.setText(byteArrToHexString(ncaProvider.getTitleId()));
contentIndexLbl.setText(byteArrToHexString(ncaProvider.getContentIndx())); //
sdkVersionLbl.setText(ncaProvider.getSdkVersion()[3]
+"."+ncaProvider.getSdkVersion()[2]
+"."+ncaProvider.getSdkVersion()[1]
+"."+ncaProvider.getSdkVersion()[0]);
cryptoType2Lbl.setText(Byte.toString(ncaProvider.getCryptoType2()));
header1SignatureKeyGenerationLbl.setText(Byte.toString(ncaProvider.getHeader1SignatureKeyGeneration()));
keyGenerationReservedLbl.setText(byteArrToHexString(ncaProvider.getKeyGenerationReserved()));
ticketLbl.setText(byteArrToHexString(ncaProvider.getRightsId()));
sha256section1TF.setText(byteArrToHexString(ncaProvider.getSha256hash0()));
sha256section2TF.setText(byteArrToHexString(ncaProvider.getSha256hash1()));
sha256section3TF.setText(byteArrToHexString(ncaProvider.getSha256hash2()));
sha256section4TF.setText(byteArrToHexString(ncaProvider.getSha256hash3()));
keyAreaEnKey0TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey0()));
keyAreaEnKey1TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey1()));
keyAreaEnKey2TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey2()));
keyAreaEnKey3TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey3()));
if (ncaProvider == null)
return;
rsa2048oneTF.setText(byteArrToHexString(ncaProvider.getRsa2048one()));
rsa2048twoTF.setText(byteArrToHexString(ncaProvider.getRsa2048two()));
magicnumLbl.setText(ncaProvider.getMagicnum());
systemOrGcIndLbl.setText(Byte.toString(ncaProvider.getSystemOrGcIndicator()));
contentTypeLbl.setText(Byte.toString(ncaProvider.getContentType()));
cryptoType1Lbl.setText(Byte.toString(ncaProvider.getCryptoType1()));
keyIndexLbl.setText(Byte.toString(ncaProvider.getKeyIndex()));
ncaSizeLbl.setText(Long.toString(ncaProvider.getNcaSize()));
titleIdLbl.setText(byteArrToHexString(ncaProvider.getTitleId()));
contentIndexLbl.setText(byteArrToHexString(ncaProvider.getContentIndx())); //
sdkVersionLbl.setText(ncaProvider.getSdkVersion()[3]
+"."+ncaProvider.getSdkVersion()[2]
+"."+ncaProvider.getSdkVersion()[1]
+"."+ncaProvider.getSdkVersion()[0]);
cryptoType2Lbl.setText(Byte.toString(ncaProvider.getCryptoType2()));
header1SignatureKeyGenerationLbl.setText(Byte.toString(ncaProvider.getHeader1SignatureKeyGeneration()));
keyGenerationReservedLbl.setText(byteArrToHexString(ncaProvider.getKeyGenerationReserved()));
ticketLbl.setText(byteArrToHexString(ncaProvider.getRightsId()));
sha256section1TF.setText(byteArrToHexString(ncaProvider.getSha256hash0()));
sha256section2TF.setText(byteArrToHexString(ncaProvider.getSha256hash1()));
sha256section3TF.setText(byteArrToHexString(ncaProvider.getSha256hash2()));
sha256section4TF.setText(byteArrToHexString(ncaProvider.getSha256hash3()));
keyAreaEnKey0TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey0()));
keyAreaEnKey1TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey1()));
keyAreaEnKey2TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey2()));
keyAreaEnKey3TF.setText(byteArrToHexString(ncaProvider.getEncryptedKey3()));
keyAreaDecKey0TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey0()));
keyAreaDecKey1TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey1()));
keyAreaDecKey2TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey2()));
keyAreaDecKey3TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey3()));
// Tables
NCATable1Controller.populateTab(ncaProvider.getTableEntry0());
NCATable2Controller.populateTab(ncaProvider.getTableEntry1());
NCATable3Controller.populateTab(ncaProvider.getTableEntry2());
NCATable4Controller.populateTab(ncaProvider.getTableEntry3());
// Table blocks
NCASectionHeaderFirstController.populateTab(ncaProvider.getSectionBlock0());
NCASectionHeaderSecondController.populateTab(ncaProvider.getSectionBlock1());
NCASectionHeaderThirdController.populateTab(ncaProvider.getSectionBlock2());
NCASectionHeaderFourthController.populateTab(ncaProvider.getSectionBlock3());
// Section content blocks
// TODO: FIX: This code executes getNCAContentPFS0() method twice
NCAContentPFS0 ncaContentPFS0;
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(0);
NCASectionContentFirstController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(1);
NCASectionContentSecondController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(2);
NCASectionContentThirdController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(3);
NCASectionContentFourthController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
}
keyAreaDecKey0TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey0()));
keyAreaDecKey1TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey1()));
keyAreaDecKey2TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey2()));
keyAreaDecKey3TF.setText(byteArrToHexString(ncaProvider.getDecryptedKey3()));
// Tables
NCATable1Controller.populateTab(ncaProvider.getTableEntry0());
NCATable2Controller.populateTab(ncaProvider.getTableEntry1());
NCATable3Controller.populateTab(ncaProvider.getTableEntry2());
NCATable4Controller.populateTab(ncaProvider.getTableEntry3());
// Table blocks
NCASectionHeaderFirstController.populateTab(ncaProvider.getSectionBlock0());
NCASectionHeaderSecondController.populateTab(ncaProvider.getSectionBlock1());
NCASectionHeaderThirdController.populateTab(ncaProvider.getSectionBlock2());
NCASectionHeaderFourthController.populateTab(ncaProvider.getSectionBlock3());
// Section content blocks
// TODO: FIX: This code executes getNCAContentPFS0() method twice
NCAContentPFS0 ncaContentPFS0;
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(0);
NCASectionContentFirstController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(1);
NCASectionContentSecondController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(2);
NCASectionContentThirdController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
ncaContentPFS0 = ncaProvider.getNCAContentPFS0(3);
NCASectionContentFourthController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
}
}

View File

@ -70,7 +70,7 @@ public class ListSelectorController implements Initializable {
newRecordName.setText(predictionPattern);
newRecordName.setTextFormatter(new TextFormatter<Object>(change -> {
if (change.getControlNewText().matches("^"+predictionPattern+"[0-9]{0,2}$"))
if (change.getControlNewText().matches("^"+predictionPattern+"[a-fA-F0-9]{0,2}$"))
return change;
return null;
}));
@ -110,7 +110,7 @@ public class ListSelectorController implements Initializable {
newRecordValue.clear();
}
else {
if (newRecordName.getText().matches("^"+predictionPattern+"[0-9]{2}$")){
if (newRecordName.getText().matches("^"+predictionPattern+"[a-fA-F0-9]{2}$")){
validateAndAdd(newRecordName.getText() + " = " + newRecordValue.getText());
newRecordName.setText(predictionPattern);
newRecordValue.clear();

View File

@ -78,25 +78,25 @@ public class SettingsController implements Initializable {
LinkedHashMap<String, String> preparedPairsMapInit = new LinkedHashMap<>();
for (int i = 0; i < AppPreferences.getInstance().getKAKAppCount(); i++){
preparedPairsMapInit.put(String.format("key_area_key_application_%02d", i), AppPreferences.getInstance().getApplicationKey(i));
preparedPairsMapInit.put(String.format("key_area_key_application_%02x", i), AppPreferences.getInstance().getApplicationKey(i));
}
ListSelectorKAEKAppController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
for (int i = 0; i < AppPreferences.getInstance().getKAKOceanCount(); i++){
preparedPairsMapInit.put(String.format("key_area_key_ocean_%02d", i), AppPreferences.getInstance().getOceanKey(i));
preparedPairsMapInit.put(String.format("key_area_key_ocean_%02x", i), AppPreferences.getInstance().getOceanKey(i));
}
ListSelectorKAEKOceanController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
for (int i = 0; i < AppPreferences.getInstance().getKAKSysCount(); i++){
preparedPairsMapInit.put(String.format("key_area_key_system_%02d", i), AppPreferences.getInstance().getSystemKey(i));
preparedPairsMapInit.put(String.format("key_area_key_system_%02x", i), AppPreferences.getInstance().getSystemKey(i));
}
ListSelectorKAEKSysController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
for (int i = 0; i < AppPreferences.getInstance().getTitleKeksCount(); i++){
preparedPairsMapInit.put(String.format("titlekek_%02d", i), AppPreferences.getInstance().getTitleKek(i));
preparedPairsMapInit.put(String.format("titlekek_%02x", i), AppPreferences.getInstance().getTitleKek(i));
}
ListSelectorTitleKeksController.setList(preparedPairsMapInit);
preparedPairsMapInit.clear();
@ -143,32 +143,32 @@ public class SettingsController implements Initializable {
String keyParsed;
int counter = 0;
while ((keyParsed = fileMap.get(String.format("key_area_key_application_%02d", counter))) != null){
kaekSingle.put(String.format("key_area_key_application_%02d", counter), keyParsed);
while ((keyParsed = fileMap.get(String.format("key_area_key_application_%02x", counter))) != null){
kaekSingle.put(String.format("key_area_key_application_%02x", counter), keyParsed);
counter++;
}
ListSelectorKAEKAppController.setList(kaekSingle);
kaekSingle.clear();
counter = 0;
while ((keyParsed = fileMap.get(String.format("key_area_key_ocean_%02d", counter))) != null){
kaekSingle.put(String.format("key_area_key_ocean_%02d", counter), keyParsed);
while ((keyParsed = fileMap.get(String.format("key_area_key_ocean_%02x", counter))) != null){
kaekSingle.put(String.format("key_area_key_ocean_%02x", counter), keyParsed);
counter++;
}
ListSelectorKAEKOceanController.setList(kaekSingle);
kaekSingle.clear();
counter = 0;
while ((keyParsed = fileMap.get(String.format("key_area_key_system_%02d", counter))) != null){
kaekSingle.put(String.format("key_area_key_system_%02d", counter), keyParsed);
while ((keyParsed = fileMap.get(String.format("key_area_key_system_%02x", counter))) != null){
kaekSingle.put(String.format("key_area_key_system_%02x", counter), keyParsed);
counter++;
}
ListSelectorKAEKSysController.setList(kaekSingle);
kaekSingle.clear();
counter = 0;
while ((keyParsed = fileMap.get(String.format("titlekek_%02d", counter))) != null){
kaekSingle.put(String.format("titlekek_%02d", counter), keyParsed);
while ((keyParsed = fileMap.get(String.format("titlekek_%02x", counter))) != null){
kaekSingle.put(String.format("titlekek_%02x", counter), keyParsed);
counter++;
}
ListSelectorTitleKeksController.setList(kaekSingle);

View File

@ -194,13 +194,13 @@ public class NCAProvider {
String keyAreaKey;
switch (keyIndex){
case 0:
keyAreaKey = keys.get(String.format("key_area_key_application_%02d", cryptoTypeReal));
keyAreaKey = keys.get(String.format("key_area_key_application_%02x", cryptoTypeReal));
break;
case 1:
keyAreaKey = keys.get(String.format("key_area_key_ocean_%02d", cryptoTypeReal));
keyAreaKey = keys.get(String.format("key_area_key_ocean_%02x", cryptoTypeReal));
break;
case 2:
keyAreaKey = keys.get(String.format("key_area_key_system_%02d", cryptoTypeReal));
keyAreaKey = keys.get(String.format("key_area_key_system_%02x", cryptoTypeReal));
break;
default:
keyAreaKey = null;
@ -231,7 +231,7 @@ public class NCAProvider {
exceptionStringBuilder.append(keyIndex);
exceptionStringBuilder.append("[UNKNOWN]_");
}
exceptionStringBuilder.append(String.format("%02d", cryptoTypeReal));
exceptionStringBuilder.append(String.format("%02x", cryptoTypeReal));
exceptionStringBuilder.append(" requested. Not supported or not found.");
throw new Exception(exceptionStringBuilder.toString());
@ -312,7 +312,7 @@ public class NCAProvider {
byte[] rightsIDkey = hexStrToByteArray(keys.get(byteArrToHexString(rightsId))); // throws NullPointerException
SecretKeySpec skSpec = new SecretKeySpec(
hexStrToByteArray(keys.get(String.format("titlekek_%02d", cryptoTypeReal))
hexStrToByteArray(keys.get(String.format("titlekek_%02x", cryptoTypeReal))
), "AES");
Cipher cipher = Cipher.getInstance("AES/ECB/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, skSpec);

View File

@ -107,26 +107,6 @@
</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" 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>
<fx:include fx:id="ListSelectorTitleKeys" source="ListSelectorLayout.fxml" />
</children>
</VBox>
</content>
</ScrollPane>
</content>
<graphic>
<VBox alignment="TOP_CENTER" spacing="5.0">
<children>
@ -135,6 +115,22 @@
</children>
</VBox>
</graphic>
<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" 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>
<fx:include fx:id="ListSelectorTitleKeys" source="ListSelectorLayout.fxml" />
</children>
</VBox>
</content>
</Tab>
</tabs>
</TabPane>