forked from swdunlop/AndBug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
andbug
executable file
·67 lines (56 loc) · 2.05 KB
/
andbug
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
#!/usr/bin/env python
## Copyright 2011, IOActive, Inc. All rights reserved.
##
## AndBug is free software: you can redistribute it and/or modify it under
## the terms of version 3 of the GNU Lesser General Public License as
## published by the Free Software Foundation.
##
## AndBug is distributed in the hope that it will be useful, but WITHOUT ANY
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
## FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
## more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with AndBug. If not, see <http://www.gnu.org/licenses/>.
'this script executes command modules found in andbug.commands'
import os, os.path, sys, traceback, atexit
def panic(why, exit=True, exc=False):
sys.stderr.write("!! %s\n" % (why,))
sys.stderr.flush()
if exc:
traceback.print_exc()
if exit:
sys.exit(-1)
def main(args):
import andbug, andbug.cmd, andbug.command
atexit.register(sys.stdout.write, '\x1B[0m\n')
andbug.command.load_commands()
try:
andbug.command.run_command(args)
sys.exit(0)
except andbug.UserError as err:
panic(err)
except Exception as err:
panic(err, exc=True)
def find_python2():
path = os.environ.get("PATH")
if path == None:
panic("no PATH in your environment to search for python2")
for path in path.split(os.pathsep):
python2 = os.path.join(path, "python2")
if os.path.exists(python2):
return python2
panic("andbug does not support python != 2")
if __name__ == '__main__':
inv = os.path.basename(sys.argv[0]).lower()
if inv == "andbug":
args = sys.argv[1:]
else:
args = [inv] + sys.argv[1:]
if not args: args = ['help']
if sys.version_info[0] != 2:
python2 = find_python2()
panic('andbug requires python2, chaining to ' + python2, exit=False)
os.execv(python2, [python2] + sys.argv)
panic('could not execv %s' % python2)
main(args)