about summary refs log tree commit diff stats
path: root/miasm2/core/cpu.py
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/core/cpu.py')
-rw-r--r--miasm2/core/cpu.py49
1 files changed, 10 insertions, 39 deletions
diff --git a/miasm2/core/cpu.py b/miasm2/core/cpu.py
index 050648f5..92bde778 100644
--- a/miasm2/core/cpu.py
+++ b/miasm2/core/cpu.py
@@ -41,7 +41,6 @@ class bitobj:
     def getbits(self, n):
         if not n:
             return 0
-        o = 0
         if n > len(self.bits) - self.offset:
             raise ValueError('not enought bits %r %r' % (n, len(self.bits)))
         b = self.bits[self.offset:self.offset + n]
@@ -174,7 +173,6 @@ def ast_parse_op(t):
         if t[0] in ['-', '+', '!']:
             return m2_expr.ExprOp(t[0], t[1])
     if len(t) == 3:
-        args = [t[0], t[2]]
         if t[1] == '-':
             # a - b => a + (-b)
             t[1] = '+'
@@ -524,9 +522,8 @@ class bs_name(bs_divert):
 
     def divert(self, i, candidates):
         out = []
-        for candidate in candidates:
-            cls, name, bases, dct, fields = candidate
-            for new_name, value in self.args['name'].items():
+        for cls, _, bases, dct, fields in candidates:
+            for new_name, value in self.args['name'].iteritems():
                 nfields = fields[:]
                 s = int2bin(value, self.args['l'])
                 args = dict(self.args)
@@ -544,15 +541,14 @@ class bs_mod_name(bs_divert):
 
     def divert(self, i, candidates):
         out = []
-        for candidate in candidates:
-            cls, name, bases, dct, fields = candidate
+        for cls, _, bases, dct, fields in candidates:
             tab = self.args['mn_mod']
             if isinstance(tab, list):
                 tmp = {}
                 for j, v in enumerate(tab):
                     tmp[j] = v
                 tab = tmp
-            for value, new_name in tab.items():
+            for value, new_name in tab.iteritems():
                 nfields = fields[:]
                 s = int2bin(value, self.args['l'])
                 args = dict(self.args)
@@ -669,9 +665,7 @@ class reg_noarg(object):
 
 
 class mn_prefix:
-
-    def __init__(self):
-        b = None
+    pass
 
 
 def swap16(v):
@@ -701,7 +695,7 @@ total_scans = 0
 
 def branch2nodes(branch, nodes=None):
     if nodes is None:
-        node = []
+        nodes = []
     for k, v in branch.items():
         if not isinstance(v, dict):
             continue
@@ -794,15 +788,6 @@ def factor_fields_all(tree):
     return new_keys
 
 
-def factor_tree(tree):
-    new_keys = {}
-    i = 1
-    min_len = min([x[0] for x in tree.keys()])
-    while i < min_len:
-
-        i += 1
-
-
 def graph_tree(tree):
     nodes = []
     branch2nodes(tree, nodes)
@@ -899,7 +884,6 @@ class metamn(type):
             bases[0].all_mn_inst[c].append(i)
             add_candidate(bases, c)
             # gen byte lookup
-            off = 0
             o = ""
             for f in i.fields_order:
                 if not isinstance(f, bsi):
@@ -996,14 +980,8 @@ class cls_mn(object):
         fname_values = pre_dis_info
         todo = [(dict(fname_values), branch, offset * 8)
                 for branch in cls.bintree.items()]
-        cpt = 0
-        if hasattr(bs, 'getlen'):
-            bs_l = bs.getlen()
-        else:
-            bs_l = len(bs)
         for fname_values, branch, offset_b in todo:
             (l, fmask, fbits, fname, flen), vals = branch
-            cpt += 1
 
             if flen is not None:
                 l = flen(attrib, fname_values)
@@ -1127,7 +1105,6 @@ class cls_mn(object):
             if not c.add_pre_dis_info(pre_dis_info):
                 continue
 
-            args = []
             todo = {}
             getok = True
             fname_values = dict(pre_dis_info)
@@ -1257,7 +1234,6 @@ class cls_mn(object):
                         raise NotImplementedError('not fully functional')
                     f.expr = expr_simp(f.expr)
                     args_expr.append(f.expr)
-                    a = args_str[start:stop]
                     args_str = args_str[stop:].strip(' ')
                     if args_str.startswith(','):
                         args_str = args_str[1:]
@@ -1341,7 +1317,7 @@ class cls_mn(object):
     @classmethod
     def filter_asm_candidates(cls, instr, candidates):
         o = []
-        for c, v in candidates:
+        for _, v in candidates:
             o += v
         o.sort(key=len)
         return o
@@ -1351,18 +1327,16 @@ class cls_mn(object):
 
         result = []
         done = []
-        cpt = 0
 
         while todo:
             index, cur_len, to_decode = todo.pop()
             # TEST XXX
-            for i, f in to_decode:
+            for _, f in to_decode:
                 setattr(self, f.fname, f)
             if (index, [x[1].value for x in to_decode]) in done:
                 continue
             done.append((index, [x[1].value for x in to_decode]))
 
-            cpt += 1
             can_encode = True
             for i, f in to_decode[index:]:
                 f.parent.l = cur_len
@@ -1377,9 +1351,7 @@ class cls_mn(object):
                 if ret is True:
                     continue
 
-                gcpt = 0
-                for i in ret:
-                    gcpt += 1
+                for _ in ret:
                     o = []
                     if ((index, cur_len, [xx[1].value for xx in to_decode]) in todo or
                         (index, cur_len, [xx[1].value for xx in to_decode]) in done):
@@ -1400,14 +1372,13 @@ class cls_mn(object):
 
     def encodefields(self, decoded):
         bits = bitobj()
-        for p, f in decoded:
+        for _, f in decoded:
             setattr(self, f.fname, f)
 
             if f.value is None:
                 continue
             bits.putbits(f.value, f.l)
 
-        xx = bits.tostring()
         return bits.tostring()
 
     def decoded2bytes(self, result):