This repository was archived by the owner on Dec 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathregs64.rs
2326 lines (2059 loc) · 69.5 KB
/
regs64.rs
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
use crate::emu::maps::Maps;
use iced_x86::Register;
use rand;
use uint::construct_uint;
macro_rules! set_reg32 {
($reg:expr, $val:expr) => {
$reg = ($val & 0x00000000ffffffff);
};
}
macro_rules! set_reg16 {
($reg:expr, $val:expr) => {
$reg &= 0xffffffffffff0000;
$reg += ($val & 0x000000000000ffff);
};
}
macro_rules! set_reg8l {
($reg:expr, $val:expr) => {
$reg &= 0xffffffffffffff00;
$reg += ($val & 0x00000000000000ff);
};
}
macro_rules! set_reg8h {
($reg:expr, $val:expr) => {
$reg &= 0xffffffffffff00ff;
$reg = $reg + (($val & 0x00000000000000ff) << 8);
};
}
macro_rules! get_reg32l {
($reg:expr) => {
return $reg & 0x00000000ffffffff;
};
}
macro_rules! get_reg32h {
($reg:expr) => {
return $reg >> 32;
};
}
macro_rules! get_reg16 {
($reg:expr) => {
return $reg & 0x000000000000ffff;
};
}
macro_rules! get_reg8l {
($reg:expr) => {
return $reg & 0x00000000000000ff;
};
}
macro_rules! get_reg8h {
($reg:expr) => {
return ($reg & 0x000000000000ff00) >> 8;
};
}
// https://wiki.osdev.org/CPU_Registers_x86-64
construct_uint! {
pub struct U256(4);
}
#[derive(Clone, Copy)]
pub struct Regs64 {
pub dr0: u64, // bp
pub dr1: u64, // bp
pub dr2: u64, // bp
pub dr3: u64, // bp
pub dr6: u64, // dbg stat
pub dr7: u64, // dbg ctrl
pub rax: u64,
pub rbx: u64,
pub rcx: u64,
pub rdx: u64,
pub rsi: u64,
pub rdi: u64,
pub rbp: u64,
pub rsp: u64,
pub rip: u64,
pub r8: u64,
pub r9: u64,
pub r10: u64,
pub r11: u64,
pub r12: u64,
pub r13: u64,
pub r14: u64,
pub r15: u64,
pub cr0: u64,
pub cr1: u64, // reserved
pub cr2: u64,
pub cr3: u64,
pub cr4: u64,
pub cr5: u64, // reserved
pub cr6: u64, // reserved
pub cr7: u64, // reserved
pub cr8: u64,
pub cr9: u64, // reserved
pub cr10: u64, // reserved
pub cr11: u64, // reserved
pub cr12: u64, // reserved
pub cr13: u64, // reserved
pub cr14: u64, // reserved
pub cr15: u64, // reserved
pub msr: u64,
pub tr3: u64,
pub tr4: u64,
pub tr5: u64,
pub tr6: u64,
pub tr7: u64,
pub xmm0: u128,
pub xmm1: u128,
pub xmm2: u128,
pub xmm3: u128,
pub xmm4: u128,
pub xmm5: u128,
pub xmm6: u128,
pub xmm7: u128,
pub xmm8: u128,
pub xmm9: u128,
pub xmm10: u128,
pub xmm11: u128,
pub xmm12: u128,
pub xmm13: u128,
pub xmm14: u128,
pub xmm15: u128,
pub ymm0: U256,
pub ymm1: U256,
pub ymm2: U256,
pub ymm3: U256,
pub ymm4: U256,
pub ymm5: U256,
pub ymm6: U256,
pub ymm7: U256,
pub ymm8: U256,
pub ymm9: U256,
pub ymm10: U256,
pub ymm11: U256,
pub ymm12: U256,
pub ymm13: U256,
pub ymm14: U256,
pub ymm15: U256,
pub mm0: u128,
pub mm1: u128,
pub mm2: u128,
pub mm3: u128,
pub mm4: u128,
pub mm5: u128,
pub mm6: u128,
pub mm7: u128,
pub gs: u64,
pub fs: u64,
}
impl Regs64 {
pub fn new() -> Regs64 {
Regs64 {
dr0: 0,
dr1: 0,
dr2: 0,
dr3: 0,
dr6: 0,
dr7: 0,
rax: 0,
rbx: 0,
rcx: 0,
rdx: 0,
rsi: 0,
rdi: 0,
rbp: 0,
rsp: 0,
rip: 0,
r8: 0,
r9: 0,
r10: 0,
r11: 0,
r12: 0,
r13: 0,
r14: 0,
r15: 0,
cr0: 0,
cr1: 0,
cr2: 0,
cr3: 0,
cr4: 0,
cr5: 0,
cr6: 0,
cr7: 0,
cr8: 0,
cr9: 0,
cr10: 0,
cr11: 0,
cr12: 0,
cr13: 0,
cr14: 0,
cr15: 0,
msr: 0,
tr3: 0,
tr4: 0,
tr5: 0,
tr6: 0,
tr7: 0,
xmm0: 0,
xmm1: 0,
xmm2: 0,
xmm3: 0,
xmm4: 0,
xmm5: 0,
xmm6: 0,
xmm7: 0,
xmm8: 0,
xmm9: 0,
xmm10: 0,
xmm11: 0,
xmm12: 0,
xmm13: 0,
xmm14: 0,
xmm15: 0,
ymm0: U256::from(0),
ymm1: U256::from(0),
ymm2: U256::from(0),
ymm3: U256::from(0),
ymm4: U256::from(0),
ymm5: U256::from(0),
ymm6: U256::from(0),
ymm7: U256::from(0),
ymm8: U256::from(0),
ymm9: U256::from(0),
ymm10: U256::from(0),
ymm11: U256::from(0),
ymm12: U256::from(0),
ymm13: U256::from(0),
ymm14: U256::from(0),
ymm15: U256::from(0),
mm0: 0,
mm1: 0,
mm2: 0,
mm3: 0,
mm4: 0,
mm5: 0,
mm6: 0,
mm7: 0,
gs: 0,
fs: 0,
}
}
pub fn diff(a: Regs64, b: Regs64) -> String {
let mut output = String::new();
if a.dr0 != b.dr0 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr0", a.dr0, b.dr0);
}
if a.dr1 != b.dr1 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr1", a.dr1, b.dr1);
}
if a.dr2 != b.dr2 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr2", a.dr2, b.dr2);
}
if a.dr3 != b.dr3 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr3", a.dr3, b.dr3);
}
if a.dr6 != b.dr6 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr6", a.dr6, b.dr6);
}
if a.dr7 != b.dr7 {
output = format!("{}{}: {:x} -> {:x} ", output, "dr7", a.dr7, b.dr7);
}
if a.rax != b.rax {
output = format!("{}{}: {:x} -> {:x} ", output, "rax", a.rax, b.rax);
}
if a.rbx != b.rbx {
output = format!("{}{}: {:x} -> {:x} ", output, "rbx", a.rbx, b.rbx);
}
if a.rcx != b.rcx {
output = format!("{}{}: {:x} -> {:x} ", output, "rcx", a.rcx, b.rcx);
}
if a.rdx != b.rdx {
output = format!("{}{}: {:x} -> {:x} ", output, "rdx", a.rdx, b.rdx);
}
if a.rsi != b.rsi {
output = format!("{}{}: {:x} -> {:x} ", output, "rsi", a.rsi, b.rsi);
}
if a.rdi != b.rdi {
output = format!("{}{}: {:x} -> {:x} ", output, "rdi", a.rdi, b.rdi);
}
if a.rbp != b.rbp {
output = format!("{}{}: {:x} -> {:x} ", output, "rbp", a.rbp, b.rbp);
}
if a.rsp != b.rsp {
output = format!("{}{}: {:x} -> {:x} ", output, "rsp", a.rsp, b.rsp);
}
//if a.rip != b.rip { output = format!("{}{}: {:x} -> {:x} ", output, "rip", a.rip, b.rip) }
if a.r8 != b.r8 {
output = format!("{}{}: {:x} -> {:x} ", output, "r8", a.r8, b.r8);
}
if a.r9 != b.r9 {
output = format!("{}{}: {:x} -> {:x} ", output, "r9", a.r9, b.r9);
}
if a.r10 != b.r10 {
output = format!("{}{}: {:x} -> {:x} ", output, "r10", a.r10, b.r10);
}
if a.r11 != b.r11 {
output = format!("{}{}: {:x} -> {:x} ", output, "r11", a.r11, b.r11);
}
if a.r12 != b.r12 {
output = format!("{}{}: {:x} -> {:x} ", output, "r12", a.r12, b.r12);
}
if a.r13 != b.r13 {
output = format!("{}{}: {:x} -> {:x} ", output, "r13", a.r13, b.r13);
}
if a.r14 != b.r14 {
output = format!("{}{}: {:x} -> {:x} ", output, "r14", a.r14, b.r14);
}
if a.r15 != b.r15 {
output = format!("{}{}: {:x} -> {:x} ", output, "r15", a.r15, b.r15);
}
if a.cr0 != b.cr0 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr0", a.cr0, b.cr0);
}
if a.cr1 != b.cr1 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr1", a.cr1, b.cr1);
}
if a.cr2 != b.cr2 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr2", a.cr2, b.cr2);
}
if a.cr3 != b.cr3 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr3", a.cr3, b.cr3);
}
if a.cr4 != b.cr4 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr4", a.cr4, b.cr4);
}
if a.cr5 != b.cr5 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr5", a.cr5, b.cr5);
}
if a.cr6 != b.cr6 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr6", a.cr6, b.cr6);
}
if a.cr7 != b.cr7 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr7", a.cr7, b.cr7);
}
if a.cr8 != b.cr8 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr8", a.cr8, b.cr8);
}
if a.cr9 != b.cr9 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr9", a.cr9, b.cr9);
}
if a.cr10 != b.cr10 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr10", a.cr10, b.cr10);
}
if a.cr11 != b.cr11 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr11", a.cr11, b.cr11);
}
if a.cr12 != b.cr12 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr12", a.cr12, b.cr12);
}
if a.cr13 != b.cr13 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr13", a.cr13, b.cr13);
}
if a.cr14 != b.cr14 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr14", a.cr14, b.cr14);
}
if a.cr15 != b.cr15 {
output = format!("{}{}: {:x} -> {:x} ", output, "cr15", a.cr15, b.cr15);
}
if a.msr != b.msr {
output = format!("{}{}: {:x} -> {:x} ", output, "msr", a.msr, b.msr);
}
if a.tr3 != b.tr3 {
output = format!("{}{}: {:x} -> {:x} ", output, "tr3", a.tr3, b.tr3);
}
if a.tr4 != b.tr4 {
output = format!("{}{}: {:x} -> {:x} ", output, "tr4", a.tr4, b.tr4);
}
if a.tr5 != b.tr5 {
output = format!("{}{}: {:x} -> {:x} ", output, "tr5", a.tr5, b.tr5);
}
if a.tr6 != b.tr6 {
output = format!("{}{}: {:x} -> {:x} ", output, "tr6", a.tr6, b.tr6);
}
if a.tr7 != b.tr7 {
output = format!("{}{}: {:x} -> {:x} ", output, "tr7", a.tr7, b.tr7);
}
if a.xmm0 != b.xmm0 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm0", a.xmm0, b.xmm0);
}
if a.xmm1 != b.xmm1 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm1", a.xmm1, b.xmm1);
}
if a.xmm2 != b.xmm2 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm2", a.xmm2, b.xmm2);
}
if a.xmm3 != b.xmm3 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm3", a.xmm3, b.xmm3);
}
if a.xmm4 != b.xmm4 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm4", a.xmm4, b.xmm4);
}
if a.xmm5 != b.xmm5 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm5", a.xmm5, b.xmm5);
}
if a.xmm6 != b.xmm6 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm6", a.xmm6, b.xmm6);
}
if a.xmm7 != b.xmm7 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm7", a.xmm7, b.xmm7);
}
if a.xmm8 != b.xmm8 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm8", a.xmm8, b.xmm8);
}
if a.xmm9 != b.xmm9 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm9", a.xmm9, b.xmm9);
}
if a.xmm10 != b.xmm10 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm10", a.xmm10, b.xmm10);
}
if a.xmm11 != b.xmm11 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm11", a.xmm11, b.xmm11);
}
if a.xmm12 != b.xmm12 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm12", a.xmm12, b.xmm12);
}
if a.xmm13 != b.xmm13 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm13", a.xmm13, b.xmm13);
}
if a.xmm14 != b.xmm14 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm14", a.xmm14, b.xmm14);
}
if a.xmm15 != b.xmm15 {
output = format!("{}{}: {:x} -> {:x} ", output, "xmm15", a.xmm15, b.xmm15);
}
if a.ymm0 != b.ymm0 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm0", a.ymm0, b.ymm0);
}
if a.ymm1 != b.ymm1 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm1", a.ymm1, b.ymm1);
}
if a.ymm2 != b.ymm2 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm2", a.ymm2, b.ymm2);
}
if a.ymm3 != b.ymm3 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm3", a.ymm3, b.ymm3);
}
if a.ymm4 != b.ymm4 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm4", a.ymm4, b.ymm4);
}
if a.ymm5 != b.ymm5 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm5", a.ymm5, b.ymm5);
}
if a.ymm6 != b.ymm6 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm6", a.ymm6, b.ymm6);
}
if a.ymm7 != b.ymm7 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm7", a.ymm7, b.ymm7);
}
if a.ymm8 != b.ymm8 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm8", a.ymm8, b.ymm8);
}
if a.ymm9 != b.ymm9 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm9", a.ymm9, b.ymm9);
}
if a.ymm10 != b.ymm10 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm10", a.ymm10, b.ymm10);
}
if a.ymm11 != b.ymm11 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm11", a.ymm11, b.ymm11);
}
if a.ymm12 != b.ymm12 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm12", a.ymm12, b.ymm12);
}
if a.ymm13 != b.ymm13 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm13", a.ymm13, b.ymm13);
}
if a.ymm14 != b.ymm14 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm14", a.ymm14, b.ymm14);
}
if a.ymm15 != b.ymm15 {
output = format!("{}{}: {:x} -> {:x} ", output, "ymm15", a.ymm15, b.ymm15);
}
if a.mm0 != b.mm0 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm0", a.mm0, b.mm0);
}
if a.mm1 != b.mm1 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm1", a.mm1, b.mm1);
}
if a.mm2 != b.mm2 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm2", a.mm2, b.mm2);
}
if a.mm3 != b.mm3 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm3", a.mm3, b.mm3);
}
if a.mm4 != b.mm4 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm4", a.mm4, b.mm4);
}
if a.mm5 != b.mm5 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm5", a.mm5, b.mm5);
}
if a.mm6 != b.mm6 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm6", a.mm6, b.mm6);
}
if a.mm7 != b.mm7 {
output = format!("{}{}: {:x} -> {:x} ", output, "mm7", a.mm7, b.mm7);
}
if a.gs != b.gs {
output = format!("{}{}: {:x} -> {:x} ", output, "gs", a.gs, b.gs);
}
if a.fs != b.fs {
output = format!("{}{}: {:x} -> {:x} ", output, "fs", a.fs, b.fs);
}
output
}
pub fn clear<const B: usize>(&mut self) {
match B {
64 => {
self.rax = 0;
self.rbx = 0;
self.rcx = 0;
self.rdx = 0;
self.rsi = 0;
self.rdi = 0;
self.rbp = 0;
self.rsp = 0;
self.rip = 0;
self.r8 = 0;
self.r9 = 0;
self.r10 = 0;
self.r11 = 0;
self.r12 = 0;
self.r13 = 0;
self.r14 = 0;
self.r15 = 0;
}
32 => {
self.set_eax(0);
self.set_ebx(0);
self.set_ecx(0);
self.set_edx(0);
self.set_esi(0);
self.set_edi(0);
self.set_esp(0);
self.set_ebp(0);
self.set_eip(0);
}
16 => {
self.set_ax(0);
self.set_bx(0);
self.set_cx(0);
self.set_dx(0);
self.set_si(0);
self.set_di(0);
self.set_sp(0);
self.set_bp(0);
self.set_ip(0);
}
_ => unimplemented!(),
}
}
pub fn rand(&mut self) {
self.rax = rand::random::<u64>();
self.rbx = rand::random::<u64>();
self.rcx = rand::random::<u64>();
self.rdx = rand::random::<u64>();
self.rsi = rand::random::<u64>();
self.rdi = rand::random::<u64>();
self.rbp = rand::random::<u64>();
self.rsp = rand::random::<u64>();
self.rip = rand::random::<u64>();
}
pub fn sanitize32(&mut self) {
let mask: u64 = 0x00000000ffffffff;
self.rax &= mask;
self.rbx &= mask;
self.rcx &= mask;
self.rdx &= mask;
self.rsi &= mask;
self.rdi &= mask;
self.rbp &= mask;
self.rsp &= mask;
self.rip &= mask;
}
pub fn print<const B: usize>(&self) {
log::info!("regs:");
match B {
64 => {
log::info!(" rax: 0x{:x}", self.rax);
log::info!(" rbx: 0x{:x}", self.rbx);
log::info!(" rcx: 0x{:x}", self.rcx);
log::info!(" rdx: 0x{:x}", self.rdx);
log::info!(" rsi: 0x{:x}", self.rsi);
log::info!(" rdi: 0x{:x}", self.rdi);
log::info!(" rbp: 0x{:x}", self.rbp);
log::info!(" rsp: 0x{:x}", self.rsp);
log::info!(" rip: 0x{:x}", self.rip);
}
32 => {
log::info!(" eax: 0x{:x}", self.get_eax());
log::info!(" ebx: 0x{:x}", self.get_ebx());
log::info!(" ecx: 0x{:x}", self.get_ecx());
log::info!(" edx: 0x{:x}", self.get_edx());
log::info!(" esi: 0x{:x}", self.get_esi());
log::info!(" edi: 0x{:x}", self.get_edi());
log::info!(" ebp: 0x{:x}", self.get_ebp());
log::info!(" esp: 0x{:x}", self.get_esp());
log::info!(" eip: 0x{:x}", self.get_eip());
}
_ => unimplemented!(),
}
log::info!("---");
}
pub fn print_xmm(&self) {
log::info!("xmm regs:");
log::info!(" xmm0: {}", self.xmm0);
log::info!(" xmm1: {}", self.xmm1);
log::info!(" xmm2: {}", self.xmm2);
log::info!(" xmm3: {}", self.xmm3);
log::info!(" xmm4: {}", self.xmm4);
log::info!(" xmm5: {}", self.xmm5);
log::info!(" xmm6: {}", self.xmm6);
log::info!(" xmm7: {}", self.xmm7);
log::info!(" xmm8: {}", self.xmm8);
log::info!(" xmm9: {}", self.xmm9);
log::info!(" xmm10: {}", self.xmm10);
log::info!(" xmm11: {}", self.xmm11);
log::info!(" xmm12: {}", self.xmm12);
log::info!(" xmm13: {}", self.xmm13);
log::info!(" xmm14: {}", self.xmm14);
log::info!(" xmm15: {}", self.xmm15);
}
pub fn print_ymm(&self) {
log::info!("ymm regs:");
log::info!(" ymm0: {}", self.ymm0);
log::info!(" ymm1: {}", self.ymm1);
log::info!(" ymm2: {}", self.ymm2);
log::info!(" ymm3: {}", self.ymm3);
log::info!(" ymm4: {}", self.ymm4);
log::info!(" ymm5: {}", self.ymm5);
log::info!(" ymm6: {}", self.ymm6);
log::info!(" ymm7: {}", self.ymm7);
log::info!(" ymm8: {}", self.ymm8);
log::info!(" ymm9: {}", self.ymm9);
log::info!(" ymm10: {}", self.ymm10);
log::info!(" ymm11: {}", self.ymm11);
log::info!(" ymm12: {}", self.ymm12);
log::info!(" ymm13: {}", self.ymm13);
log::info!(" ymm14: {}", self.ymm14);
log::info!(" ymm15: {}", self.ymm15);
}
// get 16 bits
pub fn get_ax(&self) -> u64 {
get_reg16!(self.rax);
}
pub fn get_bx(&self) -> u64 {
get_reg16!(self.rbx);
}
pub fn get_cx(&self) -> u64 {
get_reg16!(self.rcx);
}
pub fn get_dx(&self) -> u64 {
get_reg16!(self.rdx);
}
pub fn get_si(&self) -> u64 {
get_reg16!(self.rsi);
}
pub fn get_di(&self) -> u64 {
get_reg16!(self.rdi);
}
pub fn get_sp(&self) -> u64 {
get_reg16!(self.rsp);
}
pub fn get_bp(&self) -> u64 {
get_reg16!(self.rbp);
}
pub fn get_ip(&self) -> u64 {
get_reg16!(self.rip);
}
pub fn get_r8w(&self) -> u64 {
get_reg16!(self.r8);
}
pub fn get_r9w(&self) -> u64 {
get_reg16!(self.r9);
}
pub fn get_r10w(&self) -> u64 {
get_reg16!(self.r10);
}
pub fn get_r11w(&self) -> u64 {
get_reg16!(self.r11);
}
pub fn get_r12w(&self) -> u64 {
get_reg16!(self.r12);
}
pub fn get_r13w(&self) -> u64 {
get_reg16!(self.r13);
}
pub fn get_r14w(&self) -> u64 {
get_reg16!(self.r14);
}
pub fn get_r15w(&self) -> u64 {
get_reg16!(self.r15);
}
// get 8bits
pub fn get_ah(&self) -> u64 {
get_reg8h!(self.rax);
}
pub fn get_al(&self) -> u64 {
get_reg8l!(self.rax);
}
pub fn get_bh(&self) -> u64 {
get_reg8h!(self.rbx);
}
pub fn get_bl(&self) -> u64 {
get_reg8l!(self.rbx);
}
pub fn get_ch(&self) -> u64 {
get_reg8h!(self.rcx);
}
pub fn get_cl(&self) -> u64 {
get_reg8l!(self.rcx);
}
pub fn get_dh(&self) -> u64 {
get_reg8h!(self.rdx);
}
pub fn get_dl(&self) -> u64 {
get_reg8l!(self.rdx);
}
pub fn get_r8l(&self) -> u64 {
get_reg8l!(self.r8);
}
pub fn get_r9l(&self) -> u64 {
get_reg8l!(self.r9);
}
pub fn get_r10l(&self) -> u64 {
get_reg8l!(self.r10);
}
pub fn get_r11l(&self) -> u64 {
get_reg8l!(self.r11);
}
pub fn get_r12l(&self) -> u64 {
get_reg8l!(self.r12);
}
pub fn get_r13l(&self) -> u64 {
get_reg8l!(self.r13);
}
pub fn get_r14l(&self) -> u64 {
get_reg8l!(self.r14);
}
pub fn get_r15l(&self) -> u64 {
get_reg8l!(self.r15);
}
pub fn get_r8h(&self) -> u64 {
get_reg8h!(self.r8);
}
pub fn get_r9h(&self) -> u64 {
get_reg8h!(self.r9);
}
pub fn get_r10h(&self) -> u64 {
get_reg8h!(self.r10);
}
pub fn get_r11h(&self) -> u64 {
get_reg8h!(self.r11);
}
pub fn get_r12h(&self) -> u64 {
get_reg8h!(self.r12);
}
pub fn get_r13h(&self) -> u64 {
get_reg8h!(self.r13);
}
pub fn get_r14h(&self) -> u64 {
get_reg8h!(self.r14);
}
pub fn get_r15h(&self) -> u64 {
get_reg8h!(self.r15);
}
pub fn get_sil(&self) -> u64 {
get_reg8l!(self.rsi);
}
pub fn get_dil(&self) -> u64 {
get_reg8l!(self.rdi);
}
pub fn get_bpl(&self) -> u64 {
get_reg8l!(self.rbp);
}
pub fn get_spl(&self) -> u64 {
get_reg8l!(self.rsp);
}
// get 32bits
pub fn get_eax(&self) -> u64 {
get_reg32l!(self.rax);
}
pub fn get_ebx(&self) -> u64 {
get_reg32l!(self.rbx);
}
pub fn get_ecx(&self) -> u64 {
get_reg32l!(self.rcx);
}
pub fn get_edx(&self) -> u64 {
get_reg32l!(self.rdx);
}
pub fn get_esi(&self) -> u64 {
get_reg32l!(self.rsi);
}
pub fn get_edi(&self) -> u64 {
get_reg32l!(self.rdi);
}
pub fn get_esp(&self) -> u64 {
get_reg32l!(self.rsp);
}
pub fn get_ebp(&self) -> u64 {
get_reg32l!(self.rbp);
}
pub fn get_eip(&self) -> u64 {
get_reg32l!(self.rip);
}
pub fn get_r8d(&self) -> u64 {
get_reg32l!(self.r8);
}
pub fn get_r9d(&self) -> u64 {
get_reg32l!(self.r9);
}
pub fn get_r10d(&self) -> u64 {
get_reg32l!(self.r10);
}
pub fn get_r11d(&self) -> u64 {
get_reg32l!(self.r11);
}
pub fn get_r12d(&self) -> u64 {
get_reg32l!(self.r12);
}
pub fn get_r13d(&self) -> u64 {
get_reg32l!(self.r13);
}
pub fn get_r14d(&self) -> u64 {
get_reg32l!(self.r14);
}
pub fn get_r15d(&self) -> u64 {
get_reg32l!(self.r15);
}
// get 32-bits (upper)
pub fn get_r8u(&self) -> u64 {
get_reg32h!(self.r8);
}
pub fn get_r9u(&self) -> u64 {
get_reg32h!(self.r9);
}
pub fn get_r10u(&self) -> u64 {
get_reg32h!(self.r10);
}
pub fn get_r11u(&self) -> u64 {
get_reg32h!(self.r11);
}
pub fn get_r12u(&self) -> u64 {
get_reg32h!(self.r12);
}
pub fn get_r13u(&self) -> u64 {
get_reg32h!(self.r13);
}
pub fn get_r14u(&self) -> u64 {
get_reg32h!(self.r14);
}
pub fn get_r15u(&self) -> u64 {
get_reg32h!(self.r15);
}
// set 16bits
pub fn set_ax(&mut self, val: u64) {
set_reg16!(self.rax, val);
}
pub fn set_bx(&mut self, val: u64) {
set_reg16!(self.rbx, val);
}
pub fn set_cx(&mut self, val: u64) {
set_reg16!(self.rcx, val);
}
pub fn set_dx(&mut self, val: u64) {
set_reg16!(self.rdx, val);
}
pub fn set_si(&mut self, val: u64) {
set_reg16!(self.rsi, val);
}
pub fn set_di(&mut self, val: u64) {
set_reg16!(self.rdi, val);
}
pub fn set_sp(&mut self, val: u64) {
set_reg16!(self.rsp, val);
}
pub fn set_bp(&mut self, val: u64) {
set_reg16!(self.rbp, val);
}
pub fn set_ip(&mut self, val: u64) {