我正在编写一个程序,在该程序中我需要在二进制文件上应用shellcode(我不知道它是否清楚),所以这就是我写的内容:
int main(int argc,char** argv){
struct stat s;
int f=open(argv[1],O_RDONLY); // open the binary
fstat(f,&s);
int len = s.st_size; // get the size
char *binary = malloc(len); // allocating enough memory
read(f,binary,len); // read all of this
char *bin = malloc(len-4); // someone told me to write -4, this is the output where hex is applied
const char* find[]={0x02,0x1F,0xCC,0x00};
const char* list[]={0x00,0x60,0x49,0x35};
unsigned int j = 0;
for (j=0; j<len; j+=4){
if (memcmp(binary+j,find,4)==0){
memcpy(&bin[j], list, 4); // applying 'list' to bin
printf("address : 0x%x\n",j);
continue;
}
}
/* edit: writing bin data (new file) here.. */
free(bin);
free(binary);
return 0;
}
但是当我用bin
的数据(用write()
创建一个文件时,我可以看到printf
字符串也被应用到了该文件(类似000032: ..?..printf("0x...
之类),而未应用list
正如我想要的十六进制转储。
我做错了什么? (希望我很清楚)
您确实应该注意编译器的警告。当然,它已经告诉const char* find[]={0x02,0x1F,0xCC,0x00};
这是怎么回事。它必须是char
而不是char*
。