def by(**type):
    '''Return the segment matching the specified keywords in `type`.'''
    searchstring = utils.string.kwargs(type)
    get_segment_name = idaapi.get_segm_name if hasattr(
        idaapi, 'get_segm_name') else idaapi.get_true_segm_name

    listable = [item for item in __iterate__(**type)]
    if len(listable) > 1:
        maxaddr = max(
            builtins.map(interface.range.end, listable) if listable else [1])
        caddr = math.ceil(math.log(maxaddr) / math.log(16))
        messages = (
            (u"[{:d}] {:0{:d}x}:{:0{:d}x} {:s} {:+#x} sel:{:04x} flags:{:02x}".
             format(seg.index, interface.range.start(seg), int(caddr),
                    interface.range.end(seg), int(caddr),
                    utils.string.of(get_segment_name(seg)), seg.size(),
                    seg.sel, seg.flags)) for seg in listable)
        [logging.info(msg) for msg in messages]
        logging.warning(
            u"{:s}.by({:s}) : Found {:d} matching results. Returning the first segment at index {:d} from {:0{:d}x}<>{:0{:d}x} with the name {:s} and size {:+#x}."
            .format(__name__, searchstring, len(listable), listable[0].index,
                    interface.range.start(listable[0]), int(caddr),
                    interface.range.end(listable[0]), int(caddr),
                    utils.string.of(get_segment_name(listable[0])),
                    listable[0].size()))

    iterable = (item for item in listable)
    res = builtins.next(iterable, None)
    if res is None:
        raise E.SearchResultsError(
            u"{:s}.by({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res
Ejemplo n.º 2
0
def by(**type):
    '''Return the segment matching the specified keywords in `type`.'''
    searchstring = ', '.join("{:s}={!r}".format(key, value)
                             for key, value in six.iteritems(type))

    res = builtins.list(__iterate__(**type))
    if len(res) > 1:
        maxaddr = max(builtins.map(operator.attrgetter('endEA'), res) or [1])
        caddr = math.ceil(math.log(maxaddr) / math.log(16))
        builtins.map(
            logging.info,
            (("[{:d}] {:0{:d}x}:{:0{:d}x} {:s} {:+#x} sel:{:04x} flags:{:02x}".
              format(seg.index, seg.startEA, int(caddr), seg.endEA, int(caddr),
                     idaapi.get_true_segm_name(seg), seg.size(), seg.sel,
                     seg.flags)) for seg in res))
        logging.warn(
            "{:s}.by({:s}) : Found {:d} matching results. Returning the first segment at index {:d} from {:0{:d}x}<>{:0{:d}x} with the name {:s} and size {:+#x}."
            .format(__name__, searchstring, len(res), res[0].index,
                    res[0].startEA, int(caddr), res[0].endEA, int(caddr),
                    idaapi.get_true_segm_name(res[0]), res[0].size()))

    res = next(iter(res), None)
    if res is None:
        raise E.SearchResultsError(
            "{:s}.by({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res
Ejemplo n.º 3
0
def by(**type):
    '''Return the identifier for the first enumeration matching the keyword specified by `type`.'''
    searchstring = utils.string.kwargs(type)

    res = builtins.list(iterate(**type))
    if len(res) > 1:
        map(logging.info, (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(idaapi.get_enum_idx(n), idaapi.get_enum_name(n), mask(n), len(builtins.list(members(n))), u" // {:s}".format(comment(n)) if comment(n) else '') for i,n in enumerate(res)))
        logging.warn(u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}.".format(__name__, searchstring, len(res), res[0]))

    res = next(iter(res), None)
    if res is None:
        raise E.SearchResultsError(u"{:s}.search({:s}) : Found 0 matching results.".format(__name__, searchstring))
    return res
Ejemplo n.º 4
0
def by(**type):
    '''Return the identifier for the first enumeration matching the keyword specified by `type`.'''
    searchstring = utils.string.kwargs(type)

    listable = [item for item in iterate(**type)]
    if len(listable) > 1:
        messages = (u"[{:d}] {:s} & {:#x} ({:d} members){:s}".format(
            idaapi.get_enum_idx(item), idaapi.get_enum_name(item), mask(item),
            len(builtins.list(members(item))),
            u" // {:s}".format(comment(item)) if comment(item) else '')
                    for i, item in enumerate(listable))
        [logging.info(msg) for msg in messages]
        logging.warning(
            u"{:s}.search({:s}) : Found {:d} matching results. Returning the first enumeration {:#x}."
            .format(__name__, searchstring, len(listable), listable[0]))

    iterable = (item for item in listable)
    res = next(iterable, None)
    if res is None:
        raise E.SearchResultsError(
            u"{:s}.search({:s}) : Found 0 matching results.".format(
                __name__, searchstring))
    return res