-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gdbinit
253 lines (214 loc) · 6.97 KB
/
.gdbinit
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
python
import os
# Global variables -----------------------------------------------------------
name = None
# GGBboard --------------------------------------------------------------------
def source_plugin(path):
if path == None:
print("\033[1;32m but path to " + name + " does not exist!!!\033[0m")
print("\033[1;31m please check path to " + name + " and Try again...\033[0m")
elif os.path.exists(path):
gdb.execute('source ' + path)
else:
print("\033[1;32m but path to " + name + " does not exist!!!\033[0m")
print("\033[1;31m please check path to " + name + " and Try again...\033[0m")
class GDBboard():
"""Redisplay the ."""
def __init__(self):
self.plugins = ""
# Utility methods --------------------------------------------------------------
@staticmethod
def start():
gdbboard = GDBboard()
plugins = gdbboard.get_plugins()
print("\033[1;32m Please choose a gdb enchancer.\033[0m")
prefix = "Please input"
postfix = "\033[1;32m Nothing\033[0m!!!"
prefix += plugins;
prefix += postfix;
print(prefix)
def get_plugins(self):
# scan the scope for plugins
plugins = {}
i = 0
for name in globals():
obj = globals()[name]
try:
if issubclass(obj, gdb.Command):
self.plugins += "\033[1;31m " + obj().name.upper() + "\033[0m" + " or"
except TypeError:
continue
return self.plugins
# Default GDB Enhancer --------------------------------------------------------------
class PEDA(gdb.Command):
"""peda: """
def __init__(self):
gdb.Command.__init__(self, 'PEDA',
gdb.COMMAND_USER, gdb.COMPLETE_NONE, True)
self.name = 'peda'
# CHANGE PATH TO PLUGIN PEDA IF NECESSARY
self.path = '/home/chenzheng/Documents/peda/peda.py'
def invoke(self, arg, from_tty):
global name
if name == None:
name = self.name
print("\033[1;32m " + self.name + '\033[0m has been chosen')
source_plugin(self.path)
class GEF(gdb.Command):
"""gef: """
def __init__(self):
gdb.Command.__init__(self, 'GEF',
gdb.COMMAND_USER, gdb.COMPLETE_NONE, True)
self.name = 'gef'
# CHANGE PATH TO PLUGIN GEF IF NECESSARY
self.path = '/home/chenzheng/Documents/gef/gef.py'
def invoke(self, arg, from_tty):
global name
if name == None:
name = self.name
print("\033[1;32m " + self.name + '\033[0m has been chosen')
source_plugin(self.path)
class PWNDBG(gdb.Command):
"""pwndbg: """
def __init__(self):
gdb.Command.__init__(self, 'PWNDBG',
gdb.COMMAND_USER, gdb.COMPLETE_NONE, True)
self.name = 'pwndbg'
# CHANGE PATH TO PLUGIN PWNDBG IF NECESSARY
self.path = '/home/chenzheng/Documents/pwndbg/gdbinit.py'
def invoke(self, arg, from_tty):
global name
if name == None:
name = self.name
print("\033[1;32m " + self.name + '\033[0m has been chosen')
source_plugin(self.path)
# XXX traceback line numbers in this Python block must be increased by 1
end
# Better GDB defaults ----------------------------------------------------------
set history save
set verbose off
set print pretty on
set print array off
set print array-indexes on
set print demangle
set print asm-demangle
set python print-stack full
# Start ------------------------------------------------------------------------
python GDBboard.start()
# Pretty printer ---------------------------------------------------------------
# To make print pretty work properly, g++83 must be used to compile program.
# for example: g++83 -g - std=c++11 [program]
# g++(4.8) can NOT make it!!!
add-auto-load-safe-path /usr/local/gcc-8.3/lib/libstdc++.so.6.0.26-gdb.py
# User defined commands --------------------------------------------------------
define bret
finish
end
document bret
Syntax: bret
| Execute until selected stack frame returns (step out of current call).
| Upon return, the value returned is printed and put in the value history.
end
define binit
tbreak _init
run
end
document binit
Syntax: binit
| Run program and break on _init().
end
define bstart
tbreak _start
run
end
document bstart
Syntax: bstart
| Run program and break on _start().
end
define bcstart
tbreak __libc_start_main
run
end
document bcstart
Syntax: bcstart
| Run program and break on __libc_start_main().
| Useful for stripped executables.
end
define bmain
tbreak main
run
end
document bmain
Syntax: bmain
| Run program and break on main().
end
define bbcall
# e8: call instruction's op code.
set $_nextaddress = $pc
set $_nextaddress = ($_nextaddress + 1)
set $_opcode = *(unsigned char*)($_nextaddress)
while ($_opcode != 0xe8)
set $_opcode = *(unsigned char*)($_nextaddress++)
end
set $_nextaddress = ($_nextaddress-1)
tbreak *($_nextaddress)
continue
end
document bbcall
Syntax: bbcall (break before call)
| Run program and break on the location which is before next call instruction.
end
define bacall
bbcall
nexti
end
document bacall
Syntax: bacall (break after call)
| Run program and break on the location which is after next call instruction.
end
define cls
shell clear
end
document cls
Syntax: cls
| Clear screen. Use clear command to delete breakpoints.
end
define threads
info threads
end
document threads
Syntax: threads
| Print threads in target.
end
define lib
info sharedlibrary
end
document lib
Syntax: lib
| Print shared libraries linked to target.
end
# ------------------------------------------------------------------------------
# Copyright (c) 2018-2019 Chen Zheng <987102818@qq.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ------------------------------------------------------------------------------
# vim: filetype=python
# Local Variables:
# mode: python
# End: