aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs
blob: d349f26be8c00f86ff59464f672c54bf76b0b4d0 (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
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Text;

namespace Ryujinx.HLE.Loaders.Npdm
{
    class ServiceAccessControl
    {
        public IReadOnlyDictionary<string, bool> Services { get; }

        public ServiceAccessControl(Stream stream, int offset, int size)
        {
            stream.Seek(offset, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            int byteReaded = 0;

            Dictionary<string, bool> services = new Dictionary<string, bool>();

            while (byteReaded != size)
            {
                byte controlByte = reader.ReadByte();

                if (controlByte == 0)
                {
                    break;
                }

                int  length          = (controlByte & 0x07) + 1;
                bool registerAllowed = (controlByte & 0x80) != 0;

                services.Add(Encoding.ASCII.GetString(reader.ReadBytes(length), 0, length), registerAllowed);

                byteReaded += length + 1;
            }

            Services = new ReadOnlyDictionary<string, bool>(services);
        }
    }
}