aboutsummaryrefslogtreecommitdiffstats
path: root/src/tools/extract_syscalls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/extract_syscalls.c')
-rw-r--r--src/tools/extract_syscalls.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/tools/extract_syscalls.c b/src/tools/extract_syscalls.c
new file mode 100644
index 000000000..0e064a49e
--- /dev/null
+++ b/src/tools/extract_syscalls.c
@@ -0,0 +1,91 @@
1/*
2 * Copyright (C) 2014, 2015 netblue30 (netblue30@yahoo.com)
3 *
4 * This file is part of firejail project
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19*/
20#include <stdio.h>
21#include <stdlib.h>6
22#include <string.h>
23
24#define BUFMAX 4096
25
26int main(int argc, char **argv) {
27 if (argc != 2) {
28 printf("usage: %s /media/ubuntu/usr/include/x86_64-linux-gnu/bits/syscall.h\n", argv[0]);
29 return 1;
30 }
31
32 //open file
33 FILE *fp = fopen(argv[1], "r");
34 if (!fp) {
35 fprintf(stderr, "Error: cannot open file\n");
36 return 1;
37 }
38
39 // read file
40 char buf[BUFMAX];
41 while (fgets(buf, BUFMAX, fp)) {
42 // cleanup
43 char *start = buf;
44 while (*start == ' ' || *start == '\t')
45 start++;
46 char *end = strchr(start, '\n');
47 if (end)
48 *end = '\0';
49
50 // parsing
51 if (strncmp(start, "#endif", 6) == 0)
52 printf("%s\n", start);
53 if (strncmp(start, "#endif", 6) == 0)
54 printf("%s\n", start);
55 else if (strncmp(start, "#if", 3) == 0)
56 printf("%s\n", start);
57 else if (strncmp(start, "#define", 7) == 0) {
58 // extract data
59 char *ptr1 = strstr(start, "SYS_");
60 char *ptr2 = strstr(start, "__NR_");
61 if (!ptr1 || !ptr2) {
62 fprintf(stderr, "Error: cannot parse \"%s\"\n", start);
63 fclose(fp);
64 return 1;
65 }
66 *(ptr2 - 1) = '\0';
67
68 char *ptr3 = ptr1;
69 while (*ptr3 != ' ' && *ptr3 != '\t' && *ptr3 != '\0')
70 ptr3++;
71 *ptr3 = '\0';
72 ptr3 = ptr2;
73 while (*ptr3 != ' ' && *ptr3 != '\t' && *ptr3 != '\0')
74 ptr3++;
75 *ptr3 = '\0';
76
77 ptr3 = ptr1;
78 while (*ptr3 != '_')
79 ptr3++;
80 ptr3++;
81
82 printf("#ifdef %s\n", ptr1);
83 printf("#ifdef %s\n", ptr2);
84 printf("\t{\"%s\", %s},\n", ptr3, ptr2);
85 printf("#endif\n");
86 printf("#endif\n");
87 }
88 }
89 fclose(fp);
90 return 0;
91}