memcpy的建议

问题描述 投票:1回答:1

我正在编写一个程序,在该程序中我需要在二进制文件上应用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正如我想要的十六进制转储。

我做错了什么? (希望我很清楚)

c memory hex memcpy
1个回答
0
投票

您确实应该注意编译器的警告。当然,它已经告诉const char* find[]={0x02,0x1F,0xCC,0x00};这是怎么回事。它必须是char而不是char*

© www.soinside.com 2019 - 2024. All rights reserved.