diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-02-09 21:09:06 +0100 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-02-09 21:09:06 +0100 |
| commit | d876fd8be63a3b319d206b59d57574fc3c5da8ff (patch) | |
| tree | 5de080a63a6aa17176214756d8172884116c0611 /example/ida | |
| parent | 21e61fb531127ee2c4b18ac891b83c3548b40c8a (diff) | |
| download | miasm-d876fd8be63a3b319d206b59d57574fc3c5da8ff.tar.gz miasm-d876fd8be63a3b319d206b59d57574fc3c5da8ff.zip | |
IDA/Example: Offer all available translators instead of Miasm
Diffstat (limited to 'example/ida')
| -rw-r--r-- | example/ida/symbol_exec.py | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/example/ida/symbol_exec.py b/example/ida/symbol_exec.py index 31908f83..1ff75f41 100644 --- a/example/ida/symbol_exec.py +++ b/example/ida/symbol_exec.py @@ -10,24 +10,59 @@ from utils import expr2colorstr class translatorForm(Form): - """Form showing a translation of a Miasm expression to a Python equivalent - one""" + """Translator Form. + + Offer a ComboBox with available languages (ie. IR translators) and the + corresponding translation.""" + + flags = (Form.MultiLineTextControl.TXTF_FIXEDFONT | \ + Form.MultiLineTextControl.TXTF_READONLY) def __init__(self, expr): "@expr: Expr instance" - # Translation - text = Translator.to_language("Miasm").from_expr(expr) + # Init + self.languages = list(Translator.available_languages()) + self.expr = expr + + # Initial translation + text = Translator.to_language(self.languages[0]).from_expr(self.expr) # Create the Form Form.__init__(self, r"""STARTITEM 0 Python Expression - -<Multilinetext:{txtMultiLineText}> +{FormChangeCb} +<Language:{cbLanguage}> +<Translation:{result}> """, { - 'txtMultiLineText': Form.MultiLineTextControl(text=text) + 'result': Form.MultiLineTextControl(text=text, + flags=translatorForm.flags), + 'cbLanguage': Form.DropdownListControl( + items=self.languages, + readonly=True, + selval=0), + 'FormChangeCb': Form.FormChangeCb(self.OnFormChange), }) + def OnFormChange(self, fid): + if fid == self.cbLanguage.id: + # Display the Field (may be hide) + self.ShowField(self.result, True) + + # Translate the expression + dest_lang = self.languages[self.GetControlValue(self.cbLanguage)] + try: + text = Translator.to_language(dest_lang).from_expr(self.expr) + except Exception, error: + self.ShowField(self.result, False) + return -1 + + # Update the form + self.SetControlValue(self.result, + textctrl_info_t(text=str(text), + flags=translatorForm.flags)) + return 1 + class symbolicexec_t(idaapi.simplecustviewer_t): @@ -69,7 +104,7 @@ class symbolicexec_t(idaapi.simplecustviewer_t): self.print_lines() self.menu_expand = self.AddPopupMenu("Expand [E]") - self.menu_translate = self.AddPopupMenu("Get in Python [P]") + self.menu_translate = self.AddPopupMenu("Translate [T]") return True def OnPopupMenu(self, menu_id): @@ -88,8 +123,8 @@ class symbolicexec_t(idaapi.simplecustviewer_t): # E (expand) if vkey == 69: self.OnPopupMenu(self.menu_expand) - # P (translate in python) - if vkey == 80: + # T (translate) + if vkey == 84: self.OnPopupMenu(self.menu_translate) return False |