def parse(self, apk_path): _check_env() command = [aapt, 'dump', 'badging', apk_path] logger.debug(' '.join(command)) try: output = subprocess.check_output(command, stderr=subprocess.STDOUT) if sys.version_info[0] == 3: output = output.decode(sys.stdout.encoding or 'utf-8', 'replace') except subprocess.CalledProcessError as e: raise HostError( 'Error parsing APK file {}. `aapt` says:\n{}'.format( apk_path, e.output)) for line in output.split('\n'): if line.startswith('application-label:'): self.label = line.split(':')[1].strip().replace('\'', '') elif line.startswith('package:'): match = self.version_regex.search(line) if match: self.package = match.group('name') self.version_code = match.group('vcode') self.version_name = match.group('vname') elif line.startswith('launchable-activity:'): match = self.name_regex.search(line) self.activity = match.group('name') elif line.startswith('native-code'): apk_abis = [ entry.strip() for entry in line.split(':')[1].split("'") if entry.strip() ] mapped_abis = [] for apk_abi in apk_abis: found = False for abi, architectures in ABI_MAP.items(): if apk_abi in architectures: mapped_abis.append(abi) found = True break if not found: mapped_abis.append(apk_abi) self.native_code = mapped_abis elif line.startswith('uses-permission:'): match = self.permission_regex.search(line) if match: self.permissions.append(match.group('permission')) else: pass # not interested
def parse(self, apk_path): _check_env() output = self._run([aapt, 'dump', 'badging', apk_path]) for line in output.split('\n'): if line.startswith('application-label:'): self.label = line.split(':')[1].strip().replace('\'', '') elif line.startswith('package:'): match = self.version_regex.search(line) if match: self.package = match.group('name') self.version_code = match.group('vcode') self.version_name = match.group('vname') elif line.startswith('launchable-activity:'): match = self.name_regex.search(line) self.activity = match.group('name') elif line.startswith('native-code'): apk_abis = [ entry.strip() for entry in line.split(':')[1].split("'") if entry.strip() ] mapped_abis = [] for apk_abi in apk_abis: found = False for abi, architectures in ABI_MAP.items(): if apk_abi in architectures: mapped_abis.append(abi) found = True break if not found: mapped_abis.append(apk_abi) self.native_code = mapped_abis elif line.startswith('uses-permission:'): match = self.permission_regex.search(line) if match: self.permissions.append(match.group('permission')) else: pass # not interested self._apk_path = apk_path self._activities = None self._methods = None