2020-07-09 06:31:15 +02:00
|
|
|
using LibHac;
|
|
|
|
using LibHac.Fs;
|
|
|
|
using System;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-06-11 02:46:42 +02:00
|
|
|
namespace Ryujinx.HLE.Loaders.Executables
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2020-07-09 06:31:15 +02:00
|
|
|
class NroExecutable : Nro, IExecutable
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2020-07-09 06:31:15 +02:00
|
|
|
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);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2020-07-09 06:31:15 +02:00
|
|
|
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;
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2020-07-09 06:31:15 +02:00
|
|
|
public int Mod0Offset => Start.Mod0Offset;
|
|
|
|
public int FileSize => (int)Header.Size;
|
2018-11-28 23:18:09 +01:00
|
|
|
|
2018-12-05 01:52:39 +01:00
|
|
|
public ulong SourceAddress { get; private set; }
|
|
|
|
public ulong BssAddress { get; private set; }
|
2018-10-10 01:01:49 +02:00
|
|
|
|
2020-07-09 06:31:15 +02:00
|
|
|
public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2020-07-09 06:31:15 +02:00
|
|
|
Program = new byte[FileSize];
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
SourceAddress = sourceAddress;
|
|
|
|
BssAddress = bssAddress;
|
2018-04-22 06:21:49 +02:00
|
|
|
|
2020-07-09 06:31:15 +02:00
|
|
|
OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
|
|
|
|
OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
|
|
|
|
OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|