remove unstable features
This commit is contained in:
parent
cadd0e565e
commit
49a39ab7ed
Binary file not shown.
|
|
@ -3,7 +3,6 @@ package com.storm.wind.xpatch;
|
||||||
import static org.apache.commons.io.FileUtils.copyFile;
|
import static org.apache.commons.io.FileUtils.copyFile;
|
||||||
|
|
||||||
import com.storm.wind.xpatch.base.BaseCommand;
|
import com.storm.wind.xpatch.base.BaseCommand;
|
||||||
import com.storm.wind.xpatch.task.ApkModifyTask;
|
|
||||||
import com.storm.wind.xpatch.task.BuildAndSignApkTask;
|
import com.storm.wind.xpatch.task.BuildAndSignApkTask;
|
||||||
import com.storm.wind.xpatch.task.SaveApkSignatureTask;
|
import com.storm.wind.xpatch.task.SaveApkSignatureTask;
|
||||||
import com.storm.wind.xpatch.task.SaveOriginalApplicationNameTask;
|
import com.storm.wind.xpatch.task.SaveOriginalApplicationNameTask;
|
||||||
|
|
@ -43,24 +42,10 @@ public class MainCommand extends BaseCommand {
|
||||||
description = "disable craching the apk's signature.")
|
description = "disable craching the apk's signature.")
|
||||||
private boolean disableCrackSignature = false;
|
private boolean disableCrackSignature = false;
|
||||||
|
|
||||||
@Opt(opt = "dex", longOpt = "dex", hasArg = false, description = "insert code into the dex file, not modify manifest application name attribute")
|
|
||||||
private boolean dexModificationMode = false;
|
|
||||||
|
|
||||||
@Opt(opt = "pkg", longOpt = "packageName", description = "modify the apk package name", argName = "new package name")
|
|
||||||
private String newPackageName;
|
|
||||||
|
|
||||||
@Opt(opt = "d", longOpt = "debuggable", description = "set 1 to make the app debuggable = true, " +
|
@Opt(opt = "d", longOpt = "debuggable", description = "set 1 to make the app debuggable = true, " +
|
||||||
"set 0 to make the app debuggable = false", argName = "0 or 1")
|
"set 0 to make the app debuggable = false", argName = "0 or 1")
|
||||||
private int debuggable = -1; // 0: debuggable = false 1: debuggable = true
|
private int debuggable = -1; // 0: debuggable = false 1: debuggable = true
|
||||||
|
|
||||||
@Opt(opt = "vc", longOpt = "versionCode", description = "set the app version code",
|
|
||||||
argName = "new-version-code")
|
|
||||||
private int versionCode;
|
|
||||||
|
|
||||||
@Opt(opt = "vn", longOpt = "versionName", description = "set the app version name",
|
|
||||||
argName = "new-version-name")
|
|
||||||
private String versionName;
|
|
||||||
|
|
||||||
private int dexFileCount = 0;
|
private int dexFileCount = 0;
|
||||||
|
|
||||||
private static final String UNZIP_APK_FILE_NAME = "apk-unzip-files";
|
private static final String UNZIP_APK_FILE_NAME = "apk-unzip-files";
|
||||||
|
|
@ -185,12 +170,6 @@ public class MainCommand extends BaseCommand {
|
||||||
mXpatchTasks.add(new SaveOriginalApplicationNameTask(applicationName, unzipApkFilePath));
|
mXpatchTasks.add(new SaveOriginalApplicationNameTask(applicationName, unzipApkFilePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
// modify the apk dex file to make xposed can run in it
|
|
||||||
if (dexModificationMode && isNotEmpty(applicationName)) {
|
|
||||||
mXpatchTasks.add(new ApkModifyTask(true, true, unzipApkFilePath, applicationName,
|
|
||||||
dexFileCount));
|
|
||||||
}
|
|
||||||
|
|
||||||
// copy xposed so and dex files into the unzipped apk
|
// copy xposed so and dex files into the unzipped apk
|
||||||
mXpatchTasks.add(new SoAndDexCopyTask(dexFileCount, unzipApkFilePath));
|
mXpatchTasks.add(new SoAndDexCopyTask(dexFileCount, unzipApkFilePath));
|
||||||
|
|
||||||
|
|
@ -216,20 +195,6 @@ public class MainCommand extends BaseCommand {
|
||||||
private void modifyManifestFile(String filePath, String dstFilePath, String originalApplicationName) {
|
private void modifyManifestFile(String filePath, String dstFilePath, String originalApplicationName) {
|
||||||
ModificationProperty property = new ModificationProperty();
|
ModificationProperty property = new ModificationProperty();
|
||||||
boolean modifyEnabled = false;
|
boolean modifyEnabled = false;
|
||||||
if (isNotEmpty(newPackageName)) {
|
|
||||||
modifyEnabled = true;
|
|
||||||
property.addManifestAttribute(new AttributeItem(NodeValue.Manifest.PACKAGE, newPackageName).setNamespace(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (versionCode > 0) {
|
|
||||||
modifyEnabled = true;
|
|
||||||
property.addManifestAttribute(new AttributeItem(NodeValue.Manifest.VERSION_CODE, versionCode));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isNotEmpty(versionName)) {
|
|
||||||
modifyEnabled = true;
|
|
||||||
property.addManifestAttribute(new AttributeItem(NodeValue.Manifest.VERSION_NAME, versionName));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (debuggable >= 0) {
|
if (debuggable >= 0) {
|
||||||
modifyEnabled = true;
|
modifyEnabled = true;
|
||||||
|
|
@ -238,15 +203,11 @@ public class MainCommand extends BaseCommand {
|
||||||
|
|
||||||
property.addApplicationAttribute(new AttributeItem("extractNativeLibs", true));
|
property.addApplicationAttribute(new AttributeItem("extractNativeLibs", true));
|
||||||
|
|
||||||
if (!dexModificationMode || !isNotEmpty(originalApplicationName)) {
|
|
||||||
modifyEnabled = true;
|
modifyEnabled = true;
|
||||||
property.addApplicationAttribute(new AttributeItem(NodeValue.Application.NAME, proxyname));
|
property.addApplicationAttribute(new AttributeItem(NodeValue.Application.NAME, proxyname));
|
||||||
}
|
|
||||||
|
|
||||||
if (modifyEnabled) {
|
|
||||||
FileProcesser.processManifestFile(filePath, dstFilePath, property);
|
FileProcesser.processManifestFile(filePath, dstFilePath, property);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private int findDexFileCount(String unzipApkFilePath) {
|
private int findDexFileCount(String unzipApkFilePath) {
|
||||||
File zipfileRoot = new File(unzipApkFilePath);
|
File zipfileRoot = new File(unzipApkFilePath);
|
||||||
|
|
@ -268,6 +229,7 @@ public class MainCommand extends BaseCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the current timestamp as the name of the build file
|
// Use the current timestamp as the name of the build file
|
||||||
|
@SuppressWarnings("SimpleDateFormat")
|
||||||
private String currentTimeStr() {
|
private String currentTimeStr() {
|
||||||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
|
||||||
return df.format(new Date());
|
return df.format(new Date());
|
||||||
|
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
package com.storm.wind.xpatch.task;
|
|
||||||
|
|
||||||
import com.googlecode.dex2jar.tools.Dex2jarCmd;
|
|
||||||
import com.googlecode.dex2jar.tools.Jar2Dex;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Wind
|
|
||||||
*/
|
|
||||||
public class ApkModifyTask implements Runnable {
|
|
||||||
|
|
||||||
private static final String JAR_FILE_NAME = "output-jar.jar";
|
|
||||||
|
|
||||||
private String unzipApkFilePath;
|
|
||||||
private boolean keepJarFile;
|
|
||||||
private boolean showAllLogs;
|
|
||||||
private String applicationName;
|
|
||||||
|
|
||||||
private int dexFileCount;
|
|
||||||
|
|
||||||
public ApkModifyTask(boolean showAllLogs, boolean keepJarFile, String unzipApkFilePath, String applicationName, int
|
|
||||||
dexFileCount) {
|
|
||||||
this.showAllLogs = showAllLogs;
|
|
||||||
this.unzipApkFilePath = unzipApkFilePath;
|
|
||||||
this.keepJarFile = keepJarFile;
|
|
||||||
this.applicationName = applicationName;
|
|
||||||
this.dexFileCount = dexFileCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
File unzipApkFile = new File(unzipApkFilePath);
|
|
||||||
|
|
||||||
String jarOutputPath = unzipApkFile.getParent() + File.separator + JAR_FILE_NAME;
|
|
||||||
|
|
||||||
// classes.dex
|
|
||||||
String targetDexFileName = dumpJarFile(dexFileCount, unzipApkFilePath, jarOutputPath, applicationName);
|
|
||||||
|
|
||||||
if (showAllLogs) {
|
|
||||||
System.out.println(" the application class is in this dex file = " + targetDexFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
String dexOutputPath = unzipApkFilePath + targetDexFileName;
|
|
||||||
File dexFile = new File(dexOutputPath);
|
|
||||||
if (dexFile.exists()) {
|
|
||||||
dexFile.delete();
|
|
||||||
}
|
|
||||||
// 将jar转换为dex文件
|
|
||||||
jar2DexCmd(jarOutputPath, dexOutputPath);
|
|
||||||
|
|
||||||
// 删除掉jar文件
|
|
||||||
File jarFile = new File(jarOutputPath);
|
|
||||||
if (!keepJarFile && jarFile.exists()) {
|
|
||||||
jarFile.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private String dumpJarFile(int dexFileCount, String dexFilePath, String jarOutputPath, String applicationName) {
|
|
||||||
ArrayList<String> dexFileList = createClassesDotDexFileList(dexFileCount);
|
|
||||||
// String jarOutputPath = dexFilePath + JAR_FILE_NAME;
|
|
||||||
for (String dexFileName : dexFileList) {
|
|
||||||
String filePath = dexFilePath + dexFileName;
|
|
||||||
// 执行dex2jar命令,修改源代码
|
|
||||||
boolean isApplicationClassFound = dex2JarCmd(filePath, jarOutputPath, applicationName);
|
|
||||||
// 找到了目标应用主application的包名,说明代码注入成功,则返回当前dex文件
|
|
||||||
if (isApplicationClassFound) {
|
|
||||||
return dexFileName;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean dex2JarCmd(String dexPath, String jarOutputPath, String applicationName) {
|
|
||||||
Dex2jarCmd cmd = new Dex2jarCmd();
|
|
||||||
String[] args = new String[]{
|
|
||||||
dexPath,
|
|
||||||
"-o",
|
|
||||||
jarOutputPath,
|
|
||||||
"-app",
|
|
||||||
applicationName,
|
|
||||||
"--force"
|
|
||||||
};
|
|
||||||
cmd.doMain(args);
|
|
||||||
|
|
||||||
boolean isApplicationClassFounded = cmd.isApplicationClassFounded();
|
|
||||||
if (showAllLogs) {
|
|
||||||
System.out.println("isApplicationClassFounded -> " + isApplicationClassFounded + "the dexPath is " +
|
|
||||||
dexPath);
|
|
||||||
}
|
|
||||||
return isApplicationClassFounded;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void jar2DexCmd(String jarFilePath, String dexOutPath) {
|
|
||||||
Jar2Dex cmd = new Jar2Dex();
|
|
||||||
String[] args = new String[]{
|
|
||||||
jarFilePath,
|
|
||||||
"-o",
|
|
||||||
dexOutPath
|
|
||||||
};
|
|
||||||
cmd.doMain(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 列出目录下所有dex文件,classes.dex,classes2.dex,classes3.dex .....
|
|
||||||
private ArrayList<String> createClassesDotDexFileList(int dexFileCount) {
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
for (int i = 0; i < dexFileCount; i++) {
|
|
||||||
if (i == 0) {
|
|
||||||
list.add("classes.dex");
|
|
||||||
} else {
|
|
||||||
list.add("classes" + (i + 1) + ".dex");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue