Okay, I suppose you just want to create a program that patches the already existing file, so here's how I'd do it.
First, you need the offset in the file.
That means that offset 0 is the first byte, 1 is the second, etc, as opposed to the offset + base which you see in memory.
To get that offset, right click the instruction, and go to View > Executable file
:
And you take the offset:
which is 0x16A7
in my case.
Once you have the offset, you must code a program to patch the program.
Here's a few ways: (I only tested the Python one, but the rest should work)
C++
#include <iostream>
#include <fstream>
int main() {
std::ofstream f("file_to_patch.exe", std::ios::binary);
// seek to the desired offset
f.seekp(0x16A7);
// \x74 to \xEB, for example (conditional short to unconditional short)
const char bytes[] = "\xEB";
f.write(bytes, sizeof(bytes));
f.close();
return 0;
}
C
#include <stdio.h>
int main(void) {
FILE* f = fopen("to_patch.exe", "r+b"); // open
fseek(f, 0, 0x16A7); // seek to the offset to patch
fwrite((void*) "\xEB", 1, 1, f);
fclose(f);
return 0;
}
Python
In case you want to script it and don't wanna bother with C / C++, here's how you do it with Python:
f = open("to_patch", "r+b") # open in read/write binary
f.seek(0x16A7) # seek to the previously found offset
f.write(bytearray([0xEB])) # patch the jump
f.close()
jnz
byjz
you did not patch anything to no longer compare any flag. You merely inverted the condition. Patching it tojmp
would have been the proper way.