ServiceAccessControl.cs 1.2 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. 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 ByteReaded = 0;
  15. Dictionary<string, bool> Services = new Dictionary<string, bool>();
  16. while (ByteReaded != 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.Add(Encoding.ASCII.GetString(Reader.ReadBytes(Length), 0, Length), RegisterAllowed);
  26. ByteReaded += Length + 1;
  27. }
  28. this.Services = new ReadOnlyDictionary<string, bool>(Services);
  29. }
  30. }
  31. }