Parcel.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.IO;
  3. namespace Ryujinx.HLE.OsHle.Services.Android
  4. {
  5. static class Parcel
  6. {
  7. public static byte[] GetParcelData(byte[] Parcel)
  8. {
  9. if (Parcel == null)
  10. {
  11. throw new ArgumentNullException(nameof(Parcel));
  12. }
  13. using (MemoryStream MS = new MemoryStream(Parcel))
  14. {
  15. BinaryReader Reader = new BinaryReader(MS);
  16. int DataSize = Reader.ReadInt32();
  17. int DataOffset = Reader.ReadInt32();
  18. int ObjsSize = Reader.ReadInt32();
  19. int ObjsOffset = Reader.ReadInt32();
  20. MS.Seek(DataOffset - 0x10, SeekOrigin.Current);
  21. return Reader.ReadBytes(DataSize);
  22. }
  23. }
  24. public static byte[] MakeParcel(byte[] Data, byte[] Objs)
  25. {
  26. if (Data == null)
  27. {
  28. throw new ArgumentNullException(nameof(Data));
  29. }
  30. if (Objs == null)
  31. {
  32. throw new ArgumentNullException(nameof(Objs));
  33. }
  34. using (MemoryStream MS = new MemoryStream())
  35. {
  36. BinaryWriter Writer = new BinaryWriter(MS);
  37. Writer.Write(Data.Length);
  38. Writer.Write(0x10);
  39. Writer.Write(Objs.Length);
  40. Writer.Write(Data.Length + 0x10);
  41. Writer.Write(Data);
  42. Writer.Write(Objs);
  43. return MS.ToArray();
  44. }
  45. }
  46. }
  47. }