2020-04-07 23:41:02 +01:00
|
|
|
using LibHac.Fs;
|
2020-07-04 00:58:01 +01:00
|
|
|
using LibHac.FsSystem;
|
|
|
|
using LibHac.Loader;
|
2020-04-07 23:41:02 +01:00
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Loaders.Executables
|
|
|
|
{
|
2020-07-04 00:58:01 +01:00
|
|
|
class NsoExecutable : IExecutable
|
2020-04-07 23:41:02 +01:00
|
|
|
{
|
|
|
|
public byte[] Text { get; }
|
|
|
|
public byte[] Ro { get; }
|
|
|
|
public byte[] Data { get; }
|
|
|
|
|
2020-07-04 00:58:01 +01:00
|
|
|
public int TextOffset { get; }
|
|
|
|
public int RoOffset { get; }
|
|
|
|
public int DataOffset { get; }
|
2020-04-07 23:41:02 +01:00
|
|
|
public int BssOffset => DataOffset + Data.Length;
|
|
|
|
|
2020-07-04 00:58:01 +01:00
|
|
|
public int BssSize { get; }
|
2020-04-07 23:41:02 +01:00
|
|
|
|
2020-07-04 00:58:01 +01:00
|
|
|
public NsoExecutable(IStorage inStorage)
|
2020-04-07 23:41:02 +01:00
|
|
|
{
|
2020-07-04 00:58:01 +01:00
|
|
|
NsoReader reader = new NsoReader();
|
|
|
|
|
|
|
|
reader.Initialize(inStorage.AsFile(OpenMode.Read)).ThrowIfFailure();
|
|
|
|
|
|
|
|
TextOffset = (int)reader.Header.Segments[0].MemoryOffset;
|
|
|
|
RoOffset = (int)reader.Header.Segments[1].MemoryOffset;
|
|
|
|
DataOffset = (int)reader.Header.Segments[2].MemoryOffset;
|
|
|
|
BssSize = (int)reader.Header.BssSize;
|
|
|
|
|
|
|
|
Text = DecompressSection(reader, NsoReader.SegmentType.Text);
|
|
|
|
Ro = DecompressSection(reader, NsoReader.SegmentType.Ro);
|
|
|
|
Data = DecompressSection(reader, NsoReader.SegmentType.Data);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static byte[] DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType)
|
|
|
|
{
|
|
|
|
reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();
|
|
|
|
|
|
|
|
byte[] result = new byte[uncompressedSize];
|
|
|
|
|
|
|
|
reader.ReadSegment(segmentType, result).ThrowIfFailure();
|
|
|
|
|
|
|
|
return result;
|
2020-04-07 23:41:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|