python_packer.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:OSPTF 作者: xSploited 项目源码 文件源码
def gen_package_pickled_dic(path, module_name):
    modules_dic={}
    start_path=module_name.replace(".", "/")
    search_path=os.path.dirname(path)
    logging.info("embedding %s ..."%os.path.join(search_path, start_path))
    #TODO: remove comments from python files || compile to .pyc to make payloads lighter
    if os.path.isdir(path):
        for root, dirs, files in os.walk(os.path.join(search_path, start_path)):
            for f in files:
                module_code=""
                with open(os.path.join(root,f),'rb') as fd:
                    module_code=fd.read()
                modprefix = root[len(search_path.rstrip(os.sep))+1:]
                modpath = os.path.join(modprefix,f).replace("\\","/")
                modules_dic[modpath]=module_code
    elif os.path.isfile(path):
        ext=path.rsplit(".",1)[1]
        module_code=""
        with open(path,'rb') as f:
            module_code=f.read()
        cur=""
        for rep in start_path.split("/")[:-1]:
            if not cur+rep+"/__init__.py" in modules_dic:
                modules_dic[rep+"/__init__.py"]=""
            cur+=rep+"/"

        modules_dic[start_path+"."+ext]=module_code
    if not modules_dic:
        raise NameError("path %s not found"%path)
    return modules_dic
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号