diff options
| author | serpilliere <serpilliere@users.noreply.github.com> | 2018-02-15 15:39:10 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-02-15 15:39:10 +0100 |
| commit | a861086781d551efb4aebccff95bd1539482849a (patch) | |
| tree | ce023a9f3499fff01e410a6f8f00ccc5f4fdadcd | |
| parent | 71e4f05337c9cca134db66e86ceebc24c2a6965d (diff) | |
| parent | e28713fa12f50eaaec8753c60fa573ff427f0d1f (diff) | |
| download | miasm-a861086781d551efb4aebccff95bd1539482849a.tar.gz miasm-a861086781d551efb4aebccff95bd1539482849a.zip | |
Merge pull request #681 from commial/fix/import-z3-on-demand
Translator: import 'z3' only when it is really needed
| -rw-r--r-- | miasm2/ir/translators/z3_ir.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/miasm2/ir/translators/z3_ir.py b/miasm2/ir/translators/z3_ir.py index d33764fb..74bdd79c 100644 --- a/miasm2/ir/translators/z3_ir.py +++ b/miasm2/ir/translators/z3_ir.py @@ -1,7 +1,9 @@ +import imp import logging import operator -import z3 +# Raise an ImportError if z3 is not available WITHOUT actually importing it +imp.find_module("z3") from miasm2.core.asmblock import AsmLabel from miasm2.ir.translators.translator import Translator @@ -31,6 +33,10 @@ class Z3Mem(object): @name: name of memory Arrays generated. They will be named name+str(address size) (for example mem32, mem16...). """ + # Import z3 only on demand + global z3 + import z3 + if endianness not in ['<', '>']: raise ValueError("Endianness should be '>' (big) or '<' (little)") self.endianness = endianness @@ -114,6 +120,10 @@ class TranslatorZ3(Translator): """Instance a Z3 translator @endianness: (optional) memory endianness """ + # Import z3 only on demand + global z3 + import z3 + super(TranslatorZ3, self).__init__(**kwargs) self._mem = Z3Mem(endianness) |