批处理——修改apk并重新签名

作者:追风剑情 发布于:2018-8-7 17:34 分类:批处理

修改APK后需要重新签名才能正常安装运行

示例: 将一个org目录包括子目录拷到apk里,并重新签名

@echo off

set keystore=.\keystore\xxxx.keystore
set keypass=xxxxxxxxx
set storepass=xxxxxxxxx
set alias=yyyy

set WinRAR="C:\Program Files\WinRAR\WinRAR.exe"
set org_folder=.\org

set name=testapk
set apk_path=%name%.apk
set apk_full_path=.\Apks\%name%.apk
set apk_sign_path=%name%_sign.apk
set apk_sign_full_path=.\Apks\%name%_sign.apk
set zip_path=%name%.zip
set zip_full_path=.\Apks\%name%.zip

echo start fix %apk_path% ...

rem .apk改成.zip
ren %apk_full_path% %zip_path%

echo delete META-INF\SSSS.RSA and META-INF\SSSS.SF
echo add %org_folder%

rem 修改apk文件
rem a 压缩命令 d 删除命令
rem -ep1 排除基准目录路径 -o+ 覆盖已经存在的文件 -inul 禁止出错信息 -r 连同子文件夹操作 -ibck 后台模式运行
%WinRAR% d -ibck -inul %zip_full_path% META-INF\SSSS.RSA
%WinRAR% d -ibck -inul %zip_full_path% META-INF\SSSS.SF
%WinRAR% a -ep1 -o+ -r %zip_full_path% %org_folder%

rem .zip改回.apk
ren %zip_full_path% %apk_path%

rem 对apk重新签名
echo re-sign ...

set jarsigner=E:\software\Java\jdk8\bin\jarsigner.exe
set sourceapk=apk_full_path
set output=apk_sign_full_path
%jarsigner% -digestalg SHA1 -sigalg MD5withRSA -storepass %storepass% -keypass %keypass% -keystore %keystore% -signedjar %output% %sourceapk% %alias%

rem 如果签名成功
if exist %apk_sign_full_path% (
	del %apk_full_path%
	ren %apk_sign_full_path% %apk_path%
)

echo fix %apk_path% finished

标签: 批处理

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号