Android一键V2签名,校验

一般Android加固都自带重签名功能,但是有的加固只加了V1签名,所以还是得自己手动签名下,下面是我用python写的签名以及校验脚本

一键V2签名

# -*- coding: utf-8 -*-
#python2.7
import os
import os.path

#Android BuildTools路径
buildToolDir='...\\build-tools\\27.0.3\\'
#keyStore路径
keyStorePath='your jks file path'
#keystore密码
keyStorePassword = 'your keystore password'
#key别名
keyAlias = 'your key alias'
#key密码
keyPassword = 'your key password'

zipalignPath=buildToolDir+'zipalign.exe';
apksignerPath=buildToolDir+'lib\\apksigner.jar';

if (not os.path.exists('signed')):
    os.mkdir('signed')

if (not os.path.exists('aligned')):
    os.mkdir('aligned')


workDir = os.path.dirname(__file__)
signedDir = os.path.join(workDir, "signed")
alignedDir = os.path.join(workDir, "aligned")
apkDir = os.path.join(workDir, "apks")

#获取要签名的apk文件列表
apkFileList = os.listdir(apkDir)
for fileName in apkFileList:
    apkFilePath=os.path.join(apkDir, fileName)
    alignedFilePath=os.path.join(alignedDir, fileName)
    signedFilePath=os.path.join(signedDir, fileName)

    
    # zipalign
    print("start align:" + fileName)
    aligncmd = '%s -f 4 "%s" "%s"' % (zipalignPath,apkFilePath,alignedFilePath)
    os.system(aligncmd)

    # v1+v2签名
    print("start sign:" + fileName)
    signcmd = '%s sign --ks "%s" --ks-key-alias %s  --ks-pass pass:"%s"  --key-pass pass:"%s"  --out "%s" "%s"' %\
    (apksignerPath,keyStorePath,keyAlias,keyStorePassword,keyPassword,signedFilePath,alignedFilePath)

    os.system(signcmd)

    print(fileName + " sign finish!\n")
os.system("pause");

一键校验对齐与签名

# -*- coding: utf-8 -*-
#python2.7
import os
import sys
import os.path

#Android BuildTools路径
buildToolDir='...\\build-tools\\27.0.3\\'

zipalignPath=buildToolDir+'zipalign.exe';
apksignerPath=buildToolDir+'lib\\apksigner.jar';



if (len(sys.argv)>1):
    apkFilePath=sys.argv[1]
    
    print("start verify:" + apkFilePath)
    # zipalign 校验
    aligncmd = '%s -c -v 4 "%s"' % (zipalignPath,apkFilePath)
    os.system(aligncmd)

    # v1+v2签名校验
    signcmd = 'java -jar %s verify -v --print-certs "%s"' %(apksignerPath,apkFilePath)
    os.system(signcmd)

    print("verify finish!")
os.system("pause");

你可能感兴趣的:(Android一键V2签名,校验)