about summary refs log tree commit diff stats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--miasm2/core/sembuilder.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/miasm2/core/sembuilder.py b/miasm2/core/sembuilder.py
index b2cbb0ad..ecced326 100644
--- a/miasm2/core/sembuilder.py
+++ b/miasm2/core/sembuilder.py
@@ -16,6 +16,7 @@ class MiasmTransformer(ast.NodeTransformer):
     X if Y else Z -> ExprCond(Y, X, Z)
     'X'(Y)        -> ExprOp('X', Y)
     ('X' % Y)(Z)  -> ExprOp('X' % Y, Z)
+    {a, b}        -> ExprCompose([a, 0, a.size], [b, a.size, a.size + b.size])
     """
 
     # Parsers
@@ -93,6 +94,32 @@ class MiasmTransformer(ast.NodeTransformer):
                         keywords=[], starargs=None, kwargs=None)
         return call
 
+    def visit_Set(self, node):
+        "{a, b} -> ExprCompose([a, 0, a.size], [b, a.size, a.size + b.size])"
+        if len(node.elts) == 0:
+            return node
+
+        # Recursive visit
+        node = self.generic_visit(node)
+
+        new_elts = []
+        index = ast.Num(n=0)
+        for elt in node.elts:
+            new_index = ast.BinOp(op=ast.Add(), left=index,
+                                  right=ast.Attribute(value=elt,
+                                                      attr='size',
+                                                      ctx=ast.Load()))
+            new_elts.append(ast.List(elts=[elt, index, new_index],
+                                     ctx=ast.Load()))
+            index = new_index
+        return ast.Call(func=ast.Name(id='ExprCompose',
+                                      ctx=ast.Load()),
+                               args=[ast.List(elts=new_elts,
+                                              ctx=ast.Load())],
+                               keywords=[],
+                               starargs=None,
+                               kwargs=None)
+
 
 class SemBuilder(object):
     """Helper for building instruction's semantic side effects method