Homebrew.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using ChocolArm64.Memory;
  2. using System.Text;
  3. namespace Ryujinx.HLE.HOS
  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. //MainThreadHandle.
  12. WriteConfigEntry(Memory, ref Position, 1, 0, MainThreadHandle);
  13. //NextLoadPath.
  14. WriteConfigEntry(Memory, ref Position, 2, 0, Position + 0x200, Position + 0x400);
  15. //Argv.
  16. long ArgvPosition = Position + 0xC00;
  17. Memory.WriteBytes(ArgvPosition, Encoding.ASCII.GetBytes(SwitchPath + "\0"));
  18. WriteConfigEntry(Memory, ref Position, 5, 0, 0, ArgvPosition);
  19. //AppletType.
  20. WriteConfigEntry(Memory, ref Position, 7);
  21. //EndOfList.
  22. WriteConfigEntry(Memory, ref Position, 0);
  23. }
  24. private static void WriteConfigEntry(
  25. AMemory Memory,
  26. ref long Position,
  27. int Key,
  28. int Flags = 0,
  29. long Value0 = 0,
  30. long Value1 = 0)
  31. {
  32. Memory.WriteInt32(Position + 0x00, Key);
  33. Memory.WriteInt32(Position + 0x04, Flags);
  34. Memory.WriteInt64(Position + 0x08, Value0);
  35. Memory.WriteInt64(Position + 0x10, Value1);
  36. Position += 0x18;
  37. }
  38. public static string ReadHbAbiNextLoadPath(AMemory Memory, long Position)
  39. {
  40. string FileName = null;
  41. while (true)
  42. {
  43. long Key = Memory.ReadInt64(Position);
  44. if (Key == 2)
  45. {
  46. long Value0 = Memory.ReadInt64(Position + 0x08);
  47. long Value1 = Memory.ReadInt64(Position + 0x10);
  48. FileName = AMemoryHelper.ReadAsciiString(Memory, Value0, Value1 - Value0);
  49. break;
  50. }
  51. else if (Key == 0)
  52. {
  53. break;
  54. }
  55. Position += 0x18;
  56. }
  57. return FileName;
  58. }
  59. }
  60. }