-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgdbinit-ios-v0.3
1932 lines (1763 loc) · 48 KB
/
gdbinit-ios-v0.3
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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# INSTALL INSTRUCTIONS: save as ~/.gdbinit
#
# DESCRIPTION: A user-friendly gdb configuration file for iOS devices.
# Based on original gdbinit for Linux/OS X platforms.
#
# REVISION : 0.3 (03/02/2011) - fG!
#
# FEEDBACK: http://reverse.put.as or iosgdbinit@put.as
#
# ORIGINAL GDBINIT CONTRIBUTORS: mammon_, elaine, pusillus, mong, zhang le, l0kit,
# truthix the cyberpunk, fG!, gln
#
# iOS NOTES: iOS gdb from Cydia (and Apple probably) suffer from the same bug in OS X.
# If you are using this on Mac OS X or iOS, you must either attach gdb to a process
# or launch gdb without any options and then load the binary file you want to analyse with "exec-file" option
# If you load the binary from the command line, like $gdb binary-name, this will not work as it should
# For more information, read it here http://reverse.put.as/2008/11/28/apples-gdb-bug/
#
# NOTES: 'help user' in gdb will list the commands/descriptions in this file
# 'context on' now enables auto-display of context screen
#
# CHANGELOG:
#
# v0.1: Initial port to ARM/iOS devices.
# v0.2: Display the jump conditions for ARM and fix the stepo command also for ARM
# v0.3: Display the jump conditions for Thumb, stepo is semi-working for Thumb
# Modified the assembly display to use again x/i instead disas (both commands have column alignment problems so this must be solved with patches)
#
# __________________gdb options_________________
set confirm off
set verbose off
set prompt \033[31mgdb$ \033[0m
set output-radix 0x10
set input-radix 0x10
# These make gdb never pause in its output
set height 0
set width 0
set $SHOW_CONTEXT = 1
set $SHOW_NEST_INSN = 0
set $CONTEXTSIZE_STACK = 6
set $CONTEXTSIZE_DATA = 8
set $CONTEXTSIZE_CODE = 8
# set to 0 to remove display of objectivec messages (default is 1)
set $SHOWOBJECTIVEC = 0
# set to 0 to remove display of cpu registers (default is 1)
set $SHOWCPUREGISTERS = 1
# set to 1 to enable display of stack (default is 0)
set $SHOWSTACK = 0
# set to 1 to enable display of data window (default is 0)
set $SHOWDATAWIN = 0
# show the opcodes - change to 0 if you don't want such thing (in x/i command)
set arm show-opcode-bytes 1
# __________________end gdb options_________________
# ______________window size control___________
define contextsize-stack
if $argc != 1
help contextsize-stack
else
set $CONTEXTSIZE_STACK = $arg0
end
end
document contextsize-stack
Set stack dump window size to NUM lines.
Usage: contextsize-stack NUM
end
define contextsize-data
if $argc != 1
help contextsize-data
else
set $CONTEXTSIZE_DATA = $arg0
end
end
document contextsize-data
Set data dump window size to NUM lines.
Usage: contextsize-data NUM
end
define contextsize-code
if $argc != 1
help contextsize-code
else
set $CONTEXTSIZE_CODE = $arg0
end
end
document contextsize-code
Set code window size to NUM lines.
Usage: contextsize-code NUM
end
# _____________breakpoint aliases_____________
# status: works
define bpl
info breakpoints
end
document bpl
List all breakpoints.
end
# status: works
define bp
if $argc != 1
help bp
else
break $arg0
end
end
document bp
Set breakpoint.
Usage: bp LOCATION
LOCATION may be a line number, function name, or "*" and an address.
To break on a symbol you must enclose symbol name inside "".
Example:
bp "[NSControl stringValue]"
Or else you can use directly the break command (break [NSControl stringValue])
end
# status: works
define bpc
if $argc != 1
help bpc
else
clear $arg0
end
end
document bpc
Clear breakpoint.
Usage: bpc LOCATION
LOCATION may be a line number, function name, or "*" and an address.
end
# status: works
define bpe
if $argc != 1
help bpe
else
enable $arg0
end
end
document bpe
Enable breakpoint with number NUM.
Usage: bpe NUM
end
# status: works
define bpd
if $argc != 1
help bpd
else
disable $arg0
end
end
document bpd
Disable breakpoint with number NUM.
Usage: bpd NUM
end
# status: works
define bpt
if $argc != 1
help bpt
else
tbreak $arg0
end
end
document bpt
Set a temporary breakpoint.
This breakpoint will be automatically deleted when hit!
Usage: bpt LOCATION
LOCATION may be a line number, function name, or "*" and an address.
end
# ______________process information____________
# status: works
define argv
show args
end
document argv
Print program arguments.
end
# status: works
define stack
if $argc == 0
info stack
end
if $argc == 1
info stack $arg0
end
if $argc > 1
help stack
end
end
document stack
Print backtrace of the call stack, or innermost COUNT frames.
Usage: stack <COUNT>
end
# status: works
define frame
info frame
info args
info locals
end
document frame
Print stack frame.
end
# conditional flags are
# negative/less than (N), bit 31 of CPSR
# zero (Z), bit 30
# Carry/Borrow/Extend (C), bit 29
# Overflow (V), bit 28
# status: works
define flags
# negative/less than (N), bit 31 of CPSR
if ($cpsr->n & 1)
printf "N "
set $_n_flag = 1
else
printf "n "
set $_n_flag = 0
end
# zero (Z), bit 30
if ($cpsr->z & 1)
printf "Z "
set $_z_flag = 1
else
printf "z "
set $_z_flag = 0
end
# Carry/Borrow/Extend (C), bit 29
if ($cpsr->c & 1)
printf "C "
set $_c_flag = 1
else
printf "c "
set $_c_flag = 0
end
# Overflow (V), bit 28
if ($cpsr->v & 1)
printf "V "
set $_v_flag = 1
else
printf "v "
set $_v_flag = 0
end
# Sticky overflow (Q), bit 27
if ($cpsr->q & 1)
printf "Q "
set $_q_flag = 1
else
printf "q "
set $_q_flag = 0
end
# Java state bit (J), bit 24
# When T=1:
# J = 0 The processor is in Thumb state.
# J = 1 The processor is in ThumbEE state.
if ($cpsr->j & 1)
printf "J "
set $_j_flag = 1
else
printf "j "
set $_j_flag = 0
end
# Data endianness bit (E), bit 9
if ($cpsr->e & 1)
printf "E "
set $_e_flag = 1
else
printf "e "
set $_e_flag = 0
end
# Imprecise abort disable bit (A), bit 8
# The A bit is set to 1 automatically. It is used to disable imprecise data aborts.
# It might not be writable in the Nonsecure state if the AW bit in the SCR register is reset.
if ($cpsr->a & 1)
printf "A "
set $_a_flag = 1
else
printf "a "
set $_a_flag = 0
end
# IRQ disable bit (I), bit 7
# When the I bit is set to 1, IRQ interrupts are disabled.
if ($cpsr->i & 1)
printf "I "
set $_i_flag = 1
else
printf "i "
set $_i_flag = 0
end
# FIQ disable bit (F), bit 6
# When the F bit is set to 1, FIQ interrupts are disabled.
# FIQ can be nonmaskable in the Nonsecure state if the FW bit in SCR register is reset.
if ($cpsr->f & 1)
printf "F "
set $_f_flag = 1
else
printf "f "
set $_f_flag = 0
end
# Thumb state bit (F), bit 5
# if 1 then the processor is executing in Thumb state or ThumbEE state depending on the J bit
if ($cpsr->t & 1)
printf "T "
set $_t_flag = 1
else
printf "t "
set $_t_flag = 0
end
# TODO: GE bit ?
# printf "\n"
end
document flags
Print flags register.
end
# status: works
define eflags
printf " N <%d> Z <%d> C <%d> V <%d>",\
($cpsr->n & 1), ($cpsr->z & 1), \
($cpsr->c & 1), ($cpsr->v & 1)
printf " Q <%d> J <%d> GE <%d> E <%d> A <%d>",\
($cpsr->q & 1), ($cpsr->j & 1),\
($cpsr->ge), ($cpsr->e & 1), ($cpsr->a & 1)
printf " I <%d> F <%d> T <%d> \n",\
($cpsr->i & 1), ($cpsr->f & 1), \
($cpsr->t & 1)
end
document eflags
Print eflags register.
end
# status: works
define cpsr
eflags
end
document cpsr
Print cpsr register
end
# status: works
define reg
printf " "
echo \033[32m
printf "R0:"
echo \033[0m
printf " 0x%08X ", $r0
echo \033[32m
printf "R1:"
echo \033[0m
printf " 0x%08X ", $r1
echo \033[32m
printf "R2:"
echo \033[0m
printf " 0x%08X ", $r2
echo \033[32m
printf "R3:"
echo \033[0m
printf " 0x%08X\n", $r3
printf " "
echo \033[32m
printf "R4:"
echo \033[0m
printf " 0x%08X ", $r4
echo \033[32m
printf "R5:"
echo \033[0m
printf " 0x%08X ", $r5
echo \033[32m
printf "R6:"
echo \033[0m
printf " 0x%08X ", $r6
echo \033[32m
printf "R7:"
echo \033[0m
printf " 0x%08X\n", $r7
printf " "
echo \033[32m
printf "R8:"
echo \033[0m
printf " 0x%08X ", $r8
echo \033[32m
printf "R9:"
echo \033[0m
printf " 0x%08X ", $r9
echo \033[32m
printf "R10:"
echo \033[0m
printf " 0x%08X ", $r10
echo \033[32m
printf "R11:"
echo \033[0m
printf " 0x%08X\n", $r11
printf " "
echo \033[32m
printf "SP:"
echo \033[0m
printf " 0x%08X ", $sp
echo \033[32m
printf "LR:"
echo \033[0m
printf " 0x%08X ", $lr
echo \033[32m
printf "PC:"
echo \033[0m
printf " 0x%08X ", $pc
echo \033[1m\033[4m\033[31m
flags
echo \033[0m
# printf "\n"
dumpjump
end
document reg
Print CPU registers.
end
# status: works
define func
if $argc == 0
info functions
end
if $argc == 1
info functions $arg0
end
if $argc > 1
help func
end
end
document func
Print all function names in target, or those matching REGEXP.
Usage: func <REGEXP>
end
# status: works
define var
if $argc == 0
info variables
end
if $argc == 1
info variables $arg0
end
if $argc > 1
help var
end
end
document var
Print all global and static variable names (symbols), or those matching REGEXP.
Usage: var <REGEXP>
end
# status: works
define lib
info sharedlibrary
end
document lib
Print shared libraries linked to target.
end
# status: works
define sig
if $argc == 0
info signals
end
if $argc == 1
info signals $arg0
end
if $argc > 1
help sig
end
end
document sig
Print what debugger does when program gets various signals.
Specify a SIGNAL as argument to print info on that signal only.
Usage: sig <SIGNAL>
end
# status: works
define threads
info threads
end
document threads
Print threads in target.
end
# status: works
define dis
if $argc == 0
disassemble
end
if $argc == 1
disassemble $arg0
end
if $argc == 2
disassemble $arg0 $arg1
end
if $argc > 2
help dis
end
end
document dis
Disassemble a specified section of memory.
Default is to disassemble the function surrounding the PC (program counter)
of selected frame. With one argument, ADDR1, the function surrounding this
address is dumped. Two arguments are taken as a range of memory to dump.
Usage: dis <ADDR1> <ADDR2>
end
# __________hex/ascii dump an address_________
# status: works
define ascii_char
if $argc != 1
help ascii_char
else
# thanks elaine :)
set $_c = *(unsigned char *)($arg0)
if ($_c < 0x20 || $_c > 0x7E)
printf "."
else
printf "%c", $_c
end
end
end
document ascii_char
Print ASCII value of byte at address ADDR.
Print "." if the value is unprintable.
Usage: ascii_char ADDR
end
# status: works
define hex_quad
if $argc != 1
help hex_quad
else
printf "%02X %02X %02X %02X %02X %02X %02X %02X", \
*(unsigned char*)($arg0), *(unsigned char*)($arg0 + 1), \
*(unsigned char*)($arg0 + 2), *(unsigned char*)($arg0 + 3), \
*(unsigned char*)($arg0 + 4), *(unsigned char*)($arg0 + 5), \
*(unsigned char*)($arg0 + 6), *(unsigned char*)($arg0 + 7)
end
end
document hex_quad
Print eight hexadecimal bytes starting at address ADDR.
Usage: hex_quad ADDR
end
# status: works
define hexdump
if $argc != 1
help hexdump
else
echo \033[1m
printf "0x%08X : ", $arg0
echo \033[0m
hex_quad $arg0
echo \033[1m
printf " - "
echo \033[0m
hex_quad $arg0+8
printf " "
echo \033[1m
ascii_char $arg0+0x0
ascii_char $arg0+0x1
ascii_char $arg0+0x2
ascii_char $arg0+0x3
ascii_char $arg0+0x4
ascii_char $arg0+0x5
ascii_char $arg0+0x6
ascii_char $arg0+0x7
ascii_char $arg0+0x8
ascii_char $arg0+0x9
ascii_char $arg0+0xA
ascii_char $arg0+0xB
ascii_char $arg0+0xC
ascii_char $arg0+0xD
ascii_char $arg0+0xE
ascii_char $arg0+0xF
echo \033[0m
printf "\n"
end
end
document hexdump
Display a 16-byte hex/ASCII dump of memory at address ADDR.
Usage: hexdump ADDR
end
# _______________data window__________________
# status: works
define ddump
if $argc != 1
help ddump
else
echo \033[34m
printf "[0x%08X]", $data_addr
echo \033[34m
printf "------------------------"
printf "-------------------------------------"
echo \033[1;34m
printf "[data]\n"
echo \033[0m
set $_count = 0
while ($_count < $arg0)
set $_i = ($_count * 0x10)
hexdump $data_addr+$_i
set $_count++
end
end
end
document ddump
Display NUM lines of hexdump for address in $data_addr global variable.
Usage: ddump NUM
end
# status: works, fixme
define dd
if $argc != 1
help dd
else
# if ((($arg0 >> 0x18) == 0x40) || (($arg0 >> 0x18) == 0x08) || (($arg0 >> 0x18) == 0xBF))
set $data_addr = $arg0
ddump 0x10
# else
# printf "Invalid address: 0x%08X\n", $arg0
# end
end
end
document dd
Display 16 lines of a hex dump of address starting at ADDR.
Usage: dd ADDR
end
# status: works, fixme
# which registers do we want to display? just the stack? there's already a functionb for stack dump
define datawin
if ((($r0 >> 0x18) == 0x40) || (($r0 >> 0x18) == 0x08) || (($r0 >> 0x18) == 0xBF))
set $data_addr = $r0
else
if ((($r1 >> 0x18) == 0x40) || (($r1 >> 0x18) == 0x08) || (($r1 >> 0x18) == 0xBF))
set $data_addr = $r1
else
if ((($r2 >> 0x18) == 0x40) || (($r2 >> 0x18) == 0x08) || (($r2 >> 0x18) == 0xBF))
set $data_addr = $r2
else
set $data_addr = $sp
end
end
end
ddump $CONTEXTSIZE_DATA
end
document datawin
Display valid address from one register in data window.
Registers to choose are: esi, edi, eax, or esp.
end
# status: works
define dumpjump
## Most ARM and Thumb instructions are conditional!
# each instruction is 32 bits long
# 4 bits are for condition codes (16 in total) (bits 31:28 in ARM contain the condition or 1111 if instruction is unconditional)
# 2x4 bits for destination and first operand registers
# one for the set-status flag
# an assorted number for other stuff
# 12 bits for any immediate value
# $_t_flag == 0 => ARM mode
# $_t_flag == 1 => Thumb or ThumbEE
if $_t_flag == 0
set $_lastbyte = *(unsigned char *)($pc+3)
#set $_bit31 = ($_lastbyte >> 7) & 1
#set $_bit30 = ($_lastbyte >> 6) & 1
#set $_bit29 = ($_lastbyte >> 5) & 1
#set $_bit28 = ($_lastbyte >> 4) & 1
set $_conditional = $_lastbyte >> 4
dumpjumphelper
else
# if bits 15-12 (opcode in Thumb instructions) are equal to 1 1 0 1 (0xD) then we have a conditional branch
# bits 11-8 for the conditional execution code (check ARMv7 manual A8.3)
if ( (*(unsigned char *)($pc+1) >> 4) == 0xD )
set $_conditional = *(unsigned char *)($pc+1) ^ 0xD0
dumpjumphelper
end
end
#printf "bit31:%d bit30:%d bit29:%d bit28:%d conditional:0x%x\n", $_bit31, $_bit30, $_bit29, $_bit28, $_conditional
# end of dumpjump function
end
document dumpjump
Display if conditional jump will be taken or not, for ARM and Thumb
end
define dumpjumphelper
# 0000 - EQ: Z == 1
if ($_conditional == 0x0)
if ($_z_flag == 1)
echo \033[31m
# printf " Jump is taken (z==1)\n"
printf " Jump is taken (z==1)"
else
echo \033[31m
# printf " Jump is NOT taken (z!=1)\n"
printf " Jump is NOT taken (z!=1)"
end
end
# 0001 - NE: Z == 0
if ($_conditional == 0x1)
if ($_z_flag == 0)
echo \033[31m
# printf " Jump is taken (z==0)\n"
printf " Jump is taken (z==0)"
else
echo \033[31m
# printf " Jump is NOT taken (z!=0)\n"
printf " Jump is NOT taken (z!=0)"
end
end
# 0010 - CS: C == 1
if ($_conditional == 0x2)
if ($_c_flag == 1)
echo \033[31m
# printf " Jump is taken (c==1)\n"
printf " Jump is taken (c==1)"
else
echo \033[31m
# printf " Jump is NOT taken (c!=1)\n"
printf " Jump is NOT taken (c!=1)"
end
end
# 0011 - CC: C == 0
if ($_conditional == 0x3)
if ($_c_flag == 0)
echo \033[31m
# printf " Jump is taken (c==0)\n"
printf " Jump is taken (c==0)"
else
echo \033[31m
# printf " Jump is NOT taken (c!=0)\n"
printf " Jump is NOT taken (c!=0)"
end
end
# 0100 - MI: N == 1
if ($_conditional == 0x4)
if ($_n_flag == 1)
echo \033[31m
# printf " Jump is taken (n==1)\n"
printf " Jump is taken (n==1)"
else
echo \033[31m
# printf " Jump is NOT taken (n!=1)\n"
printf " Jump is NOT taken (n!=1)"
end
end
# 0101 - PL: N == 0
if ($_conditional == 0x5)
if ($_n_flag == 0)
echo \033[31m
# printf " Jump is taken (n==0)\n"
printf " Jump is taken (n==0)"
else
echo \033[31m
# printf " Jump is NOT taken (n!=0)\n"
printf " Jump is NOT taken (n!=0)"
end
end
# 0110 - VS: V == 1
if ($_conditional == 0x6)
if ($_v_flag == 1)
echo \033[31m
# printf " Jump is taken (v==1)\n"
printf " Jump is taken (v==1)"
else
echo \033[31m
# printf " Jump is NOT taken (v!=1)\n"
printf " Jump is NOT taken (v!=1)"
end
end
# 0111 - VC: V == 0
if ($_conditional == 0x7)
if ($_v_flag == 0)
echo \033[31m
# printf " Jump is taken (v==0)\n"
printf " Jump is taken (v==0)"
else
echo \033[31m
# printf " Jump is NOT taken (v!=0)\n"
printf " Jump is NOT taken (v!=0)"
end
end
# 1000 - HI: C == 1 and Z == 0
if ($_conditional == 0x8)
if ($_c_flag == 1 && $_z_flag == 0)
echo \033[31m
# printf " Jump is taken (c==1 and z==0)\n"
printf " Jump is taken (c==1 and z==0)"
else
echo \033[31m
# printf " Jump is NOT taken (c!=1 or z!=0)\n"
printf " Jump is NOT taken (c!=1 or z!=0)"
end
end
# 1001 - LS: C == 0 or Z == 1
if ($_conditional == 0x9)
if ($_c_flag == 0 || $_z_flag == 1)
echo \033[31m
# printf " Jump is taken (c==0 or z==1)\n"
printf " Jump is taken (c==0 or z==1)"
else
echo \033[31m
# printf " Jump is NOT taken (c!=0 or z!=1)\n"
printf " Jump is NOT taken (c!=0 or z!=1)"
end
end
# 1010 - GE: N == V
if ($_conditional == 0xA)
if ($_n_flag == $_v_flag)
echo \033[31m
# printf " Jump is taken (n==v)\n"
printf " Jump is taken (n==v)"
else
echo \033[31m
# printf " Jump is NOT taken (n!=v)\n"
printf " Jump is NOT taken (n!=v)"
end
end
# 1011 - LT: N != V
if ($_conditional == 0xB)
if ($_n_flag != $_v_flag)
echo \033[31m
# printf " Jump is taken (n!=v)\n"
printf " Jump is taken (n!=v)"
else
echo \033[31m
# printf " Jump is NOT taken (n==v)\n"
printf " Jump is NOT taken (n==v)"
end
end
# 1100 - GT: Z == 0 and N == V
if ($_conditional == 0xC)
if ($_z_flag == 0 && $_n_flag == $_v_flag)
echo \033[31m
# printf " Jump is taken (z==0 and n==v)\n"
printf " Jump is taken (z==0 and n==v)"
else
echo \033[31m
# printf " Jump is NOT taken (z!=0 or n!=v)\n"
printf " Jump is NOT taken (z!=0 or n!=v)"
end
end
# 1101 - LE: Z == 1 or N != V
if ($_conditional == 0xD)
if ($_z_flag == 1 || $_n_flag != $_v_flag)
echo \033[31m
# printf " Jump is taken (z==1 or n!=v)\n"
printf " Jump is taken (z==1 or n!=v)"
else
echo \033[31m
# printf " Jump is NOT taken (z!=1 or n==v)\n"
printf " Jump is NOT taken (z!=1 or n==v)"
end
end
#printf "\n"
# end of dumpjumphelper function
end
document dumpjumphelper
Helper function to decide if conditional jump will be taken or not, for ARM and Thumb
end
# _______________process context______________
# initialize variable
set $displayobjectivec = 0
# status: works, fixme
define context
echo \033[34m
if $SHOWCPUREGISTERS == 1
printf "----------------------------------------"
printf "----------------------------------"
echo \033[34m\033[1m
printf "[regs]\n"
echo \033[0m
reg
echo \033[36m
end
if $SHOWSTACK == 1
echo \033[34m
printf "[0x%08X]", $sp
echo \033[34m
printf "-------------------------"
printf "-----------------------------------"
echo \033[34m\033[1m
printf "[stack]\n"
echo \033[0m
set $context_i = $CONTEXTSIZE_STACK
while ($context_i > 0)
set $context_t = $sp + 0x10 * ($context_i - 1)
hexdump $context_t
set $context_i--
end
end
# show the objective C message being passed to msgSend
# FIXME
if $SHOWOBJECTIVEC == 1
#FIXME64
set $objectivec = $r1
# What a piece of crap that's going on here :)
# detect if it's the correct opcode we are searching for
# set $__byte1 = *(unsigned char *)$pc
# set $__byte = *(int *)$pc
#
# if ($__byte == 0x4244489)
# set $objectivec = $eax
# set $displayobjectivec = 1
# end
#
# if ($__byte == 0x4245489)
# set $objectivec = $edx
# set $displayobjectivec = 1
# end
#
# if ($__byte == 0x4244c89)
# set $objectivec = $edx
# set $displayobjectivec = 1
# end
# and now display it or not (we have no interest in having the info displayed after the call)
if $__byte1 == 0xE8
if $displayobjectivec == 1
echo \033[34m
printf "--------------------------------------------------------------------"
echo \033[34m\033[1m
printf "[ObjectiveC]\n"
echo \033[0m\033[30m
x/s $objectivec
end
set $displayobjectivec = 0
end
if $displayobjectivec == 1
echo \033[34m
printf "--------------------------------------------------------------------"
echo \033[34m\033[1m
printf "[ObjectiveC]\n"
echo \033[0m\033[30m
x/s $objectivec
end
end
echo \033[0m
# and this is the end of this little crap
if $SHOWDATAWIN == 1
datawin
end
echo \033[34m
printf "\n--------------------------------------------------------------------------"
echo \033[34m\033[1m
printf "[code]\n"
echo \033[0m
# gdb version from cydia already displays the disassembly bytes
# but if we use the x/i command, the output isn't aligned
# instead we can use disassemble command
# we also distinguish between ARM (32bits) and Thumb (16bits)
# only problem are the header and footer of disas command, which looks ugly :-)
# FIXME: find a better cosmetic solution?