forked from zzgang/kconnp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·154 lines (128 loc) · 4 KB
/
configure
File metadata and controls
executable file
·154 lines (128 loc) · 4 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#! /bin/sh
help(){
cat <<EOF
LKM build params:
--with-kernel-build-dir=DIR
Set kernel module build dir
--debug
Enable machine restart automatically
--clean
Clean the Makefile
EOF
exit;
}
clean(){
echo 'Cleaning...'
test -f Makefile && make clean 1>/dev/null;
rm -f Makefile;
rm -f sys_call_table_ea.h;
rm -f local_func_ea.h;
}
#kernel version.
kv=`uname -r`;
#kernel system map.
sysmap_file="";
#kernel build dir.
kmbd="/lib/modules/${kv}/build";
boot_dir="/boot"
#check sysmap.
if [ -f "${boot_dir}/System.map-$kv" ]
then
sysmap_file="${boot_dir}/System.map-$kv";
elif [ -f "${boot_dir}/Systemmap-$kv" ]
then
sysmap_file="${boot_dir}/Systemmap-$kv";
fi
while [ $# -gt 0 ]
do
case "${1%=*}" in
--with-kernel-build-dir)
kmbd="${1#*=}";
;;
--debug)
sysctl -w kernel.panic=1 > /dev/null
;;
--clean)
clean;
exit;
;;
--help)
help;
;;
*)
echo "Unrecognized param: ${1%=*}";
help;
;;
esac
shift;
done
if test ! -d $kmbd || test ! -e $sysmap_file
then
echo "Error: Can't build the ENV for building the LKM";
help;
else
echo "Check kernel devel dir for building LKM... yes";
echo "Check kernel sysmap file for building LKM... yes";
fi
if ! (which pcregrep 1>/dev/null) && echo "Check system command pcregrep... no";
then
echo "Check system command pcregrep... no";
exit
else
echo "Check system command pcregrep... yes";
fi
#######################
#Generate sys calls ea.
#######################
sys_call_table_ea=`pcregrep '\bsys_call_table\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_socketcall_ea=`pcregrep '\bsys_socketcall\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_connect_ea=`pcregrep '\bsys_connect\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_close_ea=`pcregrep '\bsys_close\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_shutdown_ea=`pcregrep '\bsys_shutdown\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_exit_group_ea=`pcregrep '\bsys_exit_group\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_exit_ea=`pcregrep '\bsys_exit\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_write_ea=`pcregrep '\bsys_write\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_send_ea=`pcregrep '\bsys_send\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
sys_sendto_ea=`pcregrep '\bsys_sendto\b' $sysmap_file | awk '{print $1;}' | sed -e 's/0x//'`;
cat sys_call_table_ea.h.in |
sed -e "s/%%SYS_CALL_TABLE_EA%%/0x${sys_call_table_ea}/" |
sed -e "s/%%SYS_SOCKETCALL_EA%%/0x${sys_socketcall_ea}/" |
sed -e "s/%%SYS_CONNECT_EA%%/0x${sys_connect_ea}/" |
sed -e "s/%%SYS_CLOSE_EA%%/0x${sys_close_ea}/" |
sed -e "s/%%SYS_SHUTDOWN_EA%%/0x${sys_shutdown_ea}/" |
sed -e "s/%%SYS_EXIT_GROUP_EA%%/0x${sys_exit_group_ea}/" |
sed -e "s/%%SYS_EXIT_EA%%/0x${sys_exit_ea}/" |
sed -e "s/%%SYS_WRITE_EA%%/0x${sys_write_ea}/" |
sed -e "s/%%SYS_SEND_EA%%/0x${sys_send_ea}/" |
sed -e "s/%%SYS_SENDTO_EA%%/0x${sys_sendto_ea}/" > sys_call_table_ea.h;
NO_OMIT_FRAME_POINTER=""
machine_type=`uname -m | sed -e 's/^i[0-9]86$/x86_32/'`
case "$machine_type" in
'x86_32')
machine_type='x86_32'
;;
'x86_64')
;;
*)
echo "Error: Unsurported machine type $machine_type"
exit
;;
esac
echo "Check machine type... $machine_type yes";
if [ "$machine_type" = 'x86_32' ] #32 bits machine
then
NO_OMIT_FRAME_POINTER="export CONFIG_FRAME_POINTER=ON"
fi
$NO_OMIT_FRAME_POINTER
cat > Makefile <<MF
obj-m = kconnp.o
kconnp-objs := connp_entry.o sys_call.o sockp.o connp.o preconnect.o connpd.o sys_socketcalls.o sys_close.o sys_exit.o sys_exit_group.o sys_sendcalls.o hash.o cfg.o lkm_util.o
$NO_OMIT_FRAME_POINTER
all:
make -C $kmbd SUBDIRS=\$(PWD) modules
clean:
make -C $kmbd SUBDIRS=\$(PWD) clean
install:
./scripts/install
MF
echo 'Successful.';