Giter Club home page Giter Club logo

apkparser's Introduction

apkparser

基于aapt2和libdexfile两个模块,封装一个命令行工具,用于解析apk中的资源和dex。

Todo list

  • 加速编译

功能

  • 解析manifest
  • 提取asrc中所有字符串
  • 解析dex所有类名和字符串

使用方法

# 解析manifest
apkparser manifest <filename>
# 输出到stdout:
# {
#     "displayNames": [
#         ""
#     ],
#     "manifest": ""
# }

# 提取asrc中所有字符串
apkparser strings <filename>
# 输出到stdout: 按行输出字符串

# 解析dex所有类名和字符串
apkparser dexes <filename>
# 输出到stdout:
# {
#     "dex_strings": [
#         ""
#     ],
#     "dex_classes": [
#         ""
#     ]
# }

# 以上命令合并
apkparser all <filename>
# 输出到stdout:
# {
#     "resources.arsc": {
#         "strings": [
#             ""
#         ]
#     },
#     "dex_strings": [
#         ""
#     ],
#     "displayNames": [
#         ""
#     ],
#     "dex_classes": [
#         ""
#     ],
#     "manifest": ""
# }

编译安装

先下载Android源码,然后将本项目放到frameworks/base/tools/目录下,通过mm apkparser命令编译。

下载Android源码

curl https://storage.googleapis.com/git-repo-downloads/repo > /usr/local/repo
chmod +x /usr/local/repo

mkdir platform-tools && cd platform-tools
repo init -u https://android.googlesource.com/platform/manifest.git -b platform-tools-33.0.3 --depth 1
repo sync

准备环境

下载apkparser源码

cd frameworks/base/tools/ && git clone https://github.com/fork-ai/apkparser

导出libdexfile模块的headers

// 在Android源码根目录,进入art/libdexfile,打开Android.bp,增加以下内容
cc_library_headers {
    name: "libdexfile_headers",
    visibility: ["//visibility:public"],
    host_supported: true,
    export_include_dirs: ["."],
}

// 同时在cc_library模块中添加以下内容
cc_library {
    visibility: ["//visibility:public"], // 增加这一行
    ......
}

导出aapt2模块的headers

// 在Android源码根目录,进入frameworks/base/tools/aapt2,打开Android.bp,增加以下内容
cc_library_headers {
    name: "libaapt2_headers",
    visibility: ["//visibility:public"],
    host_supported: true,
    export_include_dirs: ["."],
}

编译

# 在Android源码根目录执行下行命令,初始化构建环境
. build/envsetup.sh

# 编译apkparser
mm apkparser

# 调用strips命令减小体积
strips out/host/linux-x86/bin/apkparser

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.