public void Update(CVMFile cvm) { if (cvm.RootDirectory.SubEntries.Count != _rootDirectoryListing.SubEntries.Length) { throw new System.Exception("Error: Number of files in CVM root directory does not match the number of files in the executable listing!"); } _rootDirectoryListing.Update(cvm.RootDirectory); }
static void Main(string[] args) { Console.SetBufferSize(Console.BufferWidth, 32766); if (args.Length != 2) { Console.WriteLine("Usage: \n"); Console.WriteLine("PersonaPatcher.exe [SLUS FILE] [CVM FILE]"); Console.WriteLine("Tool written by TGE, please give credit where is due! :^)"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); return; } // Declare variables byte[] elfHeader; byte[] elfFooter; CVMExecutableListing[] cvmExecutableListings; Tuple<int, string[]> data; using (FileStream stream = File.OpenRead(args[0])) { if (!CvmListDataDictionary.TryGetValue((int)stream.Length, out data)) { Console.WriteLine("Error: Executable not supported"); return; } // read data before list elfHeader = stream.ReadBytes(data.Item1); // Read cvm lists cvmExecutableListings = new CVMExecutableListing[data.Item2.Length]; for (int i = 0; i < cvmExecutableListings.Length; i++) { cvmExecutableListings[i] = new CVMExecutableListing(stream); } // read data after listing elfFooter = stream.ReadBytes((int)(stream.Length - stream.Position)); } // Load cvm CVMFile cvm = new CVMFile(args[1]); // Get the index from the cvm order // Check if the name of the cvm at least contains the original name string cvmName = Path.GetFileNameWithoutExtension(args[1]).ToUpperInvariant(); int cvmIndex = Array.FindIndex(data.Item2, o => cvmName.Contains(o)); if (cvmIndex == -1) { Console.WriteLine("Error: Can't identify cvm.. Did you rename it to something else?"); Console.WriteLine("The name of the cvm has to at least contain the original name for the program to be able to identify it."); return; } // Update the listing cvmExecutableListings[cvmIndex].Update(cvm); // Write the new executable using (BinaryWriter writer = new BinaryWriter(File.Create(args[0]))) { writer.Write(elfHeader); foreach (CVMExecutableListing cvmExecutableList in cvmExecutableListings) { cvmExecutableList.Save(writer.BaseStream); } writer.Write(elfFooter); } Console.WriteLine("\nDone!, press any key to continue"); Console.ReadKey(); }