2022年 11月 4日

Python安装apk

#_*_ coding:utf-8 _*_

import os
import time
import subprocess
from nt import chdir

COMMEND1 = 'aapt dump badging '
COMMEND2 = ' | findstr package'
PREPATH = os.path.abspath('.') + '/app/'

#安装APK
def InstallAPK(ff):
    print "adb install -r " + ff
    text = os.popen("adb install -r " + ff)
    time.sleep(2)
    print text.read()
    return ff

#解析APK包,获取包名
def GetApkName(commond):
    p = subprocess.Popen(commond, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)
    #print p
    (output, err) = p.communicate()
    if output != '':
        try:
            tempresult = output[15:]
            result = ''
            for tempstr in tempresult:
                result = result + tempstr
                #print result
                if tempstr == "'":
                    break
            return result[:-1]
        except Exception, e:
            return ""
    return ''

#更改文件夹内所有文件名称
def renameAPK(preName, newName):
    chdir(os.path.dirname(preName))
    os.rename(preName, newName)

'''
1.通过AAPT工具获取到当前APK包的包名;
2.将获取到的包名更新到当前APK;
3.安装APK到手机
'''
if __name__ == "__main__":
    APPFailes = os.listdir(PREPATH)
    print PREPATH
    for files in APPFailes:

        commond = COMMEND1 + PREPATH + files + COMMEND2
        strApkName = GetApkName(commond)
        print strApkName

        #更名需要知道新文件和旧文件的完整路径
        filePre = PREPATH + files
        fileNew = PREPATH + strApkName + '.apk'

        renameAPK(filePre, fileNew)
        InstallAPK(fileNew)

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64

下载“”蜜源app“”,0投资,既省钱,又可以赚钱(平台会付给我邀请费3元每人):
Step 1: 应用宝或者苹果商店下载“蜜源”,这样下载比较安全,经过平台的病毒等检测
Setp 2: 使用手机注册后,需要激活码激活,输入 FaIlFA 激活即可
不懂得,可以私信聊