2018-02-04 18:08:20 -05:00
|
|
|
using System.IO;
|
|
|
|
|
2018-06-10 20:46:42 -04:00
|
|
|
namespace Ryujinx.HLE.Loaders.Executables
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-11-28 17:18:09 -05:00
|
|
|
class NxRelocatableObject : IExecutable
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
public byte[] Text { get; }
|
|
|
|
public byte[] Ro { get; }
|
|
|
|
public byte[] Data { get; }
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
public int Mod0Offset { get; }
|
|
|
|
public int TextOffset { get; }
|
|
|
|
public int RoOffset { get; }
|
|
|
|
public int DataOffset { get; }
|
|
|
|
public int BssSize { get; }
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-11-28 17:18:09 -05:00
|
|
|
public int BssOffset => DataOffset + Data.Length;
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
public ulong SourceAddress { get; }
|
|
|
|
public ulong BssAddress { get; }
|
2018-10-09 19:01:49 -04:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
public NxRelocatableObject(Stream input, ulong sourceAddress = 0, ulong bssAddress = 0)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
SourceAddress = sourceAddress;
|
|
|
|
BssAddress = bssAddress;
|
2018-04-22 00:21:49 -04:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
BinaryReader reader = new BinaryReader(input);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
input.Seek(4, SeekOrigin.Begin);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
int mod0Offset = reader.ReadInt32();
|
|
|
|
int padding8 = reader.ReadInt32();
|
|
|
|
int paddingC = reader.ReadInt32();
|
|
|
|
int nroMagic = reader.ReadInt32();
|
|
|
|
int unknown14 = reader.ReadInt32();
|
|
|
|
int fileSize = reader.ReadInt32();
|
|
|
|
int unknown1C = reader.ReadInt32();
|
|
|
|
int textOffset = reader.ReadInt32();
|
|
|
|
int textSize = reader.ReadInt32();
|
|
|
|
int roOffset = reader.ReadInt32();
|
|
|
|
int roSize = reader.ReadInt32();
|
|
|
|
int dataOffset = reader.ReadInt32();
|
|
|
|
int dataSize = reader.ReadInt32();
|
|
|
|
int bssSize = reader.ReadInt32();
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
Mod0Offset = mod0Offset;
|
|
|
|
TextOffset = textOffset;
|
|
|
|
RoOffset = roOffset;
|
|
|
|
DataOffset = dataOffset;
|
|
|
|
BssSize = bssSize;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
byte[] Read(long position, int size)
|
2018-02-04 18:08:20 -05:00
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
input.Seek(position, SeekOrigin.Begin);
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
return reader.ReadBytes(size);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
Text = Read(textOffset, textSize);
|
|
|
|
Ro = Read(roOffset, roSize);
|
|
|
|
Data = Read(dataOffset, dataSize);
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|