Python __builtin__ 模块,set() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用__builtin__.set()

项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_name(func, string):
    '''Set the name of the function ``func`` to ``string``.'''
    rt,ea = __addressOfRtOrSt(func)

    res = idaapi.validate_name2(buffer(string)[:])
    if string and string != res:
        logging.warn('{:s}.set_name : Stripping invalid chars from function name {!r} at {:x}. : {!r}'.format(__name__, string, ea, res))
        string = res

    if rt:
        # FIXME: shuffle the new name into the prototype and then re-mangle it
        res, ok = get_name(ea), database.set_name(ea, string)
    else:
        res, ok = get_name(ea), idaapi.set_name(ea, string, idaapi.SN_PUBLIC)
    if not ok:
        raise AssertionError('{:s}.set_name : Unable to set function name for {:x} : {!r}'.format(__name__, ea, string))
    return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def __getarray(cls, ea):
            try:
                c, = xref.data_up(ea)
                sidata,each = type.array(ea),__builtin__.set(xref.code_down(c))

                # check to see if first element is the correct dataref
                lastea, = xref.data_down(c)
                if ea != lastea: raise TypeError
                # then copy the first element since it's been decoded already
                each.add(sidata[0])

                # ensure that each element matches
                if config.bits() == sidata.itemsize*8 and all(x in each for x in sidata):
                    r, = xref.data_up(ea)
                    return cls.__getinsn(r)

            except (IndexError,TypeError,KeyError,ValueError): pass
            raise TypeError("{:s}({:x}) : Unable to instantiate a switch_info_ex_t at switch array.".format('.'.join((__name__, 'type', cls.__name__)), ea))
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_name(func, string):
    '''Set the name of the function ``func`` to ``string``.'''
    rt,ea = __addressOfRtOrSt(func)

    res = idaapi.validate_name2(buffer(string)[:])
    if string and string != res:
        logging.warn('{:s}.set_name : Stripping invalid chars from function name {!r} at {:x}. : {!r}'.format(__name__, string, ea, res))
        string = res

    if rt:
        # FIXME: shuffle the new name into the prototype and then re-mangle it
        res, ok = get_name(ea), database.set_name(ea, string)
    else:
        res, ok = get_name(ea), idaapi.set_name(ea, string, idaapi.SN_PUBLIC)
    if not ok:
        raise AssertionError('{:s}.set_name : Unable to set function name for {:x} : {!r}'.format(__name__, ea, string))
    return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, n = cls.get_color(bb), by_address(bb.startEA), idaapi.node_info_t()

        # specify the bg color
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb.id, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the colors of each item too.
        for ea in block.iterate(bb):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:fypp    作者:aradi    | 项目源码 | 文件源码
def openscope(self, customlocals=None):
        '''Opens a new (embedded) scope.

        Args:
            customlocals (dict): By default, the locals of the embedding scope
                are visible in the new one. When this is not the desired
                behaviour a dictionary of customized locals can be passed,
                and those locals will become the only visible ones.
        '''
        self._locals_stack.append(self._locals)
        self._globalrefs_stack.append(self._globalrefs)
        if customlocals is not None:
            self._locals = customlocals.copy()
        elif self._locals is not None:
            self._locals = self._locals.copy()
        else:
            self._locals = {}
        self._globalrefs = set()
        self._scope = self._globals.copy()
        self._scope.update(self._locals)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, bb = cls.get_color(ea), by_address(ea), cls.id(ea)
        n = idaapi.node_info_t()

        # specify the bgcolor
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the color of each item too
        for ea in block.iterate(ea):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at the address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(ea, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(bb, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def tag_write(func, key, none):
    '''Removes the tag identified by ``key`` from the function ``func``.'''
    #fn = by(func)
    # Check to see if function tag is being applied to an import
    try:
        rt,ea = __addressOfRtOrSt(func)
    except LookupError:
        # If we're not even in a function, then use a database tag.
        logging.warn('{:s}.tag_write : Attempted to clear tag for a non-function. Falling back to a database tag. : {:x}'.format(__name__, func))
        return database.tag_write(func, key, none)

    # If so, then write the tag to the import
    if rt:
        logging.warn('{:s}.tag_write : Attempted to set tag for a runtime-linked symbol. Falling back to a database tag. : {:x}'.format(__name__, ea))
        return database.tag_write(ea, key, none)

    # Otherwise, it's a function.
    fn = by_address(ea)

    # if the user wants to remove the '__name__' tag then remove the name from the function.
    if key == '__name__':
        return set_name(fn, None)

    state = internal.comment.decode(comment(fn, repeatable=1))
    res = state.pop(key)
    comment(fn, internal.comment.encode(state), repeatable=1)

    internal.comment.globals.dec(fn.startEA, key)
    return res

#FIXME: define tag_erase
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = set(__builtin__.list(tag) + __builtin__.list(tags))
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, **boolean):
    '''Fetch a list of addresses within the function that contain the specified tags.'''
    fn = by(func)
    boolean = dict((k,set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea in internal.comment.contents.address(fn.startEA):
            res = database.tag(ea)
            if res: yield ea, res
        return

    for ea in internal.comment.contents.address(fn.startEA):
        res,d = {},database.tag(ea)

        Or = boolean.get('Or', set())
        res.update((k,v) for k,v in d.iteritems() if k in Or)

        And = boolean.get('And', set())
        if And:
            if And.intersection(d.viewkeys()) == And:
                res.update((k,v) for k,v in d.iteritems() if k in And)
            else: continue
        if res: yield ea,res
    return

## referencing
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, bb = cls.get_color(ea), by_address(ea), cls.id(ea)
        n = idaapi.node_info_t()

        # specify the bgcolor
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the color of each item too
        for ea in block.iterate(ea):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at the address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(ea, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(bb, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def tag_write(func, key, value):
    '''Set the tag ``key`` to ``value`` for the function ``func``.'''
    if value is None:
        raise ValueError("{:s}.tag_write({!r}) : Tried to set tag {!r} to an invalid value.".format(__name__, ea, key))

    # Check to see if function tag is being applied to an import
    try:
        rt,ea = __addressOfRtOrSt(func)
    except LookupError:
        # If we're not even in a function, then use a database tag.
        logging.warn('{:s}.tag_write({!r}, {!r}, ...) : Attempted to set tag for a non-function. Falling back to a database tag.'.format(__name__, func, key))
        return database.tag_write(func, key, value)

    # If so, then write the tag to the import
    if rt:
        logging.warn('{:s}.tag_write({:x}, {!r}, ...) : Attempted to set tag for a runtime-linked symbol. Falling back to a database tag.'.format(__name__, ea, key))
        return database.tag_write(ea, key, value)

    # Otherwise, it's a function.
    fn = by_address(ea)

    # if the user wants to change the '__name__' tag then update the function's name.
    if key == '__name__':
        return set_name(fn, value)

    state = internal.comment.decode(comment(fn, repeatable=1))
    res,state[key] = state.get(key,None),value
    comment(fn, internal.comment.encode(state), repeatable=1)

    if res is None:
        internal.comment.globals.inc(fn.startEA, key)

    return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = set(__builtin__.list(tag) + __builtin__.list(tags))
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, **boolean):
    '''Fetch a list of addresses within the function that contain the specified tags.'''
    fn = by(func)
    boolean = dict((k,set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea in internal.comment.contents.address(fn.startEA):
            res = database.tag(ea)
            if res: yield ea, res
        return

    for ea in internal.comment.contents.address(fn.startEA):
        res,d = {},database.tag(ea)

        Or = boolean.get('Or', set())
        res.update((k,v) for k,v in d.iteritems() if k in Or)

        And = boolean.get('And', set())
        if And:
            if And.intersection(d.viewkeys()) == And:
                res.update((k,v) for k,v in d.iteritems() if k in And)
            else: continue
        if res: yield ea,res
    return

## referencing
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def down(func):
    '''Return all the functions that are called by the function ``func``.'''
    def codeRefs(fn):
        resultData,resultCode = [],[]
        for ea in iterate(fn):
            if len(database.down(ea)) == 0:
                if database.type.is_code(ea) and _instruction.is_call(ea):
                    logging.warn('{:s}.down({:x}) : Discovered a dynamically resolved call that is unable to be resolved. : {:s}'.format(__name__, fn.startEA, database.disasm(ea)))
                    #resultCode.append((ea, 0))
                continue
            resultData.extend( (ea,x) for x in database.dxdown(ea) )
            resultCode.extend( (ea,x) for x in database.cxdown(ea) if fn.startEA == x or not contains(fn,x) )
        return resultData,resultCode
    fn = by(func)
    return sorted(set(d for x,d in codeRefs(fn)[1]))
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, bb = cls.get_color(ea), by_address(ea), cls.id(ea)
        n = idaapi.node_info_t()

        # specify the bgcolor
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the color of each item too
        for ea in block.iterate(ea):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at the address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(ea, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(bb, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def tag_write(func, key, value):
    '''Set the tag ``key`` to ``value`` for the function ``func``.'''
    if value is None:
        raise AssertionError('{:s}.tag_write : Tried to set tag {!r} to an invalid value.'.format(__name__, key))

    # Check to see if function tag is being applied to an import
    try:
        rt,ea = __addressOfRtOrSt(func)
    except LookupError:
        # If we're not even in a function, then use a database tag.
        logging.warn('{:s}.tag_write : Attempted to set tag for a non-function. Falling back to a database tag. : {:x}'.format(__name__, func))
        return database.tag_write(func, key, value)

    # If so, then write the tag to the import
    if rt:
        logging.warn('{:s}.tag_write : Attempted to set tag for a runtime-linked symbol. Falling back to a database tag. : {:x}'.format(__name__, ea))
        return database.tag_write(ea, key, value)

    # Otherwise, it's a function.
    fn = by_address(ea)

    # if the user wants to change the '__name__' tag then update the function's name.
    if key == '__name__':
        return set_name(fn, value)

    state = internal.comment.decode(comment(fn, repeatable=1))
    res,state[key] = state.get(key,None),value
    comment(fn, internal.comment.encode(state), repeatable=1)

    if res is None:
        internal.comment.globals.inc(fn.startEA, key)

    return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = set(__builtin__.list(tag) + __builtin__.list(tags))
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, **boolean):
    '''Fetch a list of addresses within the function that contain the specified tags.'''
    fn = by(func)
    boolean = dict((k,set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea in internal.comment.contents.address(fn.startEA):
            res = database.tag(ea)
            if res: yield ea, res
        return

    for ea in internal.comment.contents.address(fn.startEA):
        res,d = {},database.tag(ea)

        Or = boolean.get('Or', set())
        res.update((k,v) for k,v in d.iteritems() if k in Or)

        And = boolean.get('And', set())
        if And:
            if And.intersection(d.viewkeys()) == And:
                res.update((k,v) for k,v in d.iteritems() if k in And)
            else: continue
        if res: yield ea,res
    return

## referencing
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def down(func):
    '''Return all the functions that are called by the function ``func``.'''
    def codeRefs(func):
        resultData,resultCode = [],[]
        for ea in iterate(func):
            if len(database.down(ea)) == 0:
                if database.type.is_code(ea) and _instruction.is_call(ea):
                    logging.warn('{:s}.down({:x}) : Discovered a dynamically resolved call that is unable to be resolved. : {:s}'.format(__name__, func.startEA, database.disasm(ea)))
                    #resultCode.append((ea, 0))
                continue
            resultData.extend( (ea,x) for x in database.dxdown(ea) )
            resultCode.extend( (ea,x) for x in database.cxdown(ea) if func.startEA == x or not contains(func,x) )
        return resultData,resultCode
    fn = by(func)
    return sorted(set(d for x,d in codeRefs(fn)[1]))
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def set_color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        res, fn, bb = cls.get_color(ea), by_address(ea), cls.id(ea)
        n = idaapi.node_info_t()

        # specify the bgcolor
        r,b = (rgb&0xff0000) >> 16, rgb&0x0000ff
        n.bg_color = n.frame_color = (b<<16)|(rgb&0x00ff00)|r

        # now the frame color
        frgb = frame.get('frame', 0x000000)
        fr, fb = (frgb & 0xff0000) >> 16, frgb&0x0000ff
        n.frame_color = (fb<<16)|(frgb&0x00ff00)|fr

        # set the node
        f = (idaapi.NIF_BG_COLOR|idaapi.NIF_FRAME_COLOR) if frame else idaapi.NIF_BG_COLOR
        try: idaapi.set_node_info2(fn.startEA, bb, n, f)
        finally: idaapi.refresh_idaview_anyway()

        # update the color of each item too
        for ea in block.iterate(ea):
            database.set_color(ea, rgb)
            #internal.netnode.alt.set(ea, 0x14, n.bg_color)
        return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, ea, rgb, **frame):
        """Sets the color of the basic-block at the address ``ea`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(ea, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def color(cls, bb, rgb, **frame):
        """Sets the color of the basic-block ``bb`` to ``rgb``.
        If the color ``frame`` is specified, set the frame to the specified color.
        """
        return cls.set_color(bb, rgb, **frame)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def tag_write(func, key, value):
    '''Set the tag ``key`` to ``value`` for the function ``func``.'''
    if value is None:
        raise AssertionError('{:s}.tag_write : Tried to set tag {!r} to an invalid value.'.format(__name__, key))

    # Check to see if function tag is being applied to an import
    try:
        rt,ea = __addressOfRtOrSt(func)
    except LookupError:
        # If we're not even in a function, then use a database tag.
        logging.warn('{:s}.tag_write : Attempted to set tag for a non-function. Falling back to a database tag. : {:x}'.format(__name__, func))
        return database.tag_write(func, key, value)

    # If so, then write the tag to the import
    if rt:
        logging.warn('{:s}.tag_write : Attempted to set tag for a runtime-linked symbol. Falling back to a database tag. : {:x}'.format(__name__, ea))
        return database.tag_write(ea, key, value)

    # Otherwise, it's a function.
    fn = by_address(ea)

    # if the user wants to change the '__name__' tag then update the function's name.
    if key == '__name__':
        return set_name(fn, value)

    state = internal.comment.decode(comment(fn, repeatable=1))
    res,state[key] = state.get(key,None),value
    comment(fn, internal.comment.encode(state), repeatable=1)

    if res is None:
        internal.comment.globals.inc(fn.startEA, key)

    return res
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, tag, *tags, **boolean):
    tags = set(__builtin__.list(tag) + __builtin__.list(tags))
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(func, **boolean):
    '''Fetch a list of addresses within the function that contain the specified tags.'''
    fn = by(func)
    boolean = dict((k,set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea in internal.comment.contents.address(fn.startEA):
            res = database.tag(ea)
            if res: yield ea, res
        return

    for ea in internal.comment.contents.address(fn.startEA):
        res,d = {},database.tag(ea)

        Or = boolean.get('Or', set())
        res.update((k,v) for k,v in d.iteritems() if k in Or)

        And = boolean.get('And', set())
        if And:
            if And.intersection(d.viewkeys()) == And:
                res.update((k,v) for k,v in d.iteritems() if k in And)
            else: continue
        if res: yield ea,res
    return

## referencing
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def down(func):
    '''Return all the functions that are called by the function ``func``.'''
    def codeRefs(func):
        resultData,resultCode = [],[]
        for ea in iterate(func):
            if len(database.down(ea)) == 0:
                if database.type.is_code(ea) and _instruction.is_call(ea):
                    logging.warn('{:s}.down({:x}) : Discovered a dynamically resolved call that is unable to be resolved. : {:s}'.format(__name__, func.startEA, database.disasm(ea)))
                    #resultCode.append((ea, 0))
                continue
            resultData.extend( (ea,x) for x in database.dxdown(ea) )
            resultCode.extend( (ea,x) for x in database.cxdown(ea) if func.startEA == x or not contains(func,x) )
        return resultData,resultCode
    fn = by(func)
    return sorted(set(d for x,d in codeRefs(fn)[1]))
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(__builtin__.set(boolean.get('And',__builtin__.set())).union(tags))
    return select(**boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def select(**boolean):
    '''Fetch all of the functions containing the specified tags within it's declaration'''
    boolean = dict((k,__builtin__.set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea in internal.comment.globals.address():
            res = function.tag(ea) if function.within(ea) else tag(ea)
            if res: yield ea, res
        return

    for ea in internal.comment.globals.address():
        res,d = {},function.tag(ea) if function.within(ea) else tag(ea)

        Or = boolean.get('Or', __builtin__.set())
        res.update((k,v) for k,v in d.iteritems() if k in Or)

        And = boolean.get('And', __builtin__.set())
        if And:
            if And.intersection(d.viewkeys()) == And:
                res.update((k,v) for k,v in d.iteritems() if k in And)
            else: continue
        if res: yield ea,res
    return

# FIXME: consolidate the boolean querying logic into the utils module
# FIXME: document this properly
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def selectcontents(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['Or'] = tuple(__builtin__.set(boolean.get('Or',__builtin__.set())).union(tags))
    return selectcontents(**boolean)
项目:idascripts    作者:ctfhacker    | 项目源码 | 文件源码
def selectcontents(**boolean):
    '''Fetch all of the functions containing the specified tags within it's contents'''
    boolean = dict((k,__builtin__.set(v if isinstance(v, (__builtin__.tuple,__builtin__.set,__builtin__.list)) else (v,))) for k,v in boolean.viewitems())

    if not boolean:
        for ea,_ in internal.comment.contents.iterate():
            res = internal.comment.contents.name(ea)
            if res: yield ea, res
        return

    for ea, res in internal.comment.contents.iterate():
        # check to see that the dict's keys match
        res,d = __builtin__.set(res),internal.comment.contents._read(None, ea)
        if __builtin__.set(d.viewkeys()) != res:
            # FIXME: include query in warning
            logging.warn("{:s}.selectcontents : Contents cache is out of sync. Using contents blob instead of supval. : {:x}".format(__name__, ea))

        # now start aggregating the keys that the user is looking for
        res, d = __builtin__.set(), internal.comment.contents.name(ea)

        Or = boolean.get('Or', __builtin__.set())
        res.update(Or.intersection(d))

        And = boolean.get('And', __builtin__.set())
        if And:
            if And.intersection(d) == And:
                res.update(And)
            else: continue
        if res: yield ea,res
    return