aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Npdm/ACID.cs
blob: 09768a92837ebf588487486b2dfb0f3e6c994006 (plain)
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
59
60
61
62
63
64
65
66
67
using System;
using System.IO;

namespace Ryujinx.HLE.Loaders.Npdm
{
    class ACID
    {
        public byte[] RSA2048Signature;
        public byte[] RSA2048Modulus;
        public int    Unknown1;
        public int    Flags;

        public string TitleIdRangeMin;
        public string TitleIdRangeMax;

        private int FSAccessControlOffset;
        private int FSAccessControlSize;
        private int ServiceAccessControlOffset;
        private int ServiceAccessControlSize;
        private int KernelAccessControlOffset;
        private int KernelAccessControlSize;

        public FSAccessControl      FSAccessControl;
        public ServiceAccessControl ServiceAccessControl;
        public KernelAccessControl  KernelAccessControl;

        public const long ACIDMagic = 'A' << 0 | 'C' << 8 | 'I' << 16 | 'D' << 24;

        public ACID(Stream ACIDStream, int Offset)
        {
            ACIDStream.Seek(Offset, SeekOrigin.Begin);

            BinaryReader Reader = new BinaryReader(ACIDStream);

            RSA2048Signature = Reader.ReadBytes(0x100);
            RSA2048Modulus   = Reader.ReadBytes(0x100);

            if (Reader.ReadInt32() != ACIDMagic)
            {
                throw new InvalidNpdmException("ACID Stream doesn't contain ACID section!");
            }

            Unknown1 = Reader.ReadInt32(); // Size field used with the above signature(?).
            Reader.ReadInt32(); // Padding / Unused
            Flags = Reader.ReadInt32(); // Bit0 must be 1 on retail, on devunit 0 is also allowed. Bit1 is unknown.

            byte[] TempTitleIdRangeMin = Reader.ReadBytes(8);
            Array.Reverse(TempTitleIdRangeMin);
            TitleIdRangeMin = BitConverter.ToString(TempTitleIdRangeMin).Replace("-", "");

            byte[] TempTitleIdRangeMax = Reader.ReadBytes(8);
            Array.Reverse(TempTitleIdRangeMax);
            TitleIdRangeMax = BitConverter.ToString(TempTitleIdRangeMax).Replace("-", "");

            FSAccessControlOffset      = Reader.ReadInt32();
            FSAccessControlSize        = Reader.ReadInt32();
            ServiceAccessControlOffset = Reader.ReadInt32();
            ServiceAccessControlSize   = Reader.ReadInt32();
            KernelAccessControlOffset  = Reader.ReadInt32();
            KernelAccessControlSize    = Reader.ReadInt32();

            FSAccessControl      = new FSAccessControl(ACIDStream, Offset + FSAccessControlOffset, FSAccessControlSize);
            ServiceAccessControl = new ServiceAccessControl(ACIDStream, Offset + ServiceAccessControlOffset, ServiceAccessControlSize);
            KernelAccessControl  = new KernelAccessControl(ACIDStream, Offset + KernelAccessControlOffset, KernelAccessControlSize);
        }
    }
}