diff options
| author | Mary <me@thog.eu> | 2020-07-04 01:58:01 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-04 01:58:01 +0200 |
| commit | 2c48750ff078e28bd395e43f0e4686c47b13c762 (patch) | |
| tree | f928a703529b067ead750948b089a1e50755c9fb /Ryujinx.HLE/Loaders | |
| parent | e13154c83d52d9e1c26c55bc5655a5df641e26a9 (diff) | |
Fix compilation warnings and use new LibHac APIs for executable loading (#1350)
* Fix compilation warnings and use new LibHac APIs for executable loading
* Migrate NSO loader to the new reader and fix kip loader
* Fix CS0162 restore
* Remove extra return lines
* Address Moose's comment
Diffstat (limited to 'Ryujinx.HLE/Loaders')
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/KipExecutable.cs | 67 | ||||
| -rw-r--r-- | Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs | 43 |
2 files changed, 85 insertions, 25 deletions
diff --git a/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs b/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs index 9f04cf4e..0f1309c0 100644 --- a/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/KipExecutable.cs @@ -1,35 +1,76 @@ -using LibHac; using LibHac.Fs; -using System.IO; +using LibHac.Loader; namespace Ryujinx.HLE.Loaders.Executables { - class KipExecutable : Kip, IExecutable + class KipExecutable : IExecutable { public byte[] Text { get; } public byte[] Ro { get; } public byte[] Data { get; } - public int TextOffset => Header.Sections[0].OutOffset; - public int RoOffset => Header.Sections[1].OutOffset; - public int DataOffset => Header.Sections[2].OutOffset; - public int BssOffset => Header.Sections[3].OutOffset; - public int BssSize => Header.Sections[3].DecompressedSize; + public int TextOffset { get; } + public int RoOffset { get; } + public int DataOffset { get; } + public int BssOffset { get; } + public int BssSize { get; } public int[] Capabilities { get; } + public bool UsesSecureMemory { get; } + public bool Is64BitAddressSpace { get; } + public bool Is64Bit { get; } + public ulong ProgramId { get; } + public byte Priority { get; } + public int StackSize { get; } + public byte IdealCoreId { get; } + public int Version { get; } + public string Name { get; } - public KipExecutable(IStorage inStorage) : base(inStorage) + public KipExecutable(IStorage inStorage) { + KipReader reader = new KipReader(); + + 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; + + StackSize = reader.StackSize; + + UsesSecureMemory = reader.UsesSecureMemory; + Is64BitAddressSpace = reader.Is64BitAddressSpace; + Is64Bit = reader.Is64Bit; + + ProgramId = reader.ProgramId; + Priority = reader.Priority; + IdealCoreId = reader.IdealCoreId; + Version = reader.Version; + Name = reader.Name.ToString(); + Capabilities = new int[32]; for (int index = 0; index < Capabilities.Length; index++) { - Capabilities[index] = System.BitConverter.ToInt32(Header.Capabilities, index * 4); + Capabilities[index] = (int)reader.Capabilities[index]; } - Text = DecompressSection(0); - Ro = DecompressSection(1); - Data = DecompressSection(2); + Text = DecompressSection(reader, KipReader.SegmentType.Text); + Ro = DecompressSection(reader, KipReader.SegmentType.Ro); + Data = DecompressSection(reader, KipReader.SegmentType.Data); + } + + private static byte[] DecompressSection(KipReader reader, KipReader.SegmentType segmentType) + { + reader.GetSegmentSize(segmentType, out int uncompressedSize).ThrowIfFailure(); + + byte[] result = new byte[uncompressedSize]; + + reader.ReadSegment(segmentType, result).ThrowIfFailure(); + + return result; } } }
\ No newline at end of file diff --git a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs index 6050432d..bbe2c87f 100644 --- a/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs +++ b/Ryujinx.HLE/Loaders/Executables/NsoExecutable.cs @@ -1,28 +1,47 @@ -using LibHac; using LibHac.Fs; -using System; -using System.IO; +using LibHac.FsSystem; +using LibHac.Loader; namespace Ryujinx.HLE.Loaders.Executables { - class NsoExecutable : Nso, IExecutable + class NsoExecutable : IExecutable { public byte[] Text { get; } public byte[] Ro { get; } public byte[] Data { get; } - public int TextOffset => (int)Sections[0].MemoryOffset; - public int RoOffset => (int)Sections[1].MemoryOffset; - public int DataOffset => (int)Sections[2].MemoryOffset; + public int TextOffset { get; } + public int RoOffset { get; } + public int DataOffset { get; } public int BssOffset => DataOffset + Data.Length; - public new int BssSize => (int)base.BssSize; + public int BssSize { get; } - public NsoExecutable(IStorage inStorage) : base(inStorage) + public NsoExecutable(IStorage inStorage) { - Text = Sections[0].DecompressSection(); - Ro = Sections[1].DecompressSection(); - Data = Sections[2].DecompressSection(); + NsoReader reader = new NsoReader(); + + 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; + + Text = DecompressSection(reader, NsoReader.SegmentType.Text); + Ro = DecompressSection(reader, NsoReader.SegmentType.Ro); + Data = DecompressSection(reader, NsoReader.SegmentType.Data); + } + + private static byte[] DecompressSection(NsoReader reader, NsoReader.SegmentType segmentType) + { + reader.GetSegmentSize(segmentType, out uint uncompressedSize).ThrowIfFailure(); + + byte[] result = new byte[uncompressedSize]; + + reader.ReadSegment(segmentType, result).ThrowIfFailure(); + + return result; } } }
\ No newline at end of file |
