From 4a803c7b082876cf1492a4a1239af42aea1ae5fa Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Mon, 26 Aug 2019 04:28:07 +0300 Subject: [PATCH] Service Access Control implemented to NPDM -> ACID --- .../Controllers/NPDM/NPDMController.java | 9 +- .../NPDM/ServiceAccessControlController.java | 44 + .../konogonka/Tools/NPDM/ACIDProvider.java | 7 +- .../konogonka/Tools/NPDM/NPDMProvider.java | 5 +- .../NPDM/ServiceAccessControlProvider.java | 30 + .../FXML/NPDM/FSAccessControlTable.fxml | 2586 ++++++++--------- src/main/resources/FXML/NPDM/NPDMTab.fxml | 1 + .../FXML/NPDM/ServiceAccessControlTable.fxml | 41 + 8 files changed, 1422 insertions(+), 1301 deletions(-) create mode 100644 src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java create mode 100644 src/main/java/konogonka/Tools/NPDM/ServiceAccessControlProvider.java create mode 100644 src/main/resources/FXML/NPDM/ServiceAccessControlTable.fxml diff --git a/src/main/java/konogonka/Controllers/NPDM/NPDMController.java b/src/main/java/konogonka/Controllers/NPDM/NPDMController.java index 21a8ddb..2d4f80b 100644 --- a/src/main/java/konogonka/Controllers/NPDM/NPDMController.java +++ b/src/main/java/konogonka/Controllers/NPDM/NPDMController.java @@ -78,6 +78,9 @@ public class NPDMController implements ITabController { @FXML private FSAccessControlController FSAccessControlTableController; + @FXML + private ServiceAccessControlController ServiceAccessControlTableController; + @Override public void initialize(URL url, ResourceBundle resourceBundle) { } @@ -163,6 +166,8 @@ public class NPDMController implements ITabController { acidReserved2Lbl.setText("-"); FSAccessControlTableController.resetTab(); + + ServiceAccessControlTableController.resetTab(); } private void setData(NPDMProvider npdmProvider, File file) { if (npdmProvider == null) @@ -223,6 +228,8 @@ public class NPDMController implements ITabController { acidKernelAccessControlSizeLbl.setText(Integer.toString(acid.getKernelAccessControlSize())); acidReserved2Lbl.setText(byteArrToHexString(acid.getReserved2())); - FSAccessControlTableController.populateFields(acid.getFSAccessControlProvider()); + FSAccessControlTableController.populateFields(acid.getFsAccessControlProvider()); + ServiceAccessControlTableController.populateFields(acid.getServiceAccessControlProvider().getCollection()); + } } \ No newline at end of file diff --git a/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java b/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java new file mode 100644 index 0000000..1f2c061 --- /dev/null +++ b/src/main/java/konogonka/Controllers/NPDM/ServiceAccessControlController.java @@ -0,0 +1,44 @@ +package konogonka.Controllers.NPDM; + +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.geometry.Insets; +import javafx.scene.control.Label; +import javafx.scene.layout.HBox; +import javafx.scene.layout.VBox; +import konogonka.LoperConverter; + +import java.net.URL; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.ResourceBundle; + +public class ServiceAccessControlController implements Initializable { + + @FXML + private VBox SACPane; + + @Override + public void initialize(URL url, ResourceBundle resourceBundle) { + + } + public void resetTab(){ + SACPane.getChildren().clear(); + } + + public void populateFields(LinkedHashMap collection){ + resetTab(); + + for (Object object : collection.entrySet()) { + Map.Entry entry = (Map.Entry) object; + + Label control = new Label(String.format("0x%02x", entry.getKey())); + Label serviceName = new Label(entry.getValue()); + + control.setPadding(new Insets(5.0, 5.0, 5.0, 5.0)); + serviceName.setPadding(new Insets(5.0, 5.0, 5.0, 5.0)); + + SACPane.getChildren().add(new HBox(control, serviceName)); + } + } +} diff --git a/src/main/java/konogonka/Tools/NPDM/ACIDProvider.java b/src/main/java/konogonka/Tools/NPDM/ACIDProvider.java index bed9327..16a8e40 100644 --- a/src/main/java/konogonka/Tools/NPDM/ACIDProvider.java +++ b/src/main/java/konogonka/Tools/NPDM/ACIDProvider.java @@ -27,7 +27,7 @@ public class ACIDProvider { private byte[] reserved2; private FSAccessControlProvider fsAccessControlProvider; - + private ServiceAccessControlProvider serviceAccessControlProvider; public ACIDProvider(byte[] acidBytes) throws Exception{ if (acidBytes.length < 0x240) @@ -53,6 +53,7 @@ public class ACIDProvider { if (fsAccessControlOffset > serviceAccessControlOffset || serviceAccessControlOffset > kernelAccessControlOffset ) throw new Exception("ACIDProvider -> blocks inside the ACID are not sorted in ascending order. Only ascending order supported."); fsAccessControlProvider = new FSAccessControlProvider(Arrays.copyOfRange(acidBytes, fsAccessControlOffset, fsAccessControlOffset+fsAccessControlSize)); + serviceAccessControlProvider = new ServiceAccessControlProvider(Arrays.copyOfRange(acidBytes, serviceAccessControlOffset, serviceAccessControlOffset+serviceAccessControlSize)); } public byte[] getRsa2048signature() { return rsa2048signature; } @@ -74,6 +75,6 @@ public class ACIDProvider { public int getKernelAccessControlSize() { return kernelAccessControlSize; } public byte[] getReserved2() { return reserved2; } - public FSAccessControlProvider getFSAccessControlProvider() { return fsAccessControlProvider; } - + public FSAccessControlProvider getFsAccessControlProvider() { return fsAccessControlProvider; } + public ServiceAccessControlProvider getServiceAccessControlProvider() { return serviceAccessControlProvider; } } \ No newline at end of file diff --git a/src/main/java/konogonka/Tools/NPDM/NPDMProvider.java b/src/main/java/konogonka/Tools/NPDM/NPDMProvider.java index a15763a..10638f1 100644 --- a/src/main/java/konogonka/Tools/NPDM/NPDMProvider.java +++ b/src/main/java/konogonka/Tools/NPDM/NPDMProvider.java @@ -1,5 +1,6 @@ package konogonka.Tools.NPDM; +import konogonka.RainbowHexDump; import konogonka.Tools.ASuperInFileProvider; import java.io.*; @@ -109,13 +110,13 @@ public class NPDMProvider extends ASuperInFileProvider { acidSize = getLEint(metaBuf, 0x7C); // Get ACI0 raf.seek(aci0offset); - metaBuf = new byte[aci0size]; // TODO: NOTE: we read all size but need only header + metaBuf = new byte[aci0size]; // TODO: NOTE: we read all size but it's memory consuming if (raf.read(metaBuf) != aci0size) throw new Exception("NPDMProvider: Failed to read 'ACI0'"); aci0 = new ACI0Provider(metaBuf); // Get ACID raf.seek(acidOffset); - metaBuf = new byte[acidSize]; // TODO: NOTE: we read all size but need only header + metaBuf = new byte[acidSize]; // TODO: NOTE: we read all size but it's memory consuming if (raf.read(metaBuf) != acidSize) throw new Exception("NPDMProvider: Failed to read 'ACID'"); acid = new ACIDProvider(metaBuf); diff --git a/src/main/java/konogonka/Tools/NPDM/ServiceAccessControlProvider.java b/src/main/java/konogonka/Tools/NPDM/ServiceAccessControlProvider.java new file mode 100644 index 0000000..4e1a0e2 --- /dev/null +++ b/src/main/java/konogonka/Tools/NPDM/ServiceAccessControlProvider.java @@ -0,0 +1,30 @@ +package konogonka.Tools.NPDM; + +import java.nio.charset.StandardCharsets; +import java.util.LinkedHashMap; + +public class ServiceAccessControlProvider { + + private LinkedHashMap collection; + + public ServiceAccessControlProvider(byte[] bytes){ + collection = new LinkedHashMap<>(); + byte key; + String value; + + int i = 0; + + while (i < bytes.length){ + key = bytes[i]; + value = new String(bytes, i+1, getSize(key), StandardCharsets.UTF_8); + collection.put(key, value); + i += getSize(key)+1; + } + } + + private int getSize(byte control) { + return ((byte) 0x7 & control) + 1; + } + + public LinkedHashMap getCollection() { return collection; } +} diff --git a/src/main/resources/FXML/NPDM/FSAccessControlTable.fxml b/src/main/resources/FXML/NPDM/FSAccessControlTable.fxml index 9113685..345dd7f 100644 --- a/src/main/resources/FXML/NPDM/FSAccessControlTable.fxml +++ b/src/main/resources/FXML/NPDM/FSAccessControlTable.fxml @@ -14,1304 +14,1300 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/FXML/NPDM/NPDMTab.fxml b/src/main/resources/FXML/NPDM/NPDMTab.fxml index 7196e98..228bc95 100644 --- a/src/main/resources/FXML/NPDM/NPDMTab.fxml +++ b/src/main/resources/FXML/NPDM/NPDMTab.fxml @@ -1174,6 +1174,7 @@