Giter Club home page Giter Club logo

manifesteditor's Introduction

ManifestEditor 修改二进制的AndroidManifest.xml

说明

在做apk分发时经常会遇到需要修改packageversionCodeversionName等等AndroidManifest.xml中的内容,但是从apk中解压出来的AndroidManifest.xml是被处理过的二进制形式,现有的aapt或者AXMLPrinter2.jar也只能查看并不能修改。原先的思路是用逆向工具apktool将apk逆向成project,然后在修改对应的源码版本的xml后再次进行build,但是部分情况下会失败,例如apktool版本不对,或者被加壳。

原先做过一个java的版本,只是当时写得比较潦草(结构乱、注释少),碰巧最近又出现了一个Bug。鼓足勇气想在原来的基础上修复,结果一边看一边骂,再加上现在的构建脚本都是用python,所以又重新用python翻新了一版修复了Bug。

想了解AndroidManifest.xml的细节,请参考一位大神画的结构图

ps: 要用python3

安装

  • 方式一:下载源码

    • git clone https://github.com/CodyGit/ManifestEditor
  • 方式二:pip安装

    • pip install git+https://github.com/CodyGit/ManifestEditor

使用举例

  • 一次性修改同一个TAG下的多个属性
  • 详细代码可以参考 test/test.py
    from ManifestEditor import *
    input_xml = "test/AndroidManifest.xml"
    output_xml = "test/cody-AndroidManifest.xml"
    attr_obj = {
        "tag":"manifest",
    }
    new_attr_obj = [
        {"key": "package", "value": "com.xxx"},
        {"key": "versionCode", "value": 100},
        {"key": "versionName", "value": "2.2.2"}
    ]
    # 不传 `output_xml` 就会把修改后的内容写回 input_xml
    modify_xml_attr(input_xml, attr_obj, new_attr_obj, output_xml)
    
    # 支持直接修改apk,不传 `output_apk` 就会直接把内容修改到原apk中 
    apk_path = "/path/to/apk"
    output_apk = "/path/to/modify-apk"
    modify_apk_attr(apk_path, attr_obj, new_attr_obj, output_apk)
  • 只修改一个属性
    from ManifestEditor import *
    # 把 android.permission.WRITE_SMS 权限修改成 android.permission.SEND_SMS
    input_xml = "test/AndroidManifest.xml"
    output_xml = "test/cody-AndroidManifest.xml"
    attr_obj = {
        "tag":"uses-permission",
        "attr_name": "name",
        "attr_value": "android.permission.WRITE_SMS"
    }
    new_attr_obj = {"key": "name", "value": "android.permission.SEND_SMS"}
    # 不传 output_xml 就会把修改后的内容写回 input_xml
    modify_xml_attr(input_xml, attr_obj, new_attr_obj, output_xml)

如果帮助到您,请不要吝啬您的小星星

TODO

等有需求再说吧

  1. 新增标签和属性
  2. 删除标签和属性

manifesteditor's People

Contributors

codygit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

manifesteditor's Issues

Delete a uses-permission on Manifest

Hi!

I would like to delete this permission on Manifest:

<uses-permission android:maxSdkVersion="28" android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

And later add this one:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

This is for deleting restriction of external storage based on Android version.

Could i do it using your python package? How could i do it?

Regards

Jps1x2

签名问题

看了下项目的逻辑,有个疑问,修改完后续重新打包的逻辑是怎么样的

meta-data相关

请问一下如何修改多个meta-data中的指定name的value?

直接修改apk

  1. readme中的参数多了一个
  2. 修改完后,apk中只剩下AndroidManifest.xml 了

修改meta-data

我尝试修改meta-data,但抛出错误
if attr_dict["type"] == TypedValue.TYPE_STRING:
TypeError: 'NoneType' object is not subscriptable

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.