diff --git a/libbs/__init__.py b/libbs/__init__.py index 8b8a1f4..0a2ad7f 100644 --- a/libbs/__init__.py +++ b/libbs/__init__.py @@ -1,4 +1,4 @@ -__version__ = "1.21.0" +__version__ = "1.22.0" import logging diff --git a/libbs/api/artifact_dict.py b/libbs/api/artifact_dict.py index a6e7751..74269e4 100644 --- a/libbs/api/artifact_dict.py +++ b/libbs/api/artifact_dict.py @@ -134,3 +134,8 @@ def values(self): def items(self): return self._lifted_art_lister().items() + + def get(self, key, default=None): + if key in self: + return self[key] + return default diff --git a/libbs/decompilers/ida/compat.py b/libbs/decompilers/ida/compat.py index 6e0173b..2be2691 100644 --- a/libbs/decompilers/ida/compat.py +++ b/libbs/decompilers/ida/compat.py @@ -697,6 +697,21 @@ def set_ida_comment(addr, cmt, decompiled=False): return True +def get_ida_comment(addr, decompiled=True): + # TODO: support more than just functions + # TODO: support more than just function headers + if decompiled and not ida_hexrays.init_hexrays_plugin(): + raise ValueError("Decompiler is not available, but you are requesting a decompiled comment") + + func = idaapi.get_func(addr) + if func is None: + return None + + if func.start_ea == addr: + cmt = idc.get_func_cmt(addr, 1) + return cmt if cmt else None + + @execute_write def set_decomp_comments(func_addr, cmt_dict: typing.Dict[int, str]): for addr in cmt_dict: diff --git a/libbs/decompilers/ida/interface.py b/libbs/decompilers/ida/interface.py index e750f2c..a43adb8 100755 --- a/libbs/decompilers/ida/interface.py +++ b/libbs/decompilers/ida/interface.py @@ -386,8 +386,12 @@ def _set_comment(self, comment: Comment, **kwargs) -> bool: return compat.set_ida_comment(comment.addr, comment.comment, decompiled=comment.decompiled) def _get_comment(self, addr) -> Optional[Comment]: - # TODO: implement me! - return None + ida_cmt = compat.get_ida_comment(addr) + if ida_cmt is None: + return None + + # TODO: need to be better implemented! + return Comment(addr=addr, comment=str(ida_cmt), decompiled=True) def _comments(self) -> Dict[int, Comment]: # TODO: implement me!