Homebrew.cs 2.0 KB

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