@@ -20,7 +20,7 @@ pub fn random_immediate_value(kind: OpKind) -> Result<u64, DeoptimizerError> {
20
20
} )
21
21
}
22
22
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 ) {
24
24
let mut new_ip = start_addr;
25
25
for inst in code. iter_mut ( ) {
26
26
inst. set_ip ( new_ip) ;
@@ -61,35 +61,35 @@ pub fn get_instruction_bytes(bitness: u32, insts: Vec<Instruction>) -> Result<Ve
61
61
Ok ( buffer)
62
62
}
63
63
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
+ // }
90
90
91
91
pub 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 ( ) {
93
93
return ;
94
94
}
95
95
let inst_column_len = 48 ;
@@ -119,18 +119,12 @@ pub fn print_inst_diff(inst: &Instruction, dinst: Vec<Instruction>) {
119
119
}
120
120
} else {
121
121
println ! (
122
- "{:016X}:\t {}|\t {}" ,
122
+ "{:016X}:\t {}{} |\t {} {}" ,
123
123
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( ) ) ,
134
128
) ;
135
129
}
136
130
}
@@ -189,18 +183,18 @@ pub fn transpose_fixed_register_operand(inst: &mut Instruction) -> Result<(), De
189
183
// }
190
184
// }
191
185
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
+ // }
204
198
205
199
pub fn get_stack_pointer_register ( bitness : u32 ) -> Result < Register , DeoptimizerError > {
206
200
Ok ( match bitness {
@@ -234,25 +228,25 @@ pub fn to_db_mnemonic(bytes: &[u8]) -> String {
234
228
db_inst. trim_end_matches ( ", " ) . to_string ( )
235
229
}
236
230
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
+ // }
256
250
257
251
pub fn get_random_register_value ( reg : Register ) -> u64 {
258
252
let mut rng = rand:: thread_rng ( ) ;
@@ -288,8 +282,7 @@ pub fn set_branch_target(
288
282
bt : u64 ,
289
283
bitness : u32 ,
290
284
) -> Result < Instruction , DeoptimizerError > {
291
- let mut my_inst = inst. clone ( ) ;
292
-
285
+ let mut my_inst = * inst;
293
286
if matches ! ( inst. op0_kind( ) , OpKind :: FarBranch16 | OpKind :: FarBranch32 ) {
294
287
if bt < u16:: MAX as u64 {
295
288
my_inst. set_op0_kind ( OpKind :: FarBranch16 ) ;
@@ -407,15 +400,15 @@ pub fn get_random_gp_register(
407
400
let index = shuffed_regs. iter ( ) . position ( |x| {
408
401
x. full_register ( ) == ex. register ( ) . full_register ( ) || x == & ex. register ( )
409
402
} ) ;
410
- if index . is_some ( ) {
411
- shuffed_regs. remove ( index . unwrap ( ) ) ;
403
+ if let Some ( idx ) = index {
404
+ shuffed_regs. remove ( idx ) ;
412
405
}
413
406
}
414
407
}
415
408
416
409
for reg in shuffed_regs {
417
410
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" ) ;
419
412
if is_extended == extended {
420
413
return Ok ( reg) ;
421
414
}
0 commit comments