我的破解心得(2) (2千字)
破解对象:IrfanView32
破解者:
chcw
在上一节中,我们已经知道,只要将执行程序I_view32.exe在Offset=0x685处
的字节从0x94改为0x95即可破解IrfanView32。在这一节,我们将介绍如何为
IrfanView32写一个Patcher,它在执行时自动完成上述的修改任务。
--------------------- Patcher.c -----------------------
#include <stdio.h>
#include <stdlib.h>
void main()
{
unsigned char patch=0x95;
long offset=0x00000685;
FILE *fp;
printf("Crack for IrfanView32\n");
printf("Written by Mr. Chcw\n");
if ((fp=fopen("I_view32.exe", "r+"))==NULL) {
printf("Error: Cannot find file I_view32.exe\n");
exit(1);
}
fseek(fp,offset,SEEK_SET);
fputc(patch,fp);
printf("Patch successful\n");
}
--------------------- End of Patcher.c ------------------
Patcher.c程序先将可执行文件I_view32.exe读入,然后通过偏移地址定位
到要Patch的地方,再用机器码0x95改写该处的字节,就完成了Patch过程。
当然,在实际应用中,待Patch的程序因版本的不同可能会产生Patch地址的
偏差或Patch代码的偏差,我们需要在Patch之前检查待Patch的程序的版本(如
根据程序的大小)和Patch处原机器码是否正确,以保证不会Patch错误。
下面是一个改进的Patcher1.c程序:
----------------------- Patcher1.c ------------------------
#include <stdio.h>
#include <io.h>
#include <stdlib.h>
void main()
{
const long filesize=614912; //614,912 bytes
const unsigned char oldcode=0x94;
unsigned char patchcode=0x95;
long offset=0x00000685;
FILE *fp;
printf("Crack for IrfanView32\n");
printf("Written by Mr. Chcw\n");
if ((fp=fopen("I_view32.exe", "r+"))==NULL) {
printf("Error: Cannot find file I_view32.exe\n");
exit(1);
}
else if (filelength(fileno(fp))!=filesize) {
printf("Error: Incorrect IrfanView32 version, cannot patch it\n");
exit(2);
}
fseek(fp,offset,SEEK_SET);
if (fgetc(fp)!=oldcode) {
printf("Error: The file I_view32.exe is corrupted\n");
exit(3);
}
fseek(fp,offset,SEEK_SET);
fputc(patchcode,fp);
fclose(fp);
printf("Patch successful\n");
}
-------------------- End of Patcher1.c --------------------
