From e84e0c77057dc783c6880c817014ded19774622d Mon Sep 17 00:00:00 2001 From: Ryan Teal Date: Wed, 3 Jul 2019 18:27:49 +0100 Subject: [PATCH] Add NRO icon loading --- .../java/gq/cyuubi/lightswitch/NroMeta.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java index e818bd04..7e8b06cf 100644 --- a/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java +++ b/app/src/main/java/gq/cyuubi/lightswitch/NroMeta.java @@ -1,8 +1,13 @@ package gq.cyuubi.lightswitch; +import android.content.Context; +import android.content.ContextWrapper; +import android.os.Environment; import android.util.Log; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.RandomAccessFile; final class TitleEntry { @@ -54,4 +59,34 @@ public class NroMeta { return null; } } + + public static String LoadImage(String file, MainActivity context) { + 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(0x4); + long iconOffset = Long.reverseBytes(f.readLong()); + long iconSize = Long.reverseBytes(f.readLong()); + if(iconOffset == 0 || iconSize == 0) + return null; + f.seek(asetOffset + iconOffset); + + byte[] iconData = new byte[(int)iconSize]; + f.read(iconData); + + new FileOutputStream(context.getFilesDir() + "/tmp.jpg").write(iconData); + return context.getFilesDir() + "/tmp.jpg"; + } + catch(IOException e) { + Log.e("app_process64", "Error while loading ASET: " + e.getMessage()); + return null; + } + } }