Homebrew.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ChocolArm64.Memory;
  2. using System.Text;
  3. namespace Ryujinx.HLE.OsHle
  4. {
  5. static class Homebrew
  6. {
  7. public const string TemporaryNroSuffix = ".ryu_tmp.nro";
  8. //http://switchbrew.org/index.php?title=Homebrew_ABI
  9. public static void WriteHbAbiData(AMemory Memory, long Position, int MainThreadHandle, string SwitchPath)
  10. {
  11. Memory.Manager.Map(Position, AMemoryMgr.PageSize, (int)MemoryType.Normal, AMemoryPerm.RW);
  12. //MainThreadHandle
  13. WriteConfigEntry(Memory, ref Position, 1, 0, MainThreadHandle);
  14. //NextLoadPath
  15. WriteConfigEntry(Memory, ref Position, 2, 0, Position + 0x200, Position + 0x400);
  16. // Argv
  17. long ArgvPosition = Position + 0xC00;
  18. WriteConfigEntry(Memory, ref Position, 5, 0, 0, ArgvPosition);
  19. Memory.WriteBytes(ArgvPosition, Encoding.ASCII.GetBytes(SwitchPath + "\0"));
  20. //AppletType
  21. WriteConfigEntry(Memory, ref Position, 7);
  22. //EndOfList
  23. WriteConfigEntry(Memory, ref Position, 0);
  24. }
  25. private static void WriteConfigEntry(
  26. AMemory Memory,
  27. ref long Position,
  28. int Key,
  29. int Flags = 0,
  30. long Value0 = 0,
  31. long Value1 = 0)
  32. {
  33. Memory.WriteInt32(Position + 0x00, Key);
  34. Memory.WriteInt32(Position + 0x04, Flags);
  35. Memory.WriteInt64(Position + 0x08, Value0);
  36. Memory.WriteInt64(Position + 0x10, Value1);
  37. Position += 0x18;
  38. }
  39. public static string ReadHbAbiNextLoadPath(AMemory Memory, long Position)
  40. {
  41. string FileName = null;
  42. while (true)
  43. {
  44. long Key = Memory.ReadInt64(Position);
  45. if (Key == 2)
  46. {
  47. long Value0 = Memory.ReadInt64(Position + 0x08);
  48. long Value1 = Memory.ReadInt64(Position + 0x10);
  49. FileName = AMemoryHelper.ReadAsciiString(Memory, Value0, Value1 - Value0);
  50. break;
  51. }
  52. else if (Key == 0)
  53. {
  54. break;
  55. }
  56. Position += 0x18;
  57. }
  58. return FileName;
  59. }
  60. }
  61. }