aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.HLE/Loaders/Executables/NroExecutable.cs')
-rw-r--r--Ryujinx.HLE/Loaders/Executables/NroExecutable.cs71
1 files changed, 21 insertions, 50 deletions
diff --git a/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs b/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs
index 4a7f2116..b7a887b7 100644
--- a/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs
+++ b/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs
@@ -1,67 +1,38 @@
-using System.IO;
+using LibHac;
+using LibHac.Fs;
+using System;
namespace Ryujinx.HLE.Loaders.Executables
{
- class NroExecutable : IExecutable
+ class NroExecutable : Nro, IExecutable
{
- public byte[] Text { get; private set; }
- public byte[] Ro { get; private set; }
- public byte[] Data { get; private set; }
+ public byte[] Program { get; }
+ public Span<byte> Text => Program.AsSpan().Slice(TextOffset, (int)Header.NroSegments[0].Size);
+ public Span<byte> Ro => Program.AsSpan().Slice(RoOffset, (int)Header.NroSegments[1].Size);
+ public Span<byte> Data => Program.AsSpan().Slice(DataOffset, (int)Header.NroSegments[2].Size);
- 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 FileSize { get; private set; }
+ public int TextOffset => (int)Header.NroSegments[0].FileOffset;
+ public int RoOffset => (int)Header.NroSegments[1].FileOffset;
+ public int DataOffset => (int)Header.NroSegments[2].FileOffset;
+ public int BssOffset => DataOffset + Data.Length;
+ public int BssSize => (int)Header.BssSize;
- public int BssOffset => DataOffset + Data.Length;
+ public int Mod0Offset => Start.Mod0Offset;
+ public int FileSize => (int)Header.Size;
public ulong SourceAddress { get; private set; }
public ulong BssAddress { get; private set; }
- public NroExecutable(Stream input, ulong sourceAddress = 0, ulong bssAddress = 0)
+ public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
{
+ Program = new byte[FileSize];
+
SourceAddress = sourceAddress;
BssAddress = bssAddress;
- BinaryReader reader = new BinaryReader(input);
-
- input.Seek(4, SeekOrigin.Begin);
-
- int mod0Offset = reader.ReadInt32();
- int padding8 = reader.ReadInt32();
- int paddingC = reader.ReadInt32();
- int nroMagic = reader.ReadInt32();
- int unknown14 = reader.ReadInt32();
- int fileSize = reader.ReadInt32();
- int unknown1C = reader.ReadInt32();
- int textOffset = reader.ReadInt32();
- int textSize = reader.ReadInt32();
- int roOffset = reader.ReadInt32();
- int roSize = reader.ReadInt32();
- int dataOffset = reader.ReadInt32();
- int dataSize = reader.ReadInt32();
- int bssSize = reader.ReadInt32();
-
- Mod0Offset = mod0Offset;
- TextOffset = textOffset;
- RoOffset = roOffset;
- DataOffset = dataOffset;
- BssSize = bssSize;
-
- byte[] Read(long position, int size)
- {
- input.Seek(position, SeekOrigin.Begin);
-
- return reader.ReadBytes(size);
- }
-
- Text = Read(textOffset, textSize);
- Ro = Read(roOffset, roSize);
- Data = Read(dataOffset, dataSize);
-
- FileSize = fileSize;
+ OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
+ OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
+ OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
}
}
} \ No newline at end of file