1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-12 06:32:03 +00:00
Ryujinx/Ryujinx.HLE/HOS/Services/SurfaceFlinger/Parcel.cs

58 lines
1.5 KiB
C#
Raw Normal View History

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