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