/ src / Ryujinx.HLE / Loaders / Executables / NroExecutable.cs
NroExecutable.cs
 1  using LibHac.Fs;
 2  using LibHac.Tools.Ro;
 3  using System;
 4  
 5  namespace Ryujinx.HLE.Loaders.Executables
 6  {
 7      class NroExecutable : Nro, IExecutable
 8      {
 9          public byte[] Program { get; }
10          public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)Header.NroSegments[0].Size);
11          public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size);
12          public Span<byte> Data => Program.AsSpan((int)DataOffset, (int)Header.NroSegments[2].Size);
13  
14          public uint TextOffset => Header.NroSegments[0].FileOffset;
15          public uint RoOffset => Header.NroSegments[1].FileOffset;
16          public uint DataOffset => Header.NroSegments[2].FileOffset;
17          public uint BssOffset => DataOffset + (uint)Data.Length;
18          public uint BssSize => Header.BssSize;
19  
20          public uint Mod0Offset => (uint)Start.Mod0Offset;
21          public uint FileSize => Header.Size;
22  
23          public ulong SourceAddress { get; private set; }
24          public ulong BssAddress { get; private set; }
25  
26          public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
27          {
28              Program = new byte[FileSize];
29  
30              SourceAddress = sourceAddress;
31              BssAddress = bssAddress;
32  
33              OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
34              OpenNroSegment(NroSegmentType.Ro, false).Read(0, Ro);
35              OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
36          }
37      }
38  }