1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-10-01 12:30:00 +02:00
Ryujinx/Ryujinx.HLE/Loaders/Npdm/ServiceAccessControl.cs

43 lines
1.1 KiB
C#
Raw Normal View History

2018-11-29 03:01:19 +01:00
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; private set; }
2018-11-29 03:01:19 +01:00
public ServiceAccessControl(Stream stream, int offset, int size)
2018-11-29 03:01:19 +01:00
{
stream.Seek(offset, SeekOrigin.Begin);
2018-11-29 03:01:19 +01:00
BinaryReader reader = new BinaryReader(stream);
2018-11-29 03:01:19 +01:00
int bytesRead = 0;
2018-11-29 03:01:19 +01:00
Dictionary<string, bool> services = new Dictionary<string, bool>();
2018-11-29 03:01:19 +01:00
while (bytesRead != size)
2018-11-29 03:01:19 +01:00
{
byte controlByte = reader.ReadByte();
2018-11-29 03:01:19 +01:00
if (controlByte == 0)
2018-11-29 03:01:19 +01:00
{
break;
}
int length = (controlByte & 0x07) + 1;
bool registerAllowed = (controlByte & 0x80) != 0;
2018-11-29 03:01:19 +01:00
services[Encoding.ASCII.GetString(reader.ReadBytes(length))] = registerAllowed;
2018-11-29 03:01:19 +01:00
bytesRead += length + 1;
2018-11-29 03:01:19 +01:00
}
Services = new ReadOnlyDictionary<string, bool>(services);
2018-11-29 03:01:19 +01:00
}
}
}