Ryujinx-uplift/Ryujinx.HLE/HOS/Services/Android/Parcel.cs

58 lines
1.5 KiB
C#
Raw Normal View History

2018-02-05 00:08:20 +01:00
using System;
using System.IO;
namespace Ryujinx.HLE.HOS.Services.Android
2018-02-05 00:08:20 +01:00
{
static class Parcel
{
public static byte[] GetParcelData(byte[] parcel)
2018-02-05 00:08:20 +01:00
{
if (parcel == null)
2018-02-05 00:08:20 +01:00
{
throw new ArgumentNullException(nameof(parcel));
2018-02-05 00:08:20 +01:00
}
using (MemoryStream ms = new MemoryStream(parcel))
2018-02-05 00:08:20 +01:00
{
BinaryReader reader = new BinaryReader(ms);
2018-02-05 00:08:20 +01:00
int dataSize = reader.ReadInt32();
int dataOffset = reader.ReadInt32();
int objsSize = reader.ReadInt32();
int objsOffset = reader.ReadInt32();
2018-02-05 00:08:20 +01:00
ms.Seek(dataOffset - 0x10, SeekOrigin.Current);
2018-02-05 00:08:20 +01:00
return reader.ReadBytes(dataSize);
2018-02-05 00:08:20 +01:00
}
}
public static byte[] MakeParcel(byte[] data, byte[] objs)
2018-02-05 00:08:20 +01:00
{
if (data == null)
2018-02-05 00:08:20 +01:00
{
throw new ArgumentNullException(nameof(data));
2018-02-05 00:08:20 +01:00
}
if (objs == null)
2018-02-05 00:08:20 +01:00
{
throw new ArgumentNullException(nameof(objs));
2018-02-05 00:08:20 +01:00
}
using (MemoryStream ms = new MemoryStream())
2018-02-05 00:08:20 +01:00
{
BinaryWriter writer = new BinaryWriter(ms);
2018-02-05 00:08:20 +01:00
writer.Write(data.Length);
writer.Write(0x10);
writer.Write(objs.Length);
writer.Write(data.Length + 0x10);
2018-02-05 00:08:20 +01:00
writer.Write(data);
writer.Write(objs);
2018-02-05 00:08:20 +01:00
return ms.ToArray();
2018-02-05 00:08:20 +01:00
}
}
}
}