-
Notifications
You must be signed in to change notification settings - Fork 5
/
debug.cpp
2056 lines (1716 loc) · 62 KB
/
debug.cpp
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
// Copyright (C) 2014 oct0xor
//
// This program is free software : you can redistribute it and / or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0.
//
// This program 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 General Public License 2.0 for more details.
//
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http ://www.gnu.org/licenses/
#define _WINSOCKAPI_
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <ida.hpp>
#include <area.hpp>
#include <ua.hpp>
#include <nalt.hpp>
#include <idd.hpp>
#include <segment.hpp>
#include <dbg.hpp>
#include <allins.hpp>
#include "debmod.h"
#include "include\ps3tmapi.h"
#include "gdb.h"
#ifdef _DEBUG
#define debug_printf ::msg
#else
#define debug_printf(...)
#endif
#define DEBUGGER_NAME "spu3"
#define DEBUGGER_ID_PLAYSTATION_3_SPU (0x8004)
#define PROCESSOR_NAME "spu"
static error_t idaapi idc_threadlst(idc_value_t *argv, idc_value_t *res);
void get_threads_info(void);
void clear_all_bp(uint32 tid);
uint32 read_pc_register(uint32 tid);
uint32 read_lr_register(uint32 tid);
uint32 read_ctr_register(uint32 tid);
int do_step(uint32 tid, uint32 dbg_notification);
bool addr_has_bp(uint32 ea);
static const char idc_threadlst_args[] = {0};
std::vector<SNPS3TargetInfo*> Targets;
std::string TargetName;
HTARGET TargetID;
uint32 ProcessID;
uint32 ThreadID;
bool LaunchTargetPicker = true;
bool AlwaysDC = false;
bool ForceDC = true;
bool WasOriginallyConnected = false;
static bool attaching = false;
static bool singlestep = false;
static bool continue_from_bp = false;
static bool dabr_is_set = false;
uint32 dabr_addr;
uint8 dabr_type;
eventlist_t events;
SNPS3_DBG_EVENT_DATA target_event;
std::unordered_map<int, std::string> process_names;
std::unordered_map<int, std::string> modules;
std::unordered_map<int, int> main_bpts_map;
std::set<uint32> step_bpts;
std::set<uint32> main_bpts;
static const unsigned char bpt_code[] = {0x7f, 0xe0, 0x00, 0x08};
#define STEP_INTO 15
#define STEP_OVER 16
#define RC_GENERAL 1
struct regval
{
uint64 lval;
uint64 rval;
};
typedef struct regval regval;
//--------------------------------------------------------------------------
const char* register_classes[] =
{
"General registers",
NULL
};
//--------------------------------------------------------------------------
const char* register_formats[] =
{
"spu_4_words",
NULL
};
#define USE_CUSTOM_FORMAT 1
#if USE_CUSTOM_FORMAT
#define REGISTER_FLAGS REGISTER_CUSTFMT
#define REGISTER_DATA_TYPE dt_byte16
#define REGISTER_DATA_FORMAT register_formats
#define GPR_COUNT (128 + 2)
#define SPU_ID_INDEX (128 + 0)
#define PC_INDEX (128 + 1)
#else
#define REGISTER_FLAGS 0
#define REGISTER_DATA_TYPE dt_dword
#define REGISTER_DATA_FORMAT nullptr
#define GPR_COUNT (128 * 4 + 2)
#define SPU_ID_INDEX (128 * 4 + 0)
#define PC_INDEX (128 * 4 + 1)
#endif
char register_names[GPR_COUNT][16] = {0};
//--------------------------------------------------------------------------
register_info_t registers[GPR_COUNT] =
{
{ "r0", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r1", REGISTER_FLAGS | REGISTER_ADDRESS | REGISTER_SP, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r2", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r3", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r4", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r5", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r6", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r7", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r8", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r9", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r10", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r11", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r12", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r13", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r14", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r15", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r16", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r17", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r18", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r19", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r20", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r21", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r22", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r23", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r24", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r25", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r26", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r27", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r28", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r29", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r30", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r31", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r32", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r33", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r34", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r35", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r36", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r37", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r38", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r39", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r40", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r41", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r42", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r43", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r44", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r45", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r46", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r47", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r48", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r49", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r50", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r51", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r52", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r53", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r54", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r55", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r56", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r57", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r58", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r59", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r60", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r61", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r62", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r63", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r64", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r65", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r66", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r67", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r68", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r69", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r70", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r71", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r72", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r73", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r74", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r75", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r76", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r77", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r78", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r79", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r80", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r81", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r82", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r83", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r84", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r85", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r86", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r87", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r88", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r89", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r90", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r91", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r92", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r93", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r94", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r95", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r96", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r97", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r98", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r99", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r100", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r101", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r102", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r103", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r104", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r105", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r106", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r107", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r108", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r109", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r110", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r111", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r112", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r113", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r114", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r115", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r116", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r117", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r118", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r119", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r120", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r121", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r122", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r123", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r124", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r125", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r126", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "r127", REGISTER_FLAGS | REGISTER_ADDRESS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 },
{ "SPU_ID", REGISTER_ADDRESS | REGISTER_READONLY, RC_GENERAL, dt_dword, NULL, 0 },
{ "PC", REGISTER_ADDRESS | REGISTER_IP, RC_GENERAL, dt_dword, NULL, 0 },
};
#define SPU_ID 0xdeadbabe
uint32 registers_id[] =
{
SNPS3_spu_gpr_0,
SNPS3_spu_gpr_1,
SNPS3_spu_gpr_2,
SNPS3_spu_gpr_3,
SNPS3_spu_gpr_4,
SNPS3_spu_gpr_5,
SNPS3_spu_gpr_6,
SNPS3_spu_gpr_7,
SNPS3_spu_gpr_8,
SNPS3_spu_gpr_9,
SNPS3_spu_gpr_10,
SNPS3_spu_gpr_11,
SNPS3_spu_gpr_12,
SNPS3_spu_gpr_13,
SNPS3_spu_gpr_14,
SNPS3_spu_gpr_15,
SNPS3_spu_gpr_16,
SNPS3_spu_gpr_17,
SNPS3_spu_gpr_18,
SNPS3_spu_gpr_19,
SNPS3_spu_gpr_20,
SNPS3_spu_gpr_21,
SNPS3_spu_gpr_22,
SNPS3_spu_gpr_23,
SNPS3_spu_gpr_24,
SNPS3_spu_gpr_25,
SNPS3_spu_gpr_26,
SNPS3_spu_gpr_27,
SNPS3_spu_gpr_28,
SNPS3_spu_gpr_29,
SNPS3_spu_gpr_30,
SNPS3_spu_gpr_31,
SNPS3_spu_gpr_32,
SNPS3_spu_gpr_33,
SNPS3_spu_gpr_34,
SNPS3_spu_gpr_35,
SNPS3_spu_gpr_36,
SNPS3_spu_gpr_37,
SNPS3_spu_gpr_38,
SNPS3_spu_gpr_39,
SNPS3_spu_gpr_40,
SNPS3_spu_gpr_41,
SNPS3_spu_gpr_42,
SNPS3_spu_gpr_43,
SNPS3_spu_gpr_44,
SNPS3_spu_gpr_45,
SNPS3_spu_gpr_46,
SNPS3_spu_gpr_47,
SNPS3_spu_gpr_48,
SNPS3_spu_gpr_49,
SNPS3_spu_gpr_50,
SNPS3_spu_gpr_51,
SNPS3_spu_gpr_52,
SNPS3_spu_gpr_53,
SNPS3_spu_gpr_54,
SNPS3_spu_gpr_55,
SNPS3_spu_gpr_56,
SNPS3_spu_gpr_57,
SNPS3_spu_gpr_58,
SNPS3_spu_gpr_59,
SNPS3_spu_gpr_60,
SNPS3_spu_gpr_61,
SNPS3_spu_gpr_62,
SNPS3_spu_gpr_63,
SNPS3_spu_gpr_64,
SNPS3_spu_gpr_65,
SNPS3_spu_gpr_66,
SNPS3_spu_gpr_67,
SNPS3_spu_gpr_68,
SNPS3_spu_gpr_69,
SNPS3_spu_gpr_70,
SNPS3_spu_gpr_71,
SNPS3_spu_gpr_72,
SNPS3_spu_gpr_73,
SNPS3_spu_gpr_74,
SNPS3_spu_gpr_75,
SNPS3_spu_gpr_76,
SNPS3_spu_gpr_77,
SNPS3_spu_gpr_78,
SNPS3_spu_gpr_79,
SNPS3_spu_gpr_80,
SNPS3_spu_gpr_81,
SNPS3_spu_gpr_82,
SNPS3_spu_gpr_83,
SNPS3_spu_gpr_84,
SNPS3_spu_gpr_85,
SNPS3_spu_gpr_86,
SNPS3_spu_gpr_87,
SNPS3_spu_gpr_88,
SNPS3_spu_gpr_89,
SNPS3_spu_gpr_90,
SNPS3_spu_gpr_91,
SNPS3_spu_gpr_92,
SNPS3_spu_gpr_93,
SNPS3_spu_gpr_94,
SNPS3_spu_gpr_95,
SNPS3_spu_gpr_96,
SNPS3_spu_gpr_97,
SNPS3_spu_gpr_98,
SNPS3_spu_gpr_99,
SNPS3_spu_gpr_100,
SNPS3_spu_gpr_101,
SNPS3_spu_gpr_102,
SNPS3_spu_gpr_103,
SNPS3_spu_gpr_104,
SNPS3_spu_gpr_105,
SNPS3_spu_gpr_106,
SNPS3_spu_gpr_107,
SNPS3_spu_gpr_108,
SNPS3_spu_gpr_109,
SNPS3_spu_gpr_110,
SNPS3_spu_gpr_111,
SNPS3_spu_gpr_112,
SNPS3_spu_gpr_113,
SNPS3_spu_gpr_114,
SNPS3_spu_gpr_115,
SNPS3_spu_gpr_116,
SNPS3_spu_gpr_117,
SNPS3_spu_gpr_118,
SNPS3_spu_gpr_119,
SNPS3_spu_gpr_120,
SNPS3_spu_gpr_121,
SNPS3_spu_gpr_122,
SNPS3_spu_gpr_123,
SNPS3_spu_gpr_124,
SNPS3_spu_gpr_125,
SNPS3_spu_gpr_126,
SNPS3_spu_gpr_127,
SPU_ID,
SNPS3_pc,
};
#if USE_CUSTOM_FORMAT
void setup_registers()
{
static register_info_t default_register_info = { "", REGISTER_FLAGS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 };
static register_info_t spu_id_register_info = { "SPU_ID", REGISTER_ADDRESS | REGISTER_READONLY, RC_GENERAL, dt_dword, NULL, 0 };
static register_info_t pc_register_info = { "PC", REGISTER_ADDRESS | REGISTER_IP, RC_GENERAL, dt_dword, NULL, 0 };
for (int i = 0; i < 128; ++i)
{
// setup register names
qsnprintf(register_names[i], 16, "r%d", i);
// setup register info
registers[i] = default_register_info; registers[i].name = register_names[i]; registers[i].flags |= (REGISTER_ADDRESS | REGISTER_NOLF | ((i == 1) ? REGISTER_SP : 0));
}
registers[SPU_ID_INDEX] = spu_id_register_info;
registers[PC_INDEX] = pc_register_info;
}
#else
void setup_registers()
{
static register_info_t default_register_info = { "", REGISTER_FLAGS, RC_GENERAL, REGISTER_DATA_TYPE, REGISTER_DATA_FORMAT, 0 };
static register_info_t spu_id_register_info = { "SPU_ID", REGISTER_ADDRESS | REGISTER_READONLY, RC_GENERAL, dt_dword, NULL, 0 };
static register_info_t pc_register_info = { "PC", REGISTER_ADDRESS | REGISTER_IP, RC_GENERAL, dt_dword, NULL, 0 };
for (int i = 0; i < 128; ++i)
{
// setup register names
qsnprintf(register_names[i * 4 + 0], 16, "r%d", i);
qsnprintf(register_names[i * 4 + 1], 16, "r%d_1", i);
qsnprintf(register_names[i * 4 + 2], 16, "r%d_2", i);
qsnprintf(register_names[i * 4 + 3], 16, "r%d_3", i);
// setup register info
registers[i * 4 + 0] = default_register_info; registers[i * 4 + 0].name = register_names[i * 4 + 0]; registers[i * 4 + 0].flags |= (REGISTER_ADDRESS | REGISTER_NOLF | ((i == 1) ? REGISTER_SP : 0));
registers[i * 4 + 1] = default_register_info; registers[i * 4 + 1].name = register_names[i * 4 + 1]; registers[i * 4 + 1].flags |= (REGISTER_NOLF);
registers[i * 4 + 2] = default_register_info; registers[i * 4 + 2].name = register_names[i * 4 + 2]; registers[i * 4 + 2].flags |= (REGISTER_NOLF);
registers[i * 4 + 3] = default_register_info; registers[i * 4 + 3].name = register_names[i * 4 + 3];
}
registers[SPU_ID_INDEX] = spu_id_register_info;
registers[PC_INDEX] = pc_register_info;
}
#endif
//-------------------------------------------------------------------------
static inline uint32 bswap32(uint32 x)
{
return ( (x << 24) & 0xff000000 ) |
( (x << 8) & 0x00ff0000 ) |
( (x >> 8) & 0x0000ff00 ) |
( (x >> 24) & 0x000000ff );
}
static inline uint64 bswap64(uint64 x)
{
return ( (x << 56) & 0xff00000000000000ULL ) |
( (x << 40) & 0x00ff000000000000ULL ) |
( (x << 24) & 0x0000ff0000000000ULL ) |
( (x << 8) & 0x000000ff00000000ULL ) |
( (x >> 8) & 0x00000000ff000000ULL ) |
( (x >> 24) & 0x0000000000ff0000ULL ) |
( (x >> 40) & 0x000000000000ff00ULL ) |
( (x >> 56) & 0x00000000000000ffULL );
}
bool GetHostnames(const char* input, std::string& ipOut, std::string& dnsNameOut)
{
WSADATA wsaData;
int iResult;
// Initialize Winsock
iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (iResult != 0) {
return false;
}
sockaddr_in remotemachine;
char hostname[NI_MAXHOST];
remotemachine.sin_family = AF_INET;
remotemachine.sin_addr.s_addr = inet_addr(input);
// IP->Hostname
DWORD dwRetVal = getnameinfo((SOCKADDR *)&remotemachine,
sizeof(sockaddr),
hostname,
NI_MAXHOST,
NULL,
0,
NI_NAMEREQD);
if (dwRetVal == 0)
{
dnsNameOut = hostname;
return true;
}
// Hostname -> IP
struct hostent *remoteHost;
remoteHost = gethostbyname(input);
int i = 0;
struct in_addr addr = { 0 };
if (remoteHost && remoteHost->h_addrtype == AF_INET)
{
if (remoteHost->h_addr_list[0] != 0)
{
addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
ipOut = inet_ntoa(addr);
return true;
}
}
WSACleanup();
return false;
}
static void handle_events(u32 signal, u32 address)
{
debug_printf("handle_events\n");
debug_event_t ev;
switch (signal)
{
case SIGABRT:
{
if (attaching)
{
debug_printf("SPU3_DBG_EVENT_PROCESS_START\n");
attaching = false;
ev.eid = PROCESS_START;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
qstrncpy(ev.modinfo.name, "SPU3", sizeof(ev.modinfo.name));
ev.modinfo.base = 0;
ev.modinfo.size = 0;
ev.modinfo.rebase_to = BADADDR;
events.enqueue(ev, IN_BACK);
ev.eid = PROCESS_SUSPEND;
ev.pid = ProcessID;
events.enqueue(ev, IN_BACK);
break;
}
}
break;
case SIGSEGV:
{
debug_printf("SPU3_DBG_EVENT_PROCESS_EXIT\n");
ev.eid = PROCESS_EXIT;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
ev.exit_code = 0;
events.enqueue(ev, IN_BACK);
}
break;
case SIGTRAP:
{
debug_printf("SPU3_DBG_EVENT_TRAP\n");
if (continue_from_bp == true)
{
debug_printf("\tContinuing from breakpoint...\n");
continue_from_bp = false;
}
else if (singlestep == true)
{
debug_printf("\tSingle step...\n");
ev.eid = STEP;
ev.pid = ProcessID;
ev.tid = ThreadID;
ev.ea = address;
ev.handled = true;
ev.exc.code = 0;
ev.exc.can_cont = true;
ev.exc.ea = BADADDR;
events.enqueue(ev, IN_BACK);
continue_from_bp = false;
singlestep = false;
}
else if (!addr_has_bp(address))
{
ev.eid = PROCESS_SUSPEND;
ev.pid = ProcessID;
ev.tid = ThreadID;
ev.ea = address;
ev.handled = true;
events.enqueue(ev, IN_BACK);
}
else
{
debug_printf("\tBreakpoint...\n");
ev.eid = BREAKPOINT;
ev.pid = ProcessID;
ev.tid = ThreadID;
ev.ea = address;
ev.handled = true;
ev.bpt.hea = BADADDR;
ev.bpt.kea = BADADDR;
ev.exc.ea = BADADDR;
events.enqueue(ev, IN_BACK);
}
for (std::set<uint32>::const_iterator step_it = step_bpts.begin(); step_it != step_bpts.end(); ++step_it)
{
uint32 addr = *step_it;
if (!addr_has_bp(addr))
{
main_bpts_map.erase(addr);
gdb_remove_bp(addr, GDB_BP_TYPE_X, 4);
debug_printf("step bpt cleared: 0x%08X\n", (uint32)addr);
}
}
step_bpts.clear();
}
break;
default:
debug_printf("Unknown event signal: 0x%08X\n");
break;
}
}
//--------------------------------------------------------------------------
// Initialize debugger
static bool idaapi init_debugger(const char *hostname, int port_num, const char *password)
{
debug_printf("init_debugger\n");
if (!gdb_init(port_num))
return false;
set_idc_func_ex("threadlst", idc_threadlst, idc_threadlst_args, 0);
return true;
}
//--------------------------------------------------------------------------
// Terminate debugger
static bool idaapi term_debugger(void)
{
debug_printf("term_debugger\n");
gdb_deinit();
set_idc_func_ex("threadlst", NULL, idc_threadlst_args, 0);
return true;
}
//--------------------------------------------------------------------------
int idaapi process_get_info(int n, process_info_t *info)
{
if (n > 0)
return 0;
info->pid = 0;
qstrncpy(info->name, "SPU3", sizeof(info->name));
return 1;
}
static const char *get_state_name(uint32 State)
{
switch ( State )
{
case SNPS3_PPU_IDLE: return "IDLE";
case SNPS3_PPU_RUNNABLE: return "RUNNABLE";
case SNPS3_PPU_ONPROC: return "ONPROC";
case SNPS3_PPU_SLEEP: return "SLEEP";
case SNPS3_PPU_SUSPENDED: return "SUSPENDED";
case SNPS3_PPU_SLEEP_SUSPENDED: return "SLEEP_SUSPENDED";
case SNPS3_PPU_STOP: return "STOP";
case SNPS3_PPU_ZOMBIE: return "ZOMBIE";
case SNPS3_PPU_DELETED: return "DELETED";
default: return "???";
}
}
static error_t idaapi idc_threadlst(idc_value_t *argv, idc_value_t *res)
{
get_threads_info();
return eOk;
}
void get_threads_info(void)
{
debug_printf("get_threads_info\n");
if (attaching == true)
{
debug_event_t ev;
attaching = false;
ThreadID = 1;
ev.eid = THREAD_START;
ev.pid = ProcessID;
ev.tid = ThreadID;
ev.ea = read_pc_register(ThreadID);
ev.handled = true;
events.enqueue(ev, IN_BACK);
clear_all_bp(0);
// set break point on current instruction
gdb_add_bp(ev.ea, GDB_BP_TYPE_X, 4);
step_bpts.insert(ev.ea);
}
}
int get_thread_state(uint32 tid)
{
SNRESULT snr = SN_S_OK;
uint32 ThreadInfoSize = 1024;
SNPS3_PPU_THREAD_INFO *ThreadInfo;
int state = 0;
return state;
}
void get_modules_info(void)
{
}
void clear_all_bp(uint32 tid)
{
}
void bp_list(void)
{
}
bool addr_has_bp(uint32 ea)
{
return (main_bpts.end() != main_bpts.find(ea));
}
uint32 debug_breakpoints[][32] =
{
{0},
{0x9FF8, 0xA020, 0xA054, 0xA080, 0},
{0x97B8, 0x97E0, 0x9834, 0x9874, 0},
{0},
{0},
{0xA3C8, 0xA3F0, 0xA424, 0xA450, 0},
{0x9D60, 0x9D88, 0x9DBC, 0x9DE8, 0},
{0xBCD8, 0xBD00, 0xBD34, 0xBD60, 0},
{0xAD68, 0xAD90, 0xADE4, 0xAE24, 0},
{0x94B8, 0x94E0, 0x94FC, 0x9534, 0},
{0xB3A8, 0xB3D0, 0xB3F8, 0xB420, 0},
{0xAA10, 0xAA38, 0xAA84, 0xAAC4, 0},
{0xB104, 0xB130, 0xB158, 0xB180, 0},
{0xA6AC, 0xA6D8, 0xA724, 0xA764, 0},
{0xBA64, 0xBA90, 0xBAA4, 0xBAD0, 0},
{0x915C, 0x9188, 0x91EC, 0x91F0, 0},
{0x94B8, 0x94E0, 0x95CC, 0x9604, 0},
{0xB850, 0xB878, 0xB88C, 0xB8B8, 0},
{0x8E78, 0x8EA0, 0x8EDC, 0x8F1C, 0},
{0xB638, 0xB660, 0xB674, 0xB6A0, 0},
{0x8B98, 0x8BC0, 0x8BFC, 0x8C3C, 0},
{0x3450, 0},
{0x7158, 0},
};
//--------------------------------------------------------------------------
// Start an executable to debug
static int idaapi deci3_start_process(const char *path,
const char *args,
const char *startdir,
int dbg_proc_flags,
const char *input_path,
uint32 input_file_crc32)
{
SNRESULT snr = SN_S_OK;
//uint64 tid;
debug_printf("start_process\n");
debug_printf("path: %s\n", path);
ProcessID = 0;
attaching = true;
debug_event_t ev;
ev.eid = PROCESS_START;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
qstrncpy(ev.modinfo.name, "SPU3", sizeof(ev.modinfo.name));
ev.modinfo.base = 0;
ev.modinfo.size = 0;
ev.modinfo.rebase_to = BADADDR;
events.enqueue(ev, IN_BACK);
get_threads_info();
get_modules_info();
clear_all_bp(-1);
#if 1
int i = 0;
uint32 breakpoint;
while (breakpoint = debug_breakpoints[0x16][i++])
{
gdb_add_bp(breakpoint, GDB_BP_TYPE_X, 4);
main_bpts.insert(breakpoint);
}
//gdb_add_bp(0x3F30, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x4140, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x44F8, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x4500, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x4710, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x4AD0, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x76C0, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0x89C8, GDB_BP_TYPE_X, 4);
//gdb_add_bp(0xB3F8, GDB_BP_TYPE_X, 4);
//main_bpts.insert(0x3F30);
//main_bpts.insert(0x4140);
//main_bpts.insert(0x44F8);
//main_bpts.insert(0x4500);
//main_bpts.insert(0x4710);
//main_bpts.insert(0x4AD0);
//main_bpts.insert(0x76C0);
//main_bpts.insert(0x89C8);
//main_bpts.insert(0xB3F8);
#endif
gdb_continue();
/*
ev.eid = PROCESS_SUSPEND;
ev.pid = ProcessID;
events.enqueue(ev, IN_BACK);
gdb_handle_events(handle_events);
*/
debug_printf("ProcessID: 0x%X\n", ProcessID);
/*debug_event_t ev;
ev.eid = PROCESS_START;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
qstrncpy(ev.modinfo.name, path, sizeof(ev.modinfo.name));
ev.modinfo.base = 0x10200;
ev.modinfo.size = 0;
ev.modinfo.rebase_to = BADADDR;
events.enqueue(ev, IN_BACK);*/
return 1;
}
//--------------------------------------------------------------------------
// Attach to an existing running process
int idaapi deci3_attach_process(pid_t pid, int event_id)
{
debug_printf("deci3_attach_process\n");
//block the process until all generated events are processed
attaching = true;
ProcessID = pid;
debug_event_t ev;
ev.eid = PROCESS_START;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
qstrncpy(ev.modinfo.name, process_names[ProcessID].c_str(), sizeof(ev.modinfo.name));
ev.modinfo.base = 0x10200;
ev.modinfo.size = 0;
ev.modinfo.rebase_to = BADADDR;
events.enqueue(ev, IN_BACK);
get_threads_info();
get_modules_info();
clear_all_bp(-1);
ev.eid = PROCESS_ATTACH;
ev.pid = ProcessID;
ev.tid = NO_THREAD;
ev.ea = BADADDR;
ev.handled = true;
qstrncpy(ev.modinfo.name, process_names[ProcessID].c_str(), sizeof(ev.modinfo.name));
ev.modinfo.base = 0x10200;
ev.modinfo.size = 0;
ev.modinfo.rebase_to = BADADDR;
events.enqueue(ev, IN_BACK);
process_names.clear();
return 1;
}
//--------------------------------------------------------------------------
int idaapi deci3_detach_process(void)
{
debug_printf("deci3_detach_process\n");
gdb_continue();
gdb_deinit();
debug_event_t ev;
ev.eid = PROCESS_DETACH;
ev.pid = ProcessID;
events.enqueue(ev, IN_BACK);
return 1;
}
//-------------------------------------------------------------------------
void idaapi rebase_if_required_to(ea_t new_base)
{
debug_printf("rebase_if_required_to: 0x%llX\n", (uint64)new_base);
}
//--------------------------------------------------------------------------
int idaapi prepare_to_pause_process(void)
{
debug_printf("prepare_to_pause_process\n");
//gdb_pause();
debug_event_t ev;
ev.eid = PROCESS_SUSPEND;
ev.pid = ProcessID;
events.enqueue(ev, IN_BACK);
return 1;
}
//--------------------------------------------------------------------------
int idaapi deci3_exit_process(void)
{