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.py2
-rw-r--r--example/asm/simple.py2
-rw-r--r--example/expression/asm_to_ir.py6
-rw-r--r--example/expression/expr_grapher.py1
-rw-r--r--example/expression/simplification_tools.py1
-rw-r--r--example/expression/solve_condition_stp.py12
-rw-r--r--example/ida/depgraph.py3
-rw-r--r--example/ida/graph_ir.py11
-rw-r--r--example/jitter/arm_sc.py4
-rw-r--r--example/jitter/mips32.py3
-rw-r--r--example/jitter/msp430.py3
-rw-r--r--example/jitter/unpack_upx.py16
12 files changed, 23 insertions, 41 deletions
diff --git a/example/asm/shellcode.py b/example/asm/shellcode.py
index 945cac8c..52630e4d 100644
--- a/example/asm/shellcode.py
+++ b/example/asm/shellcode.py
@@ -5,9 +5,7 @@ from pdb import pm
 from elfesteem import pe_init
 from elfesteem.strpatchwork import StrPatchwork
 
-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
 
diff --git a/example/asm/simple.py b/example/asm/simple.py
index 45954f91..d7623908 100644
--- a/example/asm/simple.py
+++ b/example/asm/simple.py
@@ -3,8 +3,6 @@ from pprint import pprint
 
 from miasm2.arch.x86.arch import mn_x86
 from miasm2.core import parse_asm, asmbloc
-import miasm2.expression.expression as m2_expr
-from miasm2.core import asmbloc
 
 
 # Assemble code
diff --git a/example/expression/asm_to_ir.py b/example/expression/asm_to_ir.py
index 19ffd659..ee8a481a 100644
--- a/example/expression/asm_to_ir.py
+++ b/example/expression/asm_to_ir.py
@@ -1,10 +1,10 @@
-from miasm2.core.cpu import parse_ast, ast_id2expr
-from miasm2.arch.x86.arch import mn_x86, base_expr
+from pdb import pm
+
+from miasm2.arch.x86.arch import mn_x86
 from miasm2.core import parse_asm
 from miasm2.expression.expression import *
 from miasm2.core import asmbloc
 from miasm2.arch.x86.ira import ir_a_x86_32
-from pdb import pm
 
 
 # First, asm code
diff --git a/example/expression/expr_grapher.py b/example/expression/expr_grapher.py
index d1cbb73b..22dff7cf 100644
--- a/example/expression/expr_grapher.py
+++ b/example/expression/expr_grapher.py
@@ -1,4 +1,3 @@
-from miasm2.core.graph import DiGraph
 from miasm2.expression.expression import *
 
 print "Simple Expression grapher demo"
diff --git a/example/expression/simplification_tools.py b/example/expression/simplification_tools.py
index ed147c04..b2df58d3 100644
--- a/example/expression/simplification_tools.py
+++ b/example/expression/simplification_tools.py
@@ -1,5 +1,4 @@
 from miasm2.expression.expression import *
-from miasm2.expression.simplifications import expr_simp
 from pdb import pm
 import os
 
diff --git a/example/expression/solve_condition_stp.py b/example/expression/solve_condition_stp.py
index 385c5d78..8c65c83c 100644
--- a/example/expression/solve_condition_stp.py
+++ b/example/expression/solve_condition_stp.py
@@ -1,5 +1,10 @@
 import os
 import sys
+import subprocess
+from collections import defaultdict
+from optparse import OptionParser
+from pdb import pm
+
 from miasm2.arch.x86.arch import *
 from miasm2.arch.x86.regs import *
 from miasm2.arch.x86.sem import *
@@ -9,16 +14,9 @@ from miasm2.expression.expression import get_rw
 from miasm2.ir.symbexec import symbexec
 from miasm2.expression.simplifications import expr_simp
 from miasm2.expression import stp
-from collections import defaultdict
-from optparse import OptionParser
-import subprocess
 from miasm2.core import parse_asm
-from elfesteem.strpatchwork import StrPatchwork
-
 from miasm2.arch.x86.disasm import dis_x86_32 as dis_engine
 
-from pdb import pm
-
 
 filename = os.environ.get('PYTHONSTARTUP')
 if filename and os.path.isfile(filename):
diff --git a/example/ida/depgraph.py b/example/ida/depgraph.py
index fcd87cb9..03eea3d5 100644
--- a/example/ida/depgraph.py
+++ b/example/ida/depgraph.py
@@ -1,14 +1,11 @@
-import sys
 import os
 import tempfile
 
-from idaapi import GraphViewer
 from miasm2.core.bin_stream_ida import bin_stream_ida
 from miasm2.core.asmbloc import *
 from miasm2.expression import expression as m2_expr
 
 from miasm2.expression.simplifications import expr_simp
-from miasm2.analysis.machine import Machine
 from miasm2.analysis.depgraph import DependencyGraph
 
 from utils import guess_machine
diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py
index e7fd39d0..bbb44bbb 100644
--- a/example/ida/graph_ir.py
+++ b/example/ida/graph_ir.py
@@ -2,20 +2,14 @@ import sys
 import os
 import tempfile
 
-# Set your path first!
-sys.path.append("/home/serpilliere/tools/pyparsing/pyparsing-2.0.1/build/lib.linux-x86_64-2.7")
-sys.path.append("/home/serpilliere/projet/miasm/build/lib.linux-x86_64-2.7")
-sys.path.append("/home/serpilliere/projet/elfesteem/build/lib.linux-x86_64-2.7")
-
 from idaapi import GraphViewer
 
 from miasm2.core.bin_stream_ida import bin_stream_ida
 from miasm2.core.asmbloc import *
 from miasm2.expression.simplifications import expr_simp
 from miasm2.expression.expression import *
-
-from miasm2.analysis.data_analysis import intra_bloc_flow_raw, inter_bloc_flow
-from miasm2.analysis.data_analysis import intra_bloc_flow_symbexec
+from miasm2.analysis.data_analysis import inter_bloc_flow, \
+    intra_bloc_flow_symbexec
 
 from utils import guess_machine, expr2colorstr
 
@@ -219,7 +213,6 @@ def gen_bloc_data_flow_graph(ir_arch, in_str, ad):  # arch, attrib, pool_bin, bl
     bloc2w = {}
 
     for irbloc in ir_arch.blocs.values():
-        # intra_bloc_flow_raw(ir_arch, flow_graph, irbloc)
         intra_bloc_flow_symbexec(ir_arch, flow_graph, irbloc)
         # intra_bloc_flow_symb(ir_arch, flow_graph, irbloc)
 
diff --git a/example/jitter/arm_sc.py b/example/jitter/arm_sc.py
index 80714641..ca765d31 100644
--- a/example/jitter/arm_sc.py
+++ b/example/jitter/arm_sc.py
@@ -1,12 +1,8 @@
 #!/usr/bin/env python
 #-*- coding:utf-8 -*-
-from miasm2.analysis import debugging, gdbserver
-
 from miasm2.analysis.sandbox import Sandbox_Linux_armb_str
 from miasm2.analysis.sandbox import Sandbox_Linux_arml_str
-from miasm2.analysis.machine import Machine
 from elfesteem.strpatchwork import StrPatchwork
-import logging
 
 from pdb import pm
 
diff --git a/example/jitter/mips32.py b/example/jitter/mips32.py
index 20d451ab..a03cac8e 100644
--- a/example/jitter/mips32.py
+++ b/example/jitter/mips32.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #-*- coding:utf-8 -*-
 from argparse import ArgumentParser
-from miasm2.analysis import debugging, gdbserver
+from miasm2.analysis import debugging
 from miasm2.jitter.csts import *
 from miasm2.analysis.machine import Machine
 
@@ -71,6 +71,5 @@ def jit_mips32_binary(args):
         print(myjit.continue_run())
     return myjit
 if __name__ == '__main__':
-    from sys import stderr
     args = parser.parse_args()
     myjit = jit_mips32_binary(args)
diff --git a/example/jitter/msp430.py b/example/jitter/msp430.py
index eb327e05..89ecd930 100644
--- a/example/jitter/msp430.py
+++ b/example/jitter/msp430.py
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 #-*- coding:utf-8 -*-
 from argparse import ArgumentParser
-from miasm2.analysis import debugging, gdbserver
+from miasm2.analysis import debugging
 from miasm2.jitter.csts import *
 from miasm2.analysis.machine import Machine
 
@@ -64,6 +64,5 @@ def jit_msp430_binary(args):
         print(myjit.continue_run())
 
 if __name__ == '__main__':
-    from sys import stderr
     args = parser.parse_args()
     jit_msp430_binary(args)
diff --git a/example/jitter/unpack_upx.py b/example/jitter/unpack_upx.py
index 2d0a02ea..eb03209b 100644
--- a/example/jitter/unpack_upx.py
+++ b/example/jitter/unpack_upx.py
@@ -13,16 +13,24 @@ if filename and os.path.isfile(filename):
 # User defined methods
 
 def kernel32_GetProcAddress(jitter):
+    """Hook on GetProcAddress to note where UPX stores import pointers"""
     ret_ad, args = jitter.func_args_stdcall(["libbase", "fname"])
 
+    # When the function is called, EBX is a pointer to the destination buffer
     dst_ad = jitter.cpu.EBX
     logging.info('EBX ' + hex(dst_ad))
 
+    # Handle ordinal imports
     fname = (args.fname if args.fname < 0x10000
              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
     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
+    jitter.handle_function(ad)
+
     jitter.func_ret_stdcall(ret_ad, ad)
 
 
@@ -46,13 +54,10 @@ else:
 if options.verbose is True:
     print sb.jitter.vm
 
-
-ep = sb.entry_point
-
 # Ensure there is one and only one leave (for OEP discovering)
 mdis = sb.machine.dis_engine(sb.jitter.bs)
 mdis.dont_dis_nulstart_bloc = True
-ab = mdis.dis_multibloc(ep)
+ab = mdis.dis_multibloc(sb.entry_point)
 
 bb = asmbloc.basicblocs(ab)
 leaves = bb.get_bad_dst()
@@ -92,6 +97,8 @@ sb.jitter.add_breakpoint(end_label, update_binary)
 sb.run()
 
 # Rebuild PE
+# Alternative solution: miasm2.jitter.loader.pe.vm2pe(sb.jitter, out_fname,
+# libs=sb.libs, e_orig=sb.pe)
 new_dll = []
 
 sb.pe.SHList.align_sections(0x1000, 0x1000)
@@ -111,7 +118,6 @@ sb.pe.DirImport.set_rva(s_myimp.addr)
 # XXXX TODO
 sb.pe.NThdr.optentries[pe.DIRECTORY_ENTRY_DELAY_IMPORT].rva = 0
 
-sb.pe.Opthdr.AddressOfEntryPoint = sb.pe.virt2rva(end_label)
 bname, fname = os.path.split(options.filename)
 fname = os.path.join(bname, fname.replace('.', '_'))
 open(fname + '_unupx.bin', 'w').write(str(sb.pe))