示例#1
0
        public void Restore(PatchModel patch)
        {
            var patcher = new Patcher();
            patcher.Patches.Add(patch.ToPatch());

            patcher.Apply(this.ExeFileName, false);
        }
示例#2
0
        public void Apply(PatchModel patch)
        {
            var patcher = new Patcher();
            patcher.Patches.Add(patch.ToPatch());

            patcher.Apply(this.ExeFileName, true);
        }
示例#3
0
        public void Apply(string exeFileName, bool writeNewValues)
        {
            if (exeFileName == null)
            {
                throw new ArgumentNullException("exeFileName");
            }

            using (FileStream file = File.Open(exeFileName, FileMode.Open, FileAccess.ReadWrite))
            {
                Patcher.FileVerifyExeVersion(file);

                foreach (var patch in this.Patches)
                {
                    foreach (var item in patch.Items)
                    {
                        if (writeNewValues)
                        {
                            if (!Patcher.FileCheckBytes(file, item.Offset, item.OldValues))
                            {
                                throw new InvalidDataException();
                            }
                        }
                        else
                        {
                            if (!Patcher.FileCheckBytes(file, item.Offset, item.NewValues))
                            {
                                throw new InvalidDataException();
                            }
                        }
                    }

                    foreach (var item in patch.Items)
                    {
                        if (writeNewValues)
                        {
                            file.Seek(item.Offset, SeekOrigin.Begin);
                            file.Write(item.NewValues, 0, item.NewValues.Length);
                        }
                        else
                        {
                            file.Seek(item.Offset, SeekOrigin.Begin);
                            file.Write(item.OldValues, 0, item.OldValues.Length);
                        }
                    }
                }
            }
        }
示例#4
0
        public static Patcher Read(string fileName)
        {
            Patcher patcher = new Patcher();

            XmlDocument document = new XmlDocument();
            document.Load(fileName);

            foreach (XmlNode patchNode in document.SelectNodes("/ArrayOfPatch/Patch"))
            {
                XmlNode node;

                Patch patch = new Patch();

                patch.Name = patchNode.Attributes.GetNamedItem("Name").Value;

                node = patchNode.Attributes.GetNamedItem("Description");
                patch.Description = node != null ? node.Value : null;

                foreach (XmlNode itemNode in patchNode.SelectNodes("Item"))
                {
                    patch.Items.Add(new PatchItem
                    {
                        OffsetString = itemNode.Attributes.GetNamedItem("Offset").Value,
                        OldValuesString = itemNode.Attributes.GetNamedItem("From").Value,
                        NewValuesString = itemNode.Attributes.GetNamedItem("To").Value
                    });
                }

                patcher.Patches.Add(patch);
            }

            return patcher;
        }