Giter Site home page Giter Site logo

apk-parser's Introduction

Apk parser lib, for decoding binary xml file, getting apk meta info.

Table of Contents

Features

  • Retrieve apk meta info, such as title, icon, package name, version, etc.
  • Parse and convert binary xml file to text
  • Get classes from dex file
  • Get apk singer info

Get apk-parser

Get apk-parser from maven central repo:

<dependency>
    <groupId>net.dongliu</groupId>
    <artifactId>apk-parser</artifactId>
    <version>2.6.9</version>
</dependency>

From version 2.0, apk-parser requires java7. The last version support java6 is 1.7.4.

Usage

The ordinary way is using the ApkFile class, which contains convenient methods to get AndroidManifest.xml, apk info, etc.ApkFile need to be closed when no longer used. There is also a ByteArrayApkFile class for reading apk file from byte array.

1. Apk info

ApkMeta contains name(label), packageName, version, sdk, used features, etc.

try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    ApkMeta apkMeta = apkFile.getApkMeta();
    System.out.println(apkMeta.getLabel());
    System.out.println(apkMeta.getPackageName());
    System.out.println(apkMeta.getVersionCode());
    for (UseFeature feature : apkMeta.getUsesFeatures()) {
        System.out.println(feature.getName());
    }
}
2. Get binary xml and manifest xml file
try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    String manifestXml = apkFile.getManifestXml();
    String xml = apkFile.transBinaryXml("res/menu/main.xml");
}
3. Get dex classes
try(ApkFile apkFile = new ApkFile(new File(filePath))) {
    DexClass[] classes = apkFile.getDexClasses();
    for (DexClass dexClass : classes) {
        System.out.println(dexClass);
    }
}
4. Get Apk Sign info

To get apk signer certificate info and other messages, using:

try(ApkFile apkFile = new ApkFile(new File(filePath))) {
    List<ApkSigner> signers = apkFile.getApkSingers(); // apk v1 signers
    List<ApkV2Signer> v2signers = apkFile.getApkV2Singers(); // apk v2 signers
}
5. Locales

Apk may have different info(title, icon, etc.) for different regions and languages——or we can call it Locale. If locale is not set, the default "en_US" locale(Locale.US) is used. You can set one preferred locale by:

try (ApkFile apkFile = new ApkFile(new File(filePath))) {
    apkFile.setPreferredLocale(Locale.SIMPLIFIED_CHINESE);
    ApkMeta apkMeta = apkFile.getApkMeta();
}

Apk parser will find best match languages with locale you specified.

If locale is set to null, ApkFile will not translate resource tag, just give the resource id. For example, the title will be something like '@string/app_name' instead of the real name.

Open Issue

If this parser has any problem with a specific apk, open a new issue, with the link to download the apk file.

apk-parser's People

Contributors

9re avatar furniel avatar hsiafan avatar johnjohndoe avatar ne-lexa avatar phillab avatar sorccu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.