python类set_name()的实例源码

function_LOCAL_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 28 收藏 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 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def set_name(none):
    '''Remove the custom-name from the current function.'''
    return set_name(ui.current.function(), none or '')
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def set_name(name):
    '''Set the name of the current function to ``name``.'''
    # we use ui.current.address() instead of ui.current.function()
    # in case the user might be hovering over an import table
    # function and wanting to rename that instead.
    return set_name(ui.current.address(), name)
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def name(none):
    '''Remove the custom-name from the current function.'''
    return set_name(ui.current.function(), none or '')
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def name(func, none):
    '''Remove the custom-name from the function ``func``.'''
    return set_name(func, none or '')
function_BASE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def name(func, string, *suffix):
    '''Set the name of the function ``func`` to ``string``.'''
    res = (string,) + suffix
    return set_name(func, interface.tuplename(*res))
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
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def set_name(none, **listed):
    '''Remove the name at the current address.'''
    return set_name(ui.current.address(), '', **listed)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_name(ea, none, **listed):
    '''Remove the name defined at the address ``ea``.'''
    return set_name(ea, '', **listed)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def set_name(string, **listed):
    '''Rename the current address to ``string``.'''
    return set_name(ui.current.address(), string, **listed)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def name(none):
    '''Removes the name at the current address.'''
    return set_name(ui.current.address(), None)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def name(ea, none):
    '''Removes the name at address ``ea``.'''
    return set_name(ea, None)
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def tag_write(ea, key, value):
    '''Set the tag ``key`` to ``value`` at the address ``ea``.'''
    if value is None:
        raise ValueError("{:s}.tag_write({:x}, {!r}, ...) : Tried to set tag {!r} to an invalid value. : {!r}".format(__name__, ea, key, key, value))

    # if the user wants to change the '__name__' tag, then
    # change the name fo' real.
    if key == '__name__':
        return set_name(ea, value, listed=True)
    if key == '__extra_prefix__':
        return extra.set_prefix(ea, value)
    if key == '__extra_suffix__':
        return extra.set_suffix(ea, value)
    if key == '__color__':
        return set_color(ea, value)

    # if not within a function, then use a repeatable comment
    # otherwise, use a non-repeatable one
    try: func = function.by_address(ea)
    except: func = None
    repeatable = False if func else True

    # grab the current value
    ea = interface.address.inside(ea)
    state = internal.comment.decode(comment(ea, repeatable=not repeatable))
    state and comment(ea, '', repeatable=not repeatable) # clear the old one
    state.update(internal.comment.decode(comment(ea, repeatable=repeatable)))

    # update the tag's reference
    if key not in state:
        if func:
            internal.comment.contents.inc(ea, key)
        else:
            internal.comment.globals.inc(ea, key)

    # now we can actually update the tag
    res,state[key] = state.get(key,None),value
    comment(ea, internal.comment.encode(state), repeatable=repeatable)
    return res
database.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def tag_write(ea, key, none):
    '''Removes the tag specified by ``key`` from the address ``ea``.'''
    ea = interface.address.inside(ea)

    # if the '__name__' is being cleared, then really remove it.
    if key == '__name__':
        return set_name(ea, None, listed=True)
    if key == '__extra_prefix__':
        return extra.del_prefix(ea)
    if key == '__extra_suffix__':
        return extra.del_suffix(ea)

    # if not within a function, then fetch the repeatable comment
    # otherwise update the non-repeatable one
    try: func = function.by_address(ea)
    except: func = None
    repeatable = False if func else True

    # fetch the dict, remove the key, then write it back.
    state = internal.comment.decode(comment(ea, repeatable=not repeatable))
    state and comment(ea, '', repeatable=not repeatable) # clear the old one
    state.update(internal.comment.decode(comment(ea, repeatable=repeatable)))
    res = state.pop(key)
    comment(ea, internal.comment.encode(state), repeatable=repeatable)

    # delete it's reference
    if func:
        internal.comment.contents.dec(ea, key)
    else:
        internal.comment.globals.dec(ea, key)

    return res

#FIXME: define tag_erase
function_REMOTE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def set_name(none):
    '''Remove the custom-name from the current function.'''
    return set_name(ui.current.function(), none or '')
function_REMOTE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def set_name(name):
    '''Set the name of the current function to ``name``.'''
    # we use ui.current.address() instead of ui.current.function()
    # in case the user might be hovering over an import table
    # function and wanting to rename that instead.
    return set_name(ui.current.address(), name)
function_REMOTE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def name(none):
    '''Remove the custom-name from the current function.'''
    return set_name(ui.current.function(), none or '')
function_REMOTE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def name(func, none):
    '''Remove the custom-name from the function ``func``.'''
    return set_name(func, none or '')
function_REMOTE_3024.py 文件源码 项目:idascripts 作者: ctfhacker 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def name(func, string, *suffix):
    '''Set the name of the function ``func`` to ``string``.'''
    res = (string,) + suffix
    return set_name(func, interface.tuplename(*res))


问题


面经


文章

微信
公众号

扫码关注公众号