// Author: SkyOut // Website: http://wired-security.net // Date: September 2008 // Version: 1.0 Beta // Contact: skyout[-at-]wired-security[-dot-]net // // For additional help check README.txt using System; using System.IO; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Linq; using System.Text; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { // The EXE gets called like this: // patch.exe original_program.exe patched_program.exe offset_to_jump_to byte_to_write // Example call: // patch.exe crackme.exe crackme_cracked.exe 0000067B EB // -> This will write EB at offset 0000067B and generate the new file crackme_cracked.exe // (without touching the original file!) // Make sure the program gets four arguments as input if (args.Length == 4) { string FileInput = args[0]; // What file to patch? string FileOutput = args[1]; // What file to generate? string offset = args[2]; // At what offset shall the byte be changed? string bytes = args[3]; // What shall be written as the new bytes value? // Open all necessary streams and build a BinaryReader/Writer class Stream FileToBePatched = File.Open(FileInput, FileMode.Open); Stream FileToBeWritten = File.Create(FileOutput); BinaryReader BinRead = new BinaryReader(FileToBePatched); BinaryWriter BinWrite = new BinaryWriter(FileToBeWritten); // Parse the offset int i = int.Parse(offset, System.Globalization.NumberStyles.HexNumber); // Parse the (new) byte byte b = byte.Parse(bytes, System.Globalization.NumberStyles.HexNumber); // Write the new file till the offset BinWrite.Write(BinRead.ReadBytes(i)); // Write the new byte into the file BinWrite.Write(b); // Skip one byte (the one we just changed) BinRead.ReadBytes(1); // Read the rest of the file and write it byte[] r = BinRead.ReadBytes((int)(FileToBePatched.Length - 1)); BinWrite.Write(r); // Close everything! FileToBePatched.Close(); FileToBeWritten.Close(); BinRead.Close(); BinWrite.Close(); } } } }