about summary refs log tree commit diff stats
path: root/example
diff options
context:
space:
mode:
Diffstat (limited to 'example')
-rw-r--r--example/asm/shellcode.py13
-rw-r--r--example/disasm/full.py5
-rw-r--r--example/expression/asm_to_ir.py7
-rw-r--r--example/expression/get_read_write.py5
-rw-r--r--example/expression/graph_dataflow.py1
-rw-r--r--example/ida/depgraph.py3
-rw-r--r--example/ida/graph_ir.py6
-rw-r--r--example/jitter/unpack_upx.py10
-rw-r--r--example/symbol_exec/depgraph.py3
9 files changed, 24 insertions, 29 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py
index 253386b5..9dc5c6bc 100644
--- a/example/asm/shellcode.py
+++ b/example/asm/shellcode.py
@@ -10,8 +10,8 @@ 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: " + \
-                        ",".join(Machine.available_machine()))
+parser.add_argument('architecture', help="architecture: " +
+                    ",".join(Machine.available_machine()))
 parser.add_argument("source", help="Source file to assemble")
 parser.add_argument("output", help="Output file")
 parser.add_argument("--PE", help="Create a PE with a few imports",
@@ -96,8 +96,13 @@ if args.encrypt:
     patches = new_patches
 
 print patches
-for offset, raw in patches.items():
-    virt[offset] = raw
+if isinstance(virt, StrPatchwork):
+    for offset, raw in patches.items():
+        virt[offset] = raw
+else:
+    for offset, raw in patches.items():
+        virt.set(offset, raw)
+
 
 # Produce output
 open(args.output, 'wb').write(str(output))
diff --git a/example/disasm/full.py b/example/disasm/full.py
index 03928e73..33b2f41f 100644
--- a/example/disasm/full.py
+++ b/example/disasm/full.py
@@ -194,10 +194,11 @@ if args.gen_ir:
     log.info("Print blocs (with analyse)")
     for label, bloc in ir_arch_a.blocs.iteritems():
         print bloc
-    ir_arch_a.gen_graph()
 
     if args.simplify:
         ir_arch_a.dead_simp()
 
-    out = ir_arch_a.graph()
+    out = ir_arch_a.graph.dot()
     open('graph_irflow.dot', 'w').write(out)
+    out = ir_arch.graph.dot()
+    open('graph_irflow_raw.dot', 'w').write(out)
diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py
index 3ed59ffe..2f8999a4 100644
--- a/example/expression/asm_to_ir.py
+++ b/example/expression/asm_to_ir.py
@@ -45,13 +45,10 @@ for lbl, b in ir_arch.blocs.items():
     print b
 
 # Dead propagation
-ir_arch.gen_graph()
-out = ir_arch.graph()
-open('graph.dot', 'w').write(out)
+open('graph.dot', 'w').write(ir_arch.graph.dot())
 print '*' * 80
 ir_arch.dead_simp()
-out2 = ir_arch.graph()
-open('graph2.dot', 'w').write(out2)
+open('graph2.dot', 'w').write(ir_arch.graph.dot())
 
 # Display new IR
 print 'new ir blocs'
diff --git a/example/expression/get_read_write.py b/example/expression/get_read_write.py
index f0f48015..d98b461a 100644
--- a/example/expression/get_read_write.py
+++ b/example/expression/get_read_write.py
@@ -21,6 +21,5 @@ for lbl, b in ir_arch.blocs.items():
         print 'read:   ', [str(x) for x in o_r]
         print 'written:', [str(x) for x in o_w]
         print
-ir_arch.gen_graph()
-g = ir_arch.graph()
-open('graph_instr.dot', 'w').write(g)
+
+open('graph_instr.dot', 'w').write(ir_arch.graph.dot())
diff --git a/example/expression/graph_dataflow.py b/example/expression/graph_dataflow.py
index e263a40e..64801e52 100644
--- a/example/expression/graph_dataflow.py
+++ b/example/expression/graph_dataflow.py
@@ -114,7 +114,6 @@ def gen_bloc_data_flow_graph(ir_arch, ad, block_flow_cb):
     for irbloc in ir_arch.blocs.values():
         print irbloc
 
-    ir_arch.gen_graph()
     ir_arch.dead_simp()
 
     irbloc_0 = None
diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py
index 03eea3d5..406f7200 100644
--- a/example/ida/depgraph.py
+++ b/example/ida/depgraph.py
@@ -136,9 +136,6 @@ for irb in ir_arch.blocs.values():
         for i, expr in enumerate(irs):
             irs[i] = m2_expr.ExprAff(expr_simp(expr.dst), expr_simp(expr.src))
 
-# Build the IRA Graph
-ir_arch.gen_graph()
-
 # Get settings
 settings = depGraphSettingsForm(ir_arch)
 settings.Execute()
diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py
index c3d88c36..b181f72a 100644
--- a/example/ida/graph_ir.py
+++ b/example/ida/graph_ir.py
@@ -56,7 +56,7 @@ class GraphMiasmIR(GraphViewer):
                 continue
             dst = ir_arch.dst_trackback(irbloc)
             for d in dst:
-                if not self.ir_arch.ExprIsLabel(d):
+                if not expr_is_label(d):
                     continue
 
                 d = d.name
@@ -138,8 +138,7 @@ for irb in ir_arch.blocs.values():
         for i, expr in enumerate(irs):
             irs[i] = ExprAff(expr_simp(expr.dst), expr_simp(expr.src))
 
-ir_arch.gen_graph()
-out = ir_arch.graph()
+out = ir_arch.graph.dot()
 open(os.path.join(tempfile.gettempdir(), 'graph.dot'), 'wb').write(out)
 
 
@@ -197,7 +196,6 @@ def get_modified_symbols(sb):
 def gen_bloc_data_flow_graph(ir_arch, in_str, ad):  # arch, attrib, pool_bin, bloc, symbol_pool):
     out_str = ""
 
-    ir_arch.gen_graph()
     # ir_arch.dead_simp()
 
     irbloc_0 = None
diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py
index f1f179b8..72a9feb3 100644
--- a/example/jitter/unpack_upx.py
+++ b/example/jitter/unpack_upx.py
@@ -25,7 +25,8 @@ def kernel32_GetProcAddress(jitter):
              else jitter.get_str_ansi(args.fname))
     logging.info(fname)
 
-    # Get the generated address of the library, and store it in memory to dst_ad
+    # Get the generated address of the library, and store it in memory to
+    # dst_ad
     ad = sb.libs.lib_get_add_func(args.libbase, fname, dst_ad)
     # Add a breakpoint in case of a call on the resolved function
     # NOTE: never happens in UPX, just for skeleton
@@ -34,7 +35,6 @@ def kernel32_GetProcAddress(jitter):
     jitter.func_ret_stdcall(ret_ad, ad)
 
 
-
 parser = Sandbox_Win_x86_32.parser(description="Generic UPX unpacker")
 parser.add_argument("filename", help="PE Filename")
 parser.add_argument('-v', "--verbose",
@@ -43,7 +43,9 @@ parser.add_argument("--graph",
                     help="Export the CFG graph in graph.dot",
                     action="store_true")
 options = parser.parse_args()
-sb = Sandbox_Win_x86_32(options.filename, options, globals())
+options.load_hdr = True
+sb = Sandbox_Win_x86_32(options.filename, options, globals(),
+                        parse_reloc=False)
 
 
 if options.verbose is True:
@@ -84,7 +86,7 @@ def update_binary(jitter):
     logging.info('updating binary')
     for s in sb.pe.SHList:
         sdata = sb.jitter.vm.get_mem(sb.pe.rva2virt(s.addr), s.rawsize)
-        sb.pe.virt[sb.pe.rva2virt(s.addr)] = sdata
+        sb.pe.rva.set(s.addr, sdata)
 
     # Stop execution
     jitter.run = False
diff --git a/example/symbol_exec/depgraph.py b/example/symbol_exec/depgraph.py
index 6aa9cf81..a870b275 100644
--- a/example/symbol_exec/depgraph.py
+++ b/example/symbol_exec/depgraph.py
@@ -61,9 +61,6 @@ blocks = mdis.dis_multibloc(int(args.func_addr, 0))
 for block in blocks:
     ir_arch.add_bloc(block)
 
-# Build the IRA Graph
-ir_arch.gen_graph()
-
 # Get the instance
 dg = DependencyGraph(ir_arch, implicit=args.implicit,
 		     apply_simp=not(args.do_not_simplify),