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

This commit is contained in:
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){ public void setKAKAppCount(int number){
if (this.kakAppCount > number){ if (this.kakAppCount > number){
for (int i = number; i < this.kakAppCount; i++) { 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); preferences.putInt("key_area_key_application_count", number);
@ -86,7 +86,7 @@ public class AppPreferences {
public void setKAKOceanCount(int number){ public void setKAKOceanCount(int number){
if (this.kakOceanCount > number){ if (this.kakOceanCount > number){
for (int i = number; i < this.kakOceanCount; i++) { 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); preferences.putInt("key_area_key_ocean_count", number);
@ -95,7 +95,7 @@ public class AppPreferences {
public void setKAKSysCount(int number){ public void setKAKSysCount(int number){
if (this.kakSysCount > number){ if (this.kakSysCount > number){
for (int i = number; i < this.kakSysCount; i++) { 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); preferences.putInt("key_area_key_system_count", number);
@ -105,7 +105,7 @@ public class AppPreferences {
public void setTitleKeksCount(int number){ public void setTitleKeksCount(int number){
if (this.titleKeksCount > number){ if (this.titleKeksCount > number){
for (int i = number; i < this.titleKeksCount; i++) { 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); 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 getKAKSysCount(){ return preferences.getInt("key_area_key_system_count", 0); }
public int getTitleKeksCount(){ return preferences.getInt("titlekek_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 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_%02d", number), key); } 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 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_%02d", number), key); } 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 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_%02d", number), key); } 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 String getTitleKek(int number){ return preferences.get(String.format("titlekek_%02x", number), "");}
public void setTitleKek(int number, String key){ preferences.put(String.format("titlekek_%02d", number), key); } public void setTitleKek(int number, String key){ preferences.put(String.format("titlekek_%02x", number), key); }
// Title keys // Title keys

View file

@ -101,13 +101,13 @@ public class NCAController implements ITabController {
keysMap.put("header_key", AppPreferences.getInstance().getHeaderKey()); keysMap.put("header_key", AppPreferences.getInstance().getHeaderKey());
for (int i = 0; i < AppPreferences.getInstance().getKAKAppCount(); i++) 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++) 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++) 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++) 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++){ for (int i = 0; i < AppPreferences.getInstance().getTitleKeysCount(); i++){
String[] pair = AppPreferences.getInstance().getTitleKeyPair(i); String[] pair = AppPreferences.getInstance().getTitleKeyPair(i);
if ( ! pair[0].equals("0") && ! pair[1].equals("0")) if ( ! pair[0].equals("0") && ! pair[1].equals("0"))
@ -180,7 +180,8 @@ public class NCAController implements ITabController {
} }
private void populateFields(NCAProvider ncaProvider){ private void populateFields(NCAProvider ncaProvider){
if (ncaProvider != null){ if (ncaProvider == null)
return;
rsa2048oneTF.setText(byteArrToHexString(ncaProvider.getRsa2048one())); rsa2048oneTF.setText(byteArrToHexString(ncaProvider.getRsa2048one()));
rsa2048twoTF.setText(byteArrToHexString(ncaProvider.getRsa2048two())); rsa2048twoTF.setText(byteArrToHexString(ncaProvider.getRsa2048two()));
magicnumLbl.setText(ncaProvider.getMagicnum()); magicnumLbl.setText(ncaProvider.getMagicnum());
@ -235,4 +236,3 @@ public class NCAController implements ITabController {
NCASectionContentFourthController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes()); NCASectionContentFourthController.populateFields(ncaContentPFS0.getPfs0(), ncaContentPFS0.getSHA256hashes());
} }
} }
}

View file

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

View file

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

View file

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

View file

@ -107,8 +107,14 @@
</graphic> </graphic>
</Tab> </Tab>
<Tab closable="false"> <Tab closable="false">
<content> <graphic>
<ScrollPane fitToWidth="true"> <VBox alignment="TOP_CENTER" spacing="5.0">
<children>
<SVGPath content="M7,6H17A6,6 0 0,1 23,12A6,6 0 0,1 17,18C15.22,18 13.63,17.23 12.53,16H11.47C10.37,17.23 8.78,18 7,18A6,6 0 0,1 1,12A6,6 0 0,1 7,6M6,9V11H4V13H6V15H8V13H10V11H8V9H6M15.5,12A1.5,1.5 0 0,0 14,13.5A1.5,1.5 0 0,0 15.5,15A1.5,1.5 0 0,0 17,13.5A1.5,1.5 0 0,0 15.5,12M18.5,9A1.5,1.5 0 0,0 17,10.5A1.5,1.5 0 0,0 18.5,12A1.5,1.5 0 0,0 20,10.5A1.5,1.5 0 0,0 18.5,9Z" />
<Label text="title.keys" />
</children>
</VBox>
</graphic>
<content> <content>
<VBox spacing="5.0"> <VBox spacing="5.0">
<padding> <padding>
@ -125,16 +131,6 @@
</children> </children>
</VBox> </VBox>
</content> </content>
</ScrollPane>
</content>
<graphic>
<VBox alignment="TOP_CENTER" spacing="5.0">
<children>
<SVGPath content="M7,6H17A6,6 0 0,1 23,12A6,6 0 0,1 17,18C15.22,18 13.63,17.23 12.53,16H11.47C10.37,17.23 8.78,18 7,18A6,6 0 0,1 1,12A6,6 0 0,1 7,6M6,9V11H4V13H6V15H8V13H10V11H8V9H6M15.5,12A1.5,1.5 0 0,0 14,13.5A1.5,1.5 0 0,0 15.5,15A1.5,1.5 0 0,0 17,13.5A1.5,1.5 0 0,0 15.5,12M18.5,9A1.5,1.5 0 0,0 17,10.5A1.5,1.5 0 0,0 18.5,12A1.5,1.5 0 0,0 20,10.5A1.5,1.5 0 0,0 18.5,9Z" />
<Label text="title.keys" />
</children>
</VBox>
</graphic>
</Tab> </Tab>
</tabs> </tabs>
</TabPane> </TabPane>