示例#1
0
        public Npdm(Stream NPDMStream)
        {
            BinaryReader Reader = new BinaryReader(NPDMStream);

            if (Reader.ReadInt32() != NpdmMagic)
            {
                throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
            }

            Reader.ReadInt64(); // Padding / Unused

            // MmuFlags, bit0: 64-bit instructions, bits1-3: address space width (1=64-bit, 2=32-bit). Needs to be <= 0xF
            byte MmuFlags = Reader.ReadByte();

            Is64Bits          = (MmuFlags & 1) != 0;
            AddressSpaceWidth = (MmuFlags >> 1) & 7;

            Reader.ReadByte();                      // Padding / Unused

            MainThreadPriority = Reader.ReadByte(); // (0-63)
            DefaultCpuId       = Reader.ReadByte();

            Reader.ReadInt32(); // Padding / Unused

            // System resource size (max size as of 5.x: 534773760). Unknown usage.
            SystemResourceSize = EndianSwap.Swap32(Reader.ReadInt32());

            // ProcessCategory (0: regular title, 1: kernel built-in). Should be 0 here.
            ProcessCategory = EndianSwap.Swap32(Reader.ReadInt32());

            // Main entrypoint stack size
            // (Should(?) be page-aligned. In non-nspwn scenarios, values of 0 can also rarely break in Horizon.
            // This might be something auto-adapting or a security feature of some sort ?)
            MainEntrypointStackSize = Reader.ReadInt32();

            byte[] TempTitleName = Reader.ReadBytes(0x10);
            TitleName = Encoding.UTF8.GetString(TempTitleName, 0, TempTitleName.Length).Trim('\0');

            ProductCode = Reader.ReadBytes(0x10);      // Unknown value

            NPDMStream.Seek(0x30, SeekOrigin.Current); // Skip reserved bytes

            ACI0Offset = Reader.ReadInt32();
            ACI0Size   = Reader.ReadInt32();
            ACIDOffset = Reader.ReadInt32();
            ACIDSize   = Reader.ReadInt32();

            ACI0 = new ACI0(NPDMStream, ACI0Offset);
            ACID = new ACID(NPDMStream, ACIDOffset);

            FSPerms = ACI0.FSAccessHeader.PermissionsBitmask & ACID.FSAccessControl.PermissionsBitmask;
        }
示例#2
0
文件: Npdm.cs 项目: Talkashie/Ryujinx
        public Npdm(Stream Stream)
        {
            BinaryReader Reader = new BinaryReader(Stream);

            if (Reader.ReadInt32() != MetaMagic)
            {
                throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
            }

            Reader.ReadInt64();

            //MmuFlags, bit0: 64-bit instructions, bits1-3: address space width (1=64-bit, 2=32-bit). Needs to be <= 0xF.
            byte MmuFlags = Reader.ReadByte();

            Is64Bits          = (MmuFlags & 1) != 0;
            AddressSpaceWidth = (MmuFlags >> 1) & 7;

            Reader.ReadByte();

            MainThreadPriority = Reader.ReadByte(); //(0-63).
            DefaultCpuId       = Reader.ReadByte();

            Reader.ReadInt32();

            //System resource size (max size as of 5.x: 534773760).
            SystemResourceSize = EndianSwap.Swap32(Reader.ReadInt32());

            //ProcessCategory (0: regular title, 1: kernel built-in). Should be 0 here.
            ProcessCategory = EndianSwap.Swap32(Reader.ReadInt32());

            //Main entrypoint stack size.
            MainEntrypointStackSize = Reader.ReadInt32();

            byte[] TempTitleName = Reader.ReadBytes(0x10);

            TitleName = Encoding.UTF8.GetString(TempTitleName, 0, TempTitleName.Length).Trim('\0');

            ProductCode = Reader.ReadBytes(0x10);

            Stream.Seek(0x30, SeekOrigin.Current);

            int ACI0Offset = Reader.ReadInt32();
            int ACI0Size   = Reader.ReadInt32();
            int ACIDOffset = Reader.ReadInt32();
            int ACIDSize   = Reader.ReadInt32();

            ACI0 = new ACI0(Stream, ACI0Offset);
            ACID = new ACID(Stream, ACIDOffset);
        }
示例#3
0
        public Npdm(Stream Stream)
        {
            BinaryReader Reader = new BinaryReader(Stream);

            if (Reader.ReadInt32() != MetaMagic)
            {
                throw new InvalidNpdmException("NPDM Stream doesn't contain NPDM file!");
            }

            Reader.ReadInt64();

            MmuFlags = Reader.ReadByte();

            Is64Bits = (MmuFlags & 1) != 0;

            Reader.ReadByte();

            MainThreadPriority = Reader.ReadByte();
            DefaultCpuId       = Reader.ReadByte();

            Reader.ReadInt32();

            PersonalMmHeapSize = Reader.ReadInt32();

            ProcessCategory = Reader.ReadInt32();

            MainThreadStackSize = Reader.ReadInt32();

            byte[] TempTitleName = Reader.ReadBytes(0x10);

            TitleName = Encoding.UTF8.GetString(TempTitleName, 0, TempTitleName.Length).Trim('\0');

            ProductCode = Reader.ReadBytes(0x10);

            Stream.Seek(0x30, SeekOrigin.Current);

            int ACI0Offset = Reader.ReadInt32();
            int ACI0Size   = Reader.ReadInt32();
            int ACIDOffset = Reader.ReadInt32();
            int ACIDSize   = Reader.ReadInt32();

            ACI0 = new ACI0(Stream, ACI0Offset);
            ACID = new ACID(Stream, ACIDOffset);
        }