2018-02-05 00:08:20 +01:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
|
2019-11-03 18:26:29 +01:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.SurfaceFlinger
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
|
|
|
static class Parcel
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
public static byte[] GetParcelData(byte[] parcel)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (parcel == null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new ArgumentNullException(nameof(parcel));
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream ms = new MemoryStream(parcel))
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryReader reader = new BinaryReader(ms);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +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
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
ms.Seek(dataOffset - 0x10, SeekOrigin.Current);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return reader.ReadBytes(dataSize);
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
public static byte[] MakeParcel(byte[] data, byte[] objs)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
if (data == null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new ArgumentNullException(nameof(data));
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
if (objs == null)
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
throw new ArgumentNullException(nameof(objs));
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
using (MemoryStream ms = new MemoryStream())
|
2018-02-05 00:08:20 +01:00
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
BinaryWriter writer = new BinaryWriter(ms);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +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
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
writer.Write(data);
|
|
|
|
writer.Write(objs);
|
2018-02-05 00:08:20 +01:00
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
return ms.ToArray();
|
2018-02-05 00:08:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|