Ryujinx-git/Ryujinx.HLE/Loaders/Executables/NroExecutable.cs

38 lines
1.5 KiB
C#
Raw Normal View History

using LibHac;
using LibHac.Fs;
using System;
2018-02-04 23:08:20 +00:00
namespace Ryujinx.HLE.Loaders.Executables
2018-02-04 23:08:20 +00:00
{
class NroExecutable : Nro, IExecutable
2018-02-04 23:08:20 +00:00
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan().Slice((int)TextOffset, (int)Header.NroSegments[0].Size);
public Span<byte> Ro => Program.AsSpan().Slice((int)RoOffset, (int)Header.NroSegments[1].Size);
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)Header.NroSegments[2].Size);
2018-02-04 23:08:20 +00: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 23:08:20 +00:00
public uint Mod0Offset => (uint)Start.Mod0Offset;
public uint FileSize => Header.Size;
public ulong SourceAddress { get; private set; }
public ulong BssAddress { get; private set; }
public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
2018-02-04 23:08:20 +00:00
{
Program = new byte[FileSize];
SourceAddress = sourceAddress;
BssAddress = bssAddress;
OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
2018-02-04 23:08:20 +00:00
}
}
}