NxRelocatableObject.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.IO;
  2. namespace Ryujinx.HLE.Loaders.Executables
  3. {
  4. class NxRelocatableObject : IExecutable
  5. {
  6. public byte[] Text { get; private set; }
  7. public byte[] Ro { get; private set; }
  8. public byte[] Data { get; private set; }
  9. public int Mod0Offset { get; private set; }
  10. public int TextOffset { get; private set; }
  11. public int RoOffset { get; private set; }
  12. public int DataOffset { get; private set; }
  13. public int BssSize { get; private set; }
  14. public int FileSize { get; private set; }
  15. public int BssOffset => DataOffset + Data.Length;
  16. public ulong SourceAddress { get; private set; }
  17. public ulong BssAddress { get; private set; }
  18. public NxRelocatableObject(Stream input, ulong sourceAddress = 0, ulong bssAddress = 0)
  19. {
  20. SourceAddress = sourceAddress;
  21. BssAddress = bssAddress;
  22. BinaryReader reader = new BinaryReader(input);
  23. input.Seek(4, SeekOrigin.Begin);
  24. int mod0Offset = reader.ReadInt32();
  25. int padding8 = reader.ReadInt32();
  26. int paddingC = reader.ReadInt32();
  27. int nroMagic = reader.ReadInt32();
  28. int unknown14 = reader.ReadInt32();
  29. int fileSize = reader.ReadInt32();
  30. int unknown1C = reader.ReadInt32();
  31. int textOffset = reader.ReadInt32();
  32. int textSize = reader.ReadInt32();
  33. int roOffset = reader.ReadInt32();
  34. int roSize = reader.ReadInt32();
  35. int dataOffset = reader.ReadInt32();
  36. int dataSize = reader.ReadInt32();
  37. int bssSize = reader.ReadInt32();
  38. Mod0Offset = mod0Offset;
  39. TextOffset = textOffset;
  40. RoOffset = roOffset;
  41. DataOffset = dataOffset;
  42. BssSize = bssSize;
  43. byte[] Read(long position, int size)
  44. {
  45. input.Seek(position, SeekOrigin.Begin);
  46. return reader.ReadBytes(size);
  47. }
  48. Text = Read(textOffset, textSize);
  49. Ro = Read(roOffset, roSize);
  50. Data = Read(dataOffset, dataSize);
  51. FileSize = fileSize;
  52. }
  53. }
  54. }