Preferences updated. Works as expected.
This commit is contained in:
parent
a6b46660d8
commit
e2f7f93988
4 changed files with 114 additions and 59 deletions
|
@ -7,10 +7,21 @@ public class AppPreferences {
|
||||||
public static AppPreferences getInstance() { return INSTANCE; }
|
public static AppPreferences getInstance() { return INSTANCE; }
|
||||||
|
|
||||||
private Preferences preferences;
|
private Preferences preferences;
|
||||||
private int titleKeysCount;
|
|
||||||
|
private int
|
||||||
|
kakAppCount,
|
||||||
|
kakOceanCount,
|
||||||
|
kakSysCount,
|
||||||
|
titleKeksCount,
|
||||||
|
titleKeysCount;
|
||||||
|
|
||||||
private AppPreferences(){
|
private AppPreferences(){
|
||||||
preferences = Preferences.userRoot().node("konogonka");
|
preferences = Preferences.userRoot().node("konogonka");
|
||||||
|
|
||||||
|
kakAppCount = getKAKAppCount();
|
||||||
|
kakOceanCount = getKAKOceanCount();
|
||||||
|
kakSysCount = getKAKSysCount();
|
||||||
|
titleKeksCount = getTitleKeksCount();
|
||||||
titleKeysCount = getTitleKeysCount();
|
titleKeysCount = getTitleKeysCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,23 +52,65 @@ public class AppPreferences {
|
||||||
public String getHeaderKey(){ return preferences.get("header_key", "");}
|
public String getHeaderKey(){ return preferences.get("header_key", "");}
|
||||||
public void setHeaderKey(String key){ preferences.put("header_key", key); }
|
public void setHeaderKey(String key){ preferences.put("header_key", key); }
|
||||||
|
|
||||||
public String getApplicationKey(int number){ return preferences.get("key_area_key_application_0"+number, "");}
|
// KAKs: Application/Ocean/System
|
||||||
public void setApplicationKey(int number, String key){ preferences.put("key_area_key_application_0"+number, key); }
|
public void setKAKAppCount(int number){
|
||||||
|
if (this.kakAppCount > number){
|
||||||
public String getOceanKey(int number){ return preferences.get("key_area_key_ocean_0"+number, "");}
|
for (int i = number; i < this.kakAppCount; i++) {
|
||||||
public void setOceanKey(int number, String key){ preferences.put("key_area_key_ocean_0"+number, key); }
|
preferences.remove(String.format("key_area_key_application_%02d", number));
|
||||||
|
}
|
||||||
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); }
|
preferences.putInt("key_area_key_application_count", number);
|
||||||
|
this.kakAppCount = number;
|
||||||
public String getTitleKek(int number){ return preferences.get("titlekek_"+number, "");}
|
|
||||||
public void setTitleKek(int number, String key){ preferences.put("titlekek_"+number, key); }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public int getTitleKeysCount(){ // TODO: do the same for other multi-keys and single
|
|
||||||
return preferences.getInt("title_keys_count", 0);
|
|
||||||
}
|
}
|
||||||
|
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.putInt("key_area_key_ocean_count", number);
|
||||||
|
this.kakOceanCount = number;
|
||||||
|
}
|
||||||
|
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.putInt("key_area_key_system_count", number);
|
||||||
|
this.kakSysCount = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
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.putInt("titlekek_count", number);
|
||||||
|
this.titleKeksCount = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getKAKAppCount(){ return preferences.getInt("key_area_key_application_count", 0); }
|
||||||
|
public int getKAKOceanCount(){ return preferences.getInt("key_area_key_ocean_count", 0); }
|
||||||
|
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 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 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 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); }
|
||||||
|
|
||||||
|
|
||||||
|
// Title keys
|
||||||
|
public int getTitleKeysCount(){ return preferences.getInt("title_keys_count", 0); }
|
||||||
// Since we don't want to store title keys that are no longer in use, we have to (try to) remove them.
|
// Since we don't want to store title keys that are no longer in use, we have to (try to) remove them.
|
||||||
// This part of code works as a charm. Don't touch.
|
// This part of code works as a charm. Don't touch.
|
||||||
public void setTitleKeysCount(int number){
|
public void setTitleKeysCount(int number){
|
||||||
|
@ -74,4 +127,4 @@ public class AppPreferences {
|
||||||
return preferences.get("title_key_"+number, "0 = 0").split(" = ", 2);
|
return preferences.get("title_key_"+number, "0 = 0").split(" = ", 2);
|
||||||
}
|
}
|
||||||
public void setTitleKey(int number, String pair){ preferences.put("title_key_"+number, pair); }
|
public void setTitleKey(int number, String pair){ preferences.put("title_key_"+number, pair); }
|
||||||
}
|
}
|
|
@ -76,12 +76,15 @@ public class NCAController implements TabController {
|
||||||
this.selectedFile = file;
|
this.selectedFile = file;
|
||||||
HashMap<String, String> keysMap = new HashMap<>();
|
HashMap<String, String> keysMap = new HashMap<>();
|
||||||
keysMap.put("header_key", AppPreferences.getInstance().getHeaderKey());
|
keysMap.put("header_key", AppPreferences.getInstance().getHeaderKey());
|
||||||
for (int i = 0; i < 8; i++){ // TODO: FIX!!!!!!!!! URGENT!
|
|
||||||
keysMap.put("key_area_key_application_0"+i, AppPreferences.getInstance().getApplicationKey(i));
|
for (int i = 0; i < AppPreferences.getInstance().getKAKAppCount(); i++)
|
||||||
keysMap.put("key_area_key_ocean_0"+i, AppPreferences.getInstance().getOceanKey(i));
|
keysMap.put(String.format("key_area_key_application_%02d", i), AppPreferences.getInstance().getApplicationKey(i));
|
||||||
keysMap.put("key_area_key_system_0"+i, AppPreferences.getInstance().getSystemKey(i));
|
for (int i = 0; i < AppPreferences.getInstance().getKAKOceanCount(); i++)
|
||||||
keysMap.put("titlekek_0"+i, AppPreferences.getInstance().getTitleKek(i));
|
keysMap.put(String.format("key_area_key_ocean_%02d", 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));
|
||||||
|
for (int i = 0; i < AppPreferences.getInstance().getTitleKeksCount(); i++)
|
||||||
|
keysMap.put(String.format("titlekek_%02d", 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"))
|
||||||
|
|
|
@ -42,40 +42,31 @@ public class SettingsController implements Initializable {
|
||||||
ListSelectorTitleKeysController.initSelector(32, null); // 32 required
|
ListSelectorTitleKeysController.initSelector(32, null); // 32 required
|
||||||
|
|
||||||
LinkedHashMap<String, String> preparedPairsMapInit = new LinkedHashMap<>();
|
LinkedHashMap<String, String> preparedPairsMapInit = new LinkedHashMap<>();
|
||||||
String kaekApp;
|
|
||||||
int cnt = 0;
|
|
||||||
|
|
||||||
while (!(kaekApp = AppPreferences.getInstance().getApplicationKey(cnt)).isEmpty()){
|
for (int i = 0; i < AppPreferences.getInstance().getKAKAppCount(); i++){
|
||||||
preparedPairsMapInit.put("key_area_key_application_"+String.format("%02d", cnt), kaekApp);
|
preparedPairsMapInit.put(String.format("key_area_key_application_%02d", i), AppPreferences.getInstance().getApplicationKey(i));
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
ListSelectorKAEKAppController.setList(preparedPairsMapInit);
|
ListSelectorKAEKAppController.setList(preparedPairsMapInit);
|
||||||
|
|
||||||
preparedPairsMapInit.clear();
|
preparedPairsMapInit.clear();
|
||||||
cnt = 0;
|
|
||||||
while (!(kaekApp = AppPreferences.getInstance().getOceanKey(cnt)).isEmpty()){
|
for (int i = 0; i < AppPreferences.getInstance().getKAKOceanCount(); i++){
|
||||||
preparedPairsMapInit.put("key_area_key_ocean_"+String.format("%02d", cnt), kaekApp);
|
preparedPairsMapInit.put(String.format("key_area_key_ocean_%02d", i), AppPreferences.getInstance().getOceanKey(i));
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
ListSelectorKAEKOceanController.setList(preparedPairsMapInit);
|
ListSelectorKAEKOceanController.setList(preparedPairsMapInit);
|
||||||
|
|
||||||
preparedPairsMapInit.clear();
|
preparedPairsMapInit.clear();
|
||||||
cnt = 0;
|
|
||||||
while (!(kaekApp = AppPreferences.getInstance().getTitleKek(cnt)).isEmpty()){
|
|
||||||
preparedPairsMapInit.put("titlekek_"+String.format("%02d", cnt), kaekApp);
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
ListSelectorTitleKeksController.setList(preparedPairsMapInit);
|
|
||||||
|
|
||||||
preparedPairsMapInit.clear();
|
for (int i = 0; i < AppPreferences.getInstance().getKAKSysCount(); i++){
|
||||||
cnt = 0;
|
preparedPairsMapInit.put(String.format("key_area_key_system_%02d", i), AppPreferences.getInstance().getSystemKey(i));
|
||||||
while (!(kaekApp = AppPreferences.getInstance().getSystemKey(cnt)).isEmpty()){
|
|
||||||
preparedPairsMapInit.put("key_area_key_system_"+String.format("%02d", cnt), kaekApp);
|
|
||||||
cnt++;
|
|
||||||
}
|
}
|
||||||
ListSelectorKAEKSysController.setList(preparedPairsMapInit);
|
ListSelectorKAEKSysController.setList(preparedPairsMapInit);
|
||||||
|
|
||||||
preparedPairsMapInit.clear();
|
preparedPairsMapInit.clear();
|
||||||
|
|
||||||
|
for (int i = 0; i < AppPreferences.getInstance().getTitleKeksCount(); i++){
|
||||||
|
preparedPairsMapInit.put(String.format("titlekek_%02d", i), AppPreferences.getInstance().getTitleKek(i));
|
||||||
|
}
|
||||||
|
ListSelectorTitleKeksController.setList(preparedPairsMapInit);
|
||||||
|
preparedPairsMapInit.clear();
|
||||||
|
|
||||||
for (int i = 0; i < AppPreferences.getInstance().getTitleKeysCount(); i++){
|
for (int i = 0; i < AppPreferences.getInstance().getTitleKeysCount(); i++){
|
||||||
preparedPairsMapInit.put(
|
preparedPairsMapInit.put(
|
||||||
AppPreferences.getInstance().getTitleKeyPair(i)[0],
|
AppPreferences.getInstance().getTitleKeyPair(i)[0],
|
||||||
|
@ -118,32 +109,32 @@ public class SettingsController implements Initializable {
|
||||||
|
|
||||||
String keyParsed;
|
String keyParsed;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
while ((keyParsed = fileMap.get("key_area_key_application_"+String.format("%02d", counter))) != null){
|
while ((keyParsed = fileMap.get(String.format("key_area_key_application_%02d", counter))) != null){
|
||||||
kaekSingle.put("key_area_key_application_"+String.format("%02d", counter), keyParsed);
|
kaekSingle.put(String.format("key_area_key_application_%02d", counter), keyParsed);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
ListSelectorKAEKAppController.setList(kaekSingle);
|
ListSelectorKAEKAppController.setList(kaekSingle);
|
||||||
|
|
||||||
kaekSingle.clear();
|
kaekSingle.clear();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
while ((keyParsed = fileMap.get("key_area_key_ocean_"+String.format("%02d", counter))) != null){
|
while ((keyParsed = fileMap.get(String.format("key_area_key_ocean_%02d", counter))) != null){
|
||||||
kaekSingle.put("key_area_key_ocean_"+String.format("%02d", counter), keyParsed);
|
kaekSingle.put(String.format("key_area_key_ocean_%02d", counter), keyParsed);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
ListSelectorKAEKOceanController.setList(kaekSingle);
|
ListSelectorKAEKOceanController.setList(kaekSingle);
|
||||||
|
|
||||||
kaekSingle.clear();
|
kaekSingle.clear();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
while ((keyParsed = fileMap.get("key_area_key_system_"+String.format("%02d", counter))) != null){
|
while ((keyParsed = fileMap.get(String.format("key_area_key_system_%02d", counter))) != null){
|
||||||
kaekSingle.put("key_area_key_system_"+String.format("%02d", counter), keyParsed);
|
kaekSingle.put(String.format("key_area_key_system_%02d", counter), keyParsed);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
ListSelectorKAEKSysController.setList(kaekSingle);
|
ListSelectorKAEKSysController.setList(kaekSingle);
|
||||||
|
|
||||||
kaekSingle.clear();
|
kaekSingle.clear();
|
||||||
counter = 0;
|
counter = 0;
|
||||||
while ((keyParsed = fileMap.get("titlekek_"+String.format("%02d", counter))) != null){
|
while ((keyParsed = fileMap.get(String.format("titlekek_%02d", counter))) != null){
|
||||||
kaekSingle.put("titlekek_"+String.format("%02d", counter), keyParsed);
|
kaekSingle.put(String.format("titlekek_%02d", counter), keyParsed);
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
ListSelectorTitleKeksController.setList(kaekSingle);
|
ListSelectorTitleKeksController.setList(kaekSingle);
|
||||||
|
@ -203,24 +194,32 @@ public class SettingsController implements Initializable {
|
||||||
for (int i = 0; i < kaekAppKeySet.length; i++)
|
for (int i = 0; i < kaekAppKeySet.length; i++)
|
||||||
AppPreferences.getInstance().setApplicationKey(i, kaekAppKeySet[i].split("\\s=\\s", 2)[1]);
|
AppPreferences.getInstance().setApplicationKey(i, kaekAppKeySet[i].split("\\s=\\s", 2)[1]);
|
||||||
}
|
}
|
||||||
|
if (kaekAppKeySet != null)
|
||||||
|
AppPreferences.getInstance().setKAKAppCount(kaekAppKeySet.length);
|
||||||
|
|
||||||
String[] kaekOceanKeySet = ListSelectorKAEKOceanController.getList();
|
String[] kaekOceanKeySet = ListSelectorKAEKOceanController.getList();
|
||||||
if (kaekOceanKeySet != null){
|
if (kaekOceanKeySet != null){
|
||||||
for (int i = 0; i < kaekOceanKeySet.length; i++)
|
for (int i = 0; i < kaekOceanKeySet.length; i++)
|
||||||
AppPreferences.getInstance().setOceanKey(i, kaekOceanKeySet[i].split("\\s=\\s", 2)[1]);
|
AppPreferences.getInstance().setOceanKey(i, kaekOceanKeySet[i].split("\\s=\\s", 2)[1]);
|
||||||
}
|
}
|
||||||
|
if (kaekOceanKeySet != null)
|
||||||
|
AppPreferences.getInstance().setKAKOceanCount(kaekOceanKeySet.length);
|
||||||
|
|
||||||
String[] kaekSysKeySet = ListSelectorKAEKSysController.getList();
|
String[] kaekSysKeySet = ListSelectorKAEKSysController.getList();
|
||||||
if (kaekSysKeySet != null){
|
if (kaekSysKeySet != null){
|
||||||
for (int i = 0; i < kaekSysKeySet.length; i++)
|
for (int i = 0; i < kaekSysKeySet.length; i++)
|
||||||
AppPreferences.getInstance().setSystemKey(i, kaekSysKeySet[i].split("\\s=\\s", 2)[1]);
|
AppPreferences.getInstance().setSystemKey(i, kaekSysKeySet[i].split("\\s=\\s", 2)[1]);
|
||||||
}
|
}
|
||||||
|
if (kaekSysKeySet != null)
|
||||||
|
AppPreferences.getInstance().setKAKSysCount(kaekSysKeySet.length);
|
||||||
|
|
||||||
String[] titleKekSet = ListSelectorTitleKeksController.getList();
|
String[] titleKekSet = ListSelectorTitleKeksController.getList();
|
||||||
if (titleKekSet != null){
|
if (titleKekSet != null){
|
||||||
for (int i = 0; i < titleKekSet.length; i++)
|
for (int i = 0; i < titleKekSet.length; i++)
|
||||||
AppPreferences.getInstance().setTitleKek(i, titleKekSet[i].split("\\s=\\s", 2)[1]);
|
AppPreferences.getInstance().setTitleKek(i, titleKekSet[i].split("\\s=\\s", 2)[1]);
|
||||||
}
|
}
|
||||||
|
if (titleKekSet != null)
|
||||||
|
AppPreferences.getInstance().setTitleKeksCount(titleKekSet.length);
|
||||||
|
|
||||||
String[] titleKeysSet = ListSelectorTitleKeysController.getList();
|
String[] titleKeysSet = ListSelectorTitleKeysController.getList();
|
||||||
if (titleKeysSet != null){
|
if (titleKeysSet != null){
|
||||||
|
|
|
@ -171,13 +171,13 @@ public class NCAProvider {
|
||||||
String keyAreaKey;
|
String keyAreaKey;
|
||||||
switch (keyIndex){
|
switch (keyIndex){
|
||||||
case 0:
|
case 0:
|
||||||
keyAreaKey = keys.get("key_area_key_application_"+String.format("%02d", cryptoTypeReal));
|
keyAreaKey = keys.get(String.format("key_area_key_application_%02d", cryptoTypeReal));
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
keyAreaKey = keys.get("key_area_key_ocean_"+String.format("%02d", cryptoTypeReal));
|
keyAreaKey = keys.get(String.format("key_area_key_ocean_%02d", cryptoTypeReal));
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
keyAreaKey = keys.get("key_area_key_system_"+String.format("%02d", cryptoTypeReal));
|
keyAreaKey = keys.get(String.format("key_area_key_system_%02d", cryptoTypeReal));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
keyAreaKey = null;
|
keyAreaKey = null;
|
||||||
|
@ -259,7 +259,7 @@ public class NCAProvider {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SecretKeySpec skSpec = new SecretKeySpec(
|
SecretKeySpec skSpec = new SecretKeySpec(
|
||||||
hexStrToByteArray(keys.get("titlekek_"+String.format("%02d", cryptoTypeReal))
|
hexStrToByteArray(keys.get(String.format("titlekek_%02d", 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);
|
||||||
|
|
Loading…
Reference in a new issue