apkInspector
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
- gotcha When parsing highly obfuscated or malformed APK files, the library might still encounter issues despite continuous improvements. The tool aims to process such files, but edge cases can lead to parsing errors or incomplete results.
- gotcha APK files containing non-UTF8 characters in filenames might have been problematic in older versions, leading to parsing errors or incorrect file listings. While v1.3.0 introduced fixes, extremely rare character encodings could still cause unexpected behavior.
- gotcha apkInspector is an actively developed project, meaning that while core functionalities are stable, new features or refactorings might introduce subtle changes in behavior or API additions between minor versions. Users should review release notes for updates.
Install
-
pip install apkinspector
Imports
- ZipEntry
from apkinspector.headers import ZipEntry
- Axml
from apkinspector.axml import Axml
Quickstart
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}")