Add NRO icon loading

This commit is contained in:
Ryan Teal 2019-07-03 18:27:49 +01:00
parent 892960e8fd
commit e84e0c7705
No known key found for this signature in database
GPG Key ID: 8DBEE0F12C7E2D23

View File

@ -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;
}
}
}