commit b674d5d035a38e0a1aa5e925bd52e8376a7ae947
parent 01e5eaf2d2efdbf938ae05e11a60a0169b5b4531
Author: torter <koubbamohamedrayan@gmail.com>
Date: Sat, 14 Nov 2026 19:03:37 +0000
mag relocate: read-only binaries too
Diffstat:
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/mag.c b/mag.c
@@ -1769,7 +1769,15 @@ static void reloc_file(const char *path, const char *from, const char *to)
i += tl;
}
}
- if (changed) { FILE *f = fopen(path, "r+b"); if (f) { fwrite(buf, 1, len, f); fclose(f); } }
+ if (changed) {
+ struct stat st;
+ int ro = stat(path, &st) == 0 && !(st.st_mode & 0200);
+ FILE *f;
+ if (ro) chmod(path, st.st_mode | 0200);
+ f = fopen(path, "r+b");
+ if (f) { fwrite(buf, 1, len, f); fclose(f); }
+ if (ro) chmod(path, st.st_mode);
+ }
free(buf);
}
static void reloc_walk(const char *dir, const char *from1, const char *to1, const char *from2, const char *to2)