-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_forbidden_func.sh
71 lines (62 loc) · 2 KB
/
find_forbidden_func.sh
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
set -u
# Find cub3d binary
if [ ! -f "cub3d" ]; then
echo "[Info] Error: Not found cub3d executable file " 1>&2
echo " You must build cub3d before executing this script with make" 1>&2
exit 1
fi
# Bonus part does not need to check
echo "[Info] Wait ! Checking functions are needed in only mandatory part !"
echo " Make sure compile mandatory sources !"
echo " If you want to continue ? [Y/n]"
while read buf; do
if [[ "${buf}" == "n" || "${buf}" == "no" || "${buf}" == "N" || "${buf}" == "No" ]]; then
exit 0
fi
if [[ "${buf}" == "Y" || "${buf}" == "Yes" || "${buf}" == "yes" || "${buf}" == "y" ]]; then
break
fi
echo "[Info] Enter yes or no !"
done
if [[ "${buf}" == "" ]]; then
exit 0
fi
# Allowed functions list
# open, close, read, write,
# printf, malloc, free, perror,
# strerror, exit
# cos, sin, acos, abs
allow_funcs=("open" "close" "read" "write" "printf" "malloc" "free" "perror" "strerror" "exit" "cos" "sin" "acos" "abs")
echo "[Info] You can use these functions : ${allow_funcs[@]}"
function is_func_in_allowed_funcs() {
func=${1}
for item in "${allow_funcs[@]}"; do
if [[ "${func}" == "${item}" ]]; then
return 1
fi
done
return 0
}
for func in $(nm -u cub3d | grep "^_[a-z]" | tr -d '_'); do
echo "[Info] Find ${func} in your cub3d"
# Find fobidden function
if [[ "$(is_func_in_allowed_funcs ${func}; echo $?)" == "0" ]]; then
# Ignore fobidden function in minilibx
grep -rnw 'libft' -e "${func}" | grep -v "//" > /dev/null
libft_res=$(echo $?)
grep -rnw 'src' -e "${func}" | grep -v "//" > /dev/null
src_res=$(echo $?)
if [[ ${libft_res} -eq 0 || ${src_res} -eq 0 ]]; then
echo "[Info] Find : ${func}"
echo " This function is forbidden. Check below file !"
grep -rnw 'libft' -e "${func}" | grep -v "//"
grep -rnw 'src' -e "${func}" | grep -v "//"
exit 1
fi
echo "[Info] No worry ! ${func} is in minilibx !"
continue
fi
echo "[Info] No worry ! ${func} is allowed !"
done
echo "[Info] No fobidden functions in your cub3d !"