Skip to content

Commit

Permalink
Fast fixes for IDA comment on headers
Browse files Browse the repository at this point in the history
  • Loading branch information
mahaloz committed Sep 12, 2024
1 parent 190e5f8 commit ac91c5d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion libbs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "1.21.0"
__version__ = "1.22.0"


import logging
Expand Down
5 changes: 5 additions & 0 deletions libbs/api/artifact_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions libbs/decompilers/ida/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 6 additions & 2 deletions libbs/decompilers/ida/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit ac91c5d

Please sign in to comment.