apkInspector

1.3.6 · active · verified Sat Apr 11

apkInspector is a Python library and CLI tool designed to provide detailed insights into the ZIP structure of APK files. It offers the capability to extract content and decode the AndroidManifest.xml file, notably without relying on external libraries for ZIP parsing. Currently at version 1.3.6, it maintains an active development cycle with frequent bug fix releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the library with an APK file, list its contents, and attempt to decode the `AndroidManifest.xml`. Note that for a minimal dummy APK, the manifest decoding will fail as no actual manifest is present.

import os
from apkinspector.headers import ZipEntry
from apkinspector.axml import Axml

# Assuming an APK file named 'example.apk' exists in the current directory
# For demonstration, create a dummy file if not present
if not os.path.exists('example.apk'):
    with open('example.apk', 'wb') as f:
        f.write(b'PK\x05\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00') # Empty ZIP EOCD

# Read the APK file content
with open('example.apk', 'rb') as f:
    apk_content = f.read()

# List contents of the APK
print("Listing APK entries:")
try:
    entries = ZipEntry.parse(apk_content)
    if entries:
        for entry in entries:
            print(f"  - {entry.filename}")
    else:
        print("  No entries found (this might be an empty or malformed APK).")
except Exception as e:
    print(f"Error parsing APK entries: {e}")

# Attempt to decode AndroidManifest.xml (requires a valid manifest in the APK)
# This will likely fail for a dummy APK without a real manifest
print("\nAttempting to decode AndroidManifest.xml:")
try:
    # For a real APK, 'AndroidManifest.xml' would be present
    # For this dummy example, it will likely raise an error
    manifest = Axml(apk_content, "AndroidManifest.xml")
    decoded_manifest = manifest.get_xml()
    print(decoded_manifest)
except FileNotFoundError:
    print("AndroidManifest.xml not found in the APK (as expected for a dummy APK).")
except Exception as e:
    print(f"Error decoding AndroidManifest.xml: {e}")

view raw JSON →