Skip to content

Commit a50298a

Browse files
committed
fix crash when ida is not shipped with ida_hexrays (issue gaasedelen#88)
1 parent 18ea9bb commit a50298a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

plugins/lighthouse/painting/ida_painter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from lighthouse.util import *
1111
from lighthouse.util.disassembler import disassembler
12-
from lighthouse.util.disassembler.ida_api import map_line2citem, map_line2node, lex_citem_indexes
12+
from lighthouse.util.disassembler.ida_api import map_line2citem, map_line2node, lex_citem_indexes, hexrays_available
1313
from lighthouse.painting import DatabasePainter
1414

1515
logger = logging.getLogger("Lighthouse.Painting.IDA")
@@ -153,11 +153,11 @@ def _notify_status_changed(self, status):
153153
# enable / disable hook based on the painter being enabled or disabled
154154
if status:
155155
self._idp_hooks.hook()
156-
if idaapi.init_hexrays_plugin():
156+
if hexrays_available():
157157
idaapi.install_hexrays_callback(self._hxe_callback)
158158
else:
159159
self._idp_hooks.unhook()
160-
if idaapi.init_hexrays_plugin():
160+
if hexrays_available():
161161
idaapi.remove_hexrays_callback(self._hxe_callback)
162162

163163
# send the status changed signal...

plugins/lighthouse/util/disassembler/ida_api.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,16 @@ def name_changed(self, address, new_name):
411411
# HexRays Util
412412
#------------------------------------------------------------------------------
413413

414+
def hexrays_available():
415+
"""
416+
Return True if an IDA decompiler is loaded and available for use.
417+
"""
418+
try:
419+
import ida_hexrays
420+
return ida_hexrays.init_hexrays_plugin()
421+
except ImportError:
422+
return False
423+
414424
def map_line2citem(decompilation_text):
415425
"""
416426
Map decompilation line numbers to citems.

0 commit comments

Comments
 (0)