NroExecutable.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using LibHac.Fs;
  2. using LibHac.Tools.Ro;
  3. using System;
  4. namespace Ryujinx.HLE.Loaders.Executables
  5. {
  6. class NroExecutable : Nro, IExecutable
  7. {
  8. public byte[] Program { get; }
  9. public Span<byte> Text => Program.AsSpan((int)TextOffset, (int)Header.NroSegments[0].Size);
  10. public Span<byte> Ro => Program.AsSpan((int)RoOffset, (int)Header.NroSegments[1].Size);
  11. public Span<byte> Data => Program.AsSpan((int)DataOffset, (int)Header.NroSegments[2].Size);
  12. public uint TextOffset => Header.NroSegments[0].FileOffset;
  13. public uint RoOffset => Header.NroSegments[1].FileOffset;
  14. public uint DataOffset => Header.NroSegments[2].FileOffset;
  15. public uint BssOffset => DataOffset + (uint)Data.Length;
  16. public uint BssSize => Header.BssSize;
  17. public uint Mod0Offset => (uint)Start.Mod0Offset;
  18. public uint FileSize => Header.Size;
  19. public ulong SourceAddress { get; private set; }
  20. public ulong BssAddress { get; private set; }
  21. public NroExecutable(IStorage inStorage, ulong sourceAddress = 0, ulong bssAddress = 0) : base(inStorage)
  22. {
  23. Program = new byte[FileSize];
  24. SourceAddress = sourceAddress;
  25. BssAddress = bssAddress;
  26. OpenNroSegment(NroSegmentType.Text, false).Read(0, Text);
  27. OpenNroSegment(NroSegmentType.Ro , false).Read(0, Ro);
  28. OpenNroSegment(NroSegmentType.Data, false).Read(0, Data);
  29. }
  30. }
  31. }