diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2020-02-28 10:54:58 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2020-02-28 11:01:23 +0100 |
| commit | fb5ec3e3568d7c2e6f27975d76acdd8a1db5afa9 (patch) | |
| tree | e0f26f3e8cad43c9fd91607b5bf7ae96c49df64f | |
| parent | 886f05bcc6c4285bf60cb296186b9e975698356a (diff) | |
| download | miasm-fb5ec3e3568d7c2e6f27975d76acdd8a1db5afa9.tar.gz miasm-fb5ec3e3568d7c2e6f27975d76acdd8a1db5afa9.zip | |
Fix Automod code
| -rw-r--r-- | example/samples/x86_32_automod_2.S | 25 | ||||
| -rw-r--r-- | miasm/jitter/jitcore.py | 9 | ||||
| -rwxr-xr-x | test/test_all.py | 10 |
3 files changed, 38 insertions, 6 deletions
diff --git a/example/samples/x86_32_automod_2.S b/example/samples/x86_32_automod_2.S new file mode 100644 index 00000000..832e253f --- /dev/null +++ b/example/samples/x86_32_automod_2.S @@ -0,0 +1,25 @@ +main: + MOV EAX, 0 + MOV ECX, 0x3 +block1: + DEC ECX +block2: + INC EAX +tmp: + DEC ECX + JNZ block2 + ; Modify block1 + MOV BYTE PTR [block1], 0x90 + ; Modify block2 + MOV BYTE PTR [block2], 0x90 + MOV BYTE PTR [tmp], 0x90 + MOV ECX, 4 + MOV EBX, EAX + XOR EAX, EAX + CMP EBX, 2 + JZ block2 + CMP EBX, 0 + JZ ok + INT 0x3 +ok: + RET diff --git a/miasm/jitter/jitcore.py b/miasm/jitter/jitcore.py index ebda656f..c47115fb 100644 --- a/miasm/jitter/jitcore.py +++ b/miasm/jitter/jitcore.py @@ -235,12 +235,6 @@ class JitCore(object): # Modified blocks modified_blocks.add(block) - # Generate interval to delete - del_interval = self.blocks_to_memrange(modified_blocks) - - # Remove interval from monitored interval list - self.blocks_mem_interval -= del_interval - # Remove modified blocks for block in modified_blocks: try: @@ -259,6 +253,9 @@ class JitCore(object): # Remove label -> block link del(self.loc_key_to_block[block.loc_key]) + # Re generate blocks intervals + self.blocks_mem_interval = self.blocks_to_memrange(self.loc_key_to_block.values()) + return modified_blocks def updt_automod_code_range(self, vm, mem_range): diff --git a/test/test_all.py b/test/test_all.py index 7fb43525..a8bf5330 100755 --- a/test/test_all.py +++ b/test/test_all.py @@ -548,6 +548,13 @@ test_x86_32_if_reg = ExampleShellcode(['x86_32', 'x86_32_if_reg.S', "x86_32_if_r test_x86_32_seh = ExampleShellcode(["x86_32", "x86_32_seh.S", "x86_32_seh.bin", "--PE"]) test_x86_32_dead = ExampleShellcode(['x86_32', 'x86_32_dead.S', "x86_32_dead.bin"]) +test_x86_32_automod_2 = ExampleShellcode( + [ + 'x86_32', 'x86_32_automod_2.S', "x86_32_automod_2.bin", "--PE" + ] +) + + test_x86_32_dis = ExampleShellcode( [ "x86_32", "test_x86_32_dis.S", "test_x86_32_dis.bin", "--PE" @@ -573,6 +580,7 @@ testset += test_x86_32_seh testset += test_x86_32_dead testset += test_human testset += test_x86_32_dis +testset += test_x86_32_automod_2 class ExampleDisassembler(Example): """Disassembler examples specificities: @@ -801,6 +809,8 @@ for script, dep in [(["x86_32.py", Example.get_sample("x86_32_sc.bin")], []), (["arm_sc.py", "0", Example.get_sample("demo_arm_l.bin"), "l", "-a", "0"], [test_arml]), (["sandbox_call.py", Example.get_sample("md5_arm")], []), + (["sandbox_pe_x86_32.py", Example.get_sample("x86_32_automod_2.bin")], + [test_x86_32_automod_2]) ] + [(["sandbox_pe_x86_32.py", Example.get_sample("x86_32_" + name + ".bin")], [test_box[name]]) |