Xpatch
This is a tool to repackage apk file, then the apk can load any xposed modules installed in the device. It is another way to hook an app without root device.
Top Related Projects
Tools to work with android .dex and java .class files
smali/baksmali
Dex to Java decompiler
Virtual Engine for Android(Support 14.0 in business version)
A Java 8+ Jar & Android APK Reverse Engineering Suite (Decompiler, Editor, Debugger & More)
A tool for reverse engineering Android apk files
Quick Overview
Xpatch is an Android application reinforcement tool that can generate a custom APK file by modifying an existing APK. It aims to protect Android applications from being cracked or reverse-engineered by adding a custom DEX file to the original APK, making it more difficult for attackers to analyze or modify the app's code.
Pros
- Enhances security of Android applications by making them harder to crack or reverse-engineer
- Supports both signed and unsigned APK files
- Provides a command-line interface for easy integration into build processes
- Open-source project with potential for community contributions and improvements
Cons
- May increase the size of the APK file due to the addition of custom DEX
- Could potentially impact app performance, depending on the complexity of the added protection
- Requires regular updates to keep up with evolving Android security measures and attack techniques
- May not provide complete protection against determined attackers with advanced skills
Code Examples
// Example 1: Basic usage of Xpatch
String srcApkPath = "path/to/source.apk";
String outApkPath = "path/to/output.apk";
XpatchClient.patch(srcApkPath, outApkPath);
// Example 2: Using Xpatch with custom options
XpatchOption option = new XpatchOption();
option.setDebug(true);
option.setKeepSignature(false);
XpatchClient.patch(srcApkPath, outApkPath, option);
// Example 3: Handling exceptions during patching process
try {
XpatchClient.patch(srcApkPath, outApkPath);
} catch (Exception e) {
System.err.println("Error patching APK: " + e.getMessage());
}
Getting Started
To use Xpatch in your project:
-
Clone the repository:
git clone https://github.com/WindySha/Xpatch.git
-
Build the project using Gradle:
cd Xpatch ./gradlew build
-
Use the generated JAR file in your Java project or run it from the command line:
java -jar xpatch.jar -f path/to/source.apk -o path/to/output.apk
For more detailed instructions and options, refer to the project's README file on GitHub.
Competitor Comparisons
Tools to work with android .dex and java .class files
Pros of dex2jar
- More comprehensive toolset for working with Android DEX and Java class files
- Supports conversion of DEX to Java JAR files, enabling easier analysis and decompilation
- Actively maintained with regular updates and bug fixes
Cons of dex2jar
- Primarily focused on DEX/JAR conversion, lacking Xpatch's APK patching capabilities
- May require additional tools for complete APK analysis and modification
- Less user-friendly for those specifically interested in APK patching
Code Comparison
Xpatch (Main patching logic):
public void patch(String apkPath, String outApkPath, String signatureType) throws Exception {
File apkFile = new File(apkPath);
File outApkFile = new File(outApkPath);
// ... (patching logic)
}
dex2jar (DEX to class file conversion):
public static void doFile(String dexFilePath) throws IOException {
DexFileReader reader = new DexFileReader(new File(dexFilePath));
DexFileVisitor visitor = new DexFileVisitor(ASM4);
reader.accept(visitor);
// ... (conversion logic)
}
While Xpatch focuses on APK patching, dex2jar provides tools for DEX/JAR conversion and analysis. Xpatch is more specialized for APK modification, while dex2jar offers a broader set of utilities for working with Android bytecode.
smali/baksmali
Pros of smali
- More established and widely used in the Android reverse engineering community
- Supports a broader range of Android versions and features
- Offers a more comprehensive set of tools for disassembling and assembling Android DEX files
Cons of smali
- Steeper learning curve for beginners
- Requires more manual intervention for complex modifications
- Less focused on specific patching tasks compared to Xpatch
Code Comparison
smali:
.method public static main([Ljava/lang/String;)V
.registers 2
sget-object v0, Ljava/lang/System;->out:Ljava/io/PrintStream;
const-string v1, "Hello, World!"
invoke-virtual {v0, v1}, Ljava/io/PrintStream;->println(Ljava/lang/String;)V
return-void
.end method
Xpatch:
public class XpatchPlugin implements Plugin {
@Override
public void process(File apkFile, File outputFile) {
// Xpatch-specific patching logic
}
}
Note: The code comparison showcases the different focus of each project. smali deals with low-level Dalvik bytecode, while Xpatch provides a higher-level API for APK patching.
Dex to Java decompiler
Pros of jadx
- More comprehensive decompilation tool, supporting Java and Kotlin
- Actively maintained with frequent updates and bug fixes
- Includes a GUI for easier navigation and analysis
Cons of jadx
- Larger project scope, potentially more complex for simple APK patching tasks
- May require more system resources due to its extensive features
Code comparison
Xpatch (Java):
public static void patchDexFile(byte[] dexBytes) {
DexBackedDexFile dexFile = DexBackedDexFile.fromBuffer(Opcodes.getDefault(), dexBytes);
DexRewriter rewriter = new DexRewriter(new RewriterModule());
DexFile modifiedDexFile = rewriter.rewriteDexFile(dexFile);
}
jadx (Java):
public static void decompile(File inputFile, File outputDir) {
JadxArgs args = new JadxArgs();
args.setInputFile(inputFile);
args.setOutDir(outputDir);
JadxDecompiler jadx = new JadxDecompiler(args);
jadx.load();
jadx.save();
}
While Xpatch focuses on patching APK files to bypass signature verification, jadx is a more general-purpose decompiler and analyzer for Android applications. Xpatch is specifically designed for a single task, whereas jadx offers a broader range of features for reverse engineering and analysis of Android apps.
Virtual Engine for Android(Support 14.0 in business version)
Pros of VirtualApp
- More comprehensive virtualization solution, allowing multiple apps to run in a single process
- Supports a wider range of Android versions and features
- Active community and regular updates
Cons of VirtualApp
- More complex implementation and setup process
- Potentially higher resource usage due to its comprehensive nature
- May require more frequent updates to maintain compatibility
Code Comparison
VirtualApp:
@Override
public void onCreate() {
super.onCreate();
VirtualCore.get().setComponentDelegate(new MyComponentDelegate());
VirtualCore.get().setTaskDescriptionDelegate(new MyTaskDescriptionDelegate());
VirtualCore.get().setPhoneInfoDelegate(new MyPhoneInfoDelegate());
}
Xpatch:
public class XpatchApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
XpatchManager.getInstance().init(this);
}
}
The code snippets show that VirtualApp requires more setup and configuration, while Xpatch has a simpler initialization process. VirtualApp offers more customization options through delegates, whereas Xpatch focuses on a straightforward patching approach.
A Java 8+ Jar & Android APK Reverse Engineering Suite (Decompiler, Editor, Debugger & More)
Pros of bytecode-viewer
- More comprehensive Java bytecode analysis tool with multiple decompilers
- Supports a wider range of file formats, including JAR, CLASS, and APK
- Active development with frequent updates and bug fixes
Cons of bytecode-viewer
- Larger file size and more complex setup compared to Xpatch
- May be overwhelming for users who only need simple APK patching functionality
- Requires more system resources due to its extensive features
Code Comparison
Xpatch (simplified usage):
XpatchClient client = new XpatchClient();
client.patch("input.apk", "output.apk");
bytecode-viewer (simplified usage):
BytecodeViewer.start(new String[]{"input.jar"});
// GUI-based interaction for analysis and modification
Summary
Bytecode-viewer is a more powerful and versatile tool for Java bytecode analysis and modification, offering support for multiple file formats and decompilers. It's ideal for advanced users who require in-depth analysis capabilities. Xpatch, on the other hand, is more focused on APK patching and offers a simpler, more straightforward approach for users who primarily work with Android applications. The choice between the two depends on the specific needs of the user and the complexity of the tasks they need to perform.
A tool for reverse engineering Android apk files
Pros of Apktool
- More comprehensive feature set for APK manipulation
- Larger community and better documentation
- Supports both decompiling and recompiling APKs
Cons of Apktool
- Slower processing speed for large APKs
- More complex setup and usage for beginners
- Requires additional tools for certain operations
Code Comparison
Xpatch (Java):
public static void main(String[] args) {
XpatchClient client = new XpatchClient();
client.patch(apkFile, outputFile);
}
Apktool (Java):
public static void main(String[] args) {
ApktoolDecoder decoder = new ApktoolDecoder();
decoder.decode(apkFile, outputDir);
// Additional steps for modification and recompilation
}
Xpatch focuses on a streamlined patching process, while Apktool offers more granular control over APK manipulation. Xpatch provides a simpler API for quick patching, whereas Apktool requires additional steps for decompilation, modification, and recompilation. Apktool's approach allows for more extensive customization but at the cost of increased complexity.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
English Version
Android Appç ´è§£å·¥å ·Xpatchç使ç¨æ¹æ³
Xpatchæ¦è¿°
Xpatchç¨æ¥éæ°ç¾åæå Apkæ件ï¼ä½¿éæå åçApkè½å è½½å®è£ å¨ç³»ç»éçXposedæ件ï¼ä»èå®ç°å Root Hookä»»æAppã
Xpatchåºæ¬åç
Xpatchçåçæ¯å¯¹Apkæ件è¿è¡äºæ¬¡æå ï¼éæ°ç¾åï¼å¹¶çæä¸ä¸ªæ°çapkæ件ã å¨Apkäºæ¬¡æå è¿ç¨ä¸ï¼æå ¥å è½½Xposedæ件çé»è¾ï¼è¿æ ·ï¼æ°çApkæ件就å¯ä»¥å 载任æXposedæ件ï¼ä»èå®ç°å Root Hookä»»æAppçJava代ç ã
1.0~1.4çæ¬ï¼Hookæ¡æ¶ä½¿ç¨çæ¯Lodyçwhale
2.0çæ¬å¼å§ï¼Hookæ¡æ¶åºå±ä½¿ç¨çæ¯ganyao114çSandHookã
3.0çæ¬å¼å§ï¼é»è®¤ä½¿ç¨SandHookï¼åæ¶ï¼å
¼å®¹åæ¢ä¸ºwhale
Xpatchå·¥å ·å ä¸è½½
ä¸è½½ææ°çXpatch Jarå
æè
è¿å
¥Releases页é¢ä¸è½½æå®çæ¬ï¼releases
Xpatch Appçæ¬(Xposed Tool)ä¸è½½
XposedTool ä¸è½½XposedTool Apk
Xpatch使ç¨æ¹æ³
Xpatch项ç®æç»çæç©æ¯ä¸ä¸ªJarå ï¼æ¤Jar使ç¨èµ·æ¥é常ç®åï¼åªéè¦ä¸è¡å½ä»¤ï¼ä¸ä¸ªæ¥å ¥xposed hookåè½çapkå°±çæï¼
$ java -jar XpatchJarå
è·¯å¾ apkæ件路å¾
For example:
$ java -jar ../xpatch.jar ../Test.apk
è¿æ¡å½ä»¤ä¹åï¼å¨åapkæ件(Test.apk)ç¸åçæ件夹ä¸ï¼ä¼çæä¸ä¸ªå称为Test-xposed-signed.apk
çæ°apkï¼è¿å°±æ¯éæ°ç¾åä¹åçæ¯æxposedæ件çapkã
Note: ç±äºç¾åä¸åç¾åä¸ä¸è´ï¼å æ¤éè¦å å¸è½½æç³»ç»ä¸å·²ç»å®è£ çåapkï¼æè½å®è£ è¿ä¸ªXpatchåçapk
å½ç¶ï¼ä¹å¯ä»¥å¢å -o
åæ°ï¼æå®æ°apkçæçè·¯å¾ï¼
$ java -jar ../xpatch.jar ../Test.apk -o ../new-Test.apk
æ´å¤åæ°ç±»åå¯ä»¥ä½¿ç¨--helpæ¥çï¼æè ä¸è¾å ¥ä»»ä½åæ°è¿è¡jarå ï¼
$ java -jar ../xpatch.jar --h(å¯çç¥)
è¿è¡å½ä»¤ä¹åå¾å°ç»æ(v1.0-v2.0)ï¼
Please choose one apk file you want to process.
options:
-f,--force force overwrite
-h,--help Print this help message
-k,--keep not delete the jar file that is changed by dex2jar
and the apk zip files
-l,--log show all the debug logs
-o,--output <out-apk-file> output .apk file, default is $source_apk_dir/[file
-name]-xposed-signed.apk
Xposed模åå¼å ³æ§å¶ç两ç§æ¹æ³
1. æå¨ä¿®æ¹sdcardæ件æ§å¶æ¨¡åå¼å ³
å½æ°apkå®è£ å°ç³»ç»ä¹åï¼åºç¨å¯å¨æ¶ï¼é»è®¤ä¼å è½½ææå·²å®è£ çXposedæ件(Xposed Module)ã
ä¸è¬æ åµä¸ï¼Xposedæ件ä¸é½ä¼å¯¹å åè¿æ»¤ï¼æäºXposedæ件æçé¢ï¼å¹¶ä¸å¨çé¢ä¸å¯ä»¥è®¾ç½®å¼å ³ï¼æ以é»è®¤å¯ç¨ææçXposedæ件çæ¹å¼ï¼å¤§å¤æ°æ å½¢ä¸é½å¯è¡ã
ä½å¨å°æ°æ åµå¯è½ä¼åºç°é®é¢ï¼æ¯å¦ï¼åä¸ä¸ªåºç¨å®è£ æå¤ä¸ªXposedæ件ï¼wechatæ件就é常å¤ï¼ï¼å¹¶ä¸é½æ²¡æç¬ç«çå¼å ³çé¢ï¼åæ¶å¯ç¨è¿äºæ件å¯è½ä¼äº§çå²çªã
为äºè§£å³æ¤é®é¢ï¼å½åºç¨å¯å¨æ¶ï¼ä¼æ¥æ¾ç³»ç»ä¸ææå·²å®è£
çXposedæ件ï¼å¹¶å¨æ件ç®å½ä¸çæä¸ä¸ªæ件
mnt/sdcard/xposed_config/modules.list
ï¼è®°å½è¿äºXposedæ件Appã
æ¯å¦ï¼
com.blanke.mdwechat#MDWechat
com.example.wx_plug_in3#ç
ç©å¾®ä¿¡
liubaoyua.customtext#ææ¬èªå®ä¹
è®°å½çæ¹å¼æ¯ï¼æ件appå
å#æ件appå称
éè¦ç¦ç¨æ个æ件ï¼åªéè¦ä¿®æ¹æ¤æ件ï¼å¨è¯¥æ件å
ååé¢å¢å ä¸ä¸ª#
å·å³å¯ã
æ¯å¦ï¼éè¦ç¦ç¨ç
ç©å¾®ä¿¡
åææ¬èªå®ä¹
两个æ件ï¼åªéè¦ä¿®æ¹è¯¥ææ¬æ件ï¼å¢å ä¸ä¸ª#
å·å³å¯ï¼
com.blanke.mdwechat#MDWechat
#com.example.wx_plug_in3#ç
ç©å¾®ä¿¡
#liubaoyua.customtext#ææ¬èªå®ä¹
å¦æéè¦ç¦ç¨æææ件ï¼åªéå¨ææçå
ååé¢å¢å #
ã
注æ: æäºApp没æè·åå°sdå¡æ件读åæéï¼è¿ä¼å¯¼è´æ æ³è¯»åmodules.listé ç½®æ件ï¼æ¤æ¶ä¼é»è®¤å¯ç¨æææ件ãè¿ç§æ åµä¸ï¼éè¦æå¨æå¼appçæ件读åæéã
2. éè¿Xposed Tool Appæ§å¶æ¨¡åå¼å ³
ä¸è½½å¹¶å®è£
Xpatch Appï¼Xposed Toolï¼
ç¹æä¸è½½XposedTool Apk
éè¿Xposed模å管ç
页é¢æ¥æ§å¶æ¨¡åå¼å
³ãï¼åçè·æ¹æ³1ä¸è´ï¼
å¯ç¨çXposed模å示ä¾
- MDWechat
- ææ¬èªå®ä¹
- ä½ èªå·±ç¼åçXposed模å
å ¶ä»
assetsç®å½ä¸çclasses.dexæ¯æ¥å 载设å¤ä¸å·²å®è£
çXposedæ件ï¼å
¶æºä»£ç ä¹å·²ç»å¼æºï¼
xposed_module_loader
欢è¿star and fork.
å±éæ§
Xpatchæ¯åºäºapkäºæ¬¡æå å®ç°çï¼èä¸ä½¿ç¨å°äºdex2Jarå·¥å ·ï¼å æ¤ï¼ä¹åå¨ä¸å°çå±éæ§ã大æ¦æ以ä¸å ç¹ï¼
- Hookæ¡æ¶é»è®¤ä½¿ç¨çæ¯SandHookï¼æ¤æ¡æ¶åå¨ä¸äºä¸ç¨³å®æ§ï¼å¨å°æ°æºåä¸hookå¯è½ä¼å´©æºã
- 对äºæ ¡éªäºæ件å®æ´æ§çappï¼éæå åå¯è½æ æ³å¯å¨ï¼
- Xposed Hookæ¡æ¶ææ¶ä¸æ¯æDalvikèææºã
- ææ¶ä¸æ¯æXposedæ件ä¸çèµæºHookã
Technology Discussion
QQ Group: 741998508
or
Post comments under this article: Xpatch: å
Rootå®ç°Appå è½½Xposedæ件çä¸ç§æ¹æ¡
åè½æ´æ°
1. 2019/4/15 updated
å¢å èªå¨ç ´è§£ç¾åæ£éªçåè½ï¼æ¤åè½é»è®¤å¼å¯ï¼å¦æéè¦å
³éå¯ä»¥å¢å -c
å³å¯ï¼æ¯å¦ï¼
$ java -jar ../xpatch.jar ../Test.apk -c
éè¿help(-h)å¯ä»¥æ¥çå°:
options:
-c,--crach disable craching the apk's signature.
2. 2019/4/25 updated
å¢å å°Xposed modulesæå å°apkä¸çåè½ éè¿help(-h)å¯ä»¥æ¥çå°:
-xm,--xposed-modules
the xposed mpdule files to be packaged into the ap k, multi files should be seperated by :(mac) or ;( win)
使ç¨æ¹å¼ä¸ºå¨å½ä»¤åé¢å¢å -xm path
å³å¯ï¼æ¯å¦ï¼
$ java -jar ../xpatch.jar ../source.apk -xm ../module1.apk
åå¦éè¦å°å¤ä¸ªXposedæ件æå è¿å»ï¼å¨Macä¸ä½¿ç¨":"ï¼å¨Windowsä¸ä½¿ç¨";"ï¼éå¼å¤ä¸ªæ件路å¾å³å¯ï¼æ¯å¦ï¼
mac
$ java -jar ../xpatch.jar ../source.apk -xm ../module1.apk:../module2.apk
windows
$ java -jar ../xpatch.jar ../source.apk -xm ../module1.apk;../module2.apk
注æï¼
- å¤ä¸ªXposed modules使ç¨
:
(mac)/;
(win)åå²; - åå¦æ¤moduleæ¢è¢«æå å°apkä¸ï¼åå®è£ å¨è®¾å¤ä¸ï¼ååªä¼å è½½æå å°apkä¸çmoduleï¼ä¸ä¼å è½½å®è£ çã è¿éæ¯éè¿å ååºåæ¯ä¸æ¯åä¸ä¸ªmoduleã
3. 2020/02/09 updated (Version 3.0)
3.0çæ¬å¢å äºä¸å°æ°åè½ï¼åæ¶ä¿®å¤äºä¸äºç¨æ·åé¦çBugã
æ°å¢åè½ï¼
- æ¯æandroid 10;
- æ¯ææ´æ¹æ¤å ¥çhookæ¡æ¶ï¼é»è®¤ä½¿ç¨Sandhook(æ¯æandroid10)ï¼å¯æ´æ¹ä¸ºwhale(æä¸æ¯æandroid10)(-w);
- é»è®¤ä½¿ç¨ä¿®æ¹Maniestæ件æ¹å¼ï¼æ¤å ¥åå§å代ç ï¼åæ¶ï¼æ¯ææ´æ¹ä¸ºèçæ¬ä¸çä¿®æ¹dexæ件çæ¹å¼æ¤å ¥ä»£ç (-dex)ï¼
- æ¯æä¿®æ¹apkå åï¼ä¸è¬ä¸å»ºè®®ä½¿ç¨ï¼å¾å¤åºç¨ä¼æ ¡éªå åï¼ä¼å¯¼è´æ æ³ä½¿ç¨ï¼
- æ¯æä¿®æ¹apkçversion code;
- æ¯æä¿®æ¹apkçversion name;
- æ¯æä¿®æ¹apkçdebuggable为trueæè false;
Bugä¿®å¤ï¼
- ä¿®å¤Manifestæ件ä¸æªå®ä¹ApplicationNameç±»ï¼å¯¼è´æ æ³å®ç°Hookçé®é¢;
- ä¿®å¤ç ´è§£æ soæ件çapkæ¶ï¼åºç°æ æ³æ¾å°soçé®é¢;
- ä¿®å¤ç¾åå¯è½ä¼å¤±è´¥çé®é¢ï¼
- ä¿®å¤dexæ件æ°è¶ è¿65536çé®é¢ï¼
æ°åè½ç¨æ³
å¨å½ä»¤è¡ä¸è¾å
¥-hï¼å¯ä»¥çå°3.0çæ¬å®æ´ç帮å©ææ¡£ï¼
$ java -jar ../xpatch-3.0.jar -h
options:
-c,--crach disable craching the apk's signature.
-d,--debuggable <0 or 1> set 1 to make the app debuggable = true, set 0 to
make the app debuggable = false
-dex,--dex insert code into the dex file, not modify manifest
application name attribute
-f,--force force overwrite
-h,--help Print this help message
-k,--keep not delete the jar file that is changed by dex2jar
and the apk zip files
-l,--log show all the debug logs
-o,--output <out-apk-file> output .apk file, default is $source_apk_dir/[file
-name]-xposed-signed.apk
-pkg,--packageName <new package name>modify the apk package name
-vc,--versionCode <new-version-code>set the app version code
-vn,--versionName <new-version-name>set the app version name
-w,--whale Change hook framework to Lody's whale
-xm,--xposed-modules <xposed module file path>
the xposed module files to be packaged into the ap
k, multi files should be seperated by :(mac) or ;(
win)
version: 3.0
å ·ä½ç¨æ³ï¼
- ä¿®æ¹Apkçdebuggable = trueï¼
$ java -jar ../xpatch-3.0.jar ../Test.apk -d 1
ï¼falseæ¹ä¸º0ï¼ - 使ç¨èçæ¬çç ´è§£dexæ¹æ³ç ´è§£apkï¼
$ java -jar ../xpatch-3.0.jar ../Test.apk -dex
- ä¿®æ¹å
åï¼çæ¬å·ï¼
$ java -jar ../xpatch-3.0.jar ../Test.apk -pkg com.test.test -vc 1000 -vn 1.1.1
- æ´æ¹Hookæ¡æ¶ä¸ºwhaleï¼
$ java -jar ../xpatch-3.0.jar ../Test.apk -w
4. 2021/01/13 updated (Version 4.0)
Update SandHook to the newest version and SandHook support the Android 11.
Thanks
Top Related Projects
Tools to work with android .dex and java .class files
smali/baksmali
Dex to Java decompiler
Virtual Engine for Android(Support 14.0 in business version)
A Java 8+ Jar & Android APK Reverse Engineering Suite (Decompiler, Editor, Debugger & More)
A tool for reverse engineering Android apk files
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot