2018-11-28 18:01:19 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Loaders.Npdm
|
|
|
|
|
{
|
|
|
|
|
class ServiceAccessControl
|
|
|
|
|
{
|
2018-12-04 12:23:37 -08:00
|
|
|
|
public IReadOnlyDictionary<string, bool> Services { get; }
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
public ServiceAccessControl(Stream stream, int offset, int size)
|
2018-11-28 18:01:19 -08:00
|
|
|
|
{
|
2018-12-04 12:23:37 -08:00
|
|
|
|
stream.Seek(offset, SeekOrigin.Begin);
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
BinaryReader reader = new BinaryReader(stream);
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
int byteReaded = 0;
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
Dictionary<string, bool> services = new Dictionary<string, bool>();
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
while (byteReaded != size)
|
2018-11-28 18:01:19 -08:00
|
|
|
|
{
|
2018-12-04 12:23:37 -08:00
|
|
|
|
byte controlByte = reader.ReadByte();
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
if (controlByte == 0)
|
2018-11-28 18:01:19 -08:00
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
int length = (controlByte & 0x07) + 1;
|
|
|
|
|
bool registerAllowed = (controlByte & 0x80) != 0;
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
services.Add(Encoding.ASCII.GetString(reader.ReadBytes(length), 0, length), registerAllowed);
|
2018-11-28 18:01:19 -08:00
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
byteReaded += length + 1;
|
2018-11-28 18:01:19 -08:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 12:23:37 -08:00
|
|
|
|
Services = new ReadOnlyDictionary<string, bool>(services);
|
2018-11-28 18:01:19 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|