About Patch

Patch is supported in APK Editor Pro since version 1.6.0. In general, it is a zip file, which contains patch.txt and other necessary files. Patch.txt inside the zip file specifies patch rules, and other files provide patch resources.

It is not mature yet, please be careful when combining with other modifications.

And, there is a patch editor (an open source project) at https://github.com/SnowVolf/PCompiler

Patch Format

A patch is mainly composed of patch rules. Currently, it supports 8 patch rules:

· ADD_FILES

· REMOVE_FILES

· MATCH_REPLACE

· MATCH_ASSIGN

· MATCH_GOTO

· GOTO

· MERGE

· EXECUTE_DEX

· DUMMY

Inside a rule, each line starts with ‘#’ means that is a comment line. And, each configuration starts in a new line.

Please take following illustrations and examples to see how to create patch.txt. Patch examples are also provided, you could save them to look inside it.

[ADD_FILES] (Add files)

Used to add files to the app.

NAME: specifies the name of the rule.

SOURCE: specifies the name of the file inside the archive to be copied to the app.

TARGET: specifies target path inside the app.

[REMOVE_FILES] (Deleting files)

Used to delete files or folders from the app.

NAME: specifies the name of the rule.

TARGET: specifies target path to be deleted inside the app. If you need to delete several files at once, you need to write down the names of all the files or folders, and each name must begin with a new line.

For example:

[REMOVE_FILES]

TARGET:

res/values-ru

res/values-hz

res/values​​/strings.xml

[/REMOVE_FILES]

[MATCH_REPLACE] (Find and replace)

Used to find and replace the found result.

Name: specifies the name of the rule. (You can leave it blank, but if you want to jump to this rule from other places, name is a must)

TARGET: specifies the file path to do the find and replace operation.

MATCH: specify the text you want to find.

REGEX: true or false. True means the match string is a regular expression.

REPLACE: specifies the text that will replace the found result. (Blank means to delete the found result)

[MATCH_ASSIGN] (Defining variables)

Used to define variables.

Name: specifies the name of the rule. (You can leave it blank, but if you want to jump to this rule from other places, name is a must)

TARGET: specifies the file path to do match operation.

MATCH: specifies the text you want to find.

REGEX: true or false. True means the match string is a regular expression.

ASSIGN: specifies the name and value of the variable. (For example: p1 = $ {GROUP1}) If there are more than one variables, then each next variable must begin with a new line.

[MATCH_GOTO] (If match, then go to a target rule)

Used to find some text in specified files, and in case of a successful match, will go to execute the rule written in the "GOTO" field.

If the text is not found then the rule written right after that is executed.

Name: specifies the name of the rule.

TARGET: specifies the file path to do the match operation.

MATCH: specify the text you want to find.

REGEX: true or false. True means the match string is a regular expression.

GOTO: specifies the name of the next rule. If successfully matched, then will go to execute that rule.

[GOTO] (Redirect to some rule)

Used to redirect to another rule.

GOTO: specifies the name of the next rule.

[MERGE] (Link resources)

It is a powerful rule that will merge specified resource with current app. It means that the resource will be added, together with IDs refactoring to avoid resource conflicting.

NAME: specifies the name of the rule.

SOURCE: file name of the resource file which will be merged.

[EXECUTE_DEX] (Execute a dex script)

Rule to execute a customized script.

SCRIPT: Target script file inside the zip to be executed. It must be a dex file, which could be generated through following commands:

javac -source 1.7 -target 1.7 test/AddDebugInfo.java

dx --dex --output=script.dex test/AddDebugInfo.class

SMALI_NEEDED: Indicate the script needs smali code or not.

If true, and smali code is not generated yet, then when the rule got executed, the patch will generate smali code as the first step.

MAIN_CLASS: Class path which contains the entrance

ENTRANCE: Target method to execute, the method must accepts 4 String parameters.

PARAM: Pass as the last parameter to the target method.

[DUMMY] (Dummy rule)

Dummy rule. It is more like a label which only contains NAME field. From “MATCH_GOTO” or “GOTO” rule, we could jump to a dummy rule.

And, here is an example:

# Required minimal engine version; the engine in v1.6.8 is version 2

[MIN_ENGINE_VER]

1

# The author of this patch

[AUTHOR]

apkeditor

# For which package name

[PACKAGE]

*

# Add files to target path

[ADD_FILES]

SOURCE:

layout.zip

TARGET:

res/layout

EXTRACT:

true

[/ADD_FILES]

# Remove files

# Multiple targets can be provided

[REMOVE_FILES]

TARGET:

res/values-xx

res/values-yy

[/REMOVE_FILES]

# Replace matched content inside target file, be careful when REGEX=true

# All matched occurrences will be replaced

# If REGEX=true, MATCH content must be in one line

# Following example will delete internet permission

[MATCH_REPLACE]

TARGET:

AndroidManifest.xml

MATCH:

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

REGEX:

false

REPLACE:

[/MATCH_REPLACE]

# MERGE is designed to merge resources and code from other apk

#

# Merge resources and smali files inside extra.zip

# res/values/public.xml must be provided inside extra.zip

# The patch engine will try to refactor all the added ids

# The added ids should be different with current existing ids

[MERGE]

SOURCE:

extra.zip

[/MERGE]