1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-24 10:42:06 +00:00
Ryujinx/Ryujinx.HLE/Loaders/Executables/NxRelocatableObject.cs

67 lines
2.2 KiB
C#
Raw Normal View History

2018-02-04 23:08:20 +00:00
using System.IO;
namespace Ryujinx.HLE.Loaders.Executables
2018-02-04 23:08:20 +00:00
{
class NxRelocatableObject : IExecutable
2018-02-04 23:08:20 +00:00
{
public byte[] Text { get; private set; }
public byte[] Ro { get; private set; }
public byte[] Data { get; private set; }
2018-02-04 23:08:20 +00:00
public int Mod0Offset { get; private set; }
public int TextOffset { get; private set; }
public int RoOffset { get; private set; }
public int DataOffset { get; private set; }
public int BssSize { get; private set; }
public int FileSize { get; private set; }
2018-02-04 23:08:20 +00:00
public int BssOffset => DataOffset + Data.Length;
public ulong SourceAddress { get; private set; }
public ulong BssAddress { get; private set; }
public NxRelocatableObject(Stream input, ulong sourceAddress = 0, ulong bssAddress = 0)
2018-02-04 23:08:20 +00:00
{
SourceAddress = sourceAddress;
BssAddress = bssAddress;
BinaryReader reader = new BinaryReader(input);
2018-02-04 23:08:20 +00:00
input.Seek(4, SeekOrigin.Begin);
2018-02-04 23:08:20 +00: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 23:08:20 +00:00
Mod0Offset = mod0Offset;
TextOffset = textOffset;
RoOffset = roOffset;
DataOffset = dataOffset;
BssSize = bssSize;
2018-02-04 23:08:20 +00:00
byte[] Read(long position, int size)
2018-02-04 23:08:20 +00:00
{
input.Seek(position, SeekOrigin.Begin);
2018-02-04 23:08:20 +00:00
return reader.ReadBytes(size);
2018-02-04 23:08:20 +00:00
}
Text = Read(textOffset, textSize);
Ro = Read(roOffset, roSize);
Data = Read(dataOffset, dataSize);
FileSize = fileSize;
2018-02-04 23:08:20 +00:00
}
}
}