How to use the apkutils.APK function in apkutils

To help you get started, we’ve selected a few apkutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Map-A-Droid / MAD / mapadroid / mad_apk / wizard.py View on Github external
def normalize_package(self) -> NoReturn:
        """ Normalize the package

        Validate that only valid APK files are present within the package and have the correct extension.  Exclude the
        DPI APK as it is not relevant to the installation
        """
        pruned_zip = io.BytesIO()
        zout = zipfile.ZipFile(pruned_zip, 'w')
        with zipfile.ZipFile(self._data) as zip_data:
            for item in zip_data.infolist():
                try:
                    with zip_data.open(item, 'r') as fh:
                        apk = apkutils.APK(io.BytesIO(fh.read()))
                        manifest = apk.get_manifest()
                        try:
                            self.package_version = manifest['@android:versionName']
                            self.package_name = manifest['@package']
                        except KeyError:
                            pass
                    try:
                        filename = manifest['@split']
                        if filename[-3:] == 'dpi':
                            continue
                    except KeyError:
                        filename = item.filename
                    else:
                        try:
                            # The architectures use dash but we are required to use underscores
                            self.package_arch = lookup_arch_enum(filename.rsplit('.', 1)[1].replace('-', '_'))
github NetEaseGame / ATX / atx / apkparse.py View on Github external
def parse_apkfile(file):
    '''
    Args:
        - file: filename or file object
    Returns:
        Manifest(Class)
    '''
    apk = APK(file)
    return Manifest(apk.get_org_manifest())
github Map-A-Droid / MAD / mapadroid / utils / apk_util.py View on Github external
def __validate_file(self, apk_file):
        try:
            apk = apkutils.APK(apk_file)
        except:
            logger.warning('Unable to parse APK file')
            self.valid = False
        else:
            self.version = apk.get_manifest()['@android:versionName']
            self.package = apk.get_manifest()['@package']
            log_msg = 'New APK uploaded for {}'
            args = [self.filename]
            if self.architecture:
                log_msg += ' {}'
                args.append(self.architecture)
            log_msg += ' [{}]'
            args.append(self.version)
            logger.info(log_msg, *args)
github Map-A-Droid / MAD / mapadroid / mad_apk / wizard.py View on Github external
def get_apk_info(self, downloaded_file: io.BytesIO) -> NoReturn:
        try:
            apk = apkutils.APK(downloaded_file)
        except:  # noqa: E722
            logger.warning('Unable to parse APK file')
        else:
            manifest = apk.get_manifest()
            try:
                self.package_version, self.package_name = (manifest['@android:versionName'], manifest['@package'])
            except KeyError:
                raise InvalidFile('Unable to parse the APK file')
github mikusjelly / apkutils / examples / manifest.py View on Github external
import json
import os

from apkutils import APK

file_path = os.path.abspath(os.path.join(
    os.path.dirname(__file__), "..", 'data', 'test'))
apk = APK(file_path)

m_xml = apk.get_org_manifest()
print(m_xml)

m_dict = apk.get_manifest()
print(json.dumps(m_dict, indent=1))

# get any item you want from dict
print('package:', m_dict['@package'])
print('android:versionName:', m_dict['@android:versionName'])
github mikusjelly / apkutils / apkutils / __main__.py View on Github external
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)
github pengchenglin / ATX-Test / Public / Test_data.py View on Github external
def get_apk_activity(path):
    tmp = apkutils.APK(path).get_manifest()
    data = tmp['application']['activity']
    activity_list =[]
    for activity in data:
        activity_list.append(activity['@android:name'])
    return activity_list