Exemplo n.º 1
0
def get_function_comments():
    """
    Returns a dictionary of {address -> (normal comment, repeated comment,
    anterior lines list, posterior lines list) }.
    """
    comments = {}

    for address in idautils.Functions():
        normal_comment = psida_common.get_comment(address)
        repeated_comment = psida_common.get_repeated_comment(address)
        anterior_lines = get_anterior_lines(address)
        posterior_lines = get_posterior_lines(address)

        if ((normal_comment, repeated_comment, anterior_lines, posterior_lines)
                != (None, None, None, None)):
            comments[address] = (normal_comment, repeated_comment,
                                 anterior_lines, posterior_lines)

    return comments
Exemplo n.º 2
0
    def cmt_changed(self, ea, is_repeatable):
        if CONFIGURATION[DEBUG]:
            print 'DEBUG - Hooks - IDBHook.cmt_changed(ea = 0x%x, is_repeatable = %s)' % (
                ea, is_repeatable)

        if is_repeatable:
            data = psida_common.get_repeated_comment(ea)
            comment_update = idb_push_ops.CommentUpdate(
                update_type=idb_push_ops.UpdateTypes.RepeatableComment,
                address=ea,
                data=data)
        else:
            data = psida_common.get_comment(ea)
            comment_update = idb_push_ops.CommentUpdate(
                update_type=idb_push_ops.UpdateTypes.Comment,
                address=ea,
                data=data)

        if g_hooks_enabled and (data is not None) and (len(data) > 0):
            send_push_update(comment_update)

        return idaapi.IDB_Hooks.cmt_changed(self, ea, is_repeatable)
Exemplo n.º 3
0
def get_all_comments():
    """
    Returns a dictionary of {address -> (normal comment, repeated comment,
    anterior lines list, posterior lines list) }.
    """
    comments = {}

    segments_set = psida_common.get_segments()
    for _, address, end_address in segments_set:
        while address < end_address:
            normal_comment = psida_common.get_comment(address)
            repeated_comment = psida_common.get_repeated_comment(address)
            anterior_lines = get_anterior_lines(address)
            posterior_lines = get_posterior_lines(address)

            if ((normal_comment, repeated_comment, anterior_lines,
                 posterior_lines) != (None, None, None, None)):
                comments[address] = (normal_comment, repeated_comment,
                                     anterior_lines, posterior_lines)

            address += idc.ItemSize(address)

    return comments
Exemplo n.º 4
0
    def range_cmt_changed(self, areas, cmt_range, comment, is_repeatable):
        if CONFIGURATION[DEBUG]:
            print 'DEBUG - Hooks - IDBHook.range_cmt_changed(area_start = 0x%x, comment = %s)' % (
                cmt_range.start_ea, comment)

        ea = cmt_range.start_ea
        if is_repeatable:
            data = psida_common.get_repeated_comment(ea)
            comment_update = idb_push_ops.CommentUpdate(
                update_type=idb_push_ops.UpdateTypes.RepeatableComment,
                address=ea,
                data=data)
        else:
            data = psida_common.get_comment(ea)
            comment_update = idb_push_ops.CommentUpdate(
                update_type=idb_push_ops.UpdateTypes.Comment,
                address=ea,
                data=data)

        if g_hooks_enabled and (data is not None) and (len(data) > 0):
            send_push_update(comment_update)

        return idaapi.IDB_Hooks.range_cmt_changed(self, areas, cmt_range,
                                                  comment, is_repeatable)
Exemplo n.º 5
0
def populate_form_with_items(items):
    # Fills g_item_list_model with textual representations
    # of the unpickled items.

    for item in items:
        item_type = item['type']
        address = item['address']

        if item_type == ItemType.Name:
            new_name = item['name']
            current_name = psida_common.get_non_default_name(address)

            if current_name == new_name:
                continue

            if current_name is not None:
                description = "Name [0x%x]: %s (YOURS: %s)" % (
                    address, new_name, current_name)
            else:
                description = "Name [0x%x]: %s" % (address, new_name)

        elif item_type == ItemType.Struct:
            new_name = item['name']
            new_struct_def = item['struct_def']
            orig_size = item['orig_size']
            new_struct_size = psida_common.get_struct_size(new_struct_def)
            if orig_size != new_struct_size:
                description = "Name [{}] (DANGEROUS Conflict - Size Changed!\n\tNew Size: {}, Old Size: {} ) New Struct:\n {} ".format(
                    new_name, new_struct_size, orig_size, new_struct_def)
            else:
                description = "Name [%s]: %s (YOURS: already exists)" % (
                    new_name, new_struct_def)

        elif item_type == ItemType.Comment:
            new_comment = item['comment']
            current_comment = psida_common.get_comment(address)

            if new_comment is None or len(
                    new_comment) == 0 or new_comment == current_comment:
                continue

            if (current_comment is not None) and (len(current_comment) > 0):
                description = "Comment [0x%x]: %s\n(YOURS: %s)" % (
                    address, new_comment, current_comment)
            else:
                description = "Comment [0x%x]: %s" % (address, new_comment)

        elif item_type == ItemType.RepeatableComment:
            new_comment = item['comment']
            current_comment = psida_common.get_repeated_comment(address)

            if new_comment is None or len(
                    new_comment) == 0 or new_comment == current_comment:
                continue

            if (current_comment is not None) and (len(current_comment) > 0):
                description = "RComment [0x%x]: %s\n(YOURS: %s)" % (
                    address, new_comment, current_comment)
            else:
                description = "RComment [0x%x]: %s" % (address, new_comment)

        elif item_type == ItemType.AnteriorLines:
            new_lines = item['lines']
            current_lines = get_anterior_lines(address)

            if new_lines is None or len(
                    new_lines) == 0 or new_lines == current_lines:
                continue

            if (current_lines is not None) and (len(current_lines) > 0):
                description = "AntLine [0x%x]: %s\n(YOURS: %s)" % (
                    address, '\n'.join(new_lines), '\n'.join(current_lines))
            else:
                description = "AntLine [0x%x]: %s" % (address,
                                                      '\n'.join(new_lines))

        elif item_type == ItemType.PosteriorLines:
            new_lines = item['lines']
            current_lines = get_posterior_lines(address)

            if new_lines is None or len(
                    new_lines) == 0 or new_lines == current_lines:
                continue

            if (current_lines is not None) and (len(current_lines) > 0):
                description = "PostLine [0x%x]: %s\n(YOURS: %s)" % (
                    address, '\n'.join(new_lines), '\n'.join(current_lines))
            else:
                description = "PostLine [0x%x]: %s" % (address,
                                                       '\n'.join(new_lines))
        else:
            print "WHAAAAAT does type %d mean in message %s?" % (item_type,
                                                                 str(item))
            continue

        add_item_to_form(item, description)
Exemplo n.º 6
0
def update_form(update):
    """ Processes an incoming update by adding it to the form.

    Args:
        update (IdbUpdate) - The message received from the ZMQ server, as a class that inherits IdbUpdate
    """
    try:
        g_item_list_mutex.lock()
        message_type = update.update_type
        address = update.address
        current_data = None

        if message_type == idb_push_ops.UpdateTypes.Name:
            current_data = psida_common.get_non_default_name(address, update.is_local)
            if current_data == update.data:
                return

        elif message_type == idb_push_ops.UpdateTypes.Comment:
            current_data = psida_common.get_comment(address)
            if current_data == update.data:
                return

        elif message_type == idb_push_ops.UpdateTypes.RepeatableComment:
            current_data = psida_common.get_repeated_comment(address)
            if current_data == update.data:
                return

        elif message_type in [idb_push_ops.UpdateTypes.AnteriorLine, idb_push_ops.UpdateTypes.PosteriorLine]:
            current_data = idc.get_extra_cmt(address, update.line_index)
            if current_data == update.data:
                return

        elif message_type == idb_push_ops.UpdateTypes.LookHere:
            current_data = psida_common.get_non_default_name(address)

        elif message_type == idb_push_ops.UpdateTypes.StackVariableRenamed:
            func_frame = ida_frame.get_frame(address)
            update.func_frame_pointer = func_frame
            member = ida_struct.get_member(func_frame, update.offset)
            current_data = None
            if member is not None:
                current_data = ida_struct.get_member_name(member.id)

            if current_data == update.data:
                return

            if current_data is not None:
                update.new = False
            else:
                update.new = True

        elif message_type in [idb_push_ops.UpdateTypes.MakeData, idb_push_ops.UpdateTypes.MakeCode,
                              idb_push_ops.UpdateTypes.MakeFunc]:
            current_data = update.get_conflict()
            if current_data == '':
                return

        else:
            if CONFIGURATION[DEBUG]:
                print 'DEBUG - UI - Unrecognized/Unimplemented type %d: in message %s' % (message_type, update.to_dict())
            return

        update.data_at_address = current_data
        add_item(update)
    except:
        if CONFIGURATION['debug']:
            traceback.print_exc()
        print 'ERROR - UI - General error while updating form'

    finally:
        g_item_list_mutex.unlock()