#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, shutil
# 基础路径变量
baseDir = os.path.abspath(".") + "/mulipackage"
apkTempPath = baseDir + "/cache/apks"
# 友盟各jar包路径
apkSignerJarPath = os.path.join(baseDir, "lib/apksigner.jar")
v2SignerJarPath = os.path.join(baseDir, "lib/CheckAndroidV2Signature.jar")
wallePath = os.path.join(baseDir, "lib/walle-cli-all.jar")
# 签名信息相关
keystorePath = os.path.join(baseDir, "xxxxx.keystore")
keystore_alias = "xxxx"
keystore_pass = "xxxx"
key_pass = "xxxxx"
# 可定义的Apk路径及apk名字
apkPath = raw_input("请输入待加固apk的路径:\n")
_360JiaguToolsPath = raw_input("请指定360加固工具的存放路径(eg:我本机的路径为D:\\360Downloads\\360jiaguzhushou_32_1.5.1.3b\\jiagu):\n")
_360JiaguApkPath = raw_input("请指定加固完成后apk的存放路径:\n")
_360JiaguUserName = raw_input("请输入360加固用户名:\n")
_360JiaguPwd = raw_input("请输入360加固密码:\n")
apkName = raw_input("Please Input ApkName!")
# 生成未签名Apk
zipalignPath = baseDir + "/lib"
appNoSignCall = "call " + zipalignPath + "\\zipalign -v 4 " + apkPath + " " + baseDir + "\\cache\\app_nosign.apk"
# 开始签名
callJava = "call java -jar " + baseDir + "\\lib\\apksigner.jar sign --ks " + baseDir + "\\xxxxx.keystore \
--ks-key-alias " + keystore_alias + " --ks-pass pass:" + keystore_pass + " --key-pass pass:" + key_pass + " \
--out " + baseDir + "\\cache\\app_sign.apk " + baseDir + "\\cache\\app_nosign.apk"
# 生成签名apk
genSignApk = "call java -jar " + baseDir + "\\lib\\CheckAndroidV2Signature.jar " + baseDir + "\\cache\\app_sign.apk"
# 生成渠道包
genApks = "call java -jar " + wallePath + " batch \
-f " + baseDir + "\\channelFile " + baseDir + "\\cache\\app_sign.apk " + baseDir + "\\cache\\apks"
# 清空缓存目录
def cleancaches():
if os.path.exists(baseDir):
shutil.rmtree(baseDir + "/cache")
# 重新生成缓存目录
def gencache():
exist = os.path.exists(apkTempPath)
if not exist:
os.makedirs(apkTempPath)
# 重命名文件
def renameapks():
path = baseDir + "/cache/apks"
filename = getfilename()
global apkName
if apkName == "" and not filename == "":
apkName = filename
for file in os.listdir(path):
if os.path.isfile(os.path.join(path, file)) == True:
# 将文件名与后缀名分开,只对apk文件操作
if os.path.splitext(file)[1] == '.apk':
if file.startswith("app_sign"):
newFile = file.replace("app_sign", apkName)
# 执行修改
shutil.move(path + "/" + file, path + "/" + newFile)
# 获取文件名
def getfilename():
if not (apkPath == ' '):
names = os.path.basename(apkPath)
if not names == ' ' and names.endswith(".apk"):
return names.split(".apk")[0]
def start():
# 先对apk进行加固,然后再多渠道打包
global apkPath
apkPath = exec_360_jiagu_comm()
os.system(appNoSignCall)
os.system(callJava)
os.system(genSignApk)
os.system(genApks)
renameapks()
# 测试360加固
def exec_360_jiagu_comm():
os.chdir(_360JiaguToolsPath)
os.system("java -jar jiagu.jar -login " + _360JiaguUserName + " " + _360JiaguPwd)
# 查看已配置的签名信息
os.system(" java -jar jiagu.jar -showsign")
# 导入签名配置
os.system(" java -jar jiagu.jar -importsign " + keystorePath + " " + keystore_alias + " " + keystore_pass + " " + \
key_pass)
jiagu_cmd = "java -jar jiagu.jar -jiagu " + apkPath + " \
" + _360JiaguApkPath + " -autosign"
result = os.system(jiagu_cmd)
if not result:
print "========" + str(result) + " 加固成功"
for file in os.listdir(_360JiaguApkPath):
if os.path.isfile(os.path.join(_360JiaguApkPath, file)) == True:
# 将文件名与后缀名分开,只对apk文件操作
if os.path.splitext(file)[1] == '.apk':
if file.endswith("jiagu_sign.apk"):
newFile = file.replace(os.path.splitext(file)[0], getfilename())
# 执行修改
shutil.move(_360JiaguApkPath + "/" + file, _360JiaguApkPath + "/" + newFile)
jiagu_result_path = _360JiaguApkPath + "/" + newFile
return jiagu_result_path
else:
print "加固失败"
# C:\Users\sunny\Desktop\DolphinSleep_v1.1.2_release.apk
cleancaches()
gencache()
start()
PackageTool
5星 · 超过95%的资源 需积分: 50 109 浏览量
2017-11-23
19:02:32
上传
评论 2
收藏 857KB ZIP 举报
安静的Sunny
- 粉丝: 64
- 资源: 2
最新资源
- 基于JavaScript的访客预约系统设计源码
- 基于Vue和ECharts的工作租房数据可视化系统设计源码
- 1040g0cg310ravpiu6ibg5pg00tsipsln3ju2d0g 2
- 基于Python的SAR图像去噪CNN-NLM设计源码
- redhat6升级到redhat7,过程redhat6.x-> redhat6.10->rehat7.9 主版本最高版本
- 基于Django的流程引擎设计源码
- 基于Node.js的Express框架与MySQL的后台管理系统设计源码
- 基于Java的Flink流批一体数据处理快速集成开发框架设计源码
- FirstFilterOrderCompare
- Screenshot_2024-03-28-19-17-25-020_com.ss.android.lark.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈