public static void GetNcchAesCounter(ref byte[] counter, NCCH ncch, NcchSection type) { counter = new byte[16]; if (ncch.Header.Version == 2 || ncch.Header.Version == 0) { Array.Copy(ReverseByteArray(ncch.Header.TitleID), 0, counter, 0, 8); counter[8] = (byte)type; } else if (ncch.Header.Version == 1) { long num = 0; switch (type) { case NcchSection.exheader: num = 0x200; break; case NcchSection.exefs: num = ncch.Header.ExeFSOffset * 0x200; break; case NcchSection.romfs: num = ncch.Header.RomFSOffset * 0x200; break; } Array.Copy(ReverseByteArray(ncch.Header.TitleID), 0, counter, 0, 8); for (int i = 0; i < 4; i++) { counter[i + 12] = (byte)((num >> ((3 - i) * 8)) & 0xFF); } } }
public NCCHInfoEntry(NCCH ncch, int PartitionIndex, NcchSection type, Encoding encoding, int use7x, string sectionname) { NCCHInfo.GetNcchAesCounter(ref Counter, ncch, type); Array.Copy(ncch.Header.NCCHHeaderSignature, 0, KeyY, 0, 16); if ((ncch.Header.Flags[7] & 0x20) == 0x20) { if ((type == NcchSection.romfs) || ((type == NcchSection.exefs) && (use7x == 1))) { Array.Copy(NCCHInfo.SEED.KeyY, 0, KeyY, 0, 16); } } switch (type) { case NcchSection.exefs: Size = NCCHInfo.roundUp((int)ncch.Header.ExeFSLength * 0x200, 1024 * 1024) / (1024 * 1024); break; case NcchSection.exheader: Size = NCCHInfo.roundUp((int)ncch.Header.ExtendedHeaderSize * 0x200, 1024 * 1024) / (1024 * 1024); break; case NcchSection.romfs: Size = NCCHInfo.roundUp((int)ncch.Header.RomFSLength * 0x200, 1024 * 1024) / (1024 * 1024); break; } using (MemoryStream ms = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(ms, encoding); string path = ""; if (encoding == Encoding.Unicode) path = string.Format("sdmc:/{0:X16}.{1}.{2}.xorpad", BitConverter.ToUInt64(ncch.Header.TitleID, 0), PartitionName[PartitionIndex], sectionname); else if (encoding == Encoding.UTF8) path = string.Format("/{0:X16}.{1}.{2}.xorpad", BitConverter.ToUInt64(ncch.Header.TitleID, 0), PartitionName[PartitionIndex], sectionname); writer.Write(path.ToCharArray()); Array.Copy(ms.ToArray(), 0, FileName, 0, ms.Length); } Use7x = use7x; }