[Xiang elder brother Master Invincible Road]0-002. How do I extract the information from the APK?

Source: Internet
Author: User

Face an apk software, how we go to get its information , how to get its version number, package name, or ID, user rights, this information is hidden in the APK package in the Androidmanifest.xml file, untie it We can get any information we want. But when you unzip the APK and find that Androidmanifest.xml is a bunch of numbers that you don't understand , how do you get information? We may as well make a tool to achieve the goal easily.

Required conditions

    • Installing the Java Environment
    • Own Axmlprinter2.jar file

Acquisition principle

After extracting the APK, open cmd, enter Java-jar and Drag the Axmlprinter2.jar file into , and then drag the Androidmanifest.xml file into the Enter will be able to parse the Androidmanifest.xml file, get the information inside, this is the use of JAR package parsing xml file. However, this extracted information is chaotic, we need accurate positioning of information , only the information needed to filter the information, which requires the development of tools to achieve.

Development steps

    1. Unzip apk file
    2. Get Androidmanifest.xml file
    3. Parsing androidmanifest.xml files
    4. Filter out useless content to get the information you need

Code Resources

Unzip APK

    def isapk (self,into):         # Display the file name on the text_apk        separate = os.path.split (str                )# unzip apk        myzip = ZipFile. ZipFile (into)          myfilelist=myzip.namelist ()  

Get Androidmanifest.xml file

         forNameinchmyfilelist:#find the ' androidmanifest.xml ' file            ifName = ='Androidmanifest.xml': FD= Open (separate[0]+ r'/androidmanifest.xml'. Decode ('Utf-8'),"WB") Fd.write (myzip.read (name)) Fd.close () Break  

Parsing androidmanifest.xml files

Separat = Separate[0].decode ('Utf-8') Roots= Os.popen ('Java-jar C:/dev/pythonprojects/apktool/src/res/axmlprinter2.jar'+ separat+ R'/androidmanifest.xml') Text=Roots.read () roots.close ( )#Save the contents of the anti-compilation to ' Androidmanifest.xml '        defSave (filename, contents): FH= open (filename,'W') Fh.write (contents) Fh.close () Save (Separat+ R'/androidmanifest.xml', text)returnseparat+ R'/androidmanifest.xml'

Filter out useless content to get the information you need

Get the version name, version number, package name

    defversion (self, root): Bodys= Root.getiterator ("Manifest")
#Extract VersionnameVersionname = bodys[0].attrib['{http://schemas.android.com/apk/res/android}versionname'] Self.text_version.setText (versionname)
#Extract VersioncodeVersioncode = bodys[0].attrib['{Http://schemas.android.com/apk/res/android}versioncode'] Self.text_codeversion.setText (Versioncode)
#Extract PackagePackage = bodys[0].attrib[' Package'] Self.text_package.setText (package)

Get user Permissions

    defpermission (self, root): Permission= Root.findall ("uses-permission")            #empty before outputPermissions= []         forIinchRange (len (permission)):#Output Permission ContentName = permission[i].attrib['{http://schemas.android.com/apk/res/android}name'] Permissions.append (name) Self.text_permissions.setText ('\ n'. Join (permissions))

Get ID and Plugin

    defMata (self, root): Meta= Root.getiterator ("Meta-data") Plugins=[] IDs= []         forIinchRange (len (meta)):#output Meta-data "            ifmeta[i].attrib['{http://schemas.android.com/apk/res/android}name'] =='Plugin_'+Str (i): Value= meta[i].attrib['{Http://schemas.android.com/apk/res/android}value'] Plugins.append (value)Else: Name= meta[i].attrib['{http://schemas.android.com/apk/res/android}name'] Value= meta[i].attrib['{Http://schemas.android.com/apk/res/android}value'] Complete='[%s] = [%s]'%(name, value) ids.append (str (complete)) Self.text_plugins.setText ('\ n'. Join (plugins)) Self.text_ids.setText ('\ n'. Join (IDS))

This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )

Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4495665.html

[Xiang elder brother Master Invincible Road]0-002. How do I extract the information from the APK?

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.