aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs')
-rw-r--r--Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs43
1 files changed, 31 insertions, 12 deletions
diff --git a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs
index 6050432d..bbe2c87f 100644
--- a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs
+++ b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs
@@ -1,28 +1,47 @@
-using LibHac;
using LibHac.Fs;
-using System;
-using System.IO;
+using LibHac.FsSystem;
+using LibHac.Loader;
namespace Ryujinx.HLE.Loaders.Executables
{
- class NsoExecutable : Nso, IExecutable
+ class NsoExecutable : IExecutable
{
public byte[] Text { get; }
public byte[] Ro { get; }
public byte[] Data { get; }
- public int TextOffset => (int)Sections[0].MemoryOffset;
- public int RoOffset => (int)Sections[1].MemoryOffset;
- public int DataOffset => (int)Sections[2].MemoryOffset;
+ public int TextOffset { get; }
+ public int RoOffset { get; }
+ public int DataOffset { get; }
public int BssOffset => DataOffset + Data.Length;
- public new int BssSize => (int)base.BssSize;
+ public int BssSize { get; }
- public NsoExecutable(IStorage inStorage) : base(inStorage)
+ public NsoExecutable(IStorage inStorage)
{
- Text = Sections[0].DecompressSection();
- Ro = Sections[1].DecompressSection();
- Data = Sections[2].DecompressSection();
+ NsoReader reader = new NsoReader();
+
+ reader.Initialize(inStorage.AsFile(OpenMode.Read)).ThrowIfFailure();
+
+ TextOffset = (int)reader.Header.Segments[0].MemoryOffset;
+ RoOffset = (int)reader.Header.Segments[1].MemoryOffset;
+ DataOffset = (int)reader.Header.Segments[2].MemoryOffset;
+ BssSize = (int)reader.Header.BssSize;
+
+ Text = DecompressSection(reader, NsoReader.SegmentType.Text);
+ Ro = DecompressSection(reader, NsoReader.SegmentType.Ro);
+ Data = DecompressSection(reader, NsoReader.SegmentType.Data);
+ }
+
+ private static byte[] DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType)
+ {
+ reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();
+
+ byte[] result = new byte[uncompressedSize];
+
+ reader.ReadSegment(segmentType, result).ThrowIfFailure();
+
+ return result;
}
}
} \ No newline at end of file