about summary refs log tree commit diff stats
path: root/example/asm
diff options
context:
space:
mode:
Diffstat (limited to 'example/asm')
-rw-r--r--example/asm/shellcode.py21
-rw-r--r--example/asm/simple.py4
2 files changed, 10 insertions, 15 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py
index 89914b6d..3f3aa877 100644
--- a/example/asm/shellcode.py
+++ b/example/asm/shellcode.py
@@ -9,6 +9,7 @@ from miasm2.core.cpu import parse_ast
 from miasm2.core import parse_asm, asmbloc
 import miasm2.expression.expression as m2_expr
 from miasm2.analysis.machine import Machine
+from miasm2.core.interval import interval
 
 parser = ArgumentParser("Multi-arch (32 bits) assembler")
 parser.add_argument('architecture', help="architecture: " + \
@@ -34,6 +35,7 @@ except ValueError:
     size = 32
 reg_and_id = dict(machine.mn.regs.all_regs_ids_byname)
 base_expr = machine.base_expr
+dst_interval = None
 
 # Output format
 if args.PE:
@@ -50,7 +52,8 @@ if args.PE:
     addr_main = pe.rva2virt(s_text.addr)
     virt = pe.virt
     output = pe
-
+    dst_interval = interval([(pe.rva2virt(s_text.addr),
+                              pe.rva2virt(s_text.addr + s_text.size))])
 else:
     st = StrPatchwork()
 
@@ -58,15 +61,6 @@ else:
     virt = st
     output = st
 
-# Fix the AST parser
-def my_ast_int2expr(a):
-    return m2_expr.ExprInt_fromsize(size, a)
-
-def my_ast_id2expr(t):
-    return reg_and_id.get(t, m2_expr.ExprId(t, size=size))
-
-my_var_parser = parse_ast(my_ast_id2expr, my_ast_int2expr)
-base_expr.setParseAction(my_var_parser)
 
 # Get and parse the source code
 with open(args.source) as fstream:
@@ -88,9 +82,10 @@ graph = asmbloc.bloc2graph(blocs[0])
 open("graph.txt", "w").write(graph)
 
 # Apply patches
-resolved_b, patches = asmbloc.asm_resolve_final(machine.mn,
-                                                blocs[0],
-                                                symbol_pool)
+patches = asmbloc.asm_resolve_final(machine.mn,
+                                    blocs[0],
+                                    symbol_pool,
+                                    dst_interval)
 if args.encrypt:
     # Encrypt code
     ad_start = symbol_pool.getby_name_create(args.encrypt[0]).offset
diff --git a/example/asm/simple.py b/example/asm/simple.py
index 8664672d..1929961f 100644
--- a/example/asm/simple.py
+++ b/example/asm/simple.py
@@ -27,10 +27,10 @@ loop:
 symbol_pool.set_offset(symbol_pool.getby_name("main"), 0x0)
 
 # Spread information and resolve instructions offset
-resolved_b, patches = asmbloc.asm_resolve_final(mn_x86, blocs[0], symbol_pool)
+patches = asmbloc.asm_resolve_final(mn_x86, blocs[0], symbol_pool)
 
 # Show resolved blocs
-for bloc in resolved_b:
+for bloc in blocs[0]:
     print bloc
 
 # Print offset -> bytes