hos: Cleanup the project (#2634)
* hos: Cleanup the project Since a lot of changes has been done on the HOS project, there are some leftover here and there, or class just used in one service, things at wrong places, and more. This PR fixes that, additionnally to that, I've realigned some vars because I though it make the code more readable. * Address gdkchan feedback * addresses Thog feedback * Revert ElfSymbol
This commit is contained in:
parent
3f2486342b
commit
5d08e9b495
36 changed files with 261 additions and 382 deletions
|
@ -8,13 +8,8 @@ namespace Ryujinx.HLE.Loaders.Elf
|
|||
public ElfSymbolBinding Binding { get; private set; }
|
||||
public ElfSymbolVisibility Visibility { get; private set; }
|
||||
|
||||
public bool IsFuncOrObject =>
|
||||
Type == ElfSymbolType.SttFunc ||
|
||||
Type == ElfSymbolType.SttObject;
|
||||
|
||||
public bool IsGlobalOrWeak =>
|
||||
Binding == ElfSymbolBinding.StbGlobal ||
|
||||
Binding == ElfSymbolBinding.StbWeak;
|
||||
public bool IsFuncOrObject => Type == ElfSymbolType.SttFunc || Type == ElfSymbolType.SttObject;
|
||||
public bool IsGlobalOrWeak => Binding == ElfSymbolBinding.StbGlobal || Binding == ElfSymbolBinding.StbWeak;
|
||||
|
||||
public int ShIdx { get; private set; }
|
||||
public ulong Value { get; private set; }
|
||||
|
|
|
@ -11,4 +11,4 @@
|
|||
public ushort SectionIndex;
|
||||
#pragma warning restore CS0649
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,4 +11,4 @@
|
|||
public ulong Size;
|
||||
#pragma warning restore CS0649
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,25 +12,25 @@ namespace Ryujinx.HLE.Loaders.Executables
|
|||
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize);
|
||||
|
||||
public uint TextOffset { get; }
|
||||
public uint RoOffset { get; }
|
||||
public uint RoOffset { get; }
|
||||
public uint DataOffset { get; }
|
||||
public uint BssOffset { get; }
|
||||
public uint BssOffset { get; }
|
||||
|
||||
public uint TextSize { get; }
|
||||
public uint RoSize { get; }
|
||||
public uint RoSize { get; }
|
||||
public uint DataSize { get; }
|
||||
public uint BssSize { get; }
|
||||
public uint BssSize { get; }
|
||||
|
||||
public int[] Capabilities { get; }
|
||||
public bool UsesSecureMemory { 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 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)
|
||||
{
|
||||
|
@ -39,22 +39,22 @@ namespace Ryujinx.HLE.Loaders.Executables
|
|||
reader.Initialize(inStorage).ThrowIfFailure();
|
||||
|
||||
TextOffset = (uint)reader.Segments[0].MemoryOffset;
|
||||
RoOffset = (uint)reader.Segments[1].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;
|
||||
BssOffset = (uint)reader.Segments[3].MemoryOffset;
|
||||
BssSize = (uint)reader.Segments[3].Size;
|
||||
|
||||
StackSize = reader.StackSize;
|
||||
|
||||
UsesSecureMemory = reader.UsesSecureMemory;
|
||||
UsesSecureMemory = reader.UsesSecureMemory;
|
||||
Is64BitAddressSpace = reader.Is64BitAddressSpace;
|
||||
Is64Bit = reader.Is64Bit;
|
||||
Is64Bit = reader.Is64Bit;
|
||||
|
||||
ProgramId = reader.ProgramId;
|
||||
Priority = reader.Priority;
|
||||
ProgramId = reader.ProgramId;
|
||||
Priority = reader.Priority;
|
||||
IdealCoreId = reader.IdealCoreId;
|
||||
Version = reader.Version;
|
||||
Name = reader.Name.ToString();
|
||||
Version = reader.Version;
|
||||
Name = reader.Name.ToString();
|
||||
|
||||
Capabilities = new int[32];
|
||||
|
||||
|
|
|
@ -17,14 +17,14 @@ namespace Ryujinx.HLE.Loaders.Executables
|
|||
public Span<byte> Data => Program.AsSpan().Slice((int)DataOffset, (int)DataSize);
|
||||
|
||||
public uint TextOffset { get; }
|
||||
public uint RoOffset { get; }
|
||||
public uint RoOffset { get; }
|
||||
public uint DataOffset { get; }
|
||||
public uint BssOffset => DataOffset + (uint)Data.Length;
|
||||
|
||||
public uint TextSize { get; }
|
||||
public uint RoSize { get; }
|
||||
public uint RoSize { get; }
|
||||
public uint DataSize { get; }
|
||||
public uint BssSize { get; }
|
||||
public uint BssSize { get; }
|
||||
|
||||
public string Name;
|
||||
public Buffer32 BuildId;
|
||||
|
|
|
@ -20,10 +20,10 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
|
||||
private static MemPatch ParseIps(BinaryReader reader)
|
||||
{
|
||||
Span<byte> IpsHeaderMagic = Encoding.ASCII.GetBytes("PATCH").AsSpan();
|
||||
Span<byte> IpsTailMagic = Encoding.ASCII.GetBytes("EOF").AsSpan();
|
||||
Span<byte> IpsHeaderMagic = Encoding.ASCII.GetBytes("PATCH").AsSpan();
|
||||
Span<byte> IpsTailMagic = Encoding.ASCII.GetBytes("EOF").AsSpan();
|
||||
Span<byte> Ips32HeaderMagic = Encoding.ASCII.GetBytes("IPS32").AsSpan();
|
||||
Span<byte> Ips32TailMagic = Encoding.ASCII.GetBytes("EEOF").AsSpan();
|
||||
Span<byte> Ips32TailMagic = Encoding.ASCII.GetBytes("EEOF").AsSpan();
|
||||
|
||||
MemPatch patches = new MemPatch();
|
||||
var header = reader.ReadBytes(IpsHeaderMagic.Length).AsSpan();
|
||||
|
@ -68,7 +68,7 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
}
|
||||
|
||||
int patchOffset = is32 ? buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]
|
||||
: buf[0] << 16 | buf[1] << 8 | buf[2];
|
||||
: buf[0] << 16 | buf[1] << 8 | buf[2];
|
||||
|
||||
if (ReadNext(2))
|
||||
{
|
||||
|
|
|
@ -7,11 +7,19 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
{
|
||||
class IPSwitchPatcher
|
||||
{
|
||||
readonly StreamReader _reader;
|
||||
public string BuildId { get; }
|
||||
|
||||
const string BidHeader = "@nsobid-";
|
||||
|
||||
private enum Token
|
||||
{
|
||||
Normal,
|
||||
String,
|
||||
EscapeChar,
|
||||
Comment
|
||||
}
|
||||
|
||||
private readonly StreamReader _reader;
|
||||
public string BuildId { get; }
|
||||
|
||||
public IPSwitchPatcher(StreamReader reader)
|
||||
{
|
||||
string header = reader.ReadLine();
|
||||
|
@ -26,14 +34,6 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
BuildId = header.Substring(BidHeader.Length).TrimEnd().TrimEnd('0');
|
||||
}
|
||||
|
||||
private enum Token
|
||||
{
|
||||
Normal,
|
||||
String,
|
||||
EscapeChar,
|
||||
Comment
|
||||
}
|
||||
|
||||
// Uncomments line and unescapes C style strings within
|
||||
private static string PreprocessLine(string line)
|
||||
{
|
||||
|
@ -56,24 +56,24 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
case Token.String:
|
||||
state = c switch
|
||||
{
|
||||
'"' => Token.Normal,
|
||||
'"' => Token.Normal,
|
||||
'\\' => Token.EscapeChar,
|
||||
_ => Token.String
|
||||
_ => Token.String
|
||||
};
|
||||
break;
|
||||
case Token.EscapeChar:
|
||||
state = Token.String;
|
||||
c = c switch
|
||||
{
|
||||
'a' => '\a',
|
||||
'b' => '\b',
|
||||
'f' => '\f',
|
||||
'n' => '\n',
|
||||
'r' => '\r',
|
||||
't' => '\t',
|
||||
'v' => '\v',
|
||||
'a' => '\a',
|
||||
'b' => '\b',
|
||||
'f' => '\f',
|
||||
'n' => '\n',
|
||||
'r' => '\r',
|
||||
't' => '\t',
|
||||
'v' => '\v',
|
||||
'\\' => '\\',
|
||||
_ => '?'
|
||||
_ => '?'
|
||||
};
|
||||
break;
|
||||
}
|
||||
|
@ -119,7 +119,8 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
for (int i = 0; i < hexstr.Length; i += 2)
|
||||
{
|
||||
int high = ParseHexByte((byte)hexstr[i]);
|
||||
int low = ParseHexByte((byte)hexstr[i + 1]);
|
||||
int low = ParseHexByte((byte)hexstr[i + 1]);
|
||||
|
||||
bytes[i >> 1] = (byte)((high << 4) | low);
|
||||
}
|
||||
|
||||
|
@ -131,11 +132,11 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
{
|
||||
if (str[0] == '0' && (str[1] == 'x' || str[1] == 'X'))
|
||||
{
|
||||
return Int32.TryParse(str.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out value);
|
||||
return int.TryParse(str.Substring(2), System.Globalization.NumberStyles.HexNumber, null, out value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Int32.TryParse(str, System.Globalization.NumberStyles.Integer, null, out value);
|
||||
return int.TryParse(str, System.Globalization.NumberStyles.Integer, null, out value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -148,7 +149,7 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
|
||||
MemPatch patches = new MemPatch();
|
||||
|
||||
bool enabled = false;
|
||||
bool enabled = false;
|
||||
bool printValues = false;
|
||||
int offset_shift = 0;
|
||||
|
||||
|
@ -236,7 +237,7 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!Int32.TryParse(tokens[0], System.Globalization.NumberStyles.HexNumber, null, out int offset))
|
||||
if (!int.TryParse(tokens[0], System.Globalization.NumberStyles.HexNumber, null, out int offset))
|
||||
{
|
||||
ParseWarn();
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using Ryujinx.Cpu;
|
||||
using Ryujinx.Common.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using Ryujinx.Common.Logging;
|
||||
|
||||
namespace Ryujinx.HLE.Loaders.Mods
|
||||
{
|
||||
public class MemPatch
|
||||
|
@ -71,7 +69,7 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
foreach (var (offset, patch) in _patches.OrderBy(item => item.Key))
|
||||
{
|
||||
int patchOffset = (int)offset;
|
||||
int patchSize = patch.Length;
|
||||
int patchSize = patch.Length;
|
||||
|
||||
if (patchOffset < protectedOffset || patchOffset > memory.Length)
|
||||
{
|
||||
|
@ -82,7 +80,7 @@ namespace Ryujinx.HLE.Loaders.Mods
|
|||
|
||||
if (patchOffset + patchSize > memory.Length)
|
||||
{
|
||||
patchSize = memory.Length - (int)patchOffset; // Add warning?
|
||||
patchSize = memory.Length - patchOffset; // Add warning?
|
||||
}
|
||||
|
||||
Logger.Info?.Print(LogClass.ModLoader, $"Patching address offset {patchOffset:x} <= {BitConverter.ToString(patch).Replace('-', ' ')} len={patchSize}");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue