diff options
| author | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-11-10 12:56:38 +0100 |
|---|---|---|
| committer | Theofilos Augoustis <theofilos.augoustis@gmail.com> | 2023-11-10 12:56:38 +0100 |
| commit | 1d649ee44c2f49c11077d5b851d3ed110c2d6f65 (patch) | |
| tree | 50b0a476d183efeaa7dff0b86d84debb8b786d6c /utils.py | |
| parent | ca7044cdc7fe99d8065594d455b7f41505f796ab (diff) | |
| download | focaccia-1d649ee44c2f49c11077d5b851d3ed110c2d6f65.tar.gz focaccia-1d649ee44c2f49c11077d5b851d3ed110c2d6f65.zip | |
Implement interpreter for symbolic expressions
Diffstat (limited to 'utils.py')
| -rw-r--r-- | utils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/utils.py b/utils.py index 1390283..f2c2256 100644 --- a/utils.py +++ b/utils.py @@ -14,3 +14,25 @@ def check_version(version: str): if sys.version_info.major < major and sys.version_info.minor < minor: raise EnvironmentError("Expected at least Python 3.7") +def to_str(expr): + """Convert a claripy expression to a nice string representation. + + Actually, the resulting representation is not very nice at all. It mostly + serves debugging purposes. + """ + import claripy + + if not issubclass(type(expr), claripy.ast.Base): + return f'{type(expr)}[{str(expr)}]' + + assert(expr.depth > 0) + if expr.depth == 1: + if expr.symbolic: + name = expr._encoded_name.decode() + return f'symbol[{name}]' + else: + assert(expr.concrete) + return f'value{expr.length}[{hex(expr.v)}]' + + args = [to_str(child) for child in expr.args] + return f'expr[{str(expr.op)}({", ".join(args)})]' |