python类set()的实例源码

function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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)
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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]))
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(ui.current.function(), **boolean)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def select(func, tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(set(boolean.get('And',set())).union(tags))
    return select(func, **boolean)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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]))
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def select(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['And'] = tuple(__builtin__.set(boolean.get('And',__builtin__.set())).union(tags))
    return select(**boolean)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def selectcontents(tag, *tags, **boolean):
    tags = (tag,) + tags
    boolean['Or'] = tuple(__builtin__.set(boolean.get('Or',__builtin__.set())).union(tags))
    return selectcontents(**boolean)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号