1 diff -urN fenris.orig/build fenris/build
2 --- fenris.orig/build Wed May 29 02:42:32 2002
3 +++ fenris/build Thu May 30 10:23:18 2002
9 # fenris - program execution path analysis tool
12 # 05/16/2002: Modified by Marcin Gozdalik to use libfnprints and such.
15 -test "$BASH" = "" && echo "Bash shell is required to execute this script."
16 -test "$BASH" = "" && exit 1
18 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$PATH
24 rm -f $PROGNAME6 $PROGNAME5 $PROGNAME3 $PROGNAME4 $PROGNAME $PROGNAME2 scnames.h core core.* *~ .testme.c .testme .testerr .gtmp CTORS.txt *.o a.out test/a.out doc/frep.txt aegir-decl.h fenris-decl.h gprof.out bb.out libdisasm/core test/core libdisasm/*.o libdisasm/a.out tools/fprints NEW-fnprints.dat .tmp NEW-fp.dat test/core.*
25 -rm -f beta/*.o beta/nc-aegir &>/dev/null
26 +rm -f beta/*.o beta/nc-aegir >/dev/null 2>&1
28 test "$1" = "clean" && echo "[+] Cleanup complete."
29 test "$1" = "clean" && exit 0
31 echo " 'fenris-bug' reporting application. Thanks!"
34 -test "$1" = "" && sleep 2
35 +[ -z "$1" ] && sleep 2
38 BUILD=`cat doc/.build 2>/dev/null`
39 -test "$BUILD" = "" && BUILD=0
40 +[ -z "$BUILD" ] && BUILD=0
42 if [ "$HOSTNAME" = "nimue.bos.bindview.com" ]; then
45 echo "$BUILD" >doc/.build 2>/dev/null
46 echo -n "[?] Changes in this build: "
48 - if [ ! "$x" = "" ]; then
49 + if [ -n "$x" ]; then
50 echo "$VERSION [$BUILD]: $x" >.tmp
51 cat doc/ChangeLog >>.tmp 2>/dev/null
52 cat .tmp >doc/ChangeLog
55 SYSNAME=`uname -s 2>/dev/null`
57 -test "$SYSNAME" = "" && SYSNAME="unknown"
58 +[ -z "$SYSNAME" ] && SYSNAME="unknown"
60 if [ ! "$SYSNAME" = "Linux" ]; then
61 echo "$SYSNAME is not supported!"
63 echo -n "[+] Processor check: "
65 PROC=`uname -m 2>/dev/null`
66 -test "$PROC" = "" && PROC="unknown"
67 -PROCOK=`echo $PROC|grep ^i.86\$ 2>/dev/null`
68 +[ -z "$PROC" ] && PROC="unknown"
69 +PROCOK=`echo $PROC | grep ^i.86\$ 2>/dev/null`
71 -if [ "$PROCOK" = "" ]; then
72 +if [ -z "$PROCOK" ]; then
73 echo "$PROC is not supported!"
74 echo "[-] I do not support your CPU yet. Please consult documentation."
78 echo -n "[+] GNU C library version: "
80 -LIBCVER=`/lib/libc.so.6|awk -F'version ' '{print $2}'|awk -F, '{print $1}'|head -1`
81 +LIBCVER=`/lib/libc.so.6 | awk -F'version ' '{print $2}' | awk -F, '{print $1}' | head -1`
83 -if [ "$LIBCVER" = "" ]; then
84 +if [ -z "$LIBCVER" ]; then
85 echo "cannot determine libc version!"
86 echo "[-] I am affraid I cannot continue. Please consult documentation."
90 for i in $OKLIBC; do test "$LIBCVER" = "$i" && VEROK="1"; done
92 -if [ "$VEROK" = "" ]; then
93 +if [ -z "$VEROK" ]; then
95 echo "[!] This voids your warranty ;) Please consult documentation."
96 echo " And, if this is not a big deal, contact author :)"
99 echo -n "[+] GNU C compiler version: "
101 -GCCVER=`gcc -v 2>&1|grep 'gcc version' 2>/dev/null|awk '{print $3}' 2>/dev/null`
102 +GCCVER=`gcc -v 2>&1 | grep 'gcc version' 2>/dev/null | awk '{print $3}' 2>/dev/null`
104 -if [ "$GCCVER" = "" ]; then
105 +if [ -z "$GCCVER" ]; then
106 echo "problems calling gcc!"
107 echo "[-] I cannot continue. Please consult documentation."
111 for i in $OKGCC; do test "$GCCVER" = "$i" && VEROK="1"; done
113 -if [ "$VEROK" = "" ]; then
114 +if [ -z "$VEROK" ]; then
116 echo "[!] This voids your warranty ;) Please consult documentation."
117 echo " And, if this is not a big deal, contact author :)"
118 @@ -222,10 +218,10 @@
120 echo -n "[+] GNU libc binary test: "
122 -STRILI=`file -L /lib/libc.so.6 2>/dev/null|grep 'not strip'`
123 -GENLI=`file -L /lib/libc.so.6 2>/dev/null|grep 'strip'`
124 +STRILI=`file -L /lib/libc.so.6 2>/dev/null | grep 'not strip'`
125 +GENLI=`file -L /lib/libc.so.6 2>/dev/null | grep 'strip'`
127 -if [ "$GENLI" = "" ]; then
128 +if [ -z "$GENLI" ]; then
130 echo "[-] I cannot read your /lib/libc.so.6 (or your 'file' utility"
131 echo " is broken). Please fix it. Yes, you need libc6, yes, I need"
136 -if [ "$STRILI" = "" ]; then
137 +if [ -z "$STRILI" ]; then
139 - if [ "$LAMESTRIP" = "" ]; then
140 + if [ -z "$LAMESTRIP" ]; then
141 echo "[-] Come on, you didn't strip your libc binary, did you?;)"
142 echo " I am sorry, but I really want to read some information"
143 echo " from there. Can you fix that? If not, please run me providing"
144 @@ -256,10 +252,10 @@
146 echo -n "[+] GCC crt code binary test: "
148 -STRILI=`file -L /usr/lib/crt1.o 2>/dev/null|grep 'not strip'`
149 -GENLI=`file -L /usr/lib/crt1.o 2>/dev/null|grep 'strip'`
150 +STRILI=`file -L /usr/lib/crt1.o 2>/dev/null | grep 'not strip'`
151 +GENLI=`file -L /usr/lib/crt1.o 2>/dev/null | grep 'strip'`
153 -if [ "$GENLI" = "" ]; then
154 +if [ -z "$GENLI" ]; then
156 echo "[-] I cannot read your /usr/lib/crt1.o (or your 'file' utility"
157 echo " is broken). Please fix it. Thanks =)"
162 -if [ "$STRILI" = "" ]; then
163 +if [ -z "$STRILI" ]; then
165 - if [ "$LAMESTRIP" = "" ]; then
166 + if [ -z "$LAMESTRIP" ]; then
167 echo "[-] Come on, you didn't strip your crt binary, did you?;)"
168 echo " I am sorry, but I really want to read some information"
169 echo " from there. Can you fix that? If not, please run me providing"
170 @@ -289,10 +285,10 @@
172 echo -n "[+] GNU libc linker test: "
174 -STRILI=`file -L /lib/ld-linux.so.2 2>/dev/null|grep 'not strip'`
175 -GENLI=`file -L /lib/ld-linux.so.2 2>/dev/null|grep 'strip'`
176 +STRILI=`file -L /lib/ld-linux.so.2 2>/dev/null | grep 'not strip'`
177 +GENLI=`file -L /lib/ld-linux.so.2 2>/dev/null | grep 'strip'`
179 -if [ "$GENLI" = "" ]; then
180 +if [ -z "$GENLI" ]; then
182 echo "[-] I cannot read your /lib/ld-linux.so.2 (or your 'file' utility"
183 echo " is broken). Please fix it. Yes, you need libc6, yes, I need"
188 -if [ "$STRILI" = "" ]; then
189 +if [ -z "$STRILI" ]; then
191 - if [ "$LAMESTRIP" = "" ]; then
192 + if [ -z "$LAMESTRIP" ]; then
193 echo "[-] Come on, you didn't strip your crt binary, did you?;)"
194 echo " I am sorry, but I really want to read some information"
195 echo " from there. Can you fix that? If not, please run me providing"
200 -gcc .testme.c -o .testme &>.testerr
201 +gcc .testme.c -o .testme >.testerr 2>&1
203 -if [ ! -s .testme ]; then
204 +if [ `cat .testme | wc -c` -eq 0 ]; then
205 echo "gcc failed to compile test code!"
206 echo "[-] I really have to perform tests. Please consult documentation."
208 @@ -389,14 +385,14 @@
209 echo "x/2w _dl_runtime_resolve+16" >>.testerr 2>/dev/null
211 gdb -batch -x .testerr ./.testme >.gtmp 2>/dev/null
212 -ADDR=`grep open .gtmp 2>/dev/null|grep ^0x 2>/dev/null | awk '{print $1}' 2>/dev/null`
213 +ADDR=`grep open .gtmp 2>/dev/null | grep ^0x 2>/dev/null | awk '{print $1}' 2>/dev/null`
215 RES=`grep -F resolve .gtmp 2>/dev/null`
216 JMP=`grep -F getuid .gtmp 2>/dev/null`
218 rm -f .testerr .testme
220 -if [ "$ADDR" = "" ]; then
221 +if [ -z "$ADDR" ]; then
223 echo "problems executing gdb!"
224 echo "[-] I need gdb to determine your defaults. Please consult documentation."
229 -MAPSEG=`printf "%x" $[ADDR/(256*256*256)] 2>/dev/null`
230 +MAPSEG=`printf "%x" $((16#${ADDR#0x}/256/256/256)) 2>/dev/null`
232 -if [ "$MAPSEG" = "" ]; then
233 +if [ -z "$MAPSEG" ]; then
235 echo "cannot calculate segment address!"
236 echo "[-] That's very bad. Please consult documentation."
237 @@ -424,14 +420,14 @@
239 echo -n "[+] C library _init code: "
241 -for i in `grep -B 1 enter_dynamic fenris.c |grep AS_UI|awk -F== '{print $2}'|awk -F\) '{print $1}'|awk '!(NR % 2) {print DUPA ".*" $1};(NR % 2) {DUPA=$1}'`; do
242 +for i in `grep -B 1 enter_dynamic fenris.c | grep AS_UI | awk -F== '{print $2}' | awk -F\) '{print $1}' | awk '!(NR % 2) {print DUPA ".*" $1};(NR % 2) {DUPA=$1}'`; do
243 FIKU=`grep "$i" .gtmp`
244 - test "$FIKU" = "" || CTORSOK=`echo "$i"|sed 's/\.\*/ /g'`
245 + [ -z "$FIKU" ] || CTORSOK=`echo "$i" | sed 's/\.\*/ /g'`
250 -if [ ! "$CTORSOK" = "" ]; then
251 +if [ -n "$CTORSOK" ]; then
252 echo "supported ($CTORSOK)"
254 echo "no known _init pattern!"
256 echo "disass __do_global_ctors_aux" >>.testerr 2>/dev/null
257 gdb -batch -x .testerr ./.testme >>CTORS.txt 2>&1
259 - objdump -d ./.testme 2>&1 |grep -A 20 ctors_aux\>: >>CTORS.txt 2>&1
260 + objdump -d ./.testme 2>&1 | grep -A 20 ctors_aux\>: >>CTORS.txt 2>&1
261 rm -f .testerr .testme .testme.c
264 @@ -472,11 +468,11 @@
266 R=`echo "$RES" | grep '0x0487595a.*0x0008c224'`
268 -if [ ! "$R" = "" ]; then
269 +if [ -n "$R" ]; then
272 echo "no known pattern!"
273 - if [ "$LAMESTRIP" = "" ]; then
274 + if [ -z "$LAMESTRIP" ]; then
276 echo "[-] Your GNU C library linker does not seem to use known"
277 echo " _dl_runtime_resolve() function code. This means I would not"
280 P=`echo "$JMP" | grep '25ff'`
282 -if [ ! "$P" = "" ]; then
283 +if [ -n "$P" ]; then
286 echo "no known pattern!"
289 echo -n "[+] RSA MD5 implementation: "
290 if [ ! -f /usr/include/md5.h ]; then
291 - if [ ! -f /usr/include/local/md5.h ]; then
292 + if [ ! -f /usr/local/include/md5.h ]; then
293 echo "md5.h not found!"
294 echo "[-] You need to have OpenSSL MD5 or RSA MD5 libraries installed."
296 @@ -586,14 +582,18 @@
297 CFLAGS="-DUSE_OPENSSL=1"
298 CFLAGS2="-DUSE_OPENSSL=1"
300 - if [ ! -f /usr/lib/libcrypto.so ]; then
301 - if [ ! -f /usr/local/lib/libcrypto.so ]; then
302 - if [ ! -f /usr/lib/libcrypto.a ]; then
303 - if [ ! -f /usr/local/lib/libcrypto.a ]; then
304 - echo "libcrypto.so not found!"
305 - echo "[-] Please install OpenSSL or RSA MD5 implementation."
308 + if [ ! -f /lib/libcrypto.so ]; then
309 + if [ ! -f /usr/lib/libcrypto.so ]; then
310 + if [ ! -f /usr/local/lib/libcrypto.so ]; then
311 + if [ ! -f /lib/libcrypto.a ]; then
312 + if [ ! -f /usr/lib/libcrypto.a ]; then
313 + if [ ! -f /usr/local/lib/libcrypto.a ]; then
314 + echo "libcrypto.so not found!"
315 + echo "[-] Please install OpenSSL or RSA MD5 implementation."
323 @@ -603,16 +603,20 @@
325 LDFLAGS="$LDFLAGS -lmd5"
327 - if [ ! -f /usr/lib/libmd5.so ]; then
328 - if [ ! -f /usr/local/lib/libmd5.so ]; then
329 - if [ ! -f /usr/lib/libmd5.a ]; then
330 - if [ ! -f /usr/local/lib/libmd5.a ]; then
331 + if [ ! -f /lib/libmd5.so ]; then
332 + if [ ! -f /usr/lib/libmd5.so ]; then
333 + if [ ! -f /usr/local/lib/libmd5.so ]; then
334 + if [ ! -f /lib/libmd5.a ]; then
335 + if [ ! -f /usr/lib/libmd5.a ]; then
336 + if [ ! -f /usr/local/lib/libmd5.a ]; then
337 echo "libcrypto.so not found!"
338 echo "[-] Please install OpenSSL or RSA MD5 implementation."
348 @@ -633,14 +637,18 @@
352 -if [ ! -f /usr/lib/libbfd.so ]; then
353 - if [ ! -f /usr/local/lib/libbfd.so ]; then
354 - if [ ! -f /usr/lib/libbfd.a ]; then
355 - if [ ! -f /usr/local/lib/libbfd.a ]; then
356 - echo "libbfd not found!"
357 - echo "[-] Please install binutils libraries."
360 +if [ ! -f /lib/libbfd.so ]; then
361 + if [ ! -f /usr/lib/libbfd.so ]; then
362 + if [ ! -f /usr/local/lib/libbfd.so ]; then
363 + if [ ! -f /lib/libbfd.a ]; then
364 + if [ ! -f /usr/lib/libbfd.a ]; then
365 + if [ ! -f /usr/local/lib/libbfd.a ]; then
366 + echo "libbfd not found!"
367 + echo "[-] Please install binutils libraries."
375 @@ -648,14 +656,18 @@
379 -if [ ! -f /usr/lib/libiberty.a ]; then
380 - if [ ! -f /usr/local/lib/libiberty.a ]; then
381 - if [ ! -f /usr/lib/libiberty.so ]; then
382 - if [ ! -f /usr/local/lib/libiberty.so ]; then
383 - echo "libiberty not found!"
384 - echo "[-] Please install binutils libraries."
387 +if [ ! -f /lib/libiberty.a ]; then
388 + if [ ! -f /usr/lib/libiberty.a ]; then
389 + if [ ! -f /usr/local/lib/libiberty.a ]; then
390 + if [ ! -f /lib/libiberty.so ]; then
391 + if [ ! -f /usr/lib/libiberty.so ]; then
392 + if [ ! -f /usr/local/lib/libiberty.so ]; then
393 + echo "libiberty not found!"
394 + echo "[-] Please install binutils libraries."
402 @@ -667,14 +679,14 @@
404 if [ -f /usr/include/readline/readline.h -o -f /usr/local/include/readline/readline.h ]; then
406 - if [ -f /usr/lib/libreadline.so -o -f /usr/local/lib/libreadline.so -o -f /usr/lib/libreadline.a -o -f /usr/local/lib/libreadline.a ]; then
407 + if [ -f /lib/libreadline.so -o -f /usr/lib/libreadline.so -o -f /usr/local/lib/libreadline.so -o -f /lib/libreadline.a -o -f /usr/lib/libreadline.a -o -f /usr/local/lib/libreadline.a ]; then
409 - if [ -f /usr/lib/libtinfo.so -o -f /usr/local/lib/libtinfo.so -o -f /usr/lib/libtinfo.a -o -f /usr/local/lib/libtinfo.a ]; then
410 + if [ -f /lib/libtinfo.so -o -f /usr/lib/libtinfo.so -o -f /usr/local/lib/libtinfo.so -o -f /lib/libtinfo.a -o -f /usr/lib/libtinfo.a -o -f /usr/local/lib/libtinfo.a ]; then
411 CFLAGS="-DHAVE_READLINE -D__USE_TERMCAP $CFLAGS"
412 LDFLAGS="-lreadline $LDFLAGS"
413 LDGLAGS="$LDFLAGS -ltinfo"
414 echo "yes, with libtinfo"
415 - elif [ -f /usr/lib/libtermcap.so -o -f /usr/local/lib/libtermcap.so -o -f /usr/lib/libtermcap.a -o -f /usr/local/lib/libtermcap.a ]; then
416 + elif [ -f /lib/libtermcap.so -o -f /usr/lib/libtermcap.so -o -f /usr/local/lib/libtermcap.so -o -f /lib/libtermcap.a -o -f /usr/lib/libtermcap.a -o -f /usr/local/lib/libtermcap.a ]; then
417 CFLAGS="-DHAVE_READLINE -D__USE_TERMCAP $CFLAGS"
418 LDFLAGS="-lreadline $LDFLAGS"
419 LDFLAGS="$LDFLAGS -ltermcap"
421 echo -n "[+] libncurses installed: "
423 if [ -f /usr/include/curses.h -o -f /usr/local/include/curses.h ]; then
424 - if [ -f /usr/lib/libncurses.so -o -f /usr/local/lib/libncurses.so -o -f /usr/lib/libncurses.a -o -f /usr/local/lib/libncurses.a ]; then
425 + if [ -f /lib/libncurses.so -o -f /usr/lib/libncurses.so -o -f /usr/local/lib/libncurses.so -o -f /lib/libncurses.a -o -f /usr/lib/libncurses.a -o -f /usr/local/lib/libncurses.a ]; then
426 echo "yes, nc-aegir will be built."
430 echo "no, nc-aegir will not be built."
433 -if [ ! "$NCAEGIR" = "" ]; then
434 +if [ -n "$NCAEGIR" ]; then
435 echo -n "[+] 'screen' installed: "
436 if [ -x /usr/bin/screen -o -x /usr/local/bin/screen ]; then
442 -echo "$[LIN-1] entries"
443 +echo "$((LIN-1)) entries"
445 echo -n "[*] Generating decl list for fenris.c: "
451 -echo "$[LIN-1] entries"
452 +echo "$((LIN-1)) entries"
454 echo -n "[*] Generating decl list for aegir.c: "
460 -echo "$[LIN-1] entries"
461 +echo "$((LIN-1)) entries"
464 echo -n "[*] Compiling libi386: "
469 -if [ ! "$NCAEGIR" = "" ]; then
470 +if [ -n "$NCAEGIR" ]; then
471 echo -n "[*] Compiling nc-opdis: "
472 gcc -c $CFLAGS2 libdisasm/opcodes2/nc-opdis.c 2>.testerr
474 @@ -1026,7 +1038,7 @@
478 -test "$NOSTRIP" = "" && strip $PROGNAME 2>/dev/null
479 +[ -z "$NOSTRIP" ] && strip $PROGNAME 2>/dev/null
481 echo -n "[*] Compiling $PROGNAME2: "
483 @@ -1125,7 +1137,7 @@
487 -if [ ! "$NCAEGIR" = "" ]; then
488 +if [ -n "$NCAEGIR" ]; then
489 echo -n "[*] Compiling $PROGNAME6: "
490 gcc -lncurses $LDFLAGS $CFLAGS $PROGNAME6.c libfnprints.o i386-dis.o nc-opdis.o -o $PROGNAME6 -DVERSION=\"$VERSION\" -DBUILD=\"$BUILD\" -DLIBCSEG=$MAPSEG 2>.testerr
491 if [ ! -s $PROGNAME6 ]; then
492 @@ -1156,12 +1168,12 @@
496 -test "$NOSTRIP" = "" && strip $PROGNAME 2>/dev/null
497 -test "$NOSTRIP" = "" && strip $PROGNAME4 2>/dev/null
498 -test "$NOSTRIP" = "" && strip $PROGNAME2 2>/dev/null
499 -test "$NOSTRIP" = "" && strip $PROGNAME3 2>/dev/null
500 -test "$NOSTRIP" = "" && strip $PROGNAME5 2>/dev/null
501 -test "$NOSTRIP" = "" && strip $PROGNAME6 2>/dev/null
502 +[ -z "$NOSTRIP" ] && strip $PROGNAME 2>/dev/null
503 +[ -z "$NOSTRIP" ] && strip $PROGNAME4 2>/dev/null
504 +[ -z "$NOSTRIP" ] && strip $PROGNAME2 2>/dev/null
505 +[ -z "$NOSTRIP" ] && strip $PROGNAME3 2>/dev/null
506 +[ -z "$NOSTRIP" ] && strip $PROGNAME5 2>/dev/null
507 +[ -z "$NOSTRIP" ] && strip $PROGNAME6 2>/dev/null
510 test "$1" = "" && HUH=1
511 @@ -1175,7 +1187,7 @@
512 cat .tmp >fnprints.dat
514 CNT=`grep -c . fnprints.dat`
515 - test "$CNT" = "" && CNT=0
516 + [ -z "$CNT" ] && CNT=0
517 echo "[*] Updating libc fingerprints database (this will take a while)..."
518 NOBANNER=1 ./getfprints
519 echo "[*] Sorting your fingerprints..."
520 @@ -1190,7 +1202,7 @@
524 - diff -d 'fnprints.dat' 'NEW-fnprints.dat' | grep '^> ' |awk -F'> ' '{print $2}' >.news
525 + diff -d 'fnprints.dat' 'NEW-fnprints.dat' | grep '^> ' | awk -F'> ' '{print $2}' >.news
527 rm -f NEW-fnprints.dat fnprints.dat
528 mv -f .tmp fnprints.dat
529 @@ -1203,7 +1215,7 @@
530 cat .news >>NEW-fp.dat
533 - echo "[+] Congratulations, your system has $[CNT2-CNT] new fingerprints."
534 + echo "[+] Congratulations, your system has $((CNT2-CNT)) new fingerprints."
535 echo " I created a file called NEW-fp.dat for you. It woule be very nice"
536 echo " if you can send it to the author, lcamtuf@coredump.cx. Thanks!"
538 @@ -1215,14 +1227,14 @@
542 - echo "[+] You have $[`grep -c . fnprints.dat`] fingerprints."
543 + echo "[+] You have $((`grep -c . fnprints.dat`)) fingerprints."
548 if [ -f test.c ]; then
549 echo "[+] Ah, I see you have test.c here... Lemme compile it for you!"
550 - gcc test.c &>/dev/null
551 + gcc test.c >/dev/null 2>&1
554 echo "[+] All set. Please read the documentation."