RomFs support

This commit is contained in:
Dmitry Isaenko 2020-04-29 18:07:30 +03:00
parent 416e5280a6
commit 270033b3f9
8 changed files with 36 additions and 15 deletions

View file

@ -45,6 +45,6 @@ JRE/JDK 8u60 or higher.
* [ ] CERT support * [ ] CERT support
* [ ] CNMT support * [ ] CNMT support
* [ ] NSO support * [ ] NSO support
* [ ] RomFS deep-dive * [x] RomFS
* [ ] LogPrinter to singleton implementation. * [ ] LogPrinter to singleton implementation.
* [x] 'Save to folder' option * [x] 'Save to folder' option

View file

@ -110,7 +110,7 @@ public class MainController implements Initializable {
fileChooser.setInitialDirectory(new File(System.getProperty("user.home"))); fileChooser.setInitialDirectory(new File(System.getProperty("user.home")));
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NS files", fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("NS files",
"*.nsp", "*.nsz", "*.xci", "*.nca", "*.tik", "*.xml", "*.npdm", "*.romfs")); "*.nsp", "*.nsz", "*.xci", "*.nca", "*.tik", "*.xml", "*.npdm", "*.bin"));
this.selectedFile = fileChooser.showOpenDialog(analyzeBtn.getScene().getWindow()); this.selectedFile = fileChooser.showOpenDialog(analyzeBtn.getScene().getWindow());
@ -156,7 +156,7 @@ public class MainController implements Initializable {
case "npdm": case "npdm":
tabPane.getSelectionModel().select(5); tabPane.getSelectionModel().select(5);
break; break;
case "romfs": case "bin":
tabPane.getSelectionModel().select(6); tabPane.getSelectionModel().select(6);
} }
} }
@ -185,7 +185,7 @@ public class MainController implements Initializable {
case "npdm": case "npdm":
NPDMTabController.analyze(selectedFile); NPDMTabController.analyze(selectedFile);
break; break;
case "romfs": case "bin":
RFSTabController.analyze(selectedFile); RFSTabController.analyze(selectedFile);
} }
} }
@ -198,7 +198,7 @@ public class MainController implements Initializable {
case "tik": case "tik":
case "xml": case "xml":
case "npdm": case "npdm":
case "romfs": case "bin":
return false; return false;
default: default:
return true; return true;

View file

@ -147,7 +147,15 @@ public class RomFsController implements ITabController {
@Override @Override
public void analyze(File file) { public void analyze(File file) {
Task<RomFsDecryptedProvider> analyzer = Analyzer.analyzeRomFS(file); long lv6offset = -1;
try{
System.out.println(file.getName().replaceAll("(^.*lv6\\s)|(]\\.bin)", ""));
lv6offset = Long.parseLong(file.getName().replaceAll("(^.*lv6\\s)|(]\\.bin)", ""));
}
catch (Exception e){
e.printStackTrace();
}
Task<RomFsDecryptedProvider> analyzer = Analyzer.analyzeRomFS(file, lv6offset);
analyzer.setOnSucceeded(e->{ analyzer.setOnSucceeded(e->{
RomFsDecryptedProvider provider = analyzer.getValue(); RomFsDecryptedProvider provider = analyzer.getValue();
this.setData(provider); this.setData(provider);

View file

@ -23,6 +23,7 @@ import java.io.File;
import java.io.PipedInputStream; import java.io.PipedInputStream;
public interface IRomFsProvider { public interface IRomFsProvider {
long getLevel6Offset();
Level6Header getHeader(); Level6Header getHeader();
FileSystemEntry getRootEntry(); FileSystemEntry getRootEntry();
PipedInputStream getContent(FileSystemEntry entry) throws Exception; PipedInputStream getContent(FileSystemEntry entry) throws Exception;

View file

@ -23,20 +23,24 @@ import java.io.*;
public class RomFsDecryptedProvider implements IRomFsProvider{ public class RomFsDecryptedProvider implements IRomFsProvider{
private static final long LEVEL_6_DEFAULT_OFFSET = 0x14000; // TODO: FIX incorrect private long level6Offset;
private File file; private File file;
private Level6Header header; private Level6Header header;
private FileSystemEntry rootEntry; private FileSystemEntry rootEntry;
// TODO: FIX. LEVEL 6 OFFSET MUST be provided
public RomFsDecryptedProvider(File decryptedFsImageFile) throws Exception{ // TODO: add default setup AND using meta-data headers from NCA RomFs section (?) public RomFsDecryptedProvider(File decryptedFsImageFile, long level6Offset) throws Exception{
if (level6Offset < 0)
throw new Exception("Incorrect Level 6 Offset");
this.file = decryptedFsImageFile; this.file = decryptedFsImageFile;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(decryptedFsImageFile)); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(decryptedFsImageFile));
skipBytes(bis, LEVEL_6_DEFAULT_OFFSET); this.level6Offset = level6Offset;
skipBytes(bis, level6Offset);
byte[] rawDataChunk = new byte[0x50]; byte[] rawDataChunk = new byte[0x50];
@ -98,6 +102,8 @@ public class RomFsDecryptedProvider implements IRomFsProvider{
} }
} }
@Override @Override
public long getLevel6Offset() { return level6Offset; }
@Override
public Level6Header getHeader() { return header; } public Level6Header getHeader() { return header; }
@Override @Override
public FileSystemEntry getRootEntry() { return rootEntry; } public FileSystemEntry getRootEntry() { return rootEntry; }
@ -114,7 +120,7 @@ public class RomFsDecryptedProvider implements IRomFsProvider{
workerThread = new Thread(() -> { workerThread = new Thread(() -> {
System.out.println("RomFsDecryptedProvider -> getContent(): Executing thread"); System.out.println("RomFsDecryptedProvider -> getContent(): Executing thread");
try { try {
long subFileRealPosition = LEVEL_6_DEFAULT_OFFSET + header.getFileDataOffset() + entry.getFileOffset(); long subFileRealPosition = level6Offset + header.getFileDataOffset() + entry.getFileOffset();
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file)); BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
skipBytes(bis, subFileRealPosition); skipBytes(bis, subFileRealPosition);

View file

@ -176,6 +176,8 @@ public class RomFsEncryptedProvider implements IRomFsProvider{
return metadataTable; return metadataTable;
} }
@Override
public long getLevel6Offset() { return level6Offset; }
@Override @Override
public Level6Header getHeader() { return header; } public Level6Header getHeader() { return header; }
@Override @Override

View file

@ -161,14 +161,14 @@ public class Analyzer {
}; };
} }
public static Task<RomFsDecryptedProvider> analyzeRomFS(File file){ public static Task<RomFsDecryptedProvider> analyzeRomFS(File file, long lv6offset){
LogPrinter logPrinter = new LogPrinter(); LogPrinter logPrinter = new LogPrinter();
return new Task<RomFsDecryptedProvider>() { return new Task<RomFsDecryptedProvider>() {
@Override @Override
protected RomFsDecryptedProvider call() { protected RomFsDecryptedProvider call() {
logPrinter.print("\tStart chain: RomFS", EMsgType.INFO); logPrinter.print("\tStart chain: RomFS", EMsgType.INFO);
try { try {
return new RomFsDecryptedProvider(file); return new RomFsDecryptedProvider(file, lv6offset);
} catch (Exception e) { } catch (Exception e) {
logPrinter.print(e.getMessage(), EMsgType.FAIL); logPrinter.print(e.getMessage(), EMsgType.FAIL);
return null; return null;

View file

@ -26,8 +26,12 @@ public class DumbNCA3ContentExtractor extends Task<Void> {
@Override @Override
protected Void call() { protected Void call() {
logPrinter.print("\tStart dummy extracting: \n"+filesDestPath+"NCAContent_"+ncaNumberInFile+".bin", EMsgType.INFO); String lv6mark = "";
File contentFile = new File(filesDestPath + "NCAContent_"+ncaNumberInFile+".bin"); if (ncaContent.getRomfs() != null){
lv6mark = " [lv6 "+ncaContent.getRomfs().getLevel6Offset()+"]";
}
logPrinter.print("\tStart dummy extracting: \n"+filesDestPath+"NCAContent_"+ncaNumberInFile+lv6mark+".bin", EMsgType.INFO);
File contentFile = new File(filesDestPath + "NCAContent_"+ncaNumberInFile+lv6mark+".bin");
try { try {
BufferedOutputStream extractedFileBOS = new BufferedOutputStream(new FileOutputStream(contentFile)); BufferedOutputStream extractedFileBOS = new BufferedOutputStream(new FileOutputStream(contentFile));
PipedInputStream pis = ncaContent.getRawDataContentPipedInpStream(); PipedInputStream pis = ncaContent.getRawDataContentPipedInpStream();