diff options
| author | Camille Mougey <commial@gmail.com> | 2018-05-14 13:53:04 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-05-14 13:53:04 +0200 |
| commit | d7c7527fbc4dea0f340402b62e7146b1d1916d2a (patch) | |
| tree | 45413ece50186f74a046ef2e2f30b4df8a19b963 /miasm2/core/asm_ast.py | |
| parent | f6e1c074f6a17b6a895dcf5352c213a1b6bacb99 (diff) | |
| parent | ab3635f44ab45e22150bc373e33b7cf11ea46f63 (diff) | |
| download | miasm-d7c7527fbc4dea0f340402b62e7146b1d1916d2a.tar.gz miasm-d7c7527fbc4dea0f340402b62e7146b1d1916d2a.zip | |
Merge pull request #734 from serpilliere/enhance_parser
Enhance parser
Diffstat (limited to 'miasm2/core/asm_ast.py')
| -rw-r--r-- | miasm2/core/asm_ast.py | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/miasm2/core/asm_ast.py b/miasm2/core/asm_ast.py new file mode 100644 index 00000000..7a365ba1 --- /dev/null +++ b/miasm2/core/asm_ast.py @@ -0,0 +1,94 @@ +class AstNode(object): + """ + Ast node object + """ + def __neg__(self): + if isinstance(self, AstInt): + value = AstInt(-self.value) + else: + value = AstOp('-', self) + return value + + def __add__(self, other): + return AstOp('+', self, other) + + def __sub__(self, other): + return AstOp('-', self, other) + + def __div__(self, other): + return AstOp('/', self, other) + + def __mod__(self, other): + return AstOp('%', self, other) + + def __mul__(self, other): + return AstOp('*', self, other) + + def __lshift__(self, other): + return AstOp('<<', self, other) + + def __rshift__(self, other): + return AstOp('>>', self, other) + + def __xor__(self, other): + return AstOp('^', self, other) + + def __or__(self, other): + return AstOp('|', self, other) + + def __and__(self, other): + return AstOp('&', self, other) + + def __neg__(self): + return AstOp('-', self) + + +class AstInt(AstNode): + """ + Ast integer + """ + def __init__(self, value): + self.value = value + + def __str__(self): + return "%s" % self.value + + +class AstId(AstNode): + """ + Ast Id + """ + def __init__(self, name): + self.name = name + + def __str__(self): + return "%s" % self.name + + +class AstMem(AstNode): + """ + Ast memory deref + """ + def __init__(self, ptr, size): + assert isinstance(ptr, AstNode) + assert isinstance(size, (int, long)) + self.ptr = ptr + self.size = size + + def __str__(self): + return "@%d[%s]" % (self.size, self.ptr) + + +class AstOp(AstNode): + """ + Ast operator + """ + def __init__(self, op, *args): + assert all(isinstance(arg, AstNode) for arg in args) + self.op = op + self.args = args + + def __str__(self): + if len(self.args) == 1: + return "(%s %s)" % (self.op, self.args[0]) + return '(' + ("%s" % self.op).join(str(x) for x in self.args) + ')' |