cea-sec/miasm — pull request #24 by commial (2014-12-16 16:56:48+00:00)
Title: Translator "Miasm"

Introduce a translator named "Miasm", to get back a valid IR building expression from an expression instance.

For instance:
```Python
>>> expr = ExprRandom.get(depth=3)
>>> print expr
@32[{{0x3E,0,6, sLXfC[1:2],6,7, sLXfC[1:2],7,8},0,8, yfZWD[6:17],8,19}]
>>> Translator.to_language("Miasm").from_expr(expr)
"ExprOp('^', ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprSlice(ExprCompose([(ExprInt_fromsize(25, 0x5b41fd), 0, 25), (ExprMem(ExprInt_fromsize(16, 0x78), size=11), 25, 36), (ExprMem(ExprId('OuPnz', size=31), size=1), 36, 37), (ExprOp('<<<', ExprInt_fromsize(4, 0x4), ExprId('gudnn', size=4)), 37, 41), (ExprOp('&', ExprId('swhKx', size=17), ExprInt_fromsize(17, 0xfc85), ExprInt_fromsize(17, 0x169c)), 41, 58)]), 26, 58), ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprSlice(ExprCompose([(ExprInt_fromsize(25, 0x5b41fd), 0, 25), (ExprMem(ExprInt_fromsize(16, 0x78), size=11), 25, 36), (ExprMem(ExprId('OuPnz', size=31), size=1), 36, 37), (ExprOp('<<<', ExprInt_fromsize(4, 0x4), ExprId('gudnn', size=4)), 37, 41), (ExprOp('&', ExprId('swhKx', size=17), ExprInt_fromsize(17, 0xfc85), ExprInt_fromsize(17, 0x169c)), 41, 58)]), 26, 58))"
>>> exprRebuild = ExprOp('^', ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprSlice(ExprCompose([(ExprInt_fromsize(25, 0x5b41fd), 0, 25), (ExprMem(ExprInt_fromsize(16, 0x78), size=11), 25, 36), (ExprMem(ExprId('OuPnz', size=31), size=1), 36, 37), (ExprOp('<<<', ExprInt_fromsize(4, 0x4), ExprId('gudnn', size=4)), 37, 41), (ExprOp('&', ExprId('swhKx', size=17), ExprInt_fromsize(17, 0xfc85), ExprInt_fromsize(17, 0x169c)), 41, 58)]), 26, 58), ExprCompose([(ExprCompose([(ExprInt_fromsize(9, 0x105), 0, 9), (ExprSlice(ExprId('XIZWc', size=24), 10, 21), 9, 20), (ExprMem(ExprId('OuPnz', size=31), size=1), 20, 21)]), 0, 21), (ExprCompose([(ExprInt_fromsize(3, 0x1), 0, 3)]), 21, 24), (ExprCompose([(ExprInt_fromsize(4, 0xd), 0, 4), (ExprMem(ExprInt_fromsize(9, 0x3b), size=1), 4, 5), (ExprMem(ExprId('OuPnz', size=31), size=1), 5, 6)]), 24, 30), (ExprMem(ExprId('pVnJi', size=16), size=2), 30, 32)]), ExprSlice(ExprCompose([(ExprInt_fromsize(25, 0x5b41fd), 0, 25), (ExprMem(ExprInt_fromsize(16, 0x78), size=11), 25, 36), (ExprMem(ExprId('OuPnz', size=31), size=1), 36, 37), (ExprOp('<<<', ExprInt_fromsize(4, 0x4), ExprId('gudnn', size=4)), 37, 41), (ExprOp('&', ExprId('swhKx', size=17), ExprInt_fromsize(17, 0xfc85), ExprInt_fromsize(17, 0x169c)), 41, 58)]), 26, 58))
>>> expr == exprRebuild
True
```

This pull request also updates `examples/expression/expr_translate.py` to take in account @p-l- comments (#23) and check the Miasm translator output.