forked from anbc/AndBug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
andbug
executable file
·82 lines (68 loc) · 2.55 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
# -*- coding: utf-8 -*-
## 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 cur_file_dir():
#获取脚本路径
path = sys.path[0]
#判断为脚本文件还是py2exe编译后的文件,如果是脚本文件,则返回的是脚本的目录,
#如果是py2exe编译后的文件,则返回的是编译后的文件路径
if os.path.isdir(path):
return path
elif os.path.isfile(path):
return os.path.dirname(path)
sys.path.append(cur_file_dir()+"/lib")
#sys.path.append("/home/anbc/work_folder/andbug_work/andbug/lib")
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)