def __init__(self, dirname): self.dirname = dirname self.isData = True self.isfailed = False self.ver = '' apk = APK(dirname) try: m_dict = apk.get_manifest() except BadZipFile: self.isfailed = True return if not m_dict: self.isData = False return self.package = m_dict['@package'] if '@android:versionName' in m_dict: self.ver = m_dict['@android:versionName'] elif '@versionName' in m_dict: self.ver = m_dict['@versionName'] elif '@versionCode' in m_dict: self.ver = m_dict['@android:versionCode'] if '@android:label' in m_dict['application']: self.label = m_dict['application']['@android:label'] elif '@label' in m_dict: self.label = m_dict['application']['@label'] statbuf = os.stat(dirname) self.mtime = statbuf.st_mtime
def parse_apkfile(file: str) -> Manifest: ''' Args: - file: filename Returns: Manifest(Class) ''' return Manifest(APK(file))
def main(args): apk = APK(args.p) if args.m: import json if apk.get_manifest(): print(json.dumps(apk.get_manifest(), indent=1)) elif apk.get_org_manifest(): print(apk.get_org_manifest()) elif args.s: for item in apk.get_strings(): print(binascii.unhexlify(item).decode(errors='ignore')) elif args.f: for item in apk.get_files(): print(item) elif args.c: for item in apk.get_certs(): print(item)
def showFile(dirname): apk = APK(dirname) # m_xml = apk.get_org_manifest() # print(m_xml) # m_dict = apk.get_manifest() # print(json.dumps(m_dict, indent=1)) # # f = open('phone-result.json', 'w', encoding="utf-8") # f.write(json.dumps(m_dict, indent=1)) # f.close() item = Ditem(dirname) # get any item you want from dict print('package:', item.package) print('android:versionName:', item.ver) print('label:', item.label)
def __init__(self, apk: APK): content = apk.get_org_manifest() self._dom = minidom.parseString(content) self._permissions = None self._apk = apk