Python 通過指令碼擷取Android的apk的部分屬性,再通過密碼編譯演算法產生秘鑰。,androidapk

來源:互聯網
上載者:User

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內

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.