@@ -175,6 +175,7 @@ pub struct Emu32 {
175
175
cfg : Config ,
176
176
colors : Colors ,
177
177
pos : u64 ,
178
+ force_break : bool ,
178
179
}
179
180
180
181
impl Emu32 {
@@ -193,6 +194,7 @@ impl Emu32 {
193
194
cfg : Config :: new ( ) ,
194
195
colors : Colors :: new ( ) ,
195
196
pos : 0 ,
197
+ force_break : false ,
196
198
}
197
199
}
198
200
@@ -755,11 +757,19 @@ impl Emu32 {
755
757
panic!("writting in non mapped memory");
756
758
}*/
757
759
760
+ let name = match self . maps . get_addr_name ( addr) {
761
+ Some ( n) => n,
762
+ None => "error" . to_string ( ) ,
763
+ } ;
764
+
765
+ if name == "code" {
766
+ if self . cfg . verbose >= 1 {
767
+ println ! ( "/!\\ polymorfic code" ) ;
768
+ }
769
+ self . force_break = true ;
770
+ }
771
+
758
772
if self . cfg . trace_mem {
759
- let name = match self . maps . get_addr_name ( addr) {
760
- Some ( n) => n,
761
- None => "error" . to_string ( ) ,
762
- } ;
763
773
println ! ( "mem trace write -> '{}' 0x{:x}: 0x{:x} map:'{}'" , operand, addr, value, name) ;
764
774
}
765
775
@@ -1339,7 +1349,7 @@ impl Emu32 {
1339
1349
let code = self . maps . get_mem ( map_name. as_str ( ) ) ;
1340
1350
let block = code. read_from ( eip) ;
1341
1351
let insns = cs. disasm_all ( block, eip as u64 ) . expect ( "Failed to disassemble" ) ;
1342
-
1352
+
1343
1353
for ins in insns. as_ref ( ) {
1344
1354
//TODO: use InsnDetail https://docs.rs/capstone/0.4.0/capstone/struct.InsnDetail.html
1345
1355
//let detail: InsnDetail = cs.insn_detail(&ins).expect("Failed to get insn detail");
@@ -5509,6 +5519,57 @@ impl Emu32 {
5509
5519
self . fpu . set_eip ( self . regs . eip ) ;
5510
5520
} ,
5511
5521
5522
+ Some ( "lcall" ) => {
5523
+ if !step {
5524
+ panic ! ( "{}{} {} {{{:?}}} {}" , self . colors. green, self . pos, ins, ins. bytes( ) , self . colors. nc) ;
5525
+ }
5526
+ /*
5527
+ emulated with unicorn as a loop:
5528
+ 0x1000016: add edx, 4 ebp:0x2801000
5529
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5530
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5531
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5532
+ 0x1000016: add edx, 4 ebp:0x2801000
5533
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5534
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5535
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5536
+ 0x1000016: add edx, 4 ebp:0x2801000
5537
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5538
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5539
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5540
+ 0x1000016: add edx, 4 ebp:0x2801000
5541
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5542
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5543
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5544
+ 0x1000016: add edx, 4 ebp:0x2801000
5545
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5546
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5547
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5548
+ 0x1000016: add edx, 4 ebp:0x2801000
5549
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5550
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5551
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5552
+ 0x1000016: add edx, 4 ebp:0x2801000
5553
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5554
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5555
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5556
+ 0x1000016: add edx, 4 ebp:0x2801000
5557
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5558
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5559
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5560
+ 0x1000016: add edx, 4 ebp:0x2801000
5561
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5562
+ 0x1000010: xor dword ptr [edx + 0x14], ebx ebp:0x2801000
5563
+ 0x1000013: add ebx, dword ptr [edx + 0x14] ebp:0x2801000
5564
+ 0x1000016: add edx, 4 ebp:0x2801000
5565
+ 0x1000019: lcall 0x51c0:0xd572a83f ebp:0x2801000
5566
+ 0x100001b: test al, 0x72 ebp:0x2801000
5567
+ 0x100001c: jb 0xfffff3 ebp:0x2801000
5568
+
5569
+ opcodes:
5570
+ 10 0x3c0019: lcall 0x51c0, 0xd572a83f {[154, 63, 168, 114, 213, 192, 81]}
5571
+ */
5572
+ } ,
5512
5573
5513
5574
Some ( "sysenter" ) => {
5514
5575
println ! ( "{}{} {}{} function: 0x{:x}" , self . colors. red, self . pos, ins, self . colors. nc, self . regs. eax) ;
@@ -5519,11 +5580,16 @@ impl Emu32 {
5519
5580
println ! ( "{}{} {}{}" , self . colors. red, self . pos, ins, self . colors. nc) ;
5520
5581
panic ! ( "unimplemented instruction" ) ;
5521
5582
} ,
5583
+
5522
5584
None => panic ! ( "none instruction" ) ,
5523
5585
}
5524
5586
5525
5587
self . regs . eip += sz as u32 ;
5526
5588
5589
+ if self . force_break {
5590
+ self . force_break = false ;
5591
+ break ;
5592
+ }
5527
5593
}
5528
5594
}
5529
5595
0 commit comments