Ejemplo n.º 1
0
def set_repeated_comment(address, repeated_comment):
    assert type(repeated_comment) == str
    if is_function_start(address):
        pfn = ida_funcs.get_func(address)
        ida_funcs.set_func_cmt(pfn, repeated_comment, 1)
    else:
        ida_bytes.set_cmt(address, repeated_comment, 1)
Ejemplo n.º 2
0
 def __call__(self):
     cmt = self.cmt
     if self.kind == ida_range.RANGE_KIND_FUNC:
         func = ida_funcs.get_func(self.start_ea)
         ida_funcs.set_func_cmt(func, cmt, self.rptble)
     elif self.kind == ida_range.RANGE_KIND_SEGMENT:
         segment = ida_segment.getseg(self.start_ea)
         ida_segment.set_segment_cmt(segment, cmt, self.rptble)
     else:
         raise Exception("Unsupported range kind: %d" % self.kind)
Ejemplo n.º 3
0
 def __call__(self):
     cmt = Event.encode(self.cmt)
     if self.kind == ida_range.RANGE_KIND_FUNC:
         func = ida_funcs.get_func(self.start_ea)
         ida_funcs.set_func_cmt(func, cmt, self.rptble)
     elif self.kind == ida_range.RANGE_KIND_SEGMENT:
         segment = ida_segment.getseg(self.start_ea)
         ida_segment.set_segment_cmt(segment, cmt, self.rptble)
     else:
         logger.warning("Unsupported range kind: %d" % self.kind)
Ejemplo n.º 4
0
 def _on_rangecommentchanged(self, kind, start_ea, comment, repeatable):
     comment = Unicoder.encode(comment)
     if kind == ida_range.RANGE_KIND_FUNC:
         func = ida_funcs.get_func(start_ea)
         ida_funcs.set_func_cmt(func, comment, repeatable)
     elif kind == ida_range.RANGE_KIND_SEGMENT:
         segment = ida_segment.getseg(start_ea)
         ida_segment.set_segment_cmt(segment, comment, repeatable)
     else:
         raise Exception('Unsupported range kind: {}'.format(kind))
Ejemplo n.º 5
0
def append_func_cmt(va, cmt, repeatable=False):
    """
    add the given comment to the given function,
    if it doesn't already exist.
    """
    func = ida_funcs.get_func(va)
    if not func:
        raise ValueError("not a function")

    existing = ida_funcs.get_func_cmt(func, repeatable) or ""
    if cmt in existing:
        return

    new = existing + "\n" + cmt
    ida_funcs.set_func_cmt(func, new, repeatable)
Ejemplo n.º 6
0
def set_tagged_func_cmt(tag: str, va: int, cmt: str, repeatable: bool):
    func = ida_funcs.get_func(va)
    existing = (ida_funcs.get_func_cmt(func, repeatable) or "").strip()

    prefix = f"{tag}: "
    line = f"{prefix}{cmt}"

    if prefix in existing:
        rest = existing.partition(prefix)[2].partition("\n")[0]
        new = existing.replace(f"{prefix}{rest}", line)
    elif existing == "":
        new = line
    else:
        new = existing + f"\n{line}"

    ida_funcs.set_func_cmt(func, new, repeatable)
Ejemplo n.º 7
0
def import_function_comments(comments, sections):
    """
    Import function comments into IDA

    :param comments: Dict containing function comments
    :param sections: Dict containing section info
    """

    for addr, comment in comments.items():
        addr = adjust_addr(sections, int(addr))
        if addr is None:
            continue

        func = ida_funcs.get_func(addr)
        if func is None:
            print('Failed to apply function comment at offset:{:08x}'.format(addr))
            continue

        ida_funcs.set_func_cmt(func, comment, False)