2018-11-28 21:01:19 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Loaders.Npdm
|
|
|
|
|
{
|
2019-11-28 23:32:51 -05:00
|
|
|
|
public class ServiceAccessControl
|
2018-11-28 21:01:19 -05:00
|
|
|
|
{
|
2018-12-04 19:52:39 -05:00
|
|
|
|
public IReadOnlyDictionary<string, bool> Services { get; private set; }
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
public ServiceAccessControl(Stream stream, int offset, int size)
|
2018-11-28 21:01:19 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
stream.Seek(offset, SeekOrigin.Begin);
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
BinaryReader reader = new BinaryReader(stream);
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
|
int bytesRead = 0;
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Dictionary<string, bool> services = new Dictionary<string, bool>();
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
|
while (bytesRead != size)
|
2018-11-28 21:01:19 -05:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
byte controlByte = reader.ReadByte();
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
if (controlByte == 0)
|
2018-11-28 21:01:19 -05:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
int length = (controlByte & 0x07) + 1;
|
|
|
|
|
bool registerAllowed = (controlByte & 0x80) != 0;
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2019-01-18 17:26:39 -05:00
|
|
|
|
services[Encoding.ASCII.GetString(reader.ReadBytes(length))] = registerAllowed;
|
2018-11-28 21:01:19 -05:00
|
|
|
|
|
2019-07-01 22:39:22 -04:00
|
|
|
|
bytesRead += length + 1;
|
2018-11-28 21:01:19 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
Services = new ReadOnlyDictionary<string, bool>(services);
|
2018-11-28 21:01:19 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|