diff options
author | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-01-23 02:24:43 +0300 |
---|---|---|
committer | Alexey 'Cluster' Avdyukhin <clusterrr@clusterrr.com> | 2017-01-23 02:24:43 +0300 |
commit | fb6b8383c27560c30e7a3076c67b925a7f8ff363 (patch) | |
tree | d30a5008e0fb39bdbac6e275689c2b776c4dee66 /IpsPatcher.cs | |
parent | a6328fb50012c128e41d23d2de81241aeab14de2 (diff) |
Archives support
Diffstat (limited to 'IpsPatcher.cs')
-rw-r--r-- | IpsPatcher.cs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/IpsPatcher.cs b/IpsPatcher.cs index 88da4df9..c64be4e4 100644 --- a/IpsPatcher.cs +++ b/IpsPatcher.cs @@ -8,10 +8,8 @@ namespace com.clusterrr.hakchi_gui {
public static class IpsPatcher
{
- public static void Patch(string patchFile, string inFile, string outFile)
+ public static void Patch(byte[] patch, ref byte[] data)
{
- 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)
@@ -26,7 +24,7 @@ namespace com.clusterrr.hakchi_gui while (length > 0)
{
if (address >= data.Length)
- Array.Resize(ref data, data.Length*2);
+ Array.Resize(ref data, data.Length * 2);
data[address] = patch[pos];
address++;
pos++;
@@ -40,7 +38,7 @@ namespace com.clusterrr.hakchi_gui while (length > 0)
{
if (address >= data.Length)
- Array.Resize(ref data, data.Length*2);
+ Array.Resize(ref data, data.Length * 2);
data[address] = b;
address++;
length--;
@@ -48,6 +46,18 @@ namespace com.clusterrr.hakchi_gui pos += 3;
}
}
+ }
+
+ public static void Patch(string patchFile, ref byte[] data)
+ {
+ Patch(File.ReadAllBytes(patchFile), ref data);
+ }
+
+ public static void Patch(string patchFile, string inFile, string outFile)
+ {
+ var patch = File.ReadAllBytes(patchFile);
+ var data = File.ReadAllBytes(inFile);
+ Patch(patchFile, ref data);
File.WriteAllBytes(outFile, data);
}
}
|