2020-07-09 00:31:15 -04:00
|
|
|
using LibHac.Fs;
|
2022-01-12 06:22:19 -05:00
|
|
|
using LibHac.Tools.Ro;
|
2020-07-09 00:31:15 -04:00
|
|
|
using System;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-06-10 20:46:42 -04:00
|
|
|
namespace Ryujinx.HLE.Loaders.Executables
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2020-07-09 00:31:15 -04:00
|
|
|
class NroExecutable : Nro, IExecutable
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2020-07-09 00:31:15 -04:00
|
|
|
public byte[] Program { get; }
|
2022-02-22 08:32:10 -05:00
|
|
|
public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)Header.NroSegments[0].Size);
|
|
|
|
public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size);
|
|
|
|
public Span<byte> Data => Program.AsSpan((int)DataOffset, (int)Header.NroSegments[2].Size);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2020-12-13 02:30:27 -05:00
|
|
|
public uint TextOffset => Header.NroSegments[0].FileOffset;
|
|
|
|
public uint RoOffset => Header.NroSegments[1].FileOffset;
|
|
|
|
public uint DataOffset => Header.NroSegments[2].FileOffset;
|
|
|
|
public uint BssOffset => DataOffset + (uint)Data.Length;
|
|
|
|
public uint BssSize => Header.BssSize;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2020-12-13 02:30:27 -05:00
|
|
|
public uint Mod0Offset => (uint)Start.Mod0Offset;
|
|
|
|
public uint FileSize => Header.Size;
|
2018-11-28 17:18:09 -05:00
|
|
|
|
2018-12-04 19:52:39 -05:00
|
|
|
public ulong SourceAddress { get; private set; }
|
|
|
|
public ulong BssAddress { get; private set; }
|
2018-10-09 19:01:49 -04:00
|
|
|
|
2020-07-09 00:31:15 -04:00
|
|
|
public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2020-07-09 00:31:15 -04:00
|
|
|
Program = new byte[FileSize];
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
SourceAddress = sourceAddress;
|
|
|
|
BssAddress = bssAddress;
|
2018-04-22 00:21:49 -04:00
|
|
|
|
2020-07-09 00:31:15 -04:00
|
|
|
OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
|
|
|
|
OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
|
|
|
|
OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|