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

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

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

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

  1. @echo off
  2.  
  3. set keystore=.\keystore\xxxx.keystore
  4. set keypass=xxxxxxxxx
  5. set storepass=xxxxxxxxx
  6. set alias=yyyy
  7.  
  8. set WinRAR="C:\Program Files\WinRAR\WinRAR.exe"
  9. set org_folder=.\org
  10.  
  11. set name=testapk
  12. set apk_path=%name%.apk
  13. set apk_full_path=.\Apks\%name%.apk
  14. set apk_sign_path=%name%_sign.apk
  15. set apk_sign_full_path=.\Apks\%name%_sign.apk
  16. set zip_path=%name%.zip
  17. set zip_full_path=.\Apks\%name%.zip
  18.  
  19. echo start fix %apk_path% ...
  20.  
  21. rem .apk改成.zip
  22. ren %apk_full_path% %zip_path%
  23.  
  24. echo delete META-INF\SSSS.RSA and META-INF\SSSS.SF
  25. echo add %org_folder%
  26.  
  27. rem 修改apk文件
  28. rem a 压缩命令 d 删除命令
  29. rem -ep1 排除基准目录路径 -o+ 覆盖已经存在的文件 -inul 禁止出错信息 -r 连同子文件夹操作 -ibck 后台模式运行
  30. %WinRAR% d -ibck -inul %zip_full_path% META-INF\SSSS.RSA
  31. %WinRAR% d -ibck -inul %zip_full_path% META-INF\SSSS.SF
  32. %WinRAR% a -ep1 -o+ -r %zip_full_path% %org_folder%
  33.  
  34. rem .zip改回.apk
  35. ren %zip_full_path% %apk_path%
  36.  
  37. rem apk重新签名
  38. echo re-sign ...
  39.  
  40. set jarsigner=E:\software\Java\jdk8\bin\jarsigner.exe
  41. set sourceapk=apk_full_path
  42. set output=apk_sign_full_path
  43. %jarsigner% -digestalg SHA1 -sigalg MD5withRSA -storepass %storepass% -keypass %keypass% -keystore %keystore% -signedjar %output% %sourceapk% %alias%
  44.  
  45. rem 如果签名成功
  46. if exist %apk_sign_full_path% (
  47. del %apk_full_path%
  48. ren %apk_sign_full_path% %apk_path%
  49. )
  50.  
  51. echo fix %apk_path% finished

标签: 批处理

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号