forked from chago/ADVMP
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
主要更新控制中心的代码,使其可以对一个apk进行加固。把jni的存放目录移动了一个位置。
- Loading branch information
Showing
45 changed files
with
547 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,26 @@ | ||
include $(call all-subdir-makefiles) | ||
ADVMPC_PATH := ../../template/jni/advmpc | ||
|
||
LOCAL_PATH := $(call my-dir) | ||
|
||
include $(CLEAR_VARS) | ||
|
||
LOCAL_MODULE := advmpc | ||
|
||
LOCAL_C_INCLUDES := $(ADVMPC_PATH) | ||
|
||
LOCAL_SRC_FILES := $(ADVMPC_PATH)/ioapi.c \ | ||
$(ADVMPC_PATH)/unzip.c \ | ||
$(ADVMPC_PATH)/Globals.cpp \ | ||
$(ADVMPC_PATH)/avmp.cpp \ | ||
$(ADVMPC_PATH)/BitConvert.cpp \ | ||
$(ADVMPC_PATH)/InterpC.cpp \ | ||
$(ADVMPC_PATH)/io.cpp \ | ||
$(ADVMPC_PATH)/Utils.cpp \ | ||
$(ADVMPC_PATH)/YcFile.cpp | ||
|
||
LOCAL_SRC_FILES += $(ADVMPC_PATH)/DexOpcodes.cpp \ | ||
$(ADVMPC_PATH)/Exception.cpp | ||
|
||
LOCAL_LDLIBS := -llog -lz | ||
|
||
include $(BUILD_SHARED_LIBRARY) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,54 @@ | ||
package buwai.android.shell.base; | ||
|
||
import java.io.*; | ||
|
||
/** | ||
* Created by buwai on 25/4/1. | ||
*/ | ||
public class Utils { | ||
|
||
/** | ||
* 复制整个文件夹内容 | ||
* | ||
* @param oldPath String 原文件路径 如:c:/fqf | ||
* @param newPath String 复制后路径 如:f:/fqf/ff | ||
* @return boolean | ||
*/ | ||
public static void copyFolder(String oldPath, String newPath) throws IOException { | ||
|
||
(new File(newPath)).mkdirs(); // 如果文件夹不存在 则建立新文件夹 | ||
File a = new File(oldPath); | ||
String[] file = a.list(); | ||
File temp = null; | ||
|
||
for (int i = 0; i < file.length; i++) { | ||
if (oldPath.endsWith(File.separator)) { | ||
temp = new File(oldPath + file[i]); | ||
} else { | ||
temp = new File(oldPath + File.separator + file[i]); | ||
} | ||
|
||
if (temp.isFile()) { | ||
try (FileInputStream input = new FileInputStream(temp); | ||
FileOutputStream output = new FileOutputStream(newPath | ||
+ "/" + (temp.getName()).toString())) { | ||
|
||
byte[] b = new byte[1024 * 5]; | ||
int len; | ||
while ((len = input.read(b)) != -1) { | ||
output.write(b, 0, len); | ||
} | ||
output.flush(); | ||
output.close(); | ||
input.close(); | ||
} | ||
} | ||
if (temp.isDirectory()) {// 如果是子文件夹 | ||
copyFolder(oldPath + "/" + file[i], newPath + "/" + file[i]); | ||
} | ||
} | ||
|
||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 71 additions & 13 deletions
84
control-centre/src/main/java/buwai/android/shell/controlcentre/ControlCentre.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,101 @@ | ||
package buwai.android.shell.controlcentre; | ||
|
||
import buwai.android.shell.base.TypeDescription; | ||
import buwai.android.shell.base.Utils; | ||
import buwai.android.shell.base.ZipHelper; | ||
import buwai.android.shell.base.helper.AndroidManifestHelper; | ||
import buwai.android.shell.separator.InstructionInsert01; | ||
import buwai.android.shell.separator.Separator; | ||
import buwai.android.shell.separator.SeparatorOption; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
|
||
/** | ||
* Created by Neptunian on 2015/4/1. | ||
*/ | ||
public class ControlCentre { | ||
|
||
private File mApkFile; | ||
private File mOutDir; | ||
private File mWorkspace; | ||
private ControlCentreOption mOpt; | ||
private File mApkUnpackDir; | ||
|
||
public ControlCentre(File src, File outDir) throws IOException { | ||
mApkFile = src; | ||
mOutDir = outDir; | ||
public ControlCentre(ControlCentreOption opt) throws IOException { | ||
mOpt = opt; | ||
prepare(); | ||
} | ||
|
||
/** | ||
* 做一些准备工作。 | ||
*/ | ||
private void prepare() throws IOException { | ||
// 创建工作目录。 | ||
mWorkspace = Files.createTempDirectory(mOutDir.toPath(), "advmp").toFile(); | ||
mApkUnpackDir = new File(mOpt.workspace, "apk"); | ||
mApkUnpackDir.mkdir(); | ||
|
||
// 解压缩apk中的classes.dex文件。 | ||
ZipHelper.unZipSingle(mApkFile, mWorkspace, "classes.dex"); | ||
ZipHelper.unZipSingle(mOpt.apkFile, new File(mApkUnpackDir, "classes.dex"), "classes.dex"); | ||
|
||
// 解压缩apk中的AndroidManifest.xml文件。 | ||
ZipHelper.unZipSingle(mOpt.apkFile, new File(mApkUnpackDir, "AndroidManifest.xml"), "AndroidManifest.xml"); | ||
} | ||
|
||
/** | ||
* 加壳。 | ||
* @return | ||
*/ | ||
// public boolean shell() { | ||
// | ||
// } | ||
public boolean shell() { | ||
boolean bRet = false; | ||
try { | ||
// 插入指令。 | ||
TypeDescription classDesc = AndroidManifestHelper.findFirstClass(new File(mApkUnpackDir, "AndroidManifest.xml")); | ||
InstructionInsert01 instructionInsert01 = new InstructionInsert01(new File(mApkUnpackDir, "classes.dex"), classDesc); | ||
instructionInsert01.insert(); | ||
|
||
runSeparator(); | ||
|
||
copyJniFiles(); | ||
|
||
|
||
|
||
bRet = true; | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
return bRet; | ||
} | ||
|
||
/** | ||
* 运行抽取器。 | ||
* @return | ||
* @throws IOException | ||
*/ | ||
private boolean runSeparator() throws IOException { | ||
SeparatorOption opt = new SeparatorOption(); | ||
opt.dexFile = new File(mApkUnpackDir, "classes.dex"); | ||
File outDir = new File(mOpt.workspace, "separator"); | ||
opt.outDexFile = new File(outDir, "classes.dex"); | ||
opt.outYcFile = new File(outDir, "classes.yc"); | ||
opt.outCPFile = new File(outDir, "advmp_separator.cpp"); | ||
|
||
Separator separator = new Separator(opt); | ||
return separator.run(); | ||
} | ||
|
||
/** | ||
* 将template中的jni目录拷贝到工作目录。 | ||
* @throws IOException | ||
*/ | ||
private void copyJniFiles() throws IOException { | ||
// TODO 这里写死了。 | ||
File jniTemplateDir = new File("E:\\MyProjects\\ADVMP\\template\\jni"); | ||
mOpt.jniDir = new File(mOpt.workspace, "jni"); | ||
Utils.copyFolder(jniTemplateDir.getAbsolutePath(), mOpt.jniDir.getAbsolutePath()); | ||
} | ||
|
||
/** | ||
* 更新jni目录中的文件。 | ||
*/ | ||
private void updateJniFiles() { | ||
File file = new File(mOpt.jniDir.getAbsolutePath() + File.separator + ) | ||
} | ||
|
||
} |
Oops, something went wrong.