#include #include #include int get_init_addr (char *exe) { FILE *fp; unsigned char str[5]; int i; fp = fopen (exe, "rb"); if (fp==NULL) return 0; for (i=0;i<=0x5f;i++) fgetc (fp); fgets (str,sizeof(str),fp); fclose(fp); return (str[3]*(1<<24)+str[2]*(1<<16)+str[1]*(1<<8)+str[0]); } int replace_bytes (char *exe, int repl_addr, int *bytes, int len) { FILE *fp; unsigned char ch,*ed; int i,addr,d,size; addr = get_init_addr (exe); fp=fopen (exe, "rb"); if (fp==NULL || !addr) return 0; ed=malloc(1); for (i=0;!feof (fp);) { ed=realloc (ed,++i); ed[i-1]=fgetc(fp); } size=--i; fclose (fp); for (i=addr&0x00000FFF;addr>8; arr[3]=(to_sub & 0x00FF0000)>>16; arr[4]=(to_sub & 0xFF000000)>>24; return replace_bytes (exe,addr,arr,5); }