zoukankan      html  css  js  c++  java
  • python更新zip文件中文件

    #更新zip文件中某一个文件
    import
    os import shutil import tempfile import zipfile from rat_tool.pack import * toolpath= os.getcwd()+"/tool" smalipath=os.path.join( toolpath,"smali.jar") def updateZip(zipname, filename, data): tmpfd, tmpname = tempfile.mkstemp(dir=os.path.dirname(zipname)) os.close(tmpfd) with zipfile.ZipFile(zipname, 'r') as zin: with zipfile.ZipFile(tmpname, 'w') as zout: zout.comment = zin.comment for item in zin.infolist(): if item.filename != filename: zout.writestr(item, zin.read(item.filename)) os.remove(zipname) os.rename(tmpname, zipname) with zipfile.ZipFile(zipname, mode='a', compression=zipfile.ZIP_DEFLATED) as zf: zf.writestr(filename, data)

    使用:

    #----更新apk文件中的classes3.dex文件------------------------------------------------------------------
    def main():
        #将修改后的smali文件重新打包成dex,替换原来包中dex
        indir=r"D:paapkhaoyishensmali_classes3"
        outfile=r"D:paapkclasses3.dex"
        #smali(indir, outfile)
        tempzip = r"D:paapkhaoyishenbd.apk"
        
        buff=open(outfile,"rb").read()
        #updateZip(tempzip, "classes3.dex", buff)    
        
        signapk(tempzip, tempzip)
        
    
        print"111"
    
    if __name__ == '__main__':
        main()

     原创:http://www.cnblogs.com/fply/p/8391070.html

  • 相关阅读:
    17_8_30 Mybatis 入门
    17_8_29 mysql 导入导出备份还原
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
    [MAC OSX
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
    [iOS基础控件
  • 原文地址:https://www.cnblogs.com/fply/p/8391070.html
Copyright © 2011-2022 走看看