summaryrefslogtreecommitdiff
path: root/other/adore-ng/symsed.c
diff options
context:
space:
mode:
authorSkyperTHC2026-03-03 06:28:55 +0000
committerSkyperTHC2026-03-03 06:28:55 +0000
commit5d3573ef7a109ee70416fe94db098fe6a769a798 (patch)
treedc2d5b294c9db8ab2db7433511f94e1c4bb8b698 /other/adore-ng/symsed.c
parentc6c59dc73cc4586357f93ab38ecf459e98675cc5 (diff)
packetstorm sync
Diffstat (limited to 'other/adore-ng/symsed.c')
-rw-r--r--other/adore-ng/symsed.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/other/adore-ng/symsed.c b/other/adore-ng/symsed.c
new file mode 100644
index 0000000..3755367
--- /dev/null
+++ b/other/adore-ng/symsed.c
@@ -0,0 +1,52 @@
1#include <stdio.h>
2#include <fcntl.h>
3#include <sys/mman.h>
4#include <unistd.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7#include <string.h>
8#include <errno.h>
9#include <stdlib.h>
10
11
12int main(int argc, char **argv)
13{
14 int fd = 0;
15 char *ptr = NULL, *orig_ptr = NULL;
16 struct stat st;
17
18 if (argc != 3) {
19 printf("Usage: %s <file> <subst>\n", *argv);
20 exit(1);
21 }
22 if (strlen(argv[2]) >= strlen("init_module")) {
23 printf("Can't only substitute symbols by strings with at most"
24 "%u characters.\n", strlen("init_module"));
25 exit(2);
26 }
27
28 if ((fd = open(argv[1], O_RDWR)) < 0) {
29 perror("open");
30 exit(errno);
31 }
32 if (fstat(fd, &st) < 0) {
33 perror("fstat");
34 exit(errno);
35 }
36 ptr = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
37 orig_ptr = ptr;
38 if (!ptr) {
39 perror("mmap");
40 exit(errno);
41 }
42 for (; ptr < orig_ptr + st.st_size; ++ptr) {
43 if (strncmp(ptr, "init_module", strlen("init_module")) == 0 ||
44 strncmp(ptr, "cleanup_module", strlen("cleanup_module")) == 0) {
45 memcpy(ptr, argv[2], strlen(argv[2]));
46 ptr += strlen(argv[2]);
47 }
48 }
49 munmap(ptr, st.st_size);
50 return 0;
51}
52