@@ -13,8 +13,6 @@ use capstone::{
13
13
} ;
14
14
#[ cfg( unix) ]
15
15
use frida_gum:: instruction_writer:: InstructionWriter ;
16
- #[ cfg( unix) ]
17
- use frida_gum:: CpuContext ;
18
16
use frida_gum:: {
19
17
stalker:: { StalkerIterator , StalkerOutput , Transformer } ,
20
18
Gum , Module , ModuleDetails , ModuleMap , PageProtection ,
@@ -379,16 +377,6 @@ pub fn get_module_size(module_name: &str) -> usize {
379
377
code_size
380
378
}
381
379
382
- #[ cfg( target_arch = "aarch64" ) ]
383
- fn pc ( context : & CpuContext ) -> usize {
384
- context. pc ( ) as usize
385
- }
386
-
387
- #[ cfg( all( target_arch = "x86_64" , unix) ) ]
388
- fn pc ( context : & CpuContext ) -> usize {
389
- context. rip ( ) as usize
390
- }
391
-
392
380
fn pathlist_contains_module < I , P > ( list : I , module : & ModuleDetails ) -> bool
393
381
where
394
382
I : IntoIterator < Item = P > ,
@@ -490,6 +478,8 @@ where
490
478
#[ cfg( any( target_arch = "aarch64" , all( target_arch = "x86_64" , unix) ) ) ] capstone : & Capstone ,
491
479
) {
492
480
let mut first = true ;
481
+ let mut basic_block_start = 0 ;
482
+ let mut basic_block_size = 0 ;
493
483
for instruction in basic_block {
494
484
let instr = instruction. instr ( ) ;
495
485
#[ cfg( unix) ]
@@ -511,16 +501,8 @@ where
511
501
}
512
502
513
503
#[ cfg( unix) ]
514
- if let Some ( rt) = runtimes. match_first_type_mut :: < DrCovRuntime > ( ) {
515
- instruction. put_callout ( |context| {
516
- let real_address = rt. real_address_for_stalked ( pc ( & context) ) ;
517
- //let (range, (id, name)) = helper.ranges.get_key_value(&real_address).unwrap();
518
- //log::trace!("{}:0x{:016x}", name, real_address - range.start);
519
- rt. drcov_basic_blocks . push ( DrCovBasicBlock :: new (
520
- real_address,
521
- real_address + instr_size,
522
- ) ) ;
523
- } ) ;
504
+ if let Some ( _rt) = runtimes. match_first_type_mut :: < DrCovRuntime > ( ) {
505
+ basic_block_start = address;
524
506
}
525
507
}
526
508
@@ -582,15 +564,22 @@ where
582
564
}
583
565
584
566
#[ cfg( unix) ]
585
- if let Some ( rt) = runtimes. match_first_type_mut :: < DrCovRuntime > ( ) {
586
- rt. add_stalked_address (
587
- output. writer ( ) . pc ( ) as usize - instr_size,
588
- address as usize ,
589
- ) ;
567
+ if let Some ( _rt) = runtimes. match_first_type_mut :: < DrCovRuntime > ( ) {
568
+ basic_block_size += instr_size;
590
569
}
591
570
}
592
571
instruction. keep ( ) ;
593
572
}
573
+ #[ cfg( unix) ]
574
+ if basic_block_size != 0 {
575
+ if let Some ( rt) = runtimes. borrow_mut ( ) . match_first_type_mut :: < DrCovRuntime > ( ) {
576
+ log:: trace!( "{basic_block_start:#016X}:{basic_block_size:X}" ) ;
577
+ rt. drcov_basic_blocks . push ( DrCovBasicBlock :: new (
578
+ basic_block_start as usize ,
579
+ basic_block_start as usize + basic_block_size,
580
+ ) ) ;
581
+ }
582
+ }
594
583
}
595
584
596
585
/*
0 commit comments