ServiceAccessControl.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System.Collections.Generic;
  2. using System.Collections.ObjectModel;
  3. using System.IO;
  4. using System.Text;
  5. namespace Ryujinx.HLE.Loaders.Npdm
  6. {
  7. public class ServiceAccessControl
  8. {
  9. public IReadOnlyDictionary<string, bool> Services { get; private set; }
  10. public ServiceAccessControl(Stream stream, int offset, int size)
  11. {
  12. stream.Seek(offset, SeekOrigin.Begin);
  13. BinaryReader reader = new BinaryReader(stream);
  14. int bytesRead = 0;
  15. Dictionary<string, bool> services = new Dictionary<string, bool>();
  16. while (bytesRead != size)
  17. {
  18. byte controlByte = reader.ReadByte();
  19. if (controlByte == 0)
  20. {
  21. break;
  22. }
  23. int length = (controlByte & 0x07) + 1;
  24. bool registerAllowed = (controlByte & 0x80) != 0;
  25. services[Encoding.ASCII.GetString(reader.ReadBytes(length))] = registerAllowed;
  26. bytesRead += length + 1;
  27. }
  28. Services = new ReadOnlyDictionary<string, bool>(services);
  29. }
  30. }
  31. }