]> git.saurik.com Git - apple/libsystem.git/blame - enable_asan_mode
Libsystem-1252.50.4.tar.gz
[apple/libsystem.git] / enable_asan_mode
CommitLineData
c06d156a
A
1#!/bin/bash -e
2
3if [ $# -ne 1 ]; then
4 echo "Usage:" 1>&2
5 echo " sudo $0 enable ... enables ASanification of system libraries on your system" 1>&2
6 echo " sudo $0 disable ... reverts the changes and restores the system back to normal" 1>&2
7 echo " $0 status ... prints current mode" 1>&2
8 exit 1
9fi
10
11if [ "$1" == "enable" ]; then
12 if [[ $(id -u) != 0 ]]; then echo "Must be run as root." 1>&2; exit 1; fi
13
14 if [ -f /usr/lib/libSystem.B.dylib-asan-mode-backup ]; then
15 if [ "`md5 -q /usr/lib/libSystem.B.dylib-asan-mode-backup`" != "`md5 -q /usr/lib/libSystem.B.dylib`" ]; then
16 echo "Looks like your system already has ASan mode enabled, or you have a custom /usr/lib/libSystem.B.dylib file. Not activating." 1>&2
17 exit 1
18 fi
19 fi
20
21 ditto /usr/lib/libSystem.B.dylib /usr/lib/libSystem.B.dylib-asan-mode-backup
22 ditto /usr/lib/libSystem.B_asan.dylib /usr/lib/libSystem.B.dylib
23 echo "ASan mode activated. You probably want to reboot now." 1>&2
24 exit 0
25elif [ "$1" == "disable" ]; then
26 if [[ $(id -u) != 0 ]]; then echo "Must be run as root." 1>&2; exit 1; fi
27 ditto /usr/lib/libSystem.B.dylib-asan-mode-backup /usr/lib/libSystem.B.dylib
28 echo "ASan mode deactivated. You probably want to reboot now." 1>&2
29 exit 0
30elif [ "$1" == "status" ]; then
31 if [ ! -f /usr/lib/libSystem.B.dylib-asan-mode-backup ]; then
32 echo "ASan mode is disabled." 1>&2
33 exit 0
34 fi
35
36 if [ "`md5 -q /usr/lib/libSystem.B.dylib-asan-mode-backup`" == "`md5 -q /usr/lib/libSystem.B.dylib`" ]; then
37 echo "ASan mode is disabled." 1>&2
38 exit 0
39 fi
40
41 if [ "`md5 -q /usr/lib/libSystem.B_asan.dylib`" == "`md5 -q /usr/lib/libSystem.B.dylib`" ]; then
42 echo "ASan mode is enabled." 1>&2
43 exit 0
44 fi
45
46 echo "Cannot tell whether ASan mode is enabled or not. You seem to have a custom /usr/lib/libSystem.B.dylib file." 1>&2
47 exit 1
48else
49 echo "Invalid argument. Run '$0' for usage instructions." 1>&2
50 exit 1
51fi