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")
在windows7电脑上使用,需要先安装python-2.7.msi,
把aapt.exe,Secretkey.py,目标apk放在同一个目录,通过点击Secretkey.py文件会生成一个秘钥。PS:aapt.exe文件在SDK内