From eb8f9928ed95b86d5b7e662b0ba108bae71a876c Mon Sep 17 00:00:00 2001 From: Ryan Teal Date: Wed, 3 Jul 2019 15:42:08 +0100 Subject: [PATCH] Add NRO TitleEntry parsing --- .../java/gq/cyuubi/lightswitch/NroMeta.java | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java diff --git a/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java new file mode 100644 index 00000000..e818bd04 --- /dev/null +++ b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java @@ -0,0 +1,57 @@ +package gq.cyuubi.lightswitch; + +import android.util.Log; + +import java.io.IOException; +import java.io.RandomAccessFile; + +final class TitleEntry { + private final String name; + private final String author; + + public TitleEntry(String name, String author) { + this.name = name; + this.author = author; + } + + public String Name() { + return name; + } + + public String Author() { + return author; + } +} + +public class NroMeta { + public static TitleEntry GetNroTitle(String file) { + try { + RandomAccessFile f = new RandomAccessFile(file, "r"); + f.seek(0x18); // Skip to NroHeader.size + int asetOffset = Integer.reverseBytes(f.readInt()); + f.seek(asetOffset); // Skip to the offset specified by NroHeader.size + byte[] buffer = new byte[4]; + f.read(buffer); + if(!(new String(buffer).equals("ASET"))) + return null; + + f.skipBytes(0x14); + long nacpOffset = Long.reverseBytes(f.readLong()); + long nacpSize = Long.reverseBytes(f.readLong()); + if(nacpOffset == 0 || nacpSize == 0) + return null; + + f.seek(asetOffset + nacpOffset); + byte[] name = new byte[0x200]; + f.read(name); + byte[] author = new byte[0x100]; + f.read(author); + + return new TitleEntry(new String(name).trim(), new String(author).trim()); + } + catch(IOException e) { + Log.e("app_process64", "Error while loading ASET: " + e.getMessage()); + return null; + } + } +}