heraus gekommen ist ein patcher der ein pattern sucht und
ggf. patcht ... für anfänger leicht abänderbar... wer mag baut sich eine
GUI... ich wollte nix erklären evtl. hilft es jemanden bzw ist trotzdem
zu gebrauchen.
myheader.h:
Code:
#ifndef _headerA_ #define _headerA_ #include <iostream> #include <string> #include <iomanip> #include <fstream> using namespace std; #endif
main.cpp:
Code:
#include "myheader.h"
class dateioperationen
{
private:
string inputpath;
string outputpath;
int filelength;
char* buffer;
char* bufferpointer;
public:
void readbinary(string inputpath);
void writebinary(string outputpath);
void searchPattern(string searchpattern, string patch);
};
// Setter - readbinary
void dateioperationen::readbinary(string inputpath)
{
// openfile if exists:
fstream openedfile(inputpath, ios::binary|ios::in);
if(!openedfile) {cerr << "Could not read file " << inputpath << " or read error!" << endl; system("pause"); exit(2);}
// get/set length of file:
openedfile.seekg(0, ios::end);
filelength = openedfile.tellg();
openedfile.seekg(0, ios::beg);
// create buffer:
buffer = new char [filelength];
// read data as a block:
openedfile.read (buffer,filelength);
bufferpointer = buffer;
openedfile.close();
// not in use:
// cout << "Start search at address: " << hex << (void*)bufferpointer << endl;
// cout << "Length in bytes (hex): " << hex << filelength << endl;
// cout << "End search at address: " << hex << uppercase << (((int)(void*)bufferpointer)+filelength) << endl;
//
}
// setter - writebinary
void dateioperationen::writebinary(string outputpath)
{
fstream openedfile(outputpath, ios::binary|ios::out);
if(!openedfile) {cerr << "Could not write file " << outputpath << " (May be write protected because its used by another program)" << endl; system("pause"); exit(2);}
openedfile.write (buffer,filelength);
}
// getter hex-search & replace:
void dateioperationen::searchPattern(string searchpattern, string patch)
{
int cmp, found = 0, patched = 0;
char answer;
bool allflag = 0;
for(char* i = bufferpointer-1; i < bufferpointer-1+filelength; i++)
{
cmp=memcmp ( searchpattern.c_str(), i, searchpattern.size() );
if(cmp==0)
{
found++;
if(!allflag)
{
cout << "Found at offset: " << hex << (int)((void*)i) - (int)((void*)buffer) << endl;
cout << "Execute patch ? ( (y)es / (n)o / (a)ll ):";
cin >> answer;
cout << endl;
switch(answer)
{
case 'a':
case 'A':
cout << "Patched offset: " << hex << (int)((void*)i) - (int)((void*)buffer) << endl;
memcpy(i,patch.c_str(),patch.size());
patched++; allflag = 1;
continue;
case 'y':
case 'Y':
cout << "Patched offset: " << hex << (int)((void*)i) - (int)((void*)buffer) << endl;
memcpy(i,patch.c_str(),patch.size());
patched++;
continue;
case 'n':
case 'N':
cout << "Not patched: " << hex << (int)((void*)i) - (int)((void*)buffer) << endl;
continue;
}
}
cout << "Patched offset: " << hex << (int)((void*)i) - (int)((void*)buffer) << endl;
memcpy(i,patch.c_str(),patch.size());
patched++;
}
}
cout << endl;
cout << "----------- Patchprocess ended -----------" << endl;
cout << "Results: Found pattern: " << found << endl;
cout << "Number of patched pattern: " << patched << endl;
cout << endl;
}
//main:
int main()
{
// create object:
dateioperationen datei;
//some information:
cout << endl;
cout << "--- Simple OOP byte patcher V0.01 by WhiteLion ---" << endl;
cout << "--- Credit me if you use my source code please ---" << endl;
cout << endl;
cout << "--------------------------------------------------" << endl;
cout << "--- PaTcH iNfOrMaTiOn: ---" << endl;
cout << "--- IP - P*ro*filer V 5.30.124 and latest ---" << endl;
cout << "--------------------------------------------------" << endl;
// read file + path:
datei.readbinary("ipprofiler.exe");
// backup file + path
datei.writebinary("ipprofiler.bak");
// search pattern position + new pattern to write:
datei.searchPattern("\x74\x49\x8B\x45\xFC\x83\x78","\x90\x90");
// save patched file + path
datei.writebinary("ipprofiler.exe");
system("pause");
return 0;
}







