Added NRO Asset parsing

This commit is contained in:
emmaus 2018-06-17 09:37:34 +00:00
parent 3c4dafff3f
commit 37a9880ae7

View file

@ -1,4 +1,7 @@
using System;
using System.Drawing;
using System.IO; using System.IO;
using System.Text;
namespace Ryujinx.HLE.Loaders.Executables namespace Ryujinx.HLE.Loaders.Executables
{ {
@ -6,15 +9,19 @@ namespace Ryujinx.HLE.Loaders.Executables
{ {
public string Name { get; private set; } public string Name { get; private set; }
public byte[] Text { get; private set; } public byte[] Text { get; private set; }
public byte[] RO { get; private set; } public byte[] RO { get; private set; }
public byte[] Data { get; private set; } public byte[] Data { get; private set; }
public byte[] AssetRomfData { get; set; }
public byte[] IconData { get; set; }
public byte[] NCAPData { get; set; }
public int Mod0Offset { get; private set; } public int Mod0Offset { get; private set; }
public int TextOffset { get; private set; } public int TextOffset { get; private set; }
public int ROOffset { get; private set; } public int ROOffset { get; private set; }
public int DataOffset { get; private set; } public int DataOffset { get; private set; }
public int BssSize { get; private set; } public int BssSize { get; private set; }
public int AssetOffset { get; set; }
public Nro(Stream Input, string Name) public Nro(Stream Input, string Name)
{ {
@ -39,11 +46,12 @@ namespace Ryujinx.HLE.Loaders.Executables
int DataSize = Reader.ReadInt32(); int DataSize = Reader.ReadInt32();
int BssSize = Reader.ReadInt32(); int BssSize = Reader.ReadInt32();
this.Mod0Offset = Mod0Offset; this.Mod0Offset = Mod0Offset;
this.TextOffset = TextOffset; this.TextOffset = TextOffset;
this.ROOffset = ROOffset; this.ROOffset = ROOffset;
this.DataOffset = DataOffset; this.DataOffset = DataOffset;
this.BssSize = BssSize; this.BssSize = BssSize;
this.AssetOffset = FileSize;
byte[] Read(long Position, int Size) byte[] Read(long Position, int Size)
{ {
@ -55,6 +63,37 @@ namespace Ryujinx.HLE.Loaders.Executables
Text = Read(TextOffset, TextSize); Text = Read(TextOffset, TextSize);
RO = Read(ROOffset, ROSize); RO = Read(ROOffset, ROSize);
Data = Read(DataOffset, DataSize); Data = Read(DataOffset, DataSize);
if (Input.Length > FileSize)
{
string AssetMagic = Encoding.ASCII.GetString(Read(AssetOffset, 4));
if (AssetMagic == "ASET")
{
Input.Seek(AssetOffset, SeekOrigin.Begin);
int AssetMagic0 = Reader.ReadInt32();
int AssetFormat = Reader.ReadInt32();
byte[] IconSectionInfo = Reader.ReadBytes(0x10);
byte[] NACPSectionInfo = Reader.ReadBytes(0x10);
byte[] AssetRomfSectionInfo = Reader.ReadBytes(0x10);
long IconOffset = BitConverter.ToInt64(IconSectionInfo, 0);
long IconSize = BitConverter.ToInt64(IconSectionInfo, 8);
long NACPOffset = BitConverter.ToInt64(NACPSectionInfo, 0);
long NACPSize = BitConverter.ToInt64(NACPSectionInfo, 8);
long RomfOffset = BitConverter.ToInt64(AssetRomfSectionInfo, 0);
long RomfSize = BitConverter.ToInt64(AssetRomfSectionInfo, 8);
Input.Seek(AssetOffset + IconOffset, SeekOrigin.Begin);
IconData = Reader.ReadBytes((int)IconSize);
Input.Seek(AssetOffset + NACPOffset, SeekOrigin.Begin);
NCAPData = Reader.ReadBytes((int)NACPSize);
Input.Seek(AssetOffset + RomfOffset, SeekOrigin.Begin);
AssetRomfData = Reader.ReadBytes((int)RomfSize);
}
}
} }
} }
} }