Giter VIP home page Giter VIP logo

majia's Introduction

majia

将指定的包中的类移到新包名下,通过简单的配置就可以生成马甲包。

  • 修改.class中的包名,对第三方库(.jar)中代码也有效
    • 通过 AGP 的 Artifact API 遍历所有 .jar/.class
    • 通过 ASM 的 Remapper 类可以轻松实现替换类名
  • 修改布局XML中的包名,直接修改resources-**.ap_中的BinaryXml
    • process${variant}Resources 后,所有资源文件都被打包在 resources-**.ap_
    • 遍历 resources-**.ap_ 里所有的布局XML,通过 BinaryXml 解析并修改其中的字符串
  • 修改合并后AndroidManifest.xml中的包名。
    • process${variant}MainManifest 后,可获得合并后的清单文件替换包名

使用

在 settings.gradle 中

pluginManagement {
  repositories {
    maven { url "https://gitee.com/ezy/repo/raw/cosmo/"}
    gradlePluginPortal()
    google()
    mavenCentral()
  }
}  

在根项目的 build.gradle 中,注册插件

plugins {  
    id "me.reezy.gradle.majia" version "1.0.0" apply false
}

在 app 的 build.gradle 中,应用插件并配置参数

apply plugin: "me.reezy.gradle.majia"


majia {
    // 为空处理所有的类,非空表示只处理这些包内的类
    scopes = ["com.sample.framework", "me.reezy.cosmo", "com.demo.app", "androidx.databinding.DataBinderMapperImpl"]

    // 包名映射,比如将所有的 "me.reezy.cosmo" 替换成 "hello.world"
    mappings = [
        "me.reezy.cosmo": "hello.world",
        "com.sample.framework": "hello.goodbye",
        "com.demo.app": "hello.hasayo",
    ]

    // 指定生效的variant
  variant = "release"
}

Android Binary Xml 文件格式解析

解析BinaryXml参考了此项目

https://juejin.cn/post/7005944481455439903
https://github.com/senswrong/AndroidBinaryXml

修复几它的几个BUG:

  • 它对 isUtf8 和 isSorted 分两个字段(short)读取的,实际上这里应该读取一个flags(int)
  • 当 isUtf8 为 true,且字符串长度大于127时,读到的长度是错误的
    • 这里的 utf8 字符串通常有四部分:字符数(1) + 字节数(1) + utf8(n) + 0(1)
    • 字符数大于127时会占2字节:字符数(2) + 字节数(2) + utf8(n) + 0(1)
    • 字节数大于127时会占2字节:字符数(1) + 字节数(2) + utf8(n) + 0(1)
  • 字符串数据长度必须被4整除,否则需要用0填充

参考

Android Internals: Binary XML

Android Internals: Resources

ARSC 文件格式解析
https://juejin.cn/post/6844903854165753863

Android 手把手分析resources.arsc
https://juejin.cn/post/6844903911602683918

majia's People

Contributors

czy1121 avatar

Stargazers

 avatar

Watchers

 avatar  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.