public void Restore(PatchModel patch) { var patcher = new Patcher(); patcher.Patches.Add(patch.ToPatch()); patcher.Apply(this.ExeFileName, false); }
public void Apply(PatchModel patch) { var patcher = new Patcher(); patcher.Patches.Add(patch.ToPatch()); patcher.Apply(this.ExeFileName, true); }
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); } } } } }
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; }