Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/hakchi2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-01-16 01:36:43 +0300
committerAlexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com>2017-01-16 01:36:43 +0300
commit81a106d35bab7386754e8b875eb9d355818a1a20 (patch)
treecc9675c1d6b565aa5fffa84ff349a725ecb4bbeb /IpsPatcher.cs
parenta5fa6da7e71aa14ba849abd77e841387e5e8ae67 (diff)
Automatic IPS patches
Diffstat (limited to 'IpsPatcher.cs')
-rw-r--r--IpsPatcher.cs50
1 files changed, 50 insertions, 0 deletions
diff --git a/IpsPatcher.cs b/IpsPatcher.cs
new file mode 100644
index 00000000..837df393
--- /dev/null
+++ b/IpsPatcher.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+
+namespace com.clusterrr.hakchi_gui
+{
+ public class IpsPatcher
+ {
+ public static void Patch(string patchFile, string inFile, string outFile)
+ {
+ var patch = File.ReadAllBytes(patchFile);
+ var data = File.ReadAllBytes(inFile);
+ if (Encoding.ASCII.GetString(patch, 0, 5) != "PATCH") throw new Exception("Invalid IPS file");
+ int pos = 5;
+ while (pos < data.Length)
+ {
+ UInt32 address = (UInt32)(patch[pos + 2] | patch[pos + 1] * 0x100 | patch[pos] * 0x10000);
+ if (pos + 3 >= patch.Length) break;
+ UInt16 length = (UInt16)(patch[pos + 4] | patch[pos + 3] * 0x100);
+ if (pos + 5 >= patch.Length) break;
+ pos += 5;
+ if (length > 0)
+ {
+ while (length > 0)
+ {
+ data[address] = patch[pos];
+ address++;
+ pos++;
+ length--;
+ }
+ }
+ else
+ {
+ length = (UInt16)(patch[pos + 1] | patch[pos] * 0x100);
+ var b = patch[pos + 2];
+ while (length > 0)
+ {
+ data[address] = b;
+ address++;
+ length--;
+ }
+ pos += 3;
+ }
+ }
+ File.WriteAllBytes(outFile, data);
+ }
+ }
+}