Skip to content

Commit

Permalink
修复没有resource.arsc的aar包,删除旧的sdk代码需要指定codepath和keepdir
Browse files Browse the repository at this point in the history
  • Loading branch information
dyglcc committed Apr 15, 2020
2 parents 23b1c0b + 63fa2e6 commit b44fe93
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 46 deletions.
Empty file added abc
Empty file.
30 changes: 15 additions & 15 deletions brut.apktool/apktool-cli/src/main/java/brut/apktool/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public static void main(String[] args) throws Exception {

private static void cmdMerge(CommandLine cli) throws Exception {
int paraCount = cli.getArgList().size();
String aarFileName = cli.getArgList().get(paraCount - 2);
String apkFile = cli.getArgList().get(paraCount - 3);
String aarFileName = cli.getArgList().get(paraCount - 2);
String initCodeFile = cli.getArgList().get(paraCount - 1);

// String sdk_type = null;
Expand Down Expand Up @@ -198,15 +198,15 @@ private static void cmdMerge(CommandLine cli) throws Exception {
operOptions.put("sde",true);
}
//// String uploadUrl = "https://arkpaastest.analysys.cn:4089";
if (cli.hasOption("ousc") || cli.hasOption("only-update-source-code")) {
String upuV = cli.getOptionValue("ousc");
Utils.ParaUtils.checkCmdliPara("ousc",upuV);
operOptions.put("ousc",upuV);
if (cli.hasOption("codePath") || cli.hasOption("dir-to-del-before-inject-sdk")) {
String codPath = cli.getOptionValue("codePath");
Utils.ParaUtils.checkCmdliPara("codePath",codPath);
operOptions.put("codePath",codPath);
}
if (cli.hasOption("exclude") || cli.hasOption("excludeDir")) {
String except = cli.getOptionValue("exclude");
Utils.ParaUtils.checkCmdliPara("excludeDir",except);
operOptions.put("exclude",except);
if (cli.hasOption("keepDir") || cli.hasOption("del-code-path-keep-dir")) {
String except = cli.getOptionValue("keepDir");
Utils.ParaUtils.checkCmdliPara("keepDir",except);
operOptions.put("keepDir",except);
}
//// String debugUrl ="wss://arkpaastest.analysys.cn:4091";
// if (cli.hasOption("deu") || cli.hasOption("debugUrl")) {
Expand Down Expand Up @@ -670,15 +670,15 @@ private static void _Options() {
.build();
//
//// String uploadUrl = "https://arkpaastest.analysys.cn:4089";
Option uploadUrlOption = Option.builder("ousc")
.longOpt("only-update-source-code")
.desc("仅仅更新代码")
Option uploadUrlOption = Option.builder("codePath")
.longOpt("dir-to-del-before-inject-sdk")
.desc("用于代码更新,合并之前要删除指定的路径下的代码文件 例如:com.adhoc")
.argName("tag")
.hasArg(true)
.build();
Option upgradeExcepDir = Option.builder("exclude")
.longOpt("excludeDir")
.desc("升级sdk删除旧目录但不包含目录")
Option upgradeExcepDir = Option.builder("keepDir")
.longOpt("del-code-path-keep-dir")
.desc("用于代码更新,删除旧代码,但是想保留的子目录 例如:visual(将会保留com.adhoc下面的visual目录)")
.argName("tag")
.hasArg(true)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ private void unzipCompiledTmpApk() throws IOException {
@Override
public void mergeArscFile() throws Exception {
AndrolibResources resources = new AndrolibResources();
ResTable aarTableTable = resources.getResTable(new ExtFile(getTmpApkFile()));
File apkFile = getTmpApkFile();
if(!Utils.findArsc(apkFile)){
return;
}
ResTable aarTableTable = resources.getResTable(new ExtFile(apkFile));
MergeArsc.mergeAarTable2HostTable(mHostTable,aarTableTable);
WriterNp.write(new File(hostDir,"resources.arsc"),mHostTable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public class ReflectionOper {
private final static Logger LOGGER = Logger.getLogger(ReflectionOper.class.getName());
private HashMap<String, Object> options;
String stubDir = "com.reverse.stub";
private String SDK_DIR = "com.analysys";//代码路径
// private String SDK_DIR = "com.analysys";//代码路径
private String SDK_DIR = null;//代码路径 比如吆喝科技的A/BTest代码路径是com.adhoc
private String exclue = "track";//路径路径下面有子项目不能删除
private static final String appNameStub = "com.reverse.stub.ReverseApp";
// private File jsonFile;
Expand Down Expand Up @@ -248,44 +249,41 @@ private InputStream getAssetsCodeMethodInit() {

// 删除旧sdk 的smali文件 // upgrade sdk may be useful
public void deleteOldSdkSmaliFile(File hostdir, List<File> aarSmaliFolder, XmlParser hostAndmanifestData) throws Exception {
String path = SDK_DIR;
String path = null;
String excludeSDKdir = exclue;
if (options != null) {
if (options.get("exclude") != null) {
excludeSDKdir = (String) options.get("exclude");
}
if (options.get("ousc") != null) {
path = (String) options.get("ousc");
}
if (options.get("keepDir") != null) {
excludeSDKdir = (String) options.get("exclude");
}

if (path == null || path.equals("")) {
throw new Exception("旧的SDK路径不存在");
}
if (!hostdir.exists()) {
throw new Exception("host dir 不存在");
if (options.get("codePath") != null) {
path = (String) options.get("codePath");
}
path = path.replaceAll("\\.", File.separator);
for (File file : Objects.requireNonNull(hostdir.listFiles())) {
String fileName = file.getName();
if (fileName.startsWith("smali") && !fileNameInList(fileName, aarSmaliFolder)) { // 新生成的sdk smali不删除
File existOldSdkdir = new File(file, path);
if (existOldSdkdir.exists()) {
for (File fileYiguan : Objects.requireNonNull(existOldSdkdir.listFiles())) {
if (!fileYiguan.getName().equals(excludeSDKdir)) {
LOGGER.info("删除旧的SDK目录" + existOldSdkdir.getAbsolutePath());
if (fileYiguan.isFile()) {
OS.rmfile(fileYiguan.getAbsolutePath());
} else {
OS.rmdir(fileYiguan);

if (path != null) { // code path 不未空就删除就代码,否则不做删除旧代码操作。
if (!hostdir.exists()) {
throw new Exception("host dir 不存在");
}
path = path.replaceAll("\\.", File.separator);
for (File file : Objects.requireNonNull(hostdir.listFiles())) {
String fileName = file.getName();
if (fileName.startsWith("smali") && !fileNameInList(fileName, aarSmaliFolder)) { // 新生成的sdk smali不删除
File existOldSdkdir = new File(file, path);
if (existOldSdkdir.exists()) {
for (File fileYiguan : Objects.requireNonNull(existOldSdkdir.listFiles())) {
if (!fileYiguan.getName().equals(excludeSDKdir)) {
LOGGER.info("删除旧的SDK目录" + existOldSdkdir.getAbsolutePath());
if (fileYiguan.isFile()) {
OS.rmfile(fileYiguan.getAbsolutePath());
} else {
OS.rmdir(fileYiguan);
}
}
}
}

}
}
}
}
if (options == null || options.get("upg") == null) {
if (options.get("upg") == null) {
this.addOrModifyApplicationSmali(hostdir, aarSmaliFolder, hostAndmanifestData);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static String getNameRemovedSuffix(String name) {

}

public static boolean findArsc(File apkFile) throws IOException {
return Utils.FileUtils.getZipEntryFile("resource.arsc", apkFile) != null;
}

public static class OSCMD {
private final static Logger LOGGER = Logger.getLogger(AarManager.class.getName());

Expand Down
38 changes: 38 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

1.读取host arsc文件
2。读取aar文件的arsc文件
3。合并到宿主aar文件中,保存被替换的id mapping 文件
4。写入arsc文件,检查是否正确
5。读取aar xml文件,并替换成新的id
6,合并AndroidManifesst文件。
7。合并smali文件

可以运行的app
爱奇艺、拼多多。
已知问题:
1。adhoc sdk没有更新功能
京东打包成功却运行不起来。
小红书不能运行,

需求列表
1。仅仅更新代码。

merge -ousc com.adhoc -exclude abc /Users/dongyuangui/Desktop/apk-blue/lingdandaren-release.apk /Users/dongyuangui/Desktop/aar-1/abtest-release.aar /Users/dongyuangui/Desktop/apk-blue/reverse_init_code.txt
merge -ousc com.adhoc -exclude abc /Users/dongyuangui/Desktop/apk-blue/lingdandaren-release.apk /Users/dongyuangui/Desktop/aar-1/riskmanager-release.aar /Users/dongyuangui/Desktop/apk-blue/reverse_init_code.txt
java -jar ~/work/apktool_2.4.1.jar d -f -only-main-classes signed1584858989429.apk

merge -ousc com.android.reyunsdk -exclude abc /Users/dongyuangui/Desktop/apk-blue/lingdan-fixed.apk /Users/dongyuangui/Desktop/aar-1/riskmanager-release.aar /Users/dongyuangui/Desktop/apk-blue/reverse_init_code.txt


2。debugable
3。mobileqq旧版R.raw ,暂时找不到问题原因,可以通过分析android studio的arsc报错原因找到相应代码错误的地方,推测问题。


bug:
1.msa文件找不到,arsc文件问题修复。
2。更新sdk问题
3。bugly注入成功却运行不起来。




0 comments on commit b44fe93

Please sign in to comment.