ref: 4f420d9746cba342b856e386785affb074d11675 filt/build_table -rwxr-xr-x 532 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env bash

exec 1<&-
exec 1<>table.h

echo "#include <sys/syscall.h>"
echo "#include <string.h>"
echo "long str_to_syscall_nr(const char *arg) {"

table=$(echo | gcc -E -Wp,-v - 2>&1 \
	| grep -E ' /' | xargs find | grep 'syscall.h' \
	| xargs cat | grep -E "# define SYS_[a-z]")

while read -r line; do
	splitted_line=($line)
	syscall=${splitted_line[2]}
	echo
	echo "#ifdef $syscall"
	echo "	if (strcmp(arg, \"${syscall/"SYS_"/""}\") == 0) return $syscall;"
	echo "#endif"
done <<< "$table"

echo "	return -1;"
echo "}"