aaaaaaaaaaaa
代码改变世界

python更新zip文件中文件

2018-01-31 10:43  二进制乐谱  阅读(2537)  评论(0编辑  收藏  举报
#更新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:\pa\apk\haoyishen\smali_classes3"
    outfile=r"D:\pa\apk\classes3.dex"
    #smali(indir, outfile)
    tempzip = r"D:\pa\apk\haoyishenbd.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

aaaaaaaaaaaaa