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