@@ -20,7 +20,7 @@ pub fn random_immediate_value(kind: OpKind) -> Result<u64, DeoptimizerError> {
2020 } )
2121}
2222
23- pub fn adjust_instruction_addrs ( code : & mut Vec < Instruction > , start_addr : u64 ) {
23+ pub fn adjust_instruction_addrs ( code : & mut [ Instruction ] , start_addr : u64 ) {
2424 let mut new_ip = start_addr;
2525 for inst in code. iter_mut ( ) {
2626 inst. set_ip ( new_ip) ;
@@ -61,35 +61,35 @@ pub fn get_instruction_bytes(bitness: u32, insts: Vec<Instruction>) -> Result<Ve
6161 Ok ( buffer)
6262}
6363
64- pub fn find_subsequence ( haystack : & [ u8 ] , needle : & [ u8 ] ) -> Option < usize > {
65- haystack
66- . windows ( needle. len ( ) )
67- . position ( |window| window == needle)
68- }
69-
70- pub fn generate_random_instructions ( size : usize ) -> Vec < u8 > {
71- let small_mnemonics = [
72- 0x90 , // nop
73- 0xc3 , // ret
74- 0xf1 , // int1
75- 0xf4 , // hlt
76- 0xf5 , // cmc
77- 0xf8 , // clc
78- 0xfa , // cli
79- 0xf9 , // stc
80- 0xfb , // sti
81- 0xfc , // cld
82- ]
83- . to_vec ( ) ;
84- let mut output = Vec :: new ( ) ;
85- for _ in 0 ..size {
86- output. push ( * small_mnemonics. choose ( & mut rand:: thread_rng ( ) ) . unwrap ( ) as u8 )
87- }
88- output
89- }
64+ // pub fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Option<usize> {
65+ // haystack
66+ // .windows(needle.len())
67+ // .position(|window| window == needle)
68+ // }
69+ //
70+ // pub fn generate_random_instructions(size: usize) -> Vec<u8> {
71+ // let small_mnemonics = [
72+ // 0x90, // nop
73+ // 0xc3, // ret
74+ // 0xf1, // int1
75+ // 0xf4, // hlt
76+ // 0xf5, // cmc
77+ // 0xf8, // clc
78+ // 0xfa, // cli
79+ // 0xf9, // stc
80+ // 0xfb, // sti
81+ // 0xfc, // cld
82+ // ]
83+ // .to_vec();
84+ // let mut output = Vec::new();
85+ // for _ in 0..size {
86+ // output.push(*small_mnemonics.choose(&mut rand::thread_rng()).unwrap() as u8)
87+ // }
88+ // output
89+ // }
9090
9191pub fn print_inst_diff ( inst : & Instruction , dinst : Vec < Instruction > ) {
92- if log:: max_level ( ) <= log:: Level :: Info || dinst. len ( ) == 0 {
92+ if log:: max_level ( ) <= log:: Level :: Info || dinst. is_empty ( ) {
9393 return ;
9494 }
9595 let inst_column_len = 48 ;
@@ -119,18 +119,12 @@ pub fn print_inst_diff(inst: &Instruction, dinst: Vec<Instruction>) {
119119 }
120120 } else {
121121 println ! (
122- "{:016X}:\t {}|\t {}" ,
122+ "{:016X}:\t {}{} |\t {} {}" ,
123123 inst. ip( ) ,
124- format!(
125- "{}{}" ,
126- inst_str. blue( ) ,
127- " " . repeat( inst_column_len - inst_str. len( ) )
128- ) ,
129- format!(
130- "{}{}" ,
131- inst_str. blue( ) ,
132- " " . repeat( inst_column_len - inst_str. len( ) )
133- ) ,
124+ inst_str. blue( ) ,
125+ " " . repeat( inst_column_len - inst_str. len( ) ) ,
126+ inst_str. blue( ) ,
127+ " " . repeat( inst_column_len - inst_str. len( ) ) ,
134128 ) ;
135129 }
136130}
@@ -189,18 +183,18 @@ pub fn transpose_fixed_register_operand(inst: &mut Instruction) -> Result<(), De
189183// }
190184// }
191185
192- pub fn get_immediate_indexes ( inst : & Instruction ) -> Option < Vec < u32 > > {
193- let mut indexes = Vec :: new ( ) ;
194- for i in 0 ..inst. op_count ( ) {
195- if is_immediate_operand ( inst. op_kind ( i) ) {
196- indexes. push ( i) ;
197- }
198- }
199- if indexes. len ( ) == 0 {
200- return None ;
201- }
202- Some ( indexes)
203- }
186+ // pub fn get_immediate_indexes(inst: &Instruction) -> Option<Vec<u32>> {
187+ // let mut indexes = Vec::new();
188+ // for i in 0..inst.op_count() {
189+ // if is_immediate_operand(inst.op_kind(i)) {
190+ // indexes.push(i);
191+ // }
192+ // }
193+ // if indexes.len() == 0 {
194+ // return None;
195+ // }
196+ // Some(indexes)
197+ // }
204198
205199pub fn get_stack_pointer_register ( bitness : u32 ) -> Result < Register , DeoptimizerError > {
206200 Ok ( match bitness {
@@ -234,25 +228,25 @@ pub fn to_db_mnemonic(bytes: &[u8]) -> String {
234228 db_inst. trim_end_matches ( ", " ) . to_string ( )
235229}
236230
237- pub fn get_register_save_seq (
238- bitness : u32 ,
239- reg : Register ,
240- ) -> Result < ( Instruction , Instruction ) , DeoptimizerError > {
241- let mut full_reg = reg. full_register ( ) ;
242- if bitness != 64 {
243- full_reg = reg. full_register32 ( ) ;
244- }
245- let ( c1, c2) = match bitness {
246- 16 => ( Code :: Push_r16 , Code :: Pop_r16 ) ,
247- 32 => ( Code :: Push_r32 , Code :: Pop_r32 ) ,
248- 64 => ( Code :: Push_r64 , Code :: Pop_r64 ) ,
249- _ => return Err ( DeoptimizerError :: InvalidProcessorMode ) ,
250- } ;
251- Ok ( (
252- Instruction :: with1 ( c1, full_reg) ?,
253- Instruction :: with1 ( c2, full_reg) ?,
254- ) )
255- }
231+ // pub fn get_register_save_seq(
232+ // bitness: u32,
233+ // reg: Register,
234+ // ) -> Result<(Instruction, Instruction), DeoptimizerError> {
235+ // let mut full_reg = reg.full_register();
236+ // if bitness != 64 {
237+ // full_reg = reg.full_register32();
238+ // }
239+ // let (c1, c2) = match bitness {
240+ // 16 => (Code::Push_r16, Code::Pop_r16),
241+ // 32 => (Code::Push_r32, Code::Pop_r32),
242+ // 64 => (Code::Push_r64, Code::Pop_r64),
243+ // _ => return Err(DeoptimizerError::InvalidProcessorMode),
244+ // };
245+ // Ok((
246+ // Instruction::with1(c1, full_reg)?,
247+ // Instruction::with1(c2, full_reg)?,
248+ // ))
249+ // }
256250
257251pub fn get_random_register_value ( reg : Register ) -> u64 {
258252 let mut rng = rand:: thread_rng ( ) ;
@@ -288,8 +282,7 @@ pub fn set_branch_target(
288282 bt : u64 ,
289283 bitness : u32 ,
290284) -> Result < Instruction , DeoptimizerError > {
291- let mut my_inst = inst. clone ( ) ;
292-
285+ let mut my_inst = * inst;
293286 if matches ! ( inst. op0_kind( ) , OpKind :: FarBranch16 | OpKind :: FarBranch32 ) {
294287 if bt < u16:: MAX as u64 {
295288 my_inst. set_op0_kind ( OpKind :: FarBranch16 ) ;
@@ -407,15 +400,15 @@ pub fn get_random_gp_register(
407400 let index = shuffed_regs. iter ( ) . position ( |x| {
408401 x. full_register ( ) == ex. register ( ) . full_register ( ) || x == & ex. register ( )
409402 } ) ;
410- if index . is_some ( ) {
411- shuffed_regs. remove ( index . unwrap ( ) ) ;
403+ if let Some ( idx ) = index {
404+ shuffed_regs. remove ( idx ) ;
412405 }
413406 }
414407 }
415408
416409 for reg in shuffed_regs {
417410 let reg_str = format ! ( "{:?}" , reg) ;
418- let is_extended = reg_str. contains ( "R" ) || reg_str. contains ( "IL" ) || reg_str. contains ( "PL" ) ;
411+ let is_extended = reg_str. contains ( 'R' ) || reg_str. contains ( "IL" ) || reg_str. contains ( "PL" ) ;
419412 if is_extended == extended {
420413 return Ok ( reg) ;
421414 }
0 commit comments