Npdm.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Ryujinx.HLE.Exceptions;
  2. using System.IO;
  3. using System.Text;
  4. namespace Ryujinx.HLE.Loaders.Npdm
  5. {
  6. //https://github.com/SciresM/hactool/blob/master/npdm.c
  7. //https://github.com/SciresM/hactool/blob/master/npdm.h
  8. //http://switchbrew.org/index.php?title=NPDM
  9. class Npdm
  10. {
  11. private const int MetaMagic = 'M' << 0 | 'E' << 8 | 'T' << 16 | 'A' << 24;
  12. public byte MmuFlags { get; private set; }
  13. public bool Is64Bits { get; private set; }
  14. public byte MainThreadPriority { get; private set; }
  15. public byte DefaultCpuId { get; private set; }
  16. public int PersonalMmHeapSize { get; private set; }
  17. public int ProcessCategory { get; private set; }
  18. public int MainThreadStackSize { get; private set; }
  19. public string TitleName { get; private set; }
  20. public byte[] ProductCode { get; private set; }
  21. public Aci0 Aci0 { get; private set; }
  22. public Acid Acid { get; private set; }
  23. public Npdm(Stream stream)
  24. {
  25. BinaryReader reader = new BinaryReader(stream);
  26. if (reader.ReadInt32() != MetaMagic)
  27. {
  28. throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
  29. }
  30. reader.ReadInt64();
  31. MmuFlags = reader.ReadByte();
  32. Is64Bits = (MmuFlags & 1) != 0;
  33. reader.ReadByte();
  34. MainThreadPriority = reader.ReadByte();
  35. DefaultCpuId = reader.ReadByte();
  36. reader.ReadInt32();
  37. PersonalMmHeapSize = reader.ReadInt32();
  38. ProcessCategory = reader.ReadInt32();
  39. MainThreadStackSize = reader.ReadInt32();
  40. byte[] tempTitleName = reader.ReadBytes(0x10);
  41. TitleName = Encoding.UTF8.GetString(tempTitleName, 0, tempTitleName.Length).Trim('\0');
  42. ProductCode = reader.ReadBytes(0x10);
  43. stream.Seek(0x30, SeekOrigin.Current);
  44. int aci0Offset = reader.ReadInt32();
  45. int aci0Size = reader.ReadInt32();
  46. int acidOffset = reader.ReadInt32();
  47. int acidSize = reader.ReadInt32();
  48. Aci0 = new Aci0(stream, aci0Offset);
  49. Acid = new Acid(stream, acidOffset);
  50. }
  51. }
  52. }