Simple File Patching with C
หลังจากที่หาจุดที่ต้องการแก้ไข file ที่ต้องการจะ crack ได้แล้วบางคนคงอยากจะทำ patch ของตัวเองขึ้นมา โดยทั่วไปก็มี Tool ช่วยอยู่แล้ว หากแต่ว่าบางคนไม่สะใจชอบเขียนเองทำเอง เราก็ได้หา src ภาษา c มาให้
[src]
/*===================================================
| Simple Patcher - Inspired By Detten's Patcher |
| Written by: C0debreaker |
===================================================
*/
/* NOTE: In this example the code would patch a 2 bytes (0x0F,Ox84) into
0x0F,0x85 . Bytes are located in offset 0x1CCD9. */
#include < windows.h >
#include < stdio.h >
DWORD Numb=2; /* Number of bytes to read/write , 2 in our example */
DWORD RealNumb=0; /*Number of bytes which were read, initialized to 0 */
DWORD WrittenNumb=0; /*Number of written bytes , initialized to 0 */
LONG Offset = 0x1CCD9; /* The offset */
int main(void)
{
char FileName[] = "ProgramName.exe";
HANDLE hFile;
unsigned char Buffer[2]; /* Buffer to read bytes into */
unsigned char WBuffer[2]= {0x0F,0x85}; /* Buffer to write bytes to */
HANDLE eax; /* 'eax' was created just to show connection between c and asm
*/
eax = CreateFile(FileName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,
0);
if (eax == INVALID_HANDLE_VALUE)
{
printf("Error in CreateFile()!,Please make sure file name is:
");
printf("%s",FileName);
printf("nAnd that file is accessible");
exit(1);
}
hFile = eax;
SetFilePointer(hFile,Offset,0,FILE_BEGIN);
if(!ReadFile(hFile,(LPVOID)&Buffer,Numb,(LPDWORD)&RealNumb,0))
{
printf("nError in ReadFile()!");
exit(1);
}
if (RealNumb != Numb)
{
printf("nError! Could Not read all bytes");
exit(1);
}
if((Buffer[0] != 0x0F) || (Buffer[1] != 0x84))
{
printf("nError! Values does not match");
printf("n %d - %d",Buffer[0],Buffer[1]);
exit(1);
}
SetFilePointer(hFile,Offset,0,FILE_BEGIN);
if(!WriteFile(hFile,WBuffer,Numb,&WrittenNumb,0))
{
printf("nError in CreateFile()!");
exit(1);
}
if(WrittenNumb != Numb)
{
printf("nError,Cannot write to File!");
exit(1);
}
printf("nAll Good! Enjoy your program!");
CloseHandle(hFile);
return 0;
}
[/src]