ref: d53014f85689f84574d0e4cf6bd7731f487aa71a filt/build_table -rwxr-xr-x 622 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
25
26
27
28
#!/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 "#[[:blank:]]*define SYS_[a-z]")

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

echo "	return -1;"
echo "}"