Application Scenarios
If you need to batch parse the APK as well as the Classes.dex file in each apk file. How do you extract them? It is a viable option to change the APK name to a. zip file and extract the Classes.dex file from each apk file after extracting it. But in the middle of extracting a large number of apk files will occupy our large amount of disk storage space, how to extract the Dex file without the pressure file? This is an easy way to solve this problem by using the ZipFile class that comes with Python.
Code implementation:
#!/usr/bin/env python# coding=utf-8 "@author: chicho@version:1.0@ Date:jan 4, 01:54@function:extract de xs file from apk files * Create a new directory to store all dex Files@running:python dex_extract.py ' im Port Osimport zipfilepath= "/home/chicho/test/test/" # This is apk files ' store pathdex_path= '/home/chicho/test/test/dex /"# a directory store dex files Apklist = os.listdir (path) # get all the ' names of Appsif not os.path.exists (Dex_path): Os.makedirs (Dex_path) for APK in apklist:portion = Os.path.splitext (APK) if portion[1] = = ". apk": newname = Portion[0] + ". zip" # change them into the zip file to extract Dex files Os.rename (apk,newname) if Apk.endswith (". Z IP "): Apkname = portion[0] Zip_apk_path = Os.path.join (path,apk) # get the zip files z = zipfile. ZipFile (Zip_apk_path, ' R ') # read zip files for filename in z.namelist (): If Filename.endswith (". Dex"): Dexfilename = APkname + ". Dex" Dexfilepath = Os.path.join (Dex_path, dexfilename) F = open (Dexfilepath, ' w+ ' ) # EQ:CP Classes.dex dexfilepath f.write (z.read (filename)) print "All work done!"
You can also use this method to extract additional files from the APK file in batches. such as so files.
Reprint Annotated Source: http://blog.csdn.net/chichoxian/article/details/42382695
Extract the Classes.dex file from the apk file in bulk