private void Extract(NcaFile nca) { IFileSystem fs = nca.data.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); bct = this.ReadFile("/nx/bct", ref fs); bct[0x210] = 0x77; pkg1 = this.ReadFile("/nx/package1", ref fs); pkg2 = this.ReadFile("/nx/package2", ref fs); fs.Dispose(); }
private void Extract(NcaFile nca) { IFileSystem fs = nca.data.OpenFileSystem(NcaSectionType.Data, IntegrityCheckLevel.ErrorOnInvalid); string startPath = (Config.marikoBoot) ? "/a/" : "/nx/"; bct = this.ReadFile(startPath + "bct", ref fs); if (!Config.noAutoRcm) { bct[0x210] = 0x77; } pkg1 = this.ReadFile(startPath + "package1", ref fs); pkg2 = this.ReadFile("/nx/package2", ref fs); fs.Dispose(); }
public BisExtractor(NcaFile nca) { this.Extract(nca); }
void Start(string keys, string fwPath, bool noExfat, bool verbose, bool showNcaIndex, bool fixHashes) { Config.keyset = ExternalKeyReader.ReadKeyFile(keys); Config.fwPath = fwPath; Config.noExfat = noExfat; Config.normalBisId = (noExfat) ? "0100000000000819" : "010000000000081B"; Config.safeBisId = (noExfat) ? "010000000000081A" : "010000000000081C"; Config.verbose = verbose; Config.fixHashes = fixHashes; int convertCount = 0; foreach (var foldername in Directory.GetDirectories(fwPath, "*.nca")) { convertCount++; File.Move($"{foldername}/00", $"{fwPath}/temp"); Directory.Delete(foldername); File.Move($"{fwPath}/temp", foldername); } if (convertCount > 0) { Console.WriteLine($"Converted folder ncas to files (count: {convertCount})"); } Console.WriteLine("Indexing nca files..."); NcaIndexer ncaIndex = new NcaIndexer(); NcaFile versionNca = ncaIndex.FindNca("0100000000000809", NcaContentType.Data); VersionExtractor versionExtractor = new VersionExtractor(versionNca); string destFolder = $"{versionExtractor.platform.ToUpper()}-{versionExtractor.version}"; if (!noExfat) { destFolder += "_exFAT"; } if (showNcaIndex) { ShowNcaIndex(ref ncaIndex, destFolder); return; } Console.WriteLine("\nEmmcHaccGen will now generate firmware files using the following settings:\n" + $"fw: {versionExtractor.platform}-{versionExtractor.version}\n" + $"Exfat Support: {!noExfat}\n" + $"Key path: {keys}\n" + $"Destination folder: {destFolder}\n"); if (verbose) { Console.WriteLine($"BisIds:\nNormal: {Config.normalBisId}\nSafe: {Config.safeBisId}\n"); } // Folder creation Console.WriteLine("\nCreating folders.."); foreach (string folder in FOLDERSTRUCTURE) { Directory.CreateDirectory($"{destFolder}{folder}"); } // Bis creation Console.WriteLine("\nGenerating bis.."); BisAssembler bisAssembler = new BisAssembler(ref ncaIndex, destFolder); BisFileAssembler bisFileAssembler = new BisFileAssembler($"{versionExtractor.platform.ToUpper()}-{versionExtractor.version}{((!noExfat) ? "_exFAT" : "")}", ref bisAssembler, $"{destFolder}/boot.bis"); // Copy fw files Console.WriteLine("\nCopying files..."); foreach (var file in Directory.EnumerateFiles(fwPath)) { File.Copy(file, $"{destFolder}/SYSTEM/Contents/registered/{file.Split(new char[] { '/', '\\' }).Last()}", true); } // Archive bit setting Console.WriteLine("\nSetting archive bits.."); SetArchiveRecursively($"{destFolder}/SYSTEM"); SetArchiveRecursively($"{destFolder}/USER"); //Imkv generation Console.WriteLine("\nGenerating imkvdb.."); Imkv imkvdb = new Imkv(ref ncaIndex); if (verbose) { imkvdb.DumpToFile($"{destFolder}/data.arc"); } File.Copy("save.stub", $"{destFolder}/SYSTEM/save/8000000000000120", true); using (IStorage outfile = new LocalStorage($"{destFolder}/SYSTEM/save/8000000000000120", FileAccess.ReadWrite)) { var save = new SaveDataFileSystem(Config.keyset, outfile, IntegrityCheckLevel.ErrorOnInvalid, true); save.OpenFile(out IFile file, new U8Span("/meta/imkvdb.arc"), OpenMode.AllowAppend | OpenMode.ReadWrite); using (file) { file.Write(0, imkvdb.bytes.ToArray(), WriteOption.Flush).ThrowIfFailure(); } save.Commit(Config.keyset).ThrowIfFailure(); } Console.WriteLine($"Wrote save with an imvkdb size of 0x{imkvdb.bytes.Count:X4}"); }