Working on a Cyber Security Project:
When editing the code of a .exe file in c, it's possible to edit the code of a different exe file but not the exe file itself. It results in a segmentation fault.
Is there anyway to get around this ?
Code that produces segmentation fault:
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), sizeof(cbuffer), fp2);
static char a[10000] = "hello goodbye";
printf("%s\n", a );
return 0;
}
Code that doesn't error, also 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)