-
Notifications
You must be signed in to change notification settings - Fork 7
/
exgdb.py
190 lines (168 loc) · 6.44 KB
/
exgdb.py
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import os
import sys
import re
import gdb
RE_BLUE = re.compile(r";34m")
exgdbpath = os.environ.get("EXGDBPATH")
if exgdbpath == None:
print("Please export $EXGDBPATH")
exit()
sys.path.insert(0, exgdbpath + "/lib/")
from enert import *
import utils
import exutils
class Exgdb():
THISDIR = ""
def __init__(self):
pass
class ExgdbCmd():
def __init__(self):
pass
def import_topFunctions(fname):
cmd = "grep -o '^def.*:' " + fname + " | sed -E 's@^def (.*)\((.*)\) *:@\\1:\\2@g'"
stdout, stderr = Shell(cmd).readlines()
functions = stdout
for function in functions:
(function_name, function_args) = function.split(":")
if function_name.startswith("_"):
continue
if hasattr(ExgdbCmd, function_name):
continue
if hasattr(gdb.Command, function_name):
continue
code = "lambda self, " + function_args + ": " + function_name + "(" + function_args + ")"
new_function = eval(code)
setattr(Exgdb, function_name, new_function)
def import_from_exportFile():
exportFile_paths = Shell("ls -1 %s/plugins/*/export_to_exgdb.py" % exgdbpath).readlines()[0]
if len(exportFile_paths) < 1: return
for exportFile_path in exportFile_paths:
if not File(exportFile_path).exist(): continue
plugin_name_chrs = list(exportFile_path.replace("%s/plugins/" % exgdbpath, ""))
plugin_name = ""
for ch in plugin_name_chrs:
if ch == "/": break
plugin_name += ch
if len(plugin_name) > len(".disabled") and plugin_name[-9:] == ".disabled": continue
Exgdb.THISDIR = "%s/plugins/%s" % (exgdbpath, plugin_name)
gdb.execute("source %s" % exportFile_path)
def import_other_plugins():
if "PwnCmd" in globals():
import_topFunctions("%s/plugins/Pwngdb/pwngdb.py" % exgdbpath)
import_topFunctions("%s/plugins/Pwngdb/angelheap/angelheap.py" % exgdbpath)
if "PEDA" in globals():
cmds = [cmd for cmd in dir(PEDA) if cmd != "SAVED_COMMANDS" and callable(getattr(PEDA, cmd))]
cmd_to_get_exgdb_functions = "grep -o ' *def.*:' %s/exgdbmethods.py | sed -E 's@ *def (.*)\((.*)\) *:@\\1:\\2@g'" % exgdbpath
stdout, stderr = Shell(cmd_to_get_exgdb_functions).readlines()
exgdb_functions = stdout
exgdb_functions = list(map(lambda x: x.split(":")[0], exgdb_functions))
for cmd in cmds:
if cmd.startswith("_"):
continue
if hasattr(ExgdbCmd, cmd):
continue
if hasattr(gdb.Command, cmd):
continue
if cmd in exgdb_functions:
continue
cmd_obj = getattr(PEDA, cmd)
setattr(Exgdb, cmd, cmd_obj)
if "PEDACmd" in globals():
cmds = [cmd for cmd in dir(PEDACmd) if callable(getattr(PEDACmd, cmd))]
cmd_to_get_exgdb_functions = "grep -o ' *def.*:' %s/exgdbcmdmethods.py | sed -E 's@ *def (.*)\((.*)\) *:@\\1:\\2@g'" % exgdbpath
stdout, stderr = Shell(cmd_to_get_exgdb_functions).readlines()
exgdb_functions = stdout
exgdb_functions = list(map(lambda x: x.split(":")[0], exgdb_functions))
for cmd in cmds:
if cmd.startswith("_"):
continue
if hasattr(ExgdbCmd, cmd):
continue
if hasattr(gdb.Command, cmd):
continue
if cmd in exgdb_functions:
continue
cmd_obj = getattr(PEDACmd, cmd)
setattr(ExgdbCmd, cmd, cmd_obj)
if "PwnCmd" in globals():
cmds = [cmd for cmd in dir(PwnCmd) if callable(getattr(PwnCmd, cmd))]
for cmd in cmds:
if cmd.startswith("_"):
continue
if hasattr(ExgdbCmd, cmd):
continue
if hasattr(gdb.Command, cmd):
continue
cmd_obj = getattr(PwnCmd, cmd)
setattr(ExgdbCmd, cmd, cmd_obj)
if "AngelHeapCmd" in globals():
cmds = [cmd for cmd in dir(AngelHeapCmd) if callable(getattr(AngelHeapCmd, cmd))]
for cmd in cmds:
if cmd.startswith("_"):
continue
if hasattr(ExgdbCmd, cmd):
continue
if hasattr(gdb.Command, cmd):
continue
cmd_obj = getattr(AngelHeapCmd, cmd)
setattr(ExgdbCmd, cmd, cmd_obj)
if "dashboard" in globals():
import_topFunctions("%s/plugins/gdb-dashboard/.gdbinit" % exgdbpath)
setattr(ExgdbCmd, "dashboard", dashboard)
import_from_exportFile()
class ExgdbCmdWrapper(gdb.Command):
def __init__(self):
super(ExgdbCmdWrapper,self).__init__("exgdb",gdb.COMMAND_USER)
def invoke(self,arg,from_tty):
self.dont_repeat()
args = e.string_to_argv(arg)
if len(args) > 0 :
cmd = args[0]
if cmd in c.cmds:
func = getattr(c,cmd)
if len(args) == 1:
func()
else:
func(*args[1:])
else :
print("Unknown command")
else :
print("Unknown command")
return
class ExgdbAlias(gdb.Command):
def __init__(self,alias,command):
self.command = command
super(ExgdbAlias,self).__init__(alias,gdb.COMMAND_NONE)
def invoke(self,args,from_tty):
self.dont_repeat()
gdb.execute("%s %s" % (self.command,args))
class RepeatExgdbCmdWrapper(gdb.Command):
def __init__(self):
super(RepeatExgdbCmdWrapper,self).__init__("rexgdb",gdb.COMMAND_USER)
def invoke(self,arg,from_tty):
#self.dont_repeat()
args = e.string_to_argv(arg)
if len(args) > 0 :
cmd = args[0]
if cmd in c.repeat_cmds:
func = getattr(c,cmd)
if len(args) == 1:
func()
else:
func(*args[1:])
else :
print("Unknown command")
else :
print("Unknown command")
return
class RepeatExgdbAlias(gdb.Command):
def __init__(self,alias,command):
self.command = command
super(RepeatExgdbAlias,self).__init__(alias,gdb.COMMAND_NONE)
def invoke(self,args,from_tty):
#self.dont_repeat()
gdb.execute("%s %s" % (self.command,args))
import_other_plugins()
gdb.execute("source %s/exgdbmethods.py" % exgdbpath)
gdb.execute("source %s/exgdbcmdmethods.py" % exgdbpath)
gdb.execute("source %s/initialize.py" % exgdbpath)