修复穿山甲demo存在时不获取路径的BUG

自动打包程序新增批量打包广告源SDK
配置文件manual字段新增data和end字段,data为添加的内容,end为检测到结束的表示,意思是从find到end这一段由data替换
This commit is contained in:
Yutousama 2020-03-10 17:24:19 +08:00
parent 4e2efcc143
commit 561177d0f4
4 changed files with 134 additions and 52 deletions

View File

@ -2,7 +2,7 @@
"array": [
{
"title": "广点通",
"ltName": "GDTUnionSDK_QY.lt",
"ltName": "tgd",
"manifest": [
"<service android:name=\"com.qq.e.comm.DownloadService\" android:exported=\"false\" />",
"<activity android:name=\"com.qq.e.ads.ADActivity\" android:configChanges=\"keyboard|keyboardHidden|orientation|screenSize\" />",
@ -76,7 +76,9 @@
{
"class": "com.uniplay.adsdk.basic.RuleManage",
"find": ".method public configRight",
"msg": "仅保留const-string v0, \"\" return-object v0"
"msg": "仅保留const-string v0, \"\" return-object v0",
"data":".method public configRight(Landroid/content/Context;Ljava/lang/String;)Ljava/lang/String;\n.locals 3\n.prologue\nconst-string v0, \"\" \nreturn-object v0\n",
"end":".end method"
}
]
},

View File

@ -1,21 +1,13 @@
{
"1": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"2": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"3": "F:/AndroidStudio_Data/GameSDK/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"4": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"5": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"6": "/home/yutou/AndroidStudioProjects/ADSDK_v5/Test/build/intermediates/javac/debug/classes/com/",
"1": "D:\\AndroidStudio_Data\\ADSDK_v5\\sdk_rx\\build\\intermediates\\javac\\debug\\classes\\com",
"2": "D:\\AndroidStudio_Data\\ADSDK_v5\\qyadsdk\\build\\intermediates\\javac\\debug\\classes\\com",
"switch": "1",
"input": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/com.zip",
"out": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/",
"input": "com.zip",
"out": "",
"dx": "dx.jar",
"array": [
"rd_rx",
"qy_rx",
"rx",
"rd_rx",
"qy_rx",
"atest"
"aa",
"tl"
],
"csjConfig": {
"xml": {
@ -43,8 +35,8 @@
"name": "${demoRoot}/res/raw/*"
},
{
"command":"delete",
"name":"${demoRoot}/lib/*"
"command": "delete",
"name": "${demoRoot}/lib/*"
}
]
}

View File

@ -1,12 +1,7 @@
package com.qy.utils;
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.*;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashMap;
@ -69,16 +64,67 @@ public class AutoRandomAdSDK {
public static void main(String[] args) {
// TODO Auto-generated method stub
new AutoRandomAdSDK(new File("JooMobAdSDK_6.1.8.jar"), "5600", "5", 1, null);
// new AutoRandomAdSDK(new File("JooMobAdSDK_6.1.8.jar"), "5600", "5", 1, null);
// new AutoRandomAdSDK(new File("GDTSDK.unionNormal.4.100.970.jar"), 0, null);
JSONArray array = new JSONArray();
JSONObject gdt = new JSONObject();
gdt.put("file", "D:\\IDEA\\android_sdk_tools\\GDTSDK.unionNormal.4.170.1040.jar");
gdt.put("version", "5700");
gdt.put("type", "1");
gdt.put("index", 0);
gdt.put("packageName", "com.gzlt.tgttaxc.lmd1.tgd");
array.put(gdt);
JSONObject unplay = new JSONObject();
unplay.put("file", "D:\\IDEA\\android_sdk_tools\\JooMobAdSDK_6.1.8.jar");
unplay.put("version", "5700");
unplay.put("type", "5");
unplay.put("index", 1);
unplay.put("packageName", "com.gzlt.tgttaxc.lmd1.up");
array.put(unplay);
JSONObject qy = new JSONObject();
qy.put("file", "D:\\IDEA\\android_sdk_tools\\classes.jar");
qy.put("version", "5700");
qy.put("type", "0");
qy.put("packageName", "com.gzlt.tgttaxc.lmd1.ww");
qy.put("index", 3);
array.put(qy);
new AutoRandomAdSDK(array, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("完成:"+path);
}
});
}
public AutoRandomAdSDK() {
}
public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) {
public AutoRandomAdSDK(JSONArray batch, SmaliApkToolsPath inter) {
final JSONArray array = new JSONArray();
for (Object o : batch) {
final JSONObject item = (JSONObject) o;
autoRandomAdSDK(new File(item.getString("file")), item.getString("version"), item
.getString("type"), item.getString("packageName"), item.getInt("index"), new SmaliApkToolsPath() {
public void smaliPath(String path) {
item.put("path", path);
array.put(item);
}
});
}
inter.smaliPath(array.toString());
}
public void autoRandomAdSDK(File sdk, String version, String type, String packageName, int cfgIndex, SmaliApkToolsPath inster) {
// TODO Auto-generated constructor stub
if (inster == null) {
inster = path -> {
};
}
this.inter = inster;
this.version = version;
this.sdktype = type;
@ -88,9 +134,21 @@ public class AutoRandomAdSDK {
}
this.sdk = sdk;
config = cfg.getJSONArray("array").getJSONObject(cfgIndex);
if (packageName != null) {
String[] pname = packageName.split("\\.");
JSONArray random = new JSONArray();
for (String pn : pname) {
random.put(pn);
}
this.config.put("random", random);
}
start();
}
public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) {
autoRandomAdSDK(sdk, version, type, null, cfgIndex, inster);
}
public void start() {
adClass = new HashMap<String, File>();
nowAdClass = new HashMap<String, File>();
@ -219,7 +277,7 @@ public class AutoRandomAdSDK {
if (file.exists()) {
JSONArray array = config.isNull("filter")?null:config.getJSONArray("filter");
JSONArray array = config.isNull("filter") ? null : config.getJSONArray("filter");
if (array != null) {
List<String> list = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
@ -253,20 +311,46 @@ public class AutoRandomAdSDK {
BufferedReader reader = new BufferedReader(new FileReader(file));
String tmp;
int index = 1;
boolean find = false;
boolean end = false;
boolean write = false;
StringBuilder buffer = new StringBuilder();
while ((tmp = reader.readLine()) != null) {
if (tmp.contains(json.getString("find"))) {
list.add(index);
find = true;
}
if (find && !write) {
buffer.append(json.getString("data"));
write = true;
}
if (find && tmp.contains(json.getString("end"))) {
end = true;
find = false;
}
if (!find) {
buffer.append(tmp).append("\n");
if (end) {
end = false;
write = false;
}
}
index++;
}
reader.close();
Desktop.getDesktop().open(file);
FileWriter writer = new FileWriter(file);
writer.write(buffer.toString());
writer.flush();
writer.close();
out();
reader.close();
// Desktop.getDesktop().open(file);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
}
String index = "";
/* String index = "";
for (Integer integer : list) {
System.out.println("请修改第:" + integer + " 行附近的代码");
index += integer + ",";
@ -278,21 +362,23 @@ public class AutoRandomAdSDK {
// TODO Auto-generated method stub
out();
}
});
});*/
}
}
}
private void show(File file){
private void show(File file) {
for (File listFile : file.listFiles()) {
if(listFile.isDirectory()){
if (listFile.isDirectory()) {
show(listFile);
}else{
System.out.println(">?"+listFile.getAbsolutePath());
} else {
System.out.println(">?" + listFile.getAbsolutePath());
}
}
}
private void out() {
if (!isPackage) {
if (inter != null) {
@ -334,19 +420,19 @@ public class AutoRandomAdSDK {
} else {
System.out.println(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName());
String exec=config.getString("dex2jar") + " " + sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName();
System.out.println("exec:"+exec);
String exec = config.getString("dex2jar") + " " + sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName();
System.out.println("exec:" + exec);
Process process = Runtime.getRuntime().exec(exec);
process.waitFor();
Thread.sleep(100);
process=Runtime.getRuntime().exec(exec);
process = Runtime.getRuntime().exec(exec);
process.waitFor();
lt = new File(sdk.getAbsolutePath().split(sdk.getName())[0], sdk.getName().replace(".jar", "-dex2jar.jar"));
}
System.out.println(">>>:" + lt.getAbsolutePath());
if (lt.exists()) {
nLt = new File(config.getString("ltName"));
if(nLt.exists()){
if (nLt.exists()) {
nLt.delete();
}
lt.renameTo(nLt);
@ -376,21 +462,21 @@ public class AutoRandomAdSDK {
File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
for (File fs : filePath.listFiles()) {
System.out.println(fs.getAbsolutePath().replace(new File("").getAbsolutePath(),""));
if(fs.isDirectory()){
System.out.println(fs.getAbsolutePath().replace(new File("").getAbsolutePath(), ""));
if (fs.isDirectory()) {
continue;
}
if(!fs.getName().startsWith(fileName)){
if (!fs.getName().startsWith(fileName)) {
continue;
}
String nName = getNewName(fs.getName());
if (fs.getName().startsWith(fileName + "$")) {
if (getNewName(fs.getName()).endsWith("[notmover]")) {
Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(),
nName + "$" + fs.getName().split("\\$")[1], true);
Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(), fs
.getName().replace(fs.getName().split("\\$")[0], nName), true);
} else {
moveFile(fs, key, nName + "$" + fs.getName().split("\\$")[1],false);
moveFile(fs, key, fs.getName().replace(fs.getName().split("\\$")[0], nName), false);
}
fs.delete();
}
@ -400,12 +486,12 @@ public class AutoRandomAdSDK {
Tools.copyFileToName(file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), ""),
getNewName(file.getName()) + ".smali", true);
} else {
moveFile(file, key, getNewName(file.getName()) + ".smali",true);
moveFile(file, key, getNewName(file.getName()) + ".smali", true);
}
file.delete();
}
System.out.println("配置:"+config.getBoolean("isAllPackage"));
System.out.println("配置:" + config.getBoolean("isAllPackage"));
if (config.getBoolean("isAllPackage")) {
String tmp = nowAdClass.keySet().iterator().next();
File path = new File((nowAdClass.get(tmp)).getAbsolutePath());
@ -426,7 +512,7 @@ public class AutoRandomAdSDK {
tmp = tmp.replace("/", File.separator);
String t = tmp.substring(0, 1);
if (t.equals("+")) {
path = nowAdClass.get(key).getAbsolutePath() + tmp.replace("+","");
path = nowAdClass.get(key).getAbsolutePath() + tmp.replace("+", "");
} else {
path = rootPath + File.separator + "smali" + tmp;
}
@ -466,8 +552,8 @@ public class AutoRandomAdSDK {
new File(rootPath + File.separator + tmp).mkdirs();
movesdk(file, tmp);
} else {
boolean data=file.renameTo(new File(rootPath + File.separator + toPath, file.getName()));
// System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+""+(rootPath + File.separator + toPath)+" "+data);
boolean data = file.renameTo(new File(rootPath + File.separator + toPath, file.getName()));
// System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+""+(rootPath + File.separator + toPath)+" "+data);
}
}
}
@ -516,9 +602,9 @@ public class AutoRandomAdSDK {
tmpName = name;
}
String nName;
if(config.getJSONObject("rename").isNull(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName)){
nName=name;
}else{
if (config.getJSONObject("rename").isNull(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName)) {
nName = name;
} else {
nName = config.getJSONObject("rename")
.getString(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName);
}

View File

@ -231,6 +231,8 @@ public class CsjTools {
if (new File(csjFile.getName().replace(".apk", "")).exists()) {
System.out.println(">?>>"+new File(csjFile.getName().replace(".apk", "")).getAbsolutePath());
unPackageCSJ = true;
csj_Path = new File(csjFile.getName().replace(".apk", "")).getAbsolutePath();
csj_res = csj_Path + File.separator + "res" + File.separator + "values";
}
SmaliUtils utils = new SmaliUtils();
// Tools.deleteFiles(new File("").getAbsolutePath() + File.separator + new File(csjPath).getName().replace(".apk", File.separator));