aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Core/Loaders/Executables
diff options
context:
space:
mode:
authoremmauss <emmausssss@gmail.com>2018-02-20 22:09:23 +0200
committergdkchan <gab.dark.100@gmail.com>2018-02-20 17:09:23 -0300
commit62b827f474f0aa2152dd339fcc7cf31084e16a0b (patch)
tree0e5c55b341aee4db0ccb841a084f253ec5e05657 /Ryujinx.Core/Loaders/Executables
parentcb665bb715834526d73c9469d16114b287faaecd (diff)
Split main project into core,graphics and chocolarm4 subproject (#29)
Diffstat (limited to 'Ryujinx.Core/Loaders/Executables')
-rw-r--r--Ryujinx.Core/Loaders/Executables/IExecutable.cs17
-rw-r--r--Ryujinx.Core/Loaders/Executables/Nro.cs62
-rw-r--r--Ryujinx.Core/Loaders/Executables/Nso.cs122
3 files changed, 201 insertions, 0 deletions
diff --git a/Ryujinx.Core/Loaders/Executables/IExecutable.cs b/Ryujinx.Core/Loaders/Executables/IExecutable.cs
new file mode 100644
index 00000000..73787b1d
--- /dev/null
+++ b/Ryujinx.Core/Loaders/Executables/IExecutable.cs
@@ -0,0 +1,17 @@
+using System.Collections.ObjectModel;
+
+namespace Ryujinx.Core.Loaders.Executables
+{
+ public interface IExecutable
+ {
+ ReadOnlyCollection<byte> Text { get; }
+ ReadOnlyCollection<byte> RO { get; }
+ ReadOnlyCollection<byte> Data { get; }
+
+ int Mod0Offset { get; }
+ int TextOffset { get; }
+ int ROOffset { get; }
+ int DataOffset { get; }
+ int BssSize { get; }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.Core/Loaders/Executables/Nro.cs b/Ryujinx.Core/Loaders/Executables/Nro.cs
new file mode 100644
index 00000000..3cbc4c5d
--- /dev/null
+++ b/Ryujinx.Core/Loaders/Executables/Nro.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.ObjectModel;
+using System.IO;
+
+namespace Ryujinx.Core.Loaders.Executables
+{
+ class Nro : IExecutable
+ {
+ private byte[] m_Text;
+ private byte[] m_RO;
+ private byte[] m_Data;
+
+ public ReadOnlyCollection<byte> Text => Array.AsReadOnly(m_Text);
+ public ReadOnlyCollection<byte> RO => Array.AsReadOnly(m_RO);
+ public ReadOnlyCollection<byte> Data => Array.AsReadOnly(m_Data);
+
+ 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 Nro(Stream Input)
+ {
+ BinaryReader Reader = new BinaryReader(Input);
+
+ Input.Seek(4, SeekOrigin.Begin);
+
+ 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();
+
+ this.Mod0Offset = Mod0Offset;
+ this.TextOffset = TextOffset;
+ this.ROOffset = ROOffset;
+ this.DataOffset = DataOffset;
+ this.BssSize = BssSize;
+
+ byte[] Read(long Position, int Size)
+ {
+ Input.Seek(Position, SeekOrigin.Begin);
+
+ return Reader.ReadBytes(Size);
+ }
+
+ m_Text = Read(TextOffset, TextSize);
+ m_RO = Read(ROOffset, ROSize);
+ m_Data = Read(DataOffset, DataSize);
+ }
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.Core/Loaders/Executables/Nso.cs b/Ryujinx.Core/Loaders/Executables/Nso.cs
new file mode 100644
index 00000000..7b8bf253
--- /dev/null
+++ b/Ryujinx.Core/Loaders/Executables/Nso.cs
@@ -0,0 +1,122 @@
+using Ryujinx.Core.Loaders.Compression;
+using System;
+using System.Collections.ObjectModel;
+using System.IO;
+
+namespace Ryujinx.Core.Loaders.Executables
+{
+ class Nso : IExecutable
+ {
+ private byte[] m_Text;
+ private byte[] m_RO;
+ private byte[] m_Data;
+
+ public ReadOnlyCollection<byte> Text => Array.AsReadOnly(m_Text);
+ public ReadOnlyCollection<byte> RO => Array.AsReadOnly(m_RO);
+ public ReadOnlyCollection<byte> Data => Array.AsReadOnly(m_Data);
+
+ 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; }
+
+ [Flags]
+ private enum NsoFlags
+ {
+ IsTextCompressed = 1 << 0,
+ IsROCompressed = 1 << 1,
+ IsDataCompressed = 1 << 2,
+ HasTextHash = 1 << 3,
+ HasROHash = 1 << 4,
+ HasDataHash = 1 << 5
+ }
+
+ public Nso(Stream Input)
+ {
+ BinaryReader Reader = new BinaryReader(Input);
+
+ Input.Seek(0, SeekOrigin.Begin);
+
+ int NsoMagic = Reader.ReadInt32();
+ int Version = Reader.ReadInt32();
+ int Reserved = Reader.ReadInt32();
+ int FlagsMsk = Reader.ReadInt32();
+ int TextOffset = Reader.ReadInt32();
+ int TextMemOffset = Reader.ReadInt32();
+ int TextDecSize = Reader.ReadInt32();
+ int ModNameOffset = Reader.ReadInt32();
+ int ROOffset = Reader.ReadInt32();
+ int ROMemOffset = Reader.ReadInt32();
+ int RODecSize = Reader.ReadInt32();
+ int ModNameSize = Reader.ReadInt32();
+ int DataOffset = Reader.ReadInt32();
+ int DataMemOffset = Reader.ReadInt32();
+ int DataDecSize = Reader.ReadInt32();
+ int BssSize = Reader.ReadInt32();
+
+ byte[] BuildId = Reader.ReadBytes(0x20);
+
+ int TextSize = Reader.ReadInt32();
+ int ROSize = Reader.ReadInt32();
+ int DataSize = Reader.ReadInt32();
+
+ Input.Seek(0x24, SeekOrigin.Current);
+
+ int DynStrOffset = Reader.ReadInt32();
+ int DynStrSize = Reader.ReadInt32();
+ int DynSymOffset = Reader.ReadInt32();
+ int DynSymSize = Reader.ReadInt32();
+
+ byte[] TextHash = Reader.ReadBytes(0x20);
+ byte[] ROHash = Reader.ReadBytes(0x20);
+ byte[] DataHash = Reader.ReadBytes(0x20);
+
+ NsoFlags Flags = (NsoFlags)FlagsMsk;
+
+ this.TextOffset = TextMemOffset;
+ this.ROOffset = ROMemOffset;
+ this.DataOffset = DataMemOffset;
+ this.BssSize = BssSize;
+
+ //Text segment
+ Input.Seek(TextOffset, SeekOrigin.Begin);
+
+ m_Text = Reader.ReadBytes(TextSize);
+
+ if (Flags.HasFlag(NsoFlags.IsTextCompressed) || true)
+ {
+ m_Text = Lz4.Decompress(m_Text, TextDecSize);
+ }
+
+ //Read-only data segment
+ Input.Seek(ROOffset, SeekOrigin.Begin);
+
+ m_RO = Reader.ReadBytes(ROSize);
+
+ if (Flags.HasFlag(NsoFlags.IsROCompressed) || true)
+ {
+ m_RO = Lz4.Decompress(m_RO, RODecSize);
+ }
+
+ //Data segment
+ Input.Seek(DataOffset, SeekOrigin.Begin);
+
+ m_Data = Reader.ReadBytes(DataSize);
+
+ if (Flags.HasFlag(NsoFlags.IsDataCompressed) || true)
+ {
+ m_Data = Lz4.Decompress(m_Data, DataDecSize);
+ }
+
+ using (MemoryStream Text = new MemoryStream(m_Text))
+ {
+ BinaryReader TextReader = new BinaryReader(Text);
+
+ Text.Seek(4, SeekOrigin.Begin);
+
+ Mod0Offset = TextReader.ReadInt32();
+ }
+ }
+ }
+} \ No newline at end of file