Extract the Classes.dex file from the apk file in bulk

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.