def remove(segment, contents=False):
    """Remove the specified `segment`.

    If the bool `contents` is specified, then remove the contents of the segment from the database.
    """
    if not isinstance(segment, idaapi.segment_t):
        cls = idaapi.segment_t
        raise E.InvalidParameterError(
            u"{:s}.remove({!r}) : Expected an `idaapi.segment_t`, but received a {!s}."
            .format(__name__, segment, type(segment)))

    # delete the selector defined by the segment_t
    res = idaapi.del_selector(segment.sel)
    if res == 0:
        logging.warning(
            u"{:s}.remove({!r}) : Unable to delete the selector {:#x}.".format(
                __name__, segment, segment.sel))

    # remove the actual segment using the address in the segment_t
    res = idaapi.del_segm(
        interface.range.start(segment),
        idaapi.SEGMOD_KILL if contents else idaapi.SEGMOD_KEEP)
    if res == 0:
        logging.warning(
            u"{:s}.remove({!r}) : Unable to delete the segment {:s} with the selector {:s}."
            .format(__name__, segment, segment.name, segment.sel))
    return res
Пример #2
0
def remove(segment, contents=False):
    """Remove the specified `segment`.

    If the bool `contents` is specified, then remove the contents of the segment from the database.
    """
    if not isinstance(segment, idaapi.segment_t):
        cls = idaapi.segment_t
        raise E.InvalidParameterError(
            "{:s}.remove({!r}) : Expected a {!s}, but received a {!s}.".format(
                __name__, segment, cls, type(segment)))

    res = idaapi.del_selector(segment.sel)
    if res == 0:
        logging.warn(
            "{:s}.remove({!r}) : Unable to delete the selector {:#x}.".format(
                __name__, segment, segment.sel))

    res = idaapi.del_segm(
        segment.startEA,
        idaapi.SEGMOD_KILL if contents else idaapi.SEGMOD_KEEP)
    if res == 0:
        logging.warn(
            "{:s}.remove({!r}) : Unable to delete the segment {:s} with the selector {:s}."
            .format(__name__, segment, segment.name, segment.sel))
    return res