about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2018-06-21 17:33:47 +0200
committerAjax <commial@gmail.com>2018-06-21 17:33:47 +0200
commitb8d5b255bad4b03c57356c9af474e6d8a12105db (patch)
tree1fdea855e3bd266343e4d330af5ac686d53fc240
parent98a60ebb7366cda9774fc0511185602cada1833b (diff)
downloadmiasm-b8d5b255bad4b03c57356c9af474e6d8a12105db.tar.gz
miasm-b8d5b255bad4b03c57356c9af474e6d8a12105db.zip
Code cleaning: remove useless / commented code
-rw-r--r--example/expression/simplification_tools.py1
-rw-r--r--example/ida/graph_ir.py1
-rw-r--r--miasm2/analysis/data_analysis.py62
-rw-r--r--miasm2/analysis/debugging.py2
-rw-r--r--miasm2/analysis/disasm_cb.py13
-rw-r--r--miasm2/arch/arm/arch.py6
-rw-r--r--miasm2/arch/arm/sem.py3
-rw-r--r--miasm2/arch/msp430/sem.py1
-rw-r--r--miasm2/jitter/loader/elf.py2
-rw-r--r--test/analysis/data_flow.py1
-rw-r--r--test/analysis/depgraph.py2
-rw-r--r--test/arch/arm/arch.py62
-rw-r--r--test/arch/mips32/arch.py4
-rw-r--r--test/arch/msp430/arch.py4
-rw-r--r--test/arch/sh4/arch.py4
-rw-r--r--test/arch/x86/arch.py7
16 files changed, 2 insertions, 173 deletions
diff --git a/example/expression/simplification_tools.py b/example/expression/simplification_tools.py
index 7c15b3e7..cb062fb3 100644
--- a/example/expression/simplification_tools.py
+++ b/example/expression/simplification_tools.py
@@ -32,7 +32,6 @@ x = ExprMem(a + b + ExprInt(0x42, 32), 32)
 
 
 def replace_expr(e):
-    # print 'visit', e
     dct = {c + ExprInt(0x42, 32): d,
            a + b: c, }
     if e in dct:
diff --git a/example/ida/graph_ir.py b/example/ida/graph_ir.py
index 97d30851..dd842281 100644
--- a/example/ida/graph_ir.py
+++ b/example/ida/graph_ir.py
@@ -116,7 +116,6 @@ def build_graph(verbose=False, simplify=False):
 
     # populate symbols with ida names
     for addr, name in idautils.Names():
-        # print hex(ad), repr(name)
         if name is None:
             continue
         if (mdis.symbol_pool.getby_offset(addr) or
diff --git a/miasm2/analysis/data_analysis.py b/miasm2/analysis/data_analysis.py
index 5e88665e..0782c12c 100644
--- a/miasm2/analysis/data_analysis.py
+++ b/miasm2/analysis/data_analysis.py
@@ -4,7 +4,6 @@ from miasm2.ir.symbexec import SymbolicExecutionEngine
 
 
 def get_node_name(label, i, n):
-    # n_name = "%s_%d_%s"%(label.name, i, n)
     n_name = (label, i, n)
     return n_name
 
@@ -69,18 +68,12 @@ def intra_block_flow_symbexec(ir_arch, flow_graph, irb, in_nodes, out_nodes):
 
     sb = SymbolicExecutionEngine(ir_arch, dict(symbols_init))
     sb.emulbloc(irb)
-    # print "*"*40
-    # print irb
-    # print sb.dump_id()
-    # print sb.dump_mem()
 
     for n_w in sb.symbols:
-        # print n_w
         v = sb.symbols[n_w]
         if n_w in symbols_init and symbols_init[n_w] == v:
             continue
         read_values = v.get_r(cst_read=True)
-        # print n_w, v, [str(x) for x in read_values]
         node_n_w = get_node_name(irb.loc_key, len(irb), n_w)
 
         for n_r in read_values:
@@ -97,9 +90,6 @@ def intra_block_flow_symbexec(ir_arch, flow_graph, irb, in_nodes, out_nodes):
 
 def inter_block_flow_link(ir_arch, flow_graph, irb_in_nodes, irb_out_nodes, todo, link_exec_to_data):
     lbl, current_nodes, exec_nodes = todo
-    # print 'TODO'
-    # print lbl
-    # print [(str(x[0]), str(x[1])) for x in current_nodes]
     current_nodes = dict(current_nodes)
 
     # link current nodes to bloc in_nodes
@@ -107,12 +97,10 @@ def inter_block_flow_link(ir_arch, flow_graph, irb_in_nodes, irb_out_nodes, todo
         print "cannot find bloc!!", lbl
         return set()
     irb = ir_arch.blocks[lbl]
-    # pp(('IN', lbl, [(str(x[0]), str(x[1])) for x in current_nodes.items()]))
     to_del = set()
     for n_r, node_n_r in irb_in_nodes[irb.loc_key].items():
         if not n_r in current_nodes:
             continue
-        # print 'add link', current_nodes[n_r], node_n_r
         flow_graph.add_uniq_edge(current_nodes[n_r], node_n_r)
         to_del.add(n_r)
 
@@ -137,8 +125,6 @@ def inter_block_flow_link(ir_arch, flow_graph, irb_in_nodes, irb_out_nodes, todo
     for lbl_dst in ir_arch.graph.successors(irb.loc_key):
         todo.add((lbl_dst, tuple(current_nodes.items()), x_nodes))
 
-    # pp(('OUT', lbl, [(str(x[0]), str(x[1])) for x in current_nodes.items()]))
-
     return todo
 
 
@@ -161,18 +147,11 @@ def create_implicit_flow(ir_arch, flow_graph, irb_in_nodes, irb_out_ndes):
                 if not isinstance(n_r, ExprId):
                     continue
 
-                # print "###", n_r
-                # print "###", irb
-                # print "###", 'OUT', [str(x) for x in irb.out_nodes]
-                # print "###", irb_son
-                # print "###", 'IN', [str(x) for x in irb_son.in_nodes]
-
                 node_n_w = irb.loc_key, len(irb), n_r
                 irb_out_nodes[irb.loc_key][n_r] = node_n_w
                 if not n_r in irb_in_nodes[irb.loc_key]:
                     irb_in_nodes[irb.loc_key][n_r] = irb.loc_key, 0, n_r
                 node_n_r = irb_in_nodes[irb.loc_key][n_r]
-                # print "###", node_n_r
                 for lbl_p in ir_arch.graph.predecessors(irb.loc_key):
                     todo.add(lbl_p)
 
@@ -220,46 +199,11 @@ class symb_exec_func:
         b = self.ir_arch.get_block(ad)
         if b is None:
             raise ValueError("unknown bloc! %s" % ad)
-        """
-        dead = b.dead[0]
-        for d in dead:
-            if d in variables:
-                del(variables[d])
-        """
         variables = variables.items()
 
         s = parent, ad, tuple(sorted(variables))
-        """
-        state_var = s[1]
-        if s in self.states_var_done:
-            print 'skip state'
-            return
-        if not ad in self.stateby_ad:
-            self.stateby_ad[ad] = set()
-        self.stateby_ad[ad].add(state_var)
-
-        """
         self.todo.add(s)
 
-        """
-        if not ad in self.cpt:
-            self.cpt[ad] = 0
-        """
-    """
-    def get_next_min(self):
-        state_by_ad = {}
-        for state in self.todo:
-            ad = state[1]
-            if not ad in state_by_ad:
-                state_by_ad[ad] = []
-            state_by_ad[ad].append(state)
-        print "XX", [len(x) for x in state_by_ad.values()]
-        state_by_ad = state_by_ad.items()
-        state_by_ad.sort(key=lambda x:len(x[1]))
-        state_by_ad.reverse()
-        return state_by_ad.pop()[1][0]
-    """
-
     def get_next_state(self):
         state = self.todo.pop()
         return state
@@ -273,16 +217,10 @@ class symb_exec_func:
         self.total_done += 1
         print 'CPT', self.total_done
         while self.todo:
-            # if self.total_done>20:
-            #    self.get_next_min()
-            # state = self.todo.pop()
             state = self.get_next_state()
             parent, ad, s = state
             self.states_done.add(state)
             self.states_var_done.add(state)
-            # if s in self.states_var_done:
-            #    print "state done"
-            #    continue
 
             sb = SymbolicExecutionEngine(self.ir_arch, dict(s))
 
diff --git a/miasm2/analysis/debugging.py b/miasm2/analysis/debugging.py
index fc03eb17..6b88f00a 100644
--- a/miasm2/analysis/debugging.py
+++ b/miasm2/analysis/debugging.py
@@ -273,7 +273,7 @@ class DebugCmd(cmd.Cmd, object):
 
     def add_breakpoints(self, bp_addr):
         for addr in bp_addr:
-	    addr = int(addr, 0)
+            addr = int(addr, 0)
 
             good = True
             for i, dbg_obj in enumerate(self.dbg.bp_list):
diff --git a/miasm2/analysis/disasm_cb.py b/miasm2/analysis/disasm_cb.py
index e759e313..0dc482ac 100644
--- a/miasm2/analysis/disasm_cb.py
+++ b/miasm2/analysis/disasm_cb.py
@@ -5,7 +5,6 @@ from miasm2.expression.simplifications import expr_simp
 from miasm2.core.asmblock \
     import AsmSymbolPool, AsmConstraintNext, AsmConstraintTo
 from miasm2.core.utils import upck32
-# from miasm2.core.graph import DiGraph
 
 
 def get_ira(mnemo, attrib):
@@ -32,11 +31,8 @@ def arm_guess_subcall(
     ir_arch.add_block(cur_bloc)
 
     ir_blocks = ir_arch.blocks.values()
-    # flow_graph = DiGraph()
     to_add = set()
     for irblock in ir_blocks:
-        # print 'X'*40
-        # print irblock
         pc_val = None
         lr_val = None
         for exprs in irblock:
@@ -53,17 +49,13 @@ def arm_guess_subcall(
         l = cur_bloc.lines[-1]
         if lr_val.arg != l.offset + l.l:
             continue
-        # print 'IS CALL!'
         l = symbol_pool.getby_offset_create(int(lr_val))
         c = AsmConstraintNext(l)
 
         to_add.add(c)
         offsets_to_dis.add(int(lr_val))
 
-    # if to_add:
-    #    print 'R'*70
     for c in to_add:
-        # print c
         cur_bloc.addto(c)
 
 
@@ -80,16 +72,11 @@ def arm_guess_jump_table(
 
     ir_blocks = ir_arch.blocks.values()
     for irblock in ir_blocks:
-        # print 'X'*40
-        # print irblock
         pc_val = None
-        # lr_val = None
         for exprs in irblock:
             for e in exprs:
                 if e.dst == ir_arch.pc:
                     pc_val = e.src
-                # if e.dst == mnemo.regs.LR:
-                #    lr_val = e.src
         if pc_val is None:
             continue
         if not isinstance(pc_val, ExprMem):
diff --git a/miasm2/arch/arm/arch.py b/miasm2/arch/arm/arch.py
index 17b57ba4..624642cf 100644
--- a/miasm2/arch/arm/arch.py
+++ b/miasm2/arch/arm/arch.py
@@ -1038,16 +1038,12 @@ class arm_op2(arm_arg):
         shift_kind = shift & 1
         shift_type = (shift >> 1) & 3
         shift >>= 3
-        # print self.parent.immop.value, hex(shift), hex(shift_kind),
-        # hex(shift_type)
         if shift_kind:
             # shift kind is reg
             if shift & 1:
-                # log.debug('error in shift1')
                 return False
             rs = shift >> 1
             if rs == 0xf:
-                # log.debug('error in shift2')
                 return False
             shift_op = regs_expr[rs]
         else:
@@ -2155,12 +2151,10 @@ class armt_rlist_pclr(armt_rlist):
         reg_l = list(e.args)
         self.parent.pclr.value = 0
         if self.parent.pp.value == 0:
-            # print 'push'
             if regs_expr[14] in reg_l:
                 reg_l.remove(regs_expr[14])
                 self.parent.pclr.value = 1
         else:
-            # print 'pop',
             if regs_expr[15] in reg_l:
                 reg_l.remove(regs_expr[15])
                 self.parent.pclr.value = 1
diff --git a/miasm2/arch/arm/sem.py b/miasm2/arch/arm/sem.py
index c80e9826..ccd56e8f 100644
--- a/miasm2/arch/arm/sem.py
+++ b/miasm2/arch/arm/sem.py
@@ -635,7 +635,6 @@ def st_ld_r(ir, instr, a, a2, b, store=False, size=32, s_ext=False, z_ext=False)
         base, off = b.args[0],  b.args[1]  # ExprInt(size/8, 32)
     else:
         base, off = b, ExprInt(0, 32)
-    # print a, wb, base, off, postinc
     if postinc:
         ad = base
     else:
@@ -734,13 +733,11 @@ def ldrsh(ir, instr, a, b):
 def st_ld_m(ir, instr, a, b, store=False, postinc=False, updown=False):
     e = []
     wb = False
-    # sb = False
     dst = None
     if isinstance(a, ExprOp) and a.op == 'wback':
         wb = True
         a = a.args[0]
     if isinstance(b, ExprOp) and b.op == 'sbit':
-        # sb = True
         b = b.args[0]
     regs = b.args
     base = a
diff --git a/miasm2/arch/msp430/sem.py b/miasm2/arch/msp430/sem.py
index 877c2a70..a3521fb5 100644
--- a/miasm2/arch/msp430/sem.py
+++ b/miasm2/arch/msp430/sem.py
@@ -434,7 +434,6 @@ class ir_msp430(IntermediateRepresentation):
         pass
 
     def get_ir(self, instr):
-        # print instr#, args
         args = instr.args
         instr_ir, extra_ir = mnemo_func[instr.name](self, instr, *args)
         self.mod_sr(instr, instr_ir, extra_ir)
diff --git a/miasm2/jitter/loader/elf.py b/miasm2/jitter/loader/elf.py
index deaebd09..01dea647 100644
--- a/miasm2/jitter/loader/elf.py
+++ b/miasm2/jitter/loader/elf.py
@@ -32,7 +32,6 @@ def preload_elf(vm, e, runtime_lib, patch_vm_imp=True):
     # XXX quick hack
     fa = get_import_address_elf(e)
     dyn_funcs = {}
-    # log.debug('imported funcs: %s' % fa)
     for (libname, libfunc), ads in fa.items():
         for ad in ads:
             ad_base_lib = runtime_lib.lib_get_add_base(libname)
@@ -77,7 +76,6 @@ def vm_load_elf(vm, fdata, name="", **kargs):
         # -2: Trick to avoid merging 2 consecutive pages
         i += [(a_addr, b_addr - 2)]
     for a, b in i.intervals:
-        # print hex(a), hex(b)
         vm.add_memory_page(a, PAGE_READ | PAGE_WRITE, "\x00" * (b + 2 - a),
                            repr(name))
 
diff --git a/test/analysis/data_flow.py b/test/analysis/data_flow.py
index c3469109..d5b197d2 100644
--- a/test/analysis/data_flow.py
+++ b/test/analysis/data_flow.py
@@ -673,7 +673,6 @@ for test_nb, test in enumerate([(G1_IRA, G1_EXP_IRA),
 
     reaching_defs = ReachingDefinitions(g_ira)
     defuse = DiGraphDefUse(reaching_defs, deref_mem=True)
-    #open("defuse_%02d.dot" % (test_nb+1), "w").write(defuse.dot())
 
     # # Simplify graph
     dead_simp(g_ira)
diff --git a/test/analysis/depgraph.py b/test/analysis/depgraph.py
index 4e023761..86857182 100644
--- a/test/analysis/depgraph.py
+++ b/test/analysis/depgraph.py
@@ -1058,7 +1058,7 @@ for test_nb, test in enumerate([(G1_IRA, G1_INPUT),
             all_results.add(unflatGraph(flatGraph(result.graph)))
             open("graph_test_%02d_%02d.dot" % (test_nb + 1, i),
                  "w").write(dg2graph(result.graph))
-        # print all_flat
+
         if g_ind == 0:
             all_flat = sorted(all_flat)
             all_flats.append(all_flat)
diff --git a/test/arch/arm/arch.py b/test/arch/arm/arch.py
index 90d137d0..f69bb104 100644
--- a/test/arch/arm/arch.py
+++ b/test/arch/arm/arch.py
@@ -5,41 +5,6 @@ from pdb import pm
 
 
 symbol_pool = AsmSymbolPool()
-if 0:
-    a = bs('00')
-    b = bs('01')
-    c = bs(l=2)
-    d = bs(l=4, fname='rd')
-    e = bs_name(l=1, name={'ADD': 0, 'SUB': 1})
-    assert(isinstance(e, bs_divert))
-    scc = bs_mod_name(l=1, mn_mod=['', 'S'])
-    f = bs(l=1, cls=(arm_reg,))
-
-    class arm_mov(mn_arm):
-        fields = [bs('0000'), bs('0000'), bs('0000')]
-
-    class arm_DATA(mn_arm):
-        fields = [bs('1111'), e, scc, f, bs('0')]
-    mn = mn_arm.dis(0xF000000)
-
-
-if 0:
-    import cProfile
-    cProfile.run('mn_arm.dis("\xe1\xa0\xa0\x06", "l")')
-    # l = mn_arm.dis(bin_stream("\xe1\xa0\xa0\x06"), mode_arm)
-    # print l
-    """
-    mode = 64
-    l = mn_x86.fromstring("ADC      DWORD PTR [RAX], 0x11223344", mode)
-    print 'xx'
-    #t= time.time()
-    import cProfile
-    def f():
-        x = l.asm(mode)
-        print x
-    cProfile.run('f()')
-    """
-
 
 def h2i(s):
     return s.replace(' ', '').decode('hex')
@@ -268,15 +233,11 @@ for s, l in reg_tests_arm:
     print s
     print mn
     assert(str(mn) == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     l = mn_arm.fromstring(s, symbol_pool, 'l')
-    # print l
     assert(str(l) == s)
     a = mn_arm.asm(l)
     print [x for x in a]
     print repr(b)
-    # print mn.args
     assert(b in a)
 
 reg_tests_armt = [
@@ -720,36 +681,14 @@ for s, l in reg_tests_armt:
     print s
     print mn
     assert(str(mn) == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     l = mn_armt.fromstring(s, symbol_pool, 'l')
-    # print l
     assert(str(l) == s)
     print 'Asm..', l
     a = mn_armt.asm(l)
     print [x for x in a]
     print repr(b)
-    # print mn.args
     assert(b in a)
 
-"""
-print "*"*30, "START SPECIAL PARSING", "*"*30
-parse_tests = [
-    "MOV      LR, toto",
-    "MOV      LR, 1+toto",
-    "MOV      LR, (lend-lstart)^toto<<<R1",
-    "MOV      LR, R1 LSL (l_end-l_start)^toto<<<R1",
-    "MOV      LR, R1 LSL (l_end-l_start)^toto<<<R1",
-    "EOR      R0, R1, toto^titi+1",
-    ]
-
-for l in parse_tests:
-    print "-"*80
-    l = mn_arm.fromstring(l, 'l')
-    print l.name, ", ".join([str(a) for a in l.args])
-"""
-
-
 print 'TEST time', time.time() - ts
 
 # speed test arm
@@ -787,7 +726,6 @@ instr_num = 0
 ts = time.time()
 while off < bs.getlen():
     mn = mn_armt.dis(bs, 'l', off)
-    # print instr_num, off, str(mn)
     instr_num += 1
     off += mn.l
 print 'instr per sec:', instr_num / (time.time() - ts)
diff --git a/test/arch/mips32/arch.py b/test/arch/mips32/arch.py
index c6b68c0c..6fc36d13 100644
--- a/test/arch/mips32/arch.py
+++ b/test/arch/mips32/arch.py
@@ -228,13 +228,9 @@ for s, l in reg_tests_mips32:
     print s
     print mn
     assert(str(mn) == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     l = mn_mips32.fromstring(s, symbol_pool, 'b')
-    # print l
     assert(str(l) == s)
     a = mn_mips32.asm(l, 'b')
     print [x for x in a]
     print repr(b)
-    # print mn.args
     assert(b in a)
diff --git a/test/arch/msp430/arch.py b/test/arch/msp430/arch.py
index 3df2becb..08e5bdae 100644
--- a/test/arch/msp430/arch.py
+++ b/test/arch/msp430/arch.py
@@ -95,13 +95,9 @@ for s, l in reg_tests_msp:
     print s
     print mn
     assert(str(mn) == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     l = mn_msp430.fromstring(s, symbol_pool, None)
-    # print l
     assert(str(l) == s)
     a = mn_msp430.asm(l)
     print [x for x in a]
     print repr(b)
-    # print mn.args
     assert(b in a)
diff --git a/test/arch/sh4/arch.py b/test/arch/sh4/arch.py
index 574dcf49..9162fdbc 100644
--- a/test/arch/sh4/arch.py
+++ b/test/arch/sh4/arch.py
@@ -398,15 +398,11 @@ for s, l in reg_tests_sh4:
     print s
     print mn
     assert(str(mn) == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     l = mn_sh4.fromstring(s, symbol_pool, None)
-    # print l
     assert(str(l) == s)
     a = mn_sh4.asm(l)
     print [x for x in a]
     print repr(b)
-    # print mn.args
     assert(b in a)
 
 
diff --git a/test/arch/x86/arch.py b/test/arch/x86/arch.py
index 05b31815..1865ceba 100644
--- a/test/arch/x86/arch.py
+++ b/test/arch/x86/arch.py
@@ -3062,17 +3062,13 @@ for mode, s, l, in reg_tests:
     print s
     print mn
     assert(str(mn).strip() == s)
-    # print hex(b)
-    # print [str(x.get()) for x in mn.args]
     print 'fromstring', repr(s)
     l = mn_x86.fromstring(s, symbol_pool, mode)
-    # print l
     print 'str args', [(str(x), x.size) for x in l.args]
     assert(str(l).strip(' ') == s)
     a = mn_x86.asm(l)
     print 'asm result', [x for x in a]
     print repr(b)
-    # test_file[mode[0]].write(b)
 
     for x in a:
         print "BYTES", repr(x)
@@ -3086,7 +3082,6 @@ for mode, s, l, in reg_tests:
         assert(str(rl).strip(' ') == s)
     print repr(b), a
     assert(b in a)
-    # print mn.args
 print 'TEST time', time.time() - ts
 
 
@@ -3118,9 +3113,7 @@ def profile_dis(o):
     print 'instr per sec:', instr_num / (time.time() - ts)
 
 import cProfile
-# cProfile.run(r'mn_x86.dis("\x81\x54\x18\xfe\x44\x33\x22\x11", m32)')
 cProfile.run('profile_dis(o)')
-# profile_dis(o)
 
 # Test instruction representation with prefix
 instr_bytes = '\x65\xc7\x00\x09\x00\x00\x00'