#coding=utf-8
'''
Created on 2014-3-10
@author: Administrator
'''
import zipfile
import shutil
import os
def resign(apk_path, resign_apk_path):
if not os.path.exists(apk_path):
raise 0, "apk is not exist"
#
zf = zipfile.ZipFile(apk_path)
zf.extractall("test")
zf.close()
#
shutil.rmtree(os.path.join("test", "META-INF"))
#
fileList = []
for root, dirs, files in os.walk("test"):
for name in files:
fileList.append(os.path.join(root, name))
zf = zipfile.ZipFile("test.apk", "w", zipfile.zlib.DEFLATED)
for tar in fileList:
print tar
arcname = tar[len("test"):]
zf.write(tar, arcname)
zf.close()
os.system("jarsigner -keystore debug.keystore -storepass android -signedjar %s test.apk androiddebugkey"%resign_apk_path)
if __name__ == "__main__":
resign("E:/my_work/android/baiduxinwen_3309.apk", "test1.apk")