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,0x5f ,0x2f ,0x7c ,0x5f ,0x7c ,0x20 ,0x20
,0x0a ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20
,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20 ,0x20
,0x20 ,0x20 ,0x20 ,0x7c ,0x5f ,0x7c ,0x0a ,0x20 ,0x20 ,0x20
,0x20};
//手动计算要写入的数据,还不能完全覆盖原始的logo,所以此处要有填充数据
//0x1402AD6 - 0x14029E4 + 0x1 - 0xC9 = 0x2A
BYTE nop[0x2A];
int main()
{
fpos_t filepos;
BYTE cByte[2];
int i;
//"rb+" 打开一个二进制文件,文件必须存在,允许读写
FILE *stream = fopen("G:\\xray_linux_amd64","rb+");
//首先得到文件指针的起始位置; %X表示16进制大写输出
fgetpos(stream,&filepos);
printf("Current filepos:%X\n",filepos);
//手动找到要修改的偏移位置
filepos = filepos + 0x14029E4;
/*
使用feek将文件指针移动到偏移的位置,偏移起始位置:
文件头0(SEEK_SET),
当前位置1(SEEK_CUR),
文件尾2(SEEK_END)
fseek(stream,filepos,SEEK_SET);
*/
//使用fsetpos设置文件指针位置
fsetpos(stream,&filepos);
printf("After set Filepos:%X\n",filepos);
//读取偏移位置处的字节是否正确,每次读取一个字节,最多读取两个
fread(cByte,1,2,stream);
printf("Read Byte: %X %X\n",cByte[0],cByte[1]);
//再次确认当前数据流位置是否正确,此时filepos比前面+2,所以fread是会移动文件指针的
fgetpos(stream,&filepos);
printf("Current filepos:%X\n",filepos);
//由于前面移动了文件指针,此处再-2,然后重新设置文件指针位置
filepos = filepos - 2;
fsetpos(stream,&filepos);
//重新设置好偏移位置后,写入数据,每次写入一个字节
fwrite(sByte,strlen(sByte),1,stream);
//写入填充数据
for(i = 0;i < 0x2A;i++)
{
nop[i] = (BYTE)0x20;
}
fwrite(nop,strlen(nop),1,stream);
//写入数据完成后指针的位置
fgetpos(stream,&filepos);
printf("End filepos:%X\n",filepos);
fclose(stream);
return 0;
}