1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-03 00:42:04 +00:00
Ryujinx/Ryujinx.HLE/Loaders/Executables/NxStaticObject.cs
gdkchan 00579927e4
Better process implementation (#491)
* Initial implementation of KProcess

* Some improvements to the memory manager, implement back guest stack trace printing

* Better GetInfo implementation, improve checking in some places with information from process capabilities

* Allow the cpu to read/write from the correct memory locations for accesses crossing a page boundary

* Change long -> ulong for address/size on memory related methods to avoid unnecessary casts

* Attempt at implementing ldr:ro with new KProcess

* Allow BSS with size 0 on ldr:ro

* Add checking for memory block slab heap usage, return errors if full, exit gracefully

* Use KMemoryBlockSize const from KMemoryManager

* Allow all methods to read from non-contiguous locations

* Fix for TransactParcelAuto

* Address PR feedback, additionally fix some small issues related to the KIP loader and implement SVCs GetProcessId, GetProcessList, GetSystemInfo, CreatePort and ManageNamedPort

* Fix wrong check for source pages count from page list on MapPhysicalMemory

* Fix some issues with UnloadNro on ldr:ro
2018-11-28 20:18:09 -02:00

109 lines
No EOL
3.5 KiB
C#

using Ryujinx.HLE.Loaders.Compression;
using System;
using System.IO;
namespace Ryujinx.HLE.Loaders.Executables
{
class NxStaticObject : IExecutable
{
public byte[] Text { get; private set; }
public byte[] RO { get; private set; }
public byte[] Data { 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 int BssOffset => DataOffset + Data.Length;
[Flags]
private enum NsoFlags
{
IsTextCompressed = 1 << 0,
IsROCompressed = 1 << 1,
IsDataCompressed = 1 << 2,
HasTextHash = 1 << 3,
HasROHash = 1 << 4,
HasDataHash = 1 << 5
}
public NxStaticObject(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);
Text = Reader.ReadBytes(TextSize);
if (Flags.HasFlag(NsoFlags.IsTextCompressed))
{
Text = Lz4.Decompress(Text, TextDecSize);
}
//Read-only data segment
Input.Seek(ROOffset, SeekOrigin.Begin);
RO = Reader.ReadBytes(ROSize);
if (Flags.HasFlag(NsoFlags.IsROCompressed))
{
RO = Lz4.Decompress(RO, RODecSize);
}
//Data segment
Input.Seek(DataOffset, SeekOrigin.Begin);
Data = Reader.ReadBytes(DataSize);
if (Flags.HasFlag(NsoFlags.IsDataCompressed))
{
Data = Lz4.Decompress(Data, DataDecSize);
}
}
}
}