From 37a9880ae72cf5ec6f4452d83f18915c95e5161a Mon Sep 17 00:00:00 2001 From: emmaus Date: Sun, 17 Jun 2018 09:37:34 +0000 Subject: [PATCH] Added NRO Asset parsing --- Ryujinx.HLE/Loaders/Executables/Nro.cs | 65 ++++++++++++++++++++------ 1 file changed, 52 insertions(+), 13 deletions(-) diff --git a/Ryujinx.HLE/Loaders/Executables/Nro.cs b/Ryujinx.HLE/Loaders/Executables/Nro.cs index 9e2b7e9073..671936c8ef 100644 --- a/Ryujinx.HLE/Loaders/Executables/Nro.cs +++ b/Ryujinx.HLE/Loaders/Executables/Nro.cs @@ -1,4 +1,7 @@ +using System; +using System.Drawing; using System.IO; +using System.Text; namespace Ryujinx.HLE.Loaders.Executables { @@ -6,15 +9,19 @@ namespace Ryujinx.HLE.Loaders.Executables { public string Name { get; private set; } - public byte[] Text { get; private set; } - public byte[] RO { get; private set; } - public byte[] Data { get; private set; } + public byte[] Text { get; private set; } + public byte[] RO { 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 TextOffset { get; private set; } - public int ROOffset { get; private set; } - public int DataOffset { get; private set; } - public int BssSize { get; private set; } + public int Mod0Offset { get; private set; } + public int TextOffset { get; private set; } + public int ROOffset { get; private set; } + public int DataOffset { get; private set; } + public int BssSize { get; private set; } + public int AssetOffset { get; set; } public Nro(Stream Input, string Name) { @@ -39,11 +46,12 @@ namespace Ryujinx.HLE.Loaders.Executables int DataSize = Reader.ReadInt32(); int BssSize = Reader.ReadInt32(); - this.Mod0Offset = Mod0Offset; - this.TextOffset = TextOffset; - this.ROOffset = ROOffset; - this.DataOffset = DataOffset; - this.BssSize = BssSize; + this.Mod0Offset = Mod0Offset; + this.TextOffset = TextOffset; + this.ROOffset = ROOffset; + this.DataOffset = DataOffset; + this.BssSize = BssSize; + this.AssetOffset = FileSize; byte[] Read(long Position, int Size) { @@ -55,6 +63,37 @@ namespace Ryujinx.HLE.Loaders.Executables Text = Read(TextOffset, TextSize); RO = Read(ROOffset, ROSize); 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); + } + } } } } \ No newline at end of file