//args: SLUS path, CVM path
        public static void Patch(string slusPath, string cvmPath)
        {
            // Declare variables
            byte[] elfHeader;
            byte[] elfFooter;
            CvmExecutableListing[] cvmExecutableListings;
            Tuple <int, string[]>  data;

            using (FileStream stream = File.OpenRead(slusPath))
            {
                if (!CvmListDataDictionary.TryGetValue((int)stream.Length, out data))
                {
                    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(cvmPath);

            // Get the index from the cvm order
            // Check if the name of the cvm at least contains the original name
            string cvmName  = Path.GetFileNameWithoutExtension(cvmPath).ToUpperInvariant();
            int    cvmIndex = Array.FindIndex(data.Item2, o => cvmName.Contains(o));

            // Update the listing
            cvmExecutableListings[cvmIndex].Update(cvm);

            // Write the new executable
            using (BinaryWriter writer = new BinaryWriter(File.Create(slusPath)))
            {
                writer.Write(elfHeader);

                foreach (CvmExecutableListing cvmExecutableList in cvmExecutableListings)
                {
                    cvmExecutableList.Save(writer.BaseStream);
                }

                writer.Write(elfFooter);
            }
        }
Beispiel #2
0
        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();
        }