批量修改安卓apk包名


1.准備工作

1.1 反編譯工具apktool下載

1.2 java, android SDK安裝

1.2 python安裝

2.反編譯現有包

apktool.bat d test.apk

3. 直接上代碼

import re
import os
import shutil

file_path = 'F:\\apk\\test\\AndroidManifest.xml'

root_path = "F:\\apk\\test\\smali\\com\\test\\package"  #smali文件夾下包名目錄
def modify_package(package_org, package_name):
    with open(file_path, 'r') as f:
        file_content = f.read()
        new_file = file_content.replace(package_org, package_name)
    
    with open(file_path, 'w') as f:
        f.write(new_file)

    list_dirs = os.walk(root_path)
    other_package = package_name.replace('.', '/')
    other_package_org = package_org.replace('.', '/')
    for root, dirs, files in list_dirs:
        for file_name in files:
            path = root_path + '/' + file_name
            modify_file = ''
            with open(path, 'rb') as f:
                file_s = f.read()
                modify_file = file_s.replace(other_package_org, other_package)
            
            with open(path, 'wb') as f:
                f.write(modify_file)
        

        copy_name = "F:\\apk\\" + package_name + "org.apk"
        dist_name = "F:\\apk\\" + package_name + ".apk"
        os.system('apktool b F:\\apk\\test') #重新打包
        shutil.copy('F:\\apk\\test\\dist\\test.apk', copy_name)
        shell_cmd = 'jarsigner -verbose -keystore key.key -storepass password -keypass password -signedjar ' + dist_name + ' ' + copy_name + ' alianame'
       
        os.system(shell_cmd)  # 添加簽名


if __name__ == '__main__' :
    filelines = ''
    with open('channel.txt', 'rb') as f_c:   #channel.txt是需要切的包的包名,一行一個包名
        filelines = f_c.readlines()
    
    package_org = 'com.test.pacakge'
    for line in filelines :
        modify_package(package_org, line.strip())
        package_org = line.strip()



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM