从事网络安全项目:
在c中编辑.exe文件的代码时,可以编辑其他exe文件的代码,但不能编辑exe文件本身。这会导致分段错误。
反正有解决这个问题的方法吗?
产生细分错误的代码:
sandbox.c
#include <stdio.h>
int main(){
FILE *fp2 = fopen("sandbox","r+");
char cbuffer [100000];
int exe_len = fread(cbuffer,1,sizeof(cbuffer),fp2);
fwrite (cbuffer,sizeof(char),fp2);
static char a[10000] = "hello goodbye";
printf("%s\n",a );
return 0;
}
没有错误的代码,也是sandbox.c:
#include <stdio.h>
int main(){
FILE *fp2 = fopen("readme",a );
return 0;
}
Error: Segmentation fault (core dumped)