aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Vi/Parcel.cs
blob: 63c5a82ff38a5bdb3893dec25409b7c180307e97 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.IO;

namespace Ryujinx.HLE.HOS.Services.Android
{
    static class Parcel
    {
        public static byte[] GetParcelData(byte[] parcel)
        {
            if (parcel == null)
            {
                throw new ArgumentNullException(nameof(parcel));
            }

            using (MemoryStream ms = new MemoryStream(parcel))
            {
                BinaryReader reader = new BinaryReader(ms);

                int dataSize   = reader.ReadInt32();
                int dataOffset = reader.ReadInt32();
                int objsSize   = reader.ReadInt32();
                int objsOffset = reader.ReadInt32();

                ms.Seek(dataOffset - 0x10, SeekOrigin.Current);

                return reader.ReadBytes(dataSize);
            }
        }

        public static byte[] MakeParcel(byte[] data, byte[] objs)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (objs == null)
            {
                throw new ArgumentNullException(nameof(objs));
            }

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryWriter writer = new BinaryWriter(ms);

                writer.Write(data.Length);
                writer.Write(0x10);
                writer.Write(objs.Length);
                writer.Write(data.Length + 0x10);

                writer.Write(data);
                writer.Write(objs);

                return ms.ToArray();
            }
        }
    }
}