Service Access Control implemented to NPDM -> ACID

This commit is contained in:
Dmitry Isaenko 2019-08-26 04:28:07 +03:00
parent c3c89f2659
commit 4a803c7b08
8 changed files with 1422 additions and 1301 deletions

View file

@ -78,6 +78,9 @@ public class NPDMController implements ITabController {
@FXML @FXML
private FSAccessControlController FSAccessControlTableController; private FSAccessControlController FSAccessControlTableController;
@FXML
private ServiceAccessControlController ServiceAccessControlTableController;
@Override @Override
public void initialize(URL url, ResourceBundle resourceBundle) { } public void initialize(URL url, ResourceBundle resourceBundle) { }
@ -163,6 +166,8 @@ public class NPDMController implements ITabController {
acidReserved2Lbl.setText("-"); acidReserved2Lbl.setText("-");
FSAccessControlTableController.resetTab(); FSAccessControlTableController.resetTab();
ServiceAccessControlTableController.resetTab();
} }
private void setData(NPDMProvider npdmProvider, File file) { private void setData(NPDMProvider npdmProvider, File file) {
if (npdmProvider == null) if (npdmProvider == null)
@ -223,6 +228,8 @@ public class NPDMController implements ITabController {
acidKernelAccessControlSizeLbl.setText(Integer.toString(acid.getKernelAccessControlSize())); acidKernelAccessControlSizeLbl.setText(Integer.toString(acid.getKernelAccessControlSize()));
acidReserved2Lbl.setText(byteArrToHexString(acid.getReserved2())); acidReserved2Lbl.setText(byteArrToHexString(acid.getReserved2()));
FSAccessControlTableController.populateFields(acid.getFSAccessControlProvider()); FSAccessControlTableController.populateFields(acid.getFsAccessControlProvider());
ServiceAccessControlTableController.populateFields(acid.getServiceAccessControlProvider().getCollection());
} }
} }

View file

@ -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<Byte, String> collection){
resetTab();
for (Object object : collection.entrySet()) {
Map.Entry<Byte, String> 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));
}
}
}

View file

@ -27,7 +27,7 @@ public class ACIDProvider {
private byte[] reserved2; private byte[] reserved2;
private FSAccessControlProvider fsAccessControlProvider; private FSAccessControlProvider fsAccessControlProvider;
private ServiceAccessControlProvider serviceAccessControlProvider;
public ACIDProvider(byte[] acidBytes) throws Exception{ public ACIDProvider(byte[] acidBytes) throws Exception{
if (acidBytes.length < 0x240) if (acidBytes.length < 0x240)
@ -53,6 +53,7 @@ public class ACIDProvider {
if (fsAccessControlOffset > serviceAccessControlOffset || serviceAccessControlOffset > kernelAccessControlOffset ) if (fsAccessControlOffset > serviceAccessControlOffset || serviceAccessControlOffset > kernelAccessControlOffset )
throw new Exception("ACIDProvider -> blocks inside the ACID are not sorted in ascending order. Only ascending order supported."); 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)); fsAccessControlProvider = new FSAccessControlProvider(Arrays.copyOfRange(acidBytes, fsAccessControlOffset, fsAccessControlOffset+fsAccessControlSize));
serviceAccessControlProvider = new ServiceAccessControlProvider(Arrays.copyOfRange(acidBytes, serviceAccessControlOffset, serviceAccessControlOffset+serviceAccessControlSize));
} }
public byte[] getRsa2048signature() { return rsa2048signature; } public byte[] getRsa2048signature() { return rsa2048signature; }
@ -74,6 +75,6 @@ public class ACIDProvider {
public int getKernelAccessControlSize() { return kernelAccessControlSize; } public int getKernelAccessControlSize() { return kernelAccessControlSize; }
public byte[] getReserved2() { return reserved2; } public byte[] getReserved2() { return reserved2; }
public FSAccessControlProvider getFSAccessControlProvider() { return fsAccessControlProvider; } public FSAccessControlProvider getFsAccessControlProvider() { return fsAccessControlProvider; }
public ServiceAccessControlProvider getServiceAccessControlProvider() { return serviceAccessControlProvider; }
} }

View file

@ -1,5 +1,6 @@
package konogonka.Tools.NPDM; package konogonka.Tools.NPDM;
import konogonka.RainbowHexDump;
import konogonka.Tools.ASuperInFileProvider; import konogonka.Tools.ASuperInFileProvider;
import java.io.*; import java.io.*;
@ -109,13 +110,13 @@ public class NPDMProvider extends ASuperInFileProvider {
acidSize = getLEint(metaBuf, 0x7C); acidSize = getLEint(metaBuf, 0x7C);
// Get ACI0 // Get ACI0
raf.seek(aci0offset); 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) if (raf.read(metaBuf) != aci0size)
throw new Exception("NPDMProvider: Failed to read 'ACI0'"); throw new Exception("NPDMProvider: Failed to read 'ACI0'");
aci0 = new ACI0Provider(metaBuf); aci0 = new ACI0Provider(metaBuf);
// Get ACID // Get ACID
raf.seek(acidOffset); 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) if (raf.read(metaBuf) != acidSize)
throw new Exception("NPDMProvider: Failed to read 'ACID'"); throw new Exception("NPDMProvider: Failed to read 'ACID'");
acid = new ACIDProvider(metaBuf); acid = new ACIDProvider(metaBuf);

View file

@ -0,0 +1,30 @@
package konogonka.Tools.NPDM;
import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
public class ServiceAccessControlProvider {
private LinkedHashMap<Byte, String> 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<Byte, String> getCollection() { return collection; }
}

File diff suppressed because it is too large Load diff

View file

@ -1174,6 +1174,7 @@
<Label text="** [5.0.0+] bit2-3: PoolPartition? For applets set to 0b01, for sysmodules set to 0b10. Exceptions: &quot;starter&quot; is set to 0, &quot;nvservices&quot; is set to 3" /> <Label text="** [5.0.0+] bit2-3: PoolPartition? For applets set to 0b01, for sysmodules set to 0b10. Exceptions: &quot;starter&quot; is set to 0, &quot;nvservices&quot; is set to 3" />
<Label text="*** Inside of ACID block" /> <Label text="*** Inside of ACID block" />
<fx:include fx:id="FSAccessControlTable" source="FSAccessControlTable.fxml" /> <fx:include fx:id="FSAccessControlTable" source="FSAccessControlTable.fxml" />
<fx:include fx:id="ServiceAccessControlTable" source="ServiceAccessControlTable.fxml" />
</children> </children>
</VBox> </VBox>
</content> </content>

View file

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="konogonka.Controllers.NPDM.ServiceAccessControlController">
<TitledPane text="Service Access Control">
<content>
<VBox>
<children>
<HBox VBox.vgrow="ALWAYS">
<children>
<Label text="CTRL">
<padding>
<Insets left="5.0" right="5.0" />
</padding>
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
<Label text="Service name">
<padding>
<Insets left="5.0" right="5.0" />
</padding>
<font>
<Font name="System Bold" size="13.0" />
</font>
</Label>
</children>
</HBox>
<VBox fx:id="SACPane" />
</children>
</VBox>
</content>
</TitledPane>
</VBox>