Python 通過指令碼擷取Android的apk的部分屬性,再通過密碼編譯演算法產生秘鑰。,androidapk
Python 通過指令碼擷取Android的apk的部分屬性,再通過密碼編譯演算法產生秘鑰。
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import zipfile import reimport hashlib #MD5和sha1演算法def getAppBaseInfo(apkpath): #print(apkpath) #檢查版本號碼等資訊 output = os.popen("aapt.exe d badging %s" % apkpath).read() if not output: raise Exception("can't find aapt.exe") #print('output:' + output) #package: name='com.student.xiaomuxc' versionCode='2016062800' versionName='3.2.1' match = re.compile("package: name='(\S+)' versionCode='(\d+)' versionName='(\S+)'").match(output) if not match: raise Exception("can't get packageinfo") packagename = match.group(1) versionCode = match.group(2) versionName = match.group(3) print('packageName:' + packagename) #print('versionCode:' + versionCode) print('versionName:' + versionName) return packagename + versionCode + versionName def getCurrentDirApk(): for dir in os.walk(os.curdir): for filename in dir[2]: if os.path.splitext(filename)[1] == '.apk': #print('find apk:', filename) return filenamedef md5_encode(data): #調用md5演算法,用一個變數接收 m = hashlib.md5() #調用update對傳來的data進行資料加密,encode utf-8的編碼後才能用update m.update(data.encode('utf-8')) return m.hexdigest() #經過特殊處理之後以字串形式返回 if __name__ == "__main__": #獲得apk名 if len(sys.argv) == 1: apkName = getCurrentDirApk() else: apkName = sys.argv[1] if not apkName: print('can not find apk!!!') exit() appinfo = getAppBaseInfo(apkName) if not appinfo: print('can not get appinfo!!!') exit() #print('appinfo:' + appinfo) result1 = md5_encode(appinfo) print('Secretkey:' + result1)raw_input("Press <enter>")
在windows7電腦上使用,需要先安裝python-2.7.msi,
把aapt.exe,Secretkey.py,目標apk放在同一個目錄,
通過點擊Secretkey.py檔案會產生一個秘鑰。
PS:aapt.exe檔案在SDK內