-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gdbinit
433 lines (417 loc) · 14.1 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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
set $SHOW_ASM = 1
set $SHOW_REGISTERS = 1
set $SHOW_STACK = 1
set $INSTRUCTIONS_BEFORE = 3
set $STACK_DISPLAY_SIZE = 4
set $old_eax = 0
set $old_ebx = 0
set $old_ecx = 0
set $old_edx = 0
set $old_esp = 0
set $old_ebp = 0
set $previous_eip = 0
set disassembly-flavor intel
define green-line
echo \033[32m
echo \n--------------------------------------------------------\n
echo \033[0m
end
document green-line
Print a green line
end
define reg
if $SHOW_REGISTERS == 1
green-line
echo Registers
green-line
echo \033[31m
printf "eax: "
echo \033[0m
if $eax != $old_eax
echo \033[33m
set $old_eax = $eax
end
printf "%08x ",$eax
echo \033[0m
echo \033[31m
printf "ebx: "
echo \033[0m
if $ebx != $old_ebx
echo \033[33m
set $old_ebx = $ebx
end
printf "%08x ",$ebx
echo \033[31m
printf "ecx: "
echo \033[0m
if $ecx != $old_ecx
echo \033[33m
set $old_ecx = $ecx
end
printf "%08x ",$ecx
echo \033[31m
printf "edx: "
echo \033[0m
if $edx != $old_edx
echo \033[33m
set $old_edx = $edx
end
printf "%08x\n",$edx
echo \033[31m
printf "esp: "
echo \033[0m
if $esp != $old_esp
echo \033[33m
set $old_esp = $esp
end
printf "%08x ",$esp
echo \033[31m
printf "ebp: "
echo \033[0m
if $ebp != $old_ebp
echo \033[33m
set $old_ebp = $ebp
end
printf "%08x ",$ebp
echo \033[31m
printf "eip: "
echo \033[0m
if $eip != (int)$previous_eip
echo \033[33m
set $previous_eip = $eip
end
printf "%08x",$eip
echo \033[0m
end
echo \n
end
document reg
Show values of registers
end
define stack
if $SHOW_STACK == 1
echo\n
green-line
echo Stack
green-line
set $n = 4
if $argc == 1
set $n = $arg0
set $STACK_DISPLAY_SIZE = $arg0
end
set $i = 0
while $i < $n
if $i == 0
if $ebp == $esp
echo \033[33m
printf "=> "
echo \033[0m
else
printf "=> "
end
else
if $ebp == $esp + 4*$i
echo \033[33m
printf "=> "
echo \033[0m
else
printf " "
end
end
x/xw $esp + 4*$i
set $i = $i + 1
end
end
end
document stack
Display the stack
end
define asm_context
if $SHOW_ASM == 1
echo \n
green-line
echo Assembly
green-line
set $i = $INSTRUCTIONS_BEFORE
while $i > 1
eval "set $x = $old_eip%d",$i
eval "set $y = $old_eip%d",$i - 1
if $x != $y
x/1i $x
end
set $i = $i - 1
end
if $old_eip1 != $eip
x/1i $old_eip1
end
eval "x/-%di $eip",$INSTRUCTIONS_BEFORE
x/10i $eip
end
end
document asm_context
Show code around current program counter
end
define showstack
if $argc == 0
if $SHOW_STACK == 1
set $SHOW_STACK = 0
else
set $SHOW_STACK = 1
end
else
set $SHOW_STACK = $arg0
end
end
document showstack
Toggle display of the stack
end
define showasm
if $argc == 0
if $SHOW_ASM == 1
set $SHOW_ASM = 0
else
set $SHOW_ASM = 1
end
else
set $SHOW_ASM = $arg0
end
end
document showasm
Toggle showing code around current program counter
end
define showregs
if $argc == 0
if $SHOW_REGISTERS == 1
set $SHOW_REGISTERS = 0
else
set $SHOW_REGISTERS = 1
end
else
set $SHOW_REGISTERS = $arg0
end
end
document showregs
Toggle showing registers
end
define context-off
showasm 0
showregs 0
end
document context-off
Switch display of context off
end
define context-on
showasm 1
showregs 1
end
document context-on
Switch display of context on
end
define init-eips
if $argc == 0
set $i = $INSTRUCTIONS_BEFORE
set $INSTRUCTIONS_BEFORE_SAVE = $INSTRUCTIONS_BEFORE
else
set $i = $arg0
set $INSTRUCTIONS_BEFORE_SAVE = $INSTRUCTIONS_BEFORE
set $INSTRUCTIONS_BEFORE = $arg0
end
set $j = $i
while $j > 0
eval "set $x = $old_eip%d",$j
if $_isvoid ($x) == 1
eval "set $old_eip%d = $eip",$j
end
set $j = $j - 1
end
if $i < $INSTRUCTIONS_BEFORE_SAVE
set $j = $INSTRUCTIONS_BEFORE_SAVE
while $j > $i
eval "set $old_eip%d = $old_eip%d",$j,$i
set $j = $j - 1
end
end
end
document init-eips
Initialize $old_eip<n> variables
end
define hook-stop
reg
init-eips
asm_context
stack $STACK_DISPLAY_SIZE
set $i = $INSTRUCTIONS_BEFORE
while $i > 1
eval "set $old_eip%d = $old_eip%d",$i,$i-1
set $i = $i - 1
end
set $old_eip1 = $eip
end
document hook-stop
What to do on program breaks
end
define _run
break *main + 0
if $argc == 0
run
else
if $argc == 1
run $arg0
else
if $argc == 2
run $arg0 $arg1
else
if $argc == 3
run $arg0 $arg1 $arg2
else
if $argc == 4
run $arg0 $arg1 $arg2 $arg3
else
if $argc == 5
run $arg0 $arg1 $arg2 $arg3 $arg4
else
if $argc == 6
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5
else
if $argc == 7
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6
else
if $argc == 8
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7
else
if $argc == 9
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8
else
if $argc == 10
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9
else
if $argc == 11
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10
else
if $argc == 12
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11
else
if $argc == 13
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12
else
if $argc == 14
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13
else
if $argc == 15
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14
else
if $argc == 16
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15
else
if $argc == 17
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16
else
if $argc == 18
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17
else
if $argc == 19
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18
else
if $argc == 20
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19
else
if $argc == 21
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20
else
if $argc == 22
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21
else
if $argc == 23
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22
else
if $argc == 24
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23
else
if $argc == 25
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24
else
if $argc == 26
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25
else
if $argc == 27
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26
else
if $argc == 28
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27
else
if $argc == 29
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28
else
if $argc == 30
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29
else
if $argc == 31
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30
else
if $argc == 32
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31
else
if $argc == 33
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32
else
if $argc == 34
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33
else
if $argc == 35
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34
else
if $argc == 36
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35
else
if $argc == 37
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36
else
if $argc == 38
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37
else
if $argc == 39
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38
else
if $argc == 40
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39
else
if $argc == 41
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40
else
if $argc == 42
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41
else
if $argc == 43
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42
else
if $argc == 44
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43
else
if $argc == 45
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44
else
if $argc == 46
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44 $arg45
else
if $argc == 47
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44 $arg45 $arg46
else
if $argc == 48
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44 $arg45 $arg46 $arg47
else
if $argc == 49
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44 $arg45 $arg46 $arg47 $arg48
else
if $argc == 50
run $arg0 $arg1 $arg2 $arg3 $arg4 $arg5 $arg6 $arg7 $arg8 $arg9 $arg10 $arg11 $arg12 $arg13 $arg14 $arg15 $arg16 $arg17 $arg18 $arg19 $arg20 $arg21 $arg22 $arg23 $arg24 $arg25 $arg26 $arg27 $arg28 $arg29 $arg30 $arg31 $arg32 $arg33 $arg34 $arg35 $arg36 $arg37 $arg38 $arg39 $arg40 $arg41 $arg42 $arg43 $arg44 $arg45 $arg46 $arg47 $arg48 $arg49
end
set $old_eax = $eax
set $old_ebx = $ebx
set $old_ecx = $ecx
set $old_edx = $edx
set $old_esp = $esp
set $old_ebp = $ebp
end
document _run
Create breakpoint at main and run program
end