Correct type of executable sizes (#1802)

This commit is contained in:
gdkchan 2020-12-13 04:30:27 -03:00 committed by GitHub
parent ef157bbe26
commit 19d18662ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 95 additions and 77 deletions

View file

@ -4,15 +4,15 @@ namespace Ryujinx.HLE.Loaders.Executables
{
interface IExecutable
{
byte[] Program { get; }
byte[] Program { get; }
Span<byte> Text { get; }
Span<byte> Ro { get; }
Span<byte> Data { get; }
int TextOffset { get; }
int RoOffset { get; }
int DataOffset { get; }
int BssOffset { get; }
int BssSize { get; }
uint TextOffset { get; }
uint RoOffset { get; }
uint DataOffset { get; }
uint BssOffset { get; }
uint BssSize { get; }
}
}

View file

@ -7,19 +7,19 @@ namespace Ryujinx.HLE.Loaders.Executables
class KipExecutable : IExecutable
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan().Slice(TextOffset, TextSize);
public Span<byte> Ro => Program.AsSpan().Slice(RoOffset, RoSize);
public Span<byte> Data => Program.AsSpan().Slice(DataOffset, DataSize);
public Span<byte> Text => Program.AsSpan().Slice((int)TextOffset, (int)TextSize);
public Span<byte> Ro => Program.AsSpan().Slice((int)RoOffset, (int)RoSize);
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize);
public int TextOffset { get; }
public int RoOffset { get; }
public int DataOffset { get; }
public int BssOffset { get; }
public uint TextOffset { get; }
public uint RoOffset { get; }
public uint DataOffset { get; }
public uint BssOffset { get; }
public int TextSize { get; }
public int RoSize { get; }
public int DataSize { get; }
public int BssSize { get; }
public uint TextSize { get; }
public uint RoSize { get; }
public uint DataSize { get; }
public uint BssSize { get; }
public int[] Capabilities { get; }
public bool UsesSecureMemory { get; }
@ -38,11 +38,11 @@ namespace Ryujinx.HLE.Loaders.Executables
reader.Initialize(inStorage).ThrowIfFailure();
TextOffset = reader.Segments[0].MemoryOffset;
RoOffset = reader.Segments[1].MemoryOffset;
DataOffset = reader.Segments[2].MemoryOffset;
BssOffset = reader.Segments[3].MemoryOffset;
BssSize = reader.Segments[3].Size;
TextOffset = (uint)reader.Segments[0].MemoryOffset;
RoOffset = (uint)reader.Segments[1].MemoryOffset;
DataOffset = (uint)reader.Segments[2].MemoryOffset;
BssOffset = (uint)reader.Segments[3].MemoryOffset;
BssSize = (uint)reader.Segments[3].Size;
StackSize = reader.StackSize;
@ -71,15 +71,15 @@ namespace Ryujinx.HLE.Loaders.Executables
DataSize = DecompressSection(reader, KipReader.SegmentType.Data, DataOffset, Program);
}
private static int DecompressSection(KipReader reader, KipReader.SegmentType segmentType, int offset, byte[] program)
private static uint DecompressSection(KipReader reader, KipReader.SegmentType segmentType, uint offset, byte[] program)
{
reader.GetSegmentSize(segmentType, out int uncompressedSize).ThrowIfFailure();
var span = program.AsSpan().Slice(offset, uncompressedSize);
var span = program.AsSpan().Slice((int)offset, uncompressedSize);
reader.ReadSegment(segmentType, span).ThrowIfFailure();
return uncompressedSize;
return (uint)uncompressedSize;
}
}
}

View file

@ -7,18 +7,18 @@ namespace Ryujinx.HLE.Loaders.Executables
class NroExecutable : Nro, IExecutable
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan().Slice(TextOffset, (int)Header.NroSegments[0].Size);
public Span<byte> Ro => Program.AsSpan().Slice(RoOffset, (int)Header.NroSegments[1].Size);
public Span<byte> Data => Program.AsSpan().Slice(DataOffset, (int)Header.NroSegments[2].Size);
public Span<byte> Text => Program.AsSpan().Slice((int)TextOffset, (int)Header.NroSegments[0].Size);
public Span<byte> Ro => Program.AsSpan().Slice((int)RoOffset, (int)Header.NroSegments[1].Size);
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)Header.NroSegments[2].Size);
public int TextOffset => (int)Header.NroSegments[0].FileOffset;
public int RoOffset => (int)Header.NroSegments[1].FileOffset;
public int DataOffset => (int)Header.NroSegments[2].FileOffset;
public int BssOffset => DataOffset + Data.Length;
public int BssSize => (int)Header.BssSize;
public uint TextOffset => Header.NroSegments[0].FileOffset;
public uint RoOffset => Header.NroSegments[1].FileOffset;
public uint DataOffset => Header.NroSegments[2].FileOffset;
public uint BssOffset => DataOffset + (uint)Data.Length;
public uint BssSize => Header.BssSize;
public int Mod0Offset => Start.Mod0Offset;
public int FileSize => (int)Header.Size;
public uint Mod0Offset => (uint)Start.Mod0Offset;
public uint FileSize => Header.Size;
public ulong SourceAddress { get; private set; }
public ulong BssAddress { get; private set; }

View file

@ -13,19 +13,19 @@ namespace Ryujinx.HLE.Loaders.Executables
class NsoExecutable : IExecutable
{
public byte[] Program { get; }
public Span<byte> Text => Program.AsSpan().Slice(TextOffset, TextSize);
public Span<byte> Ro => Program.AsSpan().Slice(RoOffset, RoSize);
public Span<byte> Data => Program.AsSpan().Slice(DataOffset, DataSize);
public Span<byte> Text => Program.AsSpan().Slice((int)TextOffset, (int)TextSize);
public Span<byte> Ro => Program.AsSpan().Slice((int)RoOffset, (int)RoSize);
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize);
public int TextOffset { get; }
public int RoOffset { get; }
public int DataOffset { get; }
public int BssOffset => DataOffset + Data.Length;
public uint TextOffset { get; }
public uint RoOffset { get; }
public uint DataOffset { get; }
public uint BssOffset => DataOffset + (uint)Data.Length;
public int TextSize { get; }
public int RoSize { get; }
public int DataSize { get; }
public int BssSize { get; }
public uint TextSize { get; }
public uint RoSize { get; }
public uint DataSize { get; }
public uint BssSize { get; }
public string Name;
public Buffer32 BuildId;
@ -36,10 +36,10 @@ namespace Ryujinx.HLE.Loaders.Executables
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;
TextOffset = reader.Header.Segments[0].MemoryOffset;
RoOffset = reader.Header.Segments[1].MemoryOffset;
DataOffset = reader.Header.Segments[2].MemoryOffset;
BssSize = reader.Header.BssSize;
reader.GetSegmentSize(NsoReader.SegmentType.Data, out uint uncompressedSize).ThrowIfFailure();
@ -55,21 +55,21 @@ namespace Ryujinx.HLE.Loaders.Executables
PrintRoSectionInfo();
}
private int DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType, int offset)
private uint DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType, uint offset)
{
reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure();
var span = Program.AsSpan().Slice(offset, (int)uncompressedSize);
var span = Program.AsSpan().Slice((int)offset, (int)uncompressedSize);
reader.ReadSegment(segmentType, span).ThrowIfFailure();
return (int)uncompressedSize;
return uncompressedSize;
}
private void PrintRoSectionInfo()
{
byte[] roBuffer = Ro.ToArray();
string rawTextBuffer = Encoding.ASCII.GetString(roBuffer, 0, RoSize);
string rawTextBuffer = Encoding.ASCII.GetString(roBuffer, 0, (int)RoSize);
StringBuilder stringBuilder = new StringBuilder();
int zero = BitConverter.ToInt32(roBuffer, 0);