新增自动打包程序

修复穿山甲打资源包问题
This commit is contained in:
Yutousama 2020-03-13 17:30:40 +08:00
parent 561177d0f4
commit c43093b119
10 changed files with 647 additions and 198 deletions

View File

@ -134,8 +134,8 @@
"bh"
],
"rename": {
"MyActivity": "Activity",
"QyReceiver": "Receiver",
"MyActivity": "{>+}Activity",
"QyReceiver": "{>+}Receiver",
"TMProvider": "TProvider"
},
"isAllPackage": true,
@ -179,16 +179,23 @@
"random":[
"com",
"ww",
"za"
"za",
"csc"
],
"isAllPackage":false,
"isReName":true,
"isJarLib":true,
"packagerlimit":3,
"isManual":false,
"isManual":true,
"outManifest":false,
"manual":[
{
"class":"com.bytedance.sdk.openadsdk.downloadnew.a.d",
"find":" const-string v1, \".TTFileProvider\"",
"data":" const-string v1, \".fileprovider\"\n",
"end":" invoke-virtual {v2, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;",
"msg":"把TTFileProvider改成fileprovider"
}
],
"rename":{
"TTLandingPageActivity":"{>+/activity}TTLandingPageActivity",

View File

@ -131,7 +131,7 @@ public class AppMain extends JFrame {
}
json.put("switch", configList.getSelectedIndex() + 1 + "");
path = json.getString("out");
name = json.getJSONArray("array").getString(Integer.valueOf(json.getString("switch")) - 1) + ".jar";
name = json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + ".jar";
file = new File(path + name);
if (file.exists())
file.delete();
@ -183,11 +183,11 @@ public class AppMain extends JFrame {
public void smaliPath(String path) {
// TODO Auto-generated method stub
File input = new File(json.getString("out")
+ json.getJSONArray("array").getString(Integer.valueOf(json.getString("switch")) - 1) + ".jar");
JarToAJar.toAJar(json.getString("dx"), input.getAbsolutePath(), input.getAbsolutePath().replace(input.getName(), "dexTmp.jar"));
+ json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) -1) + ".jar");
Tools.toAJar(json.getString("dx"), input.getAbsolutePath(), input.getAbsolutePath().replace(input.getName(), "dexTmp.jar"));
File outFile = new EncryptJar().encrypt(new File(input.getAbsolutePath().replace(input.getName(), "dexTmp.jar")), json.getString("out")
+ json.getJSONArray("array").getString(Integer.valueOf(json.getString("switch")) - 1) + "_encrypt.jar", Integer.valueOf(path)
, Integer.valueOf(version));
+ json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + "_encrypt.jar", Integer.parseInt(path)
, Integer.parseInt(version));
log.setText("data路径为:" + outFile.getAbsolutePath());
}
});
@ -284,7 +284,7 @@ public class AppMain extends JFrame {
@Override
public void smaliPath(String path) {
// TODO Auto-generated method stub
JarToAJar.toAJar(json.getString("dx"), file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), "dexTmp.jar"));
Tools.toAJar(json.getString("dx"), file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), "dexTmp.jar"));
File fileOut = new EncryptJar().encrypt(new File(file.getAbsolutePath().replace(file.getName(), "dexTmp.jar")), file.getAbsolutePath() + "_encrypt.jar", Integer.valueOf(path)
, Integer.valueOf(version));
System.out.println("data路径为:" + fileOut.getAbsolutePath());
@ -379,7 +379,7 @@ public class AppMain extends JFrame {
JFileChooser chooser = new JFileChooser(new File(new File("").getAbsolutePath()));
chooser.showOpenDialog(null);
File java = chooser.getSelectedFile();
JarToAJar.toAJar(json.getString("dx"), java.getAbsolutePath(),
Tools.toAJar(json.getString("dx"), java.getAbsolutePath(),
new File("").getAbsolutePath() + File.separator + java.getName() + "_jar.jar");
if (AppMain.isOpenWindows) {
try {

View File

@ -378,8 +378,13 @@ public class SmaliUi extends JFrame {
@Override
public void run() {
// TODO Auto-generated method stub
utils.start();
lblInfo.setText("完成");
utils.start(new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
lblInfo.setText("完成");
}
});
}
}, 100);
}

View File

@ -0,0 +1,241 @@
package com.qy.utils;
import com.qy.Interfaces.SmaliApkToolsPath;
import org.json.JSONArray;
import org.json.JSONObject;
import sun.applet.Main;
import java.io.*;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
public class AutoPackageSDK {
private AutoRandomAdSDK randomAdSDK;
private String version;
private String packageName;
File gdtsdk, uniplaysdk, qysdk;
public AutoPackageSDK(SmaliApkToolsPath inter, String version, String packageName) {
this.version = version;
this.packageName = packageName;
File gdtPath = new File("input" + File.separator + "gdtSDK" + File.separator);
File unplayPath = new File("input" + File.separator + "uniplaySDK" + File.separator);
File qysdkPath = new File("input" + File.separator + "qySDK" + File.separator);
if (!gdtPath.exists() || Objects.requireNonNull(gdtPath.listFiles()).length == 0) {
inter.smaliPath("广点通SDK不存在请放置到input" + File.separator + "gdtSDK文件夹中");
return;
}
gdtsdk = Objects.requireNonNull(gdtPath.listFiles())[0];
if (!unplayPath.exists() || Objects.requireNonNull(unplayPath.listFiles()).length == 0) {
inter.smaliPath("聚量SDK不存在请放置到input" + File.separator + "gdtSDK文件夹中");
return;
}
uniplaysdk = Objects.requireNonNull(unplayPath.listFiles())[0];
if (!qysdkPath.exists() || Objects.requireNonNull(qysdkPath.listFiles()).length == 0) {
inter.smaliPath("趣赢SDK不存在请放置到input" + File.separator + "gdtSDK文件夹中");
return;
}
qysdk = Objects.requireNonNull(qysdkPath.listFiles())[0];
JSONArray array = new JSONArray();
/* JSONObject gdt = new JSONObject();
gdt.put("file", gdtsdk.getAbsolutePath());
gdt.put("version", version);
gdt.put("type", "1");
gdt.put("index", 0);
gdt.put("packageName", packageName + ".tgd");
array.put(gdt);
JSONObject unplay = new JSONObject();
unplay.put("file", uniplaysdk.getAbsolutePath());
unplay.put("version", version);
unplay.put("type", "5");
unplay.put("index", 1);
unplay.put("packageName", packageName + ".up");
array.put(unplay);*/
JSONObject qy = new JSONObject();
qy.put("file", qysdk.getAbsolutePath());
qy.put("version", version);
qy.put("type", "0");
qy.put("packageName", packageName + ".ww");
qy.put("index", 3);
array.put(qy);
File sdk = new File("packageSDK");
Tools.deleteFiles(sdk.getAbsolutePath());
if (!sdk.exists()) {
sdk.mkdirs();
}
new AutoRandomAdSDK(array, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("打包完成:" + path);
delete(gdtPath,gdtsdk);
delete(unplayPath,uniplaysdk);
delete(qysdkPath,qysdk);
outAssetsADS(path);
outAssetsQY(0, "0");
outAssetsQY(1, "4");
outRes();
copy();
zip();
System.out.println("制作SDK完成");
}
private void delete(File path,File sdk){
for (File file : path.listFiles()) {
if(!file.getName().equals(sdk.getName())){
file.delete();
}
}
}
});
}
private void outAssetsQY(int index, String type) {
JSONObject json = Tools.loadConfig(new File("config.cfg"));
json.put("switch", index + 1 + "");
String path = json.getString("out");
String name = json.getJSONArray("array").getString(Integer.parseInt(json.getString("switch")) - 1) + ".jar";
File file = new File(path + name);
if (file.exists())
file.delete();
JarToAJar.start(json);
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
// TODO Auto-generated method stub
if (file.exists()) {
File input = new File(json.getString("out")
+ json.getJSONArray("array").getString(index) + ".jar");
Tools.toAJar(json.getString("dx"), input.getAbsolutePath(), input.getAbsolutePath().replace(input.getName(), "dexTmp.jar"));
File outFile = new EncryptJar().encrypt(new File(input.getAbsolutePath().replace(input.getName(), "dexTmp.jar")), json.getString("out")
+ json.getJSONArray("array").getString(index), Integer.parseInt(type)
, Integer.parseInt(version));
System.out.println(outFile.getAbsolutePath());
File assets = new File("packageSDK" + File.separator + "assets");
Tools.copyFile(outFile.getAbsolutePath(), assets.getAbsolutePath(), true);
outFile.delete();
input.delete();
timer.cancel();
}
}
}, 0, 100);
}
private void outAssetsADS(String path) {
JSONArray array = new JSONArray(path);
File assets = new File("packageSDK" + File.separator + "assets");
File libs = new File("packageSDK" + File.separator);
assets.mkdirs();
libs.mkdirs();
for (int i = 0; i < array.length(); i++) {
JSONObject item = array.getJSONObject(i);
System.out.println(">>" + item.toString());
if (item.getString("type").equals("0")) {
Tools.copyFileToName(item.getString("path"), libs.getAbsolutePath(), "classes.jar", true);
} else {
Tools.copyFile(item.getString("path"), assets.getAbsolutePath(), true);
}
File file = new File(item.getString("path"));
file.delete();
}
}
private void outRes() {
//new File("packageSDK" + File.separator + "jni").mkdirs();
File xmlFolder = new File("packageSDK" + File.separator + "res" + File.separator + "xml");
xmlFolder.mkdirs();
File manifest = new File("packageSDK" + File.separator + "AndroidManifest.xml");
File srcManifest = new File("input" + File.separator + "Documents" + File.separator + "AndroidManifest.xml");
Tools.copyFile("input" + File.separator + "Documents" + File.separator + "file_paths_5.xml",
xmlFolder.getAbsolutePath(), true);
Tools.copyFile("input" + File.separator + "Documents" + File.separator + "network_security_config.xml",
xmlFolder.getAbsolutePath(), true);
try {
BufferedReader reader = new BufferedReader(new FileReader(srcManifest));
String tmp;
StringBuilder str = new StringBuilder();
while ((tmp = reader.readLine()) != null) {
str.append(tmp.replace("{packagename}", packageName)).append("\n");
}
reader.close();
FileWriter writer = new FileWriter(manifest);
writer.write(str.toString());
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void zip(File file,OutputStream stream) throws IOException {
File sdk = new File("packageSDK" + File.separator + "sdk.aar");
File files=new File("packageSDK");
for (File listFile : file.listFiles()) {
if(listFile.isDirectory()){
zip(listFile,stream);
}else if(!listFile.getName().equals("sdk.aar")){
String path=listFile.getAbsolutePath().replace(files.getAbsolutePath(),"");
String exec="aapt r "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n";
stream.write(exec.getBytes());
stream.flush();
exec="aapt a "+sdk.getAbsolutePath()+" "+path.substring(1)+"\n";
stream.write(exec.getBytes());
stream.flush();
}
}
}
private void zip() {
try {
Tools.copyFile(new File("input" + File.separator + "Documents" + File.separator + "sdk.aar").getAbsolutePath(),
new File("packageSDK").getAbsolutePath(), true);
String cd = "cd " + new File("packageSDK").getAbsolutePath() + "\n";
OutputStream stream = Runtime.getRuntime().exec(new String[]{"cmd"}).getOutputStream();
stream.write(cd.getBytes());
stream.flush();
zip(new File("packageSDK"),stream);
File copy=new File("packageSDK"+File.separator+"copy");
if(copy.exists()){
zip(copy,stream);
}
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void copy(){
try{
File copyPath=new File("input"+File.separator+"Documents"+File.separator+"copy");
if(copyPath.exists()){
Tools.copyFile(copyPath.getAbsolutePath(),new File("packageSDK").getAbsolutePath(),true);
}
}catch (Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
int a=1;
new AutoPackageSDK(new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
//com.tanggttaxc.langtt.mi
}
}, "5700", a==0?"com.luckyboy.mmxing":"danxian.popstar");
}
}

View File

@ -59,6 +59,7 @@ public class AutoRandomAdSDK {
private String dxPath;
private String version;
private String sdktype;
private String packageName;
private SmaliApkToolsPath inter;
private boolean isDev = false;
@ -94,7 +95,7 @@ public class AutoRandomAdSDK {
new AutoRandomAdSDK(array, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("完成:"+path);
//System.out.println("完成:" + path);
}
});
}
@ -102,20 +103,32 @@ public class AutoRandomAdSDK {
public AutoRandomAdSDK() {
}
private SmaliApkToolsPath batchInter;
private JSONArray batch;
public AutoRandomAdSDK(JSONArray batch, SmaliApkToolsPath inter) {
final JSONArray array = new JSONArray();
batchInter=inter;
this.batch=batch;
for (Object o : batch) {
//System.out.println("循环");
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) {
JSONArray array = new JSONArray();
item.put("path", path);
array.put(item);
outInter(array);
//System.out.println("触发完成事件:"+outIndex+" "+batch.length()+" "+array.toString());
}
});
}
inter.smaliPath(array.toString());
}
private int outIndex=0;
private void outInter(JSONArray array) {
outIndex++;
if(batch.length()==outIndex){
batchInter.smaliPath(batch.toString());
}
}
public void autoRandomAdSDK(File sdk, String version, String type, String packageName, int cfgIndex, SmaliApkToolsPath inster) {
@ -128,6 +141,7 @@ public class AutoRandomAdSDK {
this.inter = inster;
this.version = version;
this.sdktype = type;
this.packageName = packageName;
JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
if (cfg == null) {
throw new NullPointerException("没有广告配置文件");
@ -163,7 +177,7 @@ public class AutoRandomAdSDK {
JSONObject json = Tools.loadConfig(new File("config.cfg"));
dxPath = json.getString("dx");
}
JarToAJar.toAJar(dxPath, sdk.getAbsolutePath(),
Tools.toAJar(dxPath, sdk.getAbsolutePath(),
tmpSdk.getAbsolutePath());
sdk = new File(tmpSdk.getAbsolutePath());
try {
@ -185,7 +199,7 @@ public class AutoRandomAdSDK {
boolean isPackage = true;
public void startNotUnPackage(String path, SmaliApkToolsPath inster) {
public void startNotUnPackage(String path, String packagename, SmaliApkToolsPath inster) {
this.inter = inster;
isPackage = false;
adClass = new HashMap<String, File>();
@ -194,6 +208,12 @@ public class AutoRandomAdSDK {
smalitools = new SmaliUtils();
JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
config = cfg.getJSONArray("array").getJSONObject(4);
JSONArray array = new JSONArray();
for (String str : packagename.split("\\.")) {
array.put(str);
}
array.put("csc");
config.put("random", array);
rootPath = path;
sdktype = "13";
alter();
@ -210,7 +230,7 @@ public class AutoRandomAdSDK {
}
}
for (String key : adClass.keySet()) {
System.out.println("注入的值:" + key);
//System.out.println("注入的值:" + key);
}
mkdirs();
update();
@ -236,9 +256,9 @@ public class AutoRandomAdSDK {
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
System.out.println("-------->" + adClass.size());
//System.out.println("-------->" + adClass.size());
for (String keys : adClass.keySet()) {
System.out.println(keys + " " + adClass.get(keys));
//System.out.println(keys + " " + adClass.get(keys));
}
}
@ -246,7 +266,8 @@ public class AutoRandomAdSDK {
}
}
}
File manifest = new File(sdk.getAbsolutePath() + ".out" + File.separator + "manifest.xml");
// File manifest = new File(sdk.getAbsolutePath() + ".out" + File.separator + "manifest.xml");
File manifest = new File(rootPath + File.separator + "manifest.xml");
PrintWriter writer;
try {
writer = new PrintWriter(manifest);
@ -263,17 +284,24 @@ public class AutoRandomAdSDK {
private void change() {
File file;
if (sdk == null) {
/* if (sdk == null) {
smalitools.setPath(rootPath + File.separator + "smali");
file = new File(rootPath + File.separator + "smali");
} else {
smalitools.setPath(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
}
System.out.println(smalitools.mainPath);
if(!file.exists()){
file=new File(sdk.getAbsolutePath() +File.separator + "smali");
}
smalitools.setPath(file.getAbsolutePath());
}*/
smalitools.setPath(rootPath + File.separator + "smali");
file = new File(rootPath + File.separator + "smali");
//System.out.println(file.getAbsolutePath() + " " + file.exists());
try {
Thread.sleep(200);
System.out.println(smalitools.mainPath);
//System.out.println(smalitools.mainPath);
if (file.exists()) {
@ -285,16 +313,24 @@ public class AutoRandomAdSDK {
}
smalitools.setFilter(list);
}
smalitools.start();
if (config.getBoolean("isManual")) {
manual();
} else {
out();
}
smalitools.start(new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
if (config.getBoolean("isManual")) {
manual();
} else {
out();
}
}
});
} else {
//System.out.println("没找到对应的文件夹:" + file.getAbsolutePath());
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
inter.smaliPath(e.getMessage());
}
}
@ -303,7 +339,9 @@ public class AutoRandomAdSDK {
JSONArray man = config.getJSONArray("manual");
for (int i = 0; i < man.length(); i++) {
JSONObject json = man.getJSONObject(i);
File file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali" + File.separator
String sdkPath;
sdkPath = rootPath;
File file = new File(sdkPath + File.separator + "smali" + File.separator
+ json.getString("class").replace(".", File.separator) + ".smali");
if (file.exists()) {
List<Integer> list = new ArrayList<Integer>();
@ -348,11 +386,11 @@ public class AutoRandomAdSDK {
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
//System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
}
/* String index = "";
for (Integer integer : list) {
System.out.println("请修改第:" + integer + " 行附近的代码");
//System.out.println("请修改第:" + integer + " 行附近的代码");
index += integer + ",";
}
new TextToDalog("提示", "请修改第:" + index + " 行附近的代码,备注:" + json.getString("msg"), new DalogAbs() {
@ -373,7 +411,7 @@ public class AutoRandomAdSDK {
if (listFile.isDirectory()) {
show(listFile);
} else {
System.out.println(">?" + listFile.getAbsolutePath());
//System.out.println(">?" + listFile.getAbsolutePath());
}
}
@ -388,13 +426,15 @@ public class AutoRandomAdSDK {
}
String path;
String name;
if (sdk == null) {
/* if (sdk == null) {
path = rootPath;
name = "tmp.zip";
} else {
path = sdk.getAbsolutePath() + ".out";
name = sdk.getName();
}
}*/
path = rootPath;
name = sdk == null ? "tmp.zip" : sdk.getName();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
@ -413,36 +453,31 @@ public class AutoRandomAdSDK {
File nLt = null;
try {
if (!config.getBoolean("isJarLib")) {
JarToAJar.toAJar(dxPath, sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName(), sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName() + "_dex.jar");
new EncryptJar().encrypt(new File(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName())
, sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar", sdktype, version);
lt = new File(sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar");
Tools.toAJar(dxPath, rootPath + File.separator + sdk.getName(), sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName() + "_dex.jar");
new EncryptJar().encrypt(new File(rootPath + File.separator + sdk.getName())
, rootPath + File.separator + "dexTmp.jar", sdktype, version);
lt = new File(rootPath + File.separator + "dexTmp.jar");
} else {
System.out.println(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName());
//System.out.println(rootPath + 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") + " " + rootPath + 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.waitFor();
lt = new File(sdk.getAbsolutePath().split(sdk.getName())[0], sdk.getName().replace(".jar", "-dex2jar.jar"));
lt = new File(sdk.getName().replace(".jar", "-dex2jar.jar"));
}
System.out.println(">>>:" + lt.getAbsolutePath());
//System.out.println(">>>:" + lt.getAbsolutePath());
if (lt.exists()) {
nLt = new File(config.getString("ltName"));
if (nLt.exists()) {
nLt.delete();
}
lt.renameTo(nLt);
}
} catch (Exception e) {
e.printStackTrace();
}
if (inter != null)
inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath());
} catch (Exception e) {
@ -456,22 +491,46 @@ public class AutoRandomAdSDK {
}
private void update() {
for (String key : adClass.keySet()) {
File file = adClass.get(key);
String fileName = file.getName().replace(".smali", "");
File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
//System.out.println("配置:" + config.getBoolean("isAllPackage"));
File root = null;
if (config.getBoolean("isAllPackage")) {
String tmp = nowAdClass.keySet().iterator().next();
File path = new File((nowAdClass.get(tmp)).getAbsolutePath());
String packge = path.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
root = new File(rootPath + File.separator + "smali");
allpackage(root, packge);
}
for (String key : nowAdClass.keySet()) {
System.out.println("key=" + key + " file=" + nowAdClass.get(key) + " oldFile=" + adClass.get(key));
}
for (String key : adClass.keySet()) {
File file = new File(adClass.get(key).getAbsolutePath());
String fileName = file.getName().replace(".smali", "");
File filePath = new File(nowAdClass.get(key).getAbsolutePath().replace(file.getName(), "").replace(".smali", ""));
if (!config.getBoolean("isAllPackage")) {
filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
}
System.out.println(nowAdClass.get(key)+" "+file.getName()+" "+filePath.getAbsolutePath());
// System.out.println(key + " | " + file.getAbsolutePath() + " | " + fileName + " | " + filePath.getAbsolutePath());
if (filePath.listFiles() == null) {
//System.out.println("filePath为空" + filePath.getAbsolutePath());
//System.out.println(file.getAbsolutePath());
}
//moveFile(filePath,key);
for (File fs : filePath.listFiles()) {
System.out.println(fs.getAbsolutePath().replace(new File("").getAbsolutePath(), ""));
// //System.out.println(fs.getAbsolutePath().replace(rootPath, ""));
if (fs.isDirectory()) {
continue;
}
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(), fs
.getName().replace(fs.getName().split("\\$")[0], nName), true);
@ -491,14 +550,22 @@ public class AutoRandomAdSDK {
file.delete();
}
System.out.println("配置:" + config.getBoolean("isAllPackage"));
if (config.getBoolean("isAllPackage")) {
String tmp = nowAdClass.keySet().iterator().next();
File path = new File((nowAdClass.get(tmp)).getAbsolutePath());
String packge = path.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
File root = new File(rootPath + File.separator + "smali");
allpackage(root, packge);
if (root != null)
removeNullFile(root);
}
private void moveFile(File path, String key) {
File fileName = nowAdClass.get(key);
for (File file : path.listFiles()) {
if (file.isDirectory()) {
moveFile(file, key);
} else {
if (file.getName().startsWith("TMProvider")) {
//System.out.println("移动文件:" + file.getName() + " -> " + getNewName(file.getName()) + " | " + fileName);
}
// //System.out.println("移动文件:"+path.getName()+" -> "+getNewName(path.getName()));
moveFile(file, key, getNewName(path.getName()) + ".smali", false);
}
}
}
@ -519,15 +586,22 @@ public class AutoRandomAdSDK {
} else {
path = nowAdClass.get(key).getAbsolutePath();
}
if (!file.exists()) {
file = new File(nowAdClass.get(key), file.getName());
}
if (!file.getName().endsWith(".smali")) {
file = new File(file.getAbsolutePath() + ".smali");
}
if (isAddFile)
nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath());
Tools.copyFileToName(file.getAbsolutePath(), path,
boolean t = Tools.copyFileToName(file.getAbsolutePath(), path,
nName, true);
file.delete();
////System.out.println("移动文件:" + file.getAbsolutePath() + "" + path + " 重命名为:" + nName + " 结果" + t);
}
private void allpackage(File file, String packge) {
for (File tmp : file.listFiles()) {
String pack = tmp.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
if (!packge.contains(pack) && tmp.isDirectory()) {
movesdk(tmp, File.separator + "smali" + File.separator + packge);
@ -545,17 +619,34 @@ public class AutoRandomAdSDK {
file.delete();
continue;
}
if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) {
continue;
}
if (file.isDirectory()) {
String tmp = toPath + File.separator + file.getName();
//System.out.println("创建文件夹:"+tmp);
////System.out.println("创建文件夹:"+tmp);
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);
String fileName = file.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "")
.replace(File.separator, ".")
.replace(".smali", "");
File toPathFile = new File(rootPath + File.separator + toPath);
if (!toPathFile.exists()) {
toPathFile.mkdirs();
}
boolean data = file.renameTo(new File(rootPath + toPath, file.getName()));
//System.out.println("移动文件:" + file.getAbsolutePath().replace(rootPath, "") + "" + (rootPath + toPath) + " > " + fileName + " " + nowAdClass.get(fileName) + " >! " + data);
if (nowAdClass.containsKey(fileName)) {
// System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+""+(rootPath + File.separator + toPath)+" > "+fileName+" "+nowAdClass.get(fileName));
// //System.out.println(file.getAbsolutePath().replace(rootPath,"")+" "+toPath);
nowAdClass.put(fileName, new File(rootPath + File.separator + toPath));
}
}
}
}
private void removeNullFile(File root) {
@ -579,7 +670,6 @@ public class AutoRandomAdSDK {
if (nName.endsWith("[notmover]")) {
nName = nName.replace("[notmover]", "");
}
return nName;
}
@ -613,6 +703,9 @@ public class AutoRandomAdSDK {
nName = nName.replace("[random]", tName);
config.getJSONObject("rename").put(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName, nName);
}
/*if(nName.startsWith("{>")){
nName=nName.split("}")[1];
}*/
if (wName != null) {
nName += wName;
}
@ -625,7 +718,7 @@ public class AutoRandomAdSDK {
for (int i = 0; i < clazzs.length(); i++) {
File path = new File(rootPath + File.separator + "smali");
File mkdir = null;
for (int j = 0; j < config.getInt("packagerlimit"); j++) {
for (int j = 0; j < random.length(); j++) {
String packageName;
if (random.getString(j).equals("[random]")) {
packageName = Tools.getRandomString(3);
@ -638,10 +731,13 @@ public class AutoRandomAdSDK {
mkdir = new File(mkdir.getAbsolutePath() + File.separator + packageName);
}
if (!mkdir.exists()) {
mkdir.mkdirs();
boolean t = mkdir.mkdirs();
}
}
nowAdClass.put(clazzs.getString(i), mkdir);
for (String key : nowAdClass.keySet()) {
// System.out.println("key=" + key + " file=" + nowAdClass.get(key) + " oldFile=" + adClass.get(key));
}
}
}
}

View File

@ -67,6 +67,18 @@ public class CsjTools {
return null;
}
private String getPackageName() {
try {
File apkManifest = new File(apk_Path + File.separator + "AndroidManifest.xml");
BufferedReader reader = new BufferedReader(new FileReader(apkManifest));
String tmp = reader.readLine();
reader.close();
return getXMLValue("package", tmp);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private void outManifest() {
try {
@ -77,7 +89,7 @@ public class CsjTools {
reader.close();
String apkPackage = getXMLValue("package", tmp);
System.out.println(apkPackage);
_log.smaliPath("获取到APK包名"+apkPackage);
_log.smaliPath("获取到APK包名" + apkPackage);
reader = new BufferedReader(new FileReader(demoManifest));
tmp = reader.readLine();
String manifest = tmp.replace(getXMLValue("package", tmp), apkPackage) + "\n";
@ -204,8 +216,8 @@ public class CsjTools {
}
outManifest();
File csjRes = new File("csj" + File.separator + "csc.apk");
if (!new File("csj/").exists()) {
new File("csj/").mkdirs();
if (!new File("csj").exists()) {
new File("csj").mkdirs();
}
SmaliUtils utils = new SmaliUtils();
_log.smaliPath("资源包制作完成开始打包为apk");
@ -225,17 +237,17 @@ public class CsjTools {
public void build(String csjPath, String apkPath, SmaliApkToolsPath log) {
time = System.currentTimeMillis();
_log=log;
unPackageCSJ=false;
_log = log;
unPackageCSJ = false;
File csjFile = new File(csjPath);
if (new File(csjFile.getName().replace(".apk", "")).exists()) {
System.out.println(">?>>"+new File(csjFile.getName().replace(".apk", "")).getAbsolutePath());
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));
// Tools.deleteFiles(new File("").getAbsolutePath() + File.separator + new File(csjPath).getName().replace(".apk", File.separator));
Tools.deleteFiles(new File("").getAbsolutePath() + File.separator + new File(apkPath).getName().replace(".apk", File.separator));
new Thread(new Runnable() {
@Override
@ -272,7 +284,7 @@ public class CsjTools {
new Thread(new Runnable() {
@Override
public void run() {
new AutoRandomAdSDK().startNotUnPackage(path, new SmaliApkToolsPath() {
new AutoRandomAdSDK().startNotUnPackage(path, getPackageName(), new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
_log.smaliPath("穿山甲修改完成");
@ -303,15 +315,6 @@ public class CsjTools {
//还有最后一个问题穿山甲的Activity没改
public static void main(String[] args) {
if (false) {
new AutoRandomAdSDK().startNotUnPackage("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2", new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("-------" + path);
}
});
return;
}
CsjTools tools = new CsjTools();
tools.build("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2.apk",
"D:\\IdeaProjects\\android_sdk_tools\\app-release.apk",

View File

@ -16,14 +16,14 @@ import com.qy.ui.AppMain;
public class JarToAJar {
private static JSONObject json;
private final int BUFFER_SIZE = 2 * 1024;
public static void start(JSONObject json) {
JarToAJar.json=json;
JSONArray array=json.getJSONArray("array");
String inName=json.isNull("input")?"com.zip":json.getString("input");
String outName=json.isNull("out")?"rx.jar":json.getString("out")+array.getString(Integer.valueOf(json.getString("switch"))-1)+".jar";
String outName=json.isNull("out")?"rx.jar":json.getString("out")+array.getString(Integer.parseInt(json.getString("switch"))-1)+".jar";
new JarToAJar(inName,outName);
}
@ -36,95 +36,16 @@ public class JarToAJar {
outFile.delete();
OutputStream outputStream = new FileOutputStream(
new File(inName));
toZip(json.getString(json.getString("switch")), outputStream, true);
toAJar(dx,inName, outName);
Tools.toZip(json.getString(json.getString("switch")), outputStream, true,true);
Tools.toAJar(dx,inName, outName);
System.out.println(outName);
if(AppMain.isOpenWindows)
Desktop.getDesktop().open(new File(json.getString("out")));
Desktop.getDesktop().open(new File(json.getString("out")));
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
public static void toAJar(String dx,String inName,String outName) {
try {
File file=new File(outName);
if(file.exists()) {
file.delete();
}
String exec="java -jar "+dx+" --dex --output="+outName+" "+inName+"";
System.out.println("java to dex:"+exec);
Process process=Runtime.getRuntime().exec(exec);
process.waitFor();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void toZip(String srcDir, OutputStream out, boolean KeepDirStructure) throws RuntimeException {
long start = System.currentTimeMillis();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(out);
File sourceFile = new File(srcDir);
compress(sourceFile, zos, sourceFile.getName(), KeepDirStructure);
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils", e);
} finally {
if (zos != null) {
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private void compress(File sourceFile, ZipOutputStream zos, String name, boolean KeepDirStructure)
throws Exception {
byte[] buf = new byte[BUFFER_SIZE];
if (sourceFile.isFile()) {
// 向zip输出流中添加一个zip实体构造器中name为zip实体的文件的名字
zos.putNextEntry(new ZipEntry(name));
// copy文件到zip输出流中
int len;
FileInputStream in = new FileInputStream(sourceFile);
while ((len = in.read(buf)) != -1) {
zos.write(buf, 0, len);
}
// Complete the entry
zos.closeEntry();
in.close();
} else {
File[] listFiles = sourceFile.listFiles();
if (listFiles == null || listFiles.length == 0) {
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if (KeepDirStructure) {
// 空文件夹的处理
zos.putNextEntry(new ZipEntry(name + File.separator));
// 没有文件不需要文件的copy
zos.closeEntry();
}
} else {
for (File file : listFiles) {
// 判断是否需要保留原来的文件结构
if (KeepDirStructure) {
// 注意file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,所有文件都跑到压缩包根目录下了
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure);
} else {
compress(file, zos, file.getName(), KeepDirStructure);
}
}
}
}
}
}

View File

@ -32,7 +32,9 @@ public class SmaliUtils {
mainPath=uPath;
}
public void start() {
private SmaliApkToolsPath inter;
public void start(SmaliApkToolsPath inter) {
this.inter=inter;
list=new ArrayList<>();
System.out.println("开始修改:"+mainPath);
File path = new File(mainPath);
@ -40,26 +42,23 @@ public class SmaliUtils {
try {
System.out.println(clazzList.size());
for (File file : files) {
new Thread(new Runnable() {
@Override
public void run() {
String str= null;
try {
str = loadFile(file);
writerFile(file,str);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
String str = loadFile(file);
writerFile(file,str);
}
inter.smaliPath("ok");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private int writerIndex=0;
private void test(){
writerIndex++;
if(files.size()==writerIndex){
inter.smaliPath("ok");
}
}
private void recursive(File file) {
String packname = null;
if (file.isFile()) {
@ -86,7 +85,7 @@ public class SmaliUtils {
e.printStackTrace();
}
} else {
System.out.println(file.getAbsolutePath()+" > "+file.exists());
//System.out.println(file.getAbsolutePath()+" > "+file.exists());
for (int i = 0; i < file.listFiles().length; i++) {
recursive(file.listFiles()[i]);
}
@ -198,6 +197,9 @@ public class SmaliUtils {
}
String[] args =new String[] {"d","-f",jarPath};
try {
for (String arg : args) {
System.out.print(arg+" ");
}
Main.main(args);
File jarFile=new File(jarPath);
String name;
@ -208,6 +210,7 @@ public class SmaliUtils {
}else {
name=jarFile.getName();
}
//jarFile.delete();
smaliApkToolsPath.smaliPath(new File("").getAbsolutePath()+File.separator+name);
} catch (Exception e) {
// TODO Auto-generated catch block

View File

@ -3,9 +3,15 @@ package com.qy.utils;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Random;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.json.JSONObject;
import static java.util.zip.ZipEntry.STORED;
public class Tools {
public static boolean stringIsNull(String string) {
@ -48,6 +54,7 @@ public class Tools {
File srcFile = new File(srcFileName);
// 判断源文件是否存在
if (!srcFile.exists()) {
return false;
} else if (!srcFile.isFile()) {
return false;
@ -58,11 +65,19 @@ public class Tools {
// 如果目标文件所在目录不存在则创建目录
if (!destFile.exists()) {
// 目标文件所在目录不存在
boolean t=destFile.mkdirs();
if(srcFileName.equals("Activity.smali")){
System.out.println("创建文件夹:"+destFileName+" "+t);
}
if (!destFile.mkdirs()) {
// 复制文件失败创建目标文件所在目录失败
return false;
}
}else{
if(srcFileName.equals("Activity.smali")){
System.out.println("文件夹已存在:"+destFileName);
}
}
// 复制文件
@ -109,7 +124,57 @@ public class Tools {
*/
public static boolean copyFile(String srcFileName, String destFileName,
boolean overlay) {
return copyFileToName(srcFileName, destFileName, null, overlay);
if(new File(srcFileName).isDirectory()){
return copyDir(srcFileName,destFileName);
}else {
return copyFileToName(srcFileName, destFileName, null, overlay);
}
}
private static boolean copyDir(String dir,String dest){
try{
//System.out.println("复制文件"+dir+""+dest);
File src=new File(dir);
File destFile=new File(dest);
String path="";
int index;
String ta,tb;
if(dir.length()>dest.length()){
index=dir.length();
ta=dir;
tb=dest;
}else{
index=dest.length();
ta=dest;
tb=dir;
}
for (int i = 0; i < index; i++) {
if(tb.length()>(i+1)&&ta.substring(i,i+1).equals(tb.substring(i,i+1))){
path+=ta.substring(i,i+1);
}else {
break;
}
}
if(!destFile.exists()){
destFile.mkdirs();
}
for (File file : src.listFiles()) {
if(file.isDirectory()){
copyDir(file.getAbsolutePath(),dest);
}else{
String tmp=file.getAbsolutePath().replace(file.getName(),"").replace(new File("input"+File.separator+"Documents"+File.separator+"copy"+File.separator).getAbsolutePath(),"");
System.out.println(file.getAbsolutePath()+" "+tmp);
File out=new File(dest+tmp);
if(!out.exists()){
out.mkdirs();
}
copyFile(file.getAbsolutePath(),out.getAbsolutePath(),true);
}
}
}catch (Exception e){
e.printStackTrace();
return false;
}
return true;
}
public static JSONObject loadConfig(File file) {
@ -138,4 +203,112 @@ public class Tools {
}
return json;
}
public static void toZip(String srcDir, OutputStream out, boolean KeepDirStructure,boolean zipRootName) throws RuntimeException {
long start = System.currentTimeMillis();
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(out);
zos.setMethod(ZipOutputStream.STORED);
zos.setLevel(0);
File sourceFile = new File(srcDir);
compress(sourceFile, zos, sourceFile.getName(), KeepDirStructure,zipRootName);
long end = System.currentTimeMillis();
System.out.println("压缩完成,耗时:" + (end - start) + " ms");
} catch (Exception e) {
throw new RuntimeException("zip error from ZipUtils", e);
} finally {
if (zos != null) {
try {
zos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private static void compress(File sourceFile, ZipOutputStream zos, String name, boolean KeepDirStructure,boolean zipRootName)
throws Exception {
byte[] buf = new byte[ 2 * 1024];
if (sourceFile.isFile()) {
// 向zip输出流中添加一个zip实体构造器中name为zip实体的文件的名字
ZipEntry entry=new ZipEntry(name);
entry.setMethod(STORED);
entry.setSize(sourceFile.length());
long crc=0;
crc=calFileCRC32(sourceFile);
entry.setCrc(crc);
zos.putNextEntry(entry);
// copy文件到zip输出流中
int len;
FileInputStream in = new FileInputStream(sourceFile);
while ((len = in.read(buf)) != -1) {
zos.write(buf, 0, len);
}
// Complete the entry
zos.closeEntry();
in.close();
} else {
File[] listFiles = sourceFile.listFiles();
if (listFiles == null || listFiles.length == 0) {
// 需要保留原来的文件结构时,需要对空文件夹进行处理
if (KeepDirStructure) {
// 空文件夹的处理
ZipEntry entry=new ZipEntry(name + File.separator);
entry.setMethod(STORED);
zos.putNextEntry(entry);
// 没有文件不需要文件的copy
zos.closeEntry();
}
} else {
for (File file : listFiles) {
// 判断是否需要保留原来的文件结构
if (KeepDirStructure) {
// 注意file.getName()前面需要带上父文件夹的名字加一斜杠,
// 不然最后压缩包中就不能保留原来的文件结构,所有文件都跑到压缩包根目录下了
if(zipRootName) {
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure,zipRootName);
}else{
if(name.startsWith("\\")){
compress(file, zos, name + File.separator + file.getName(), KeepDirStructure,zipRootName);
}else {
compress(file, zos, File.separator + file.getName(), KeepDirStructure, zipRootName);
}
}
} else {
compress(file, zos, file.getName(), KeepDirStructure,zipRootName);
}
}
}
}
}
public static long calFileCRC32(File file) throws IOException {
FileInputStream fi = new FileInputStream(file);
CheckedInputStream checksum = new CheckedInputStream(fi, new CRC32());
while (checksum.read() != -1) { }
long temp = checksum.getChecksum().getValue();
fi.close();
checksum.close();
return temp;
}
public static void toAJar(String dx,String inName,String outName) {
try {
File file=new File(outName);
if(file.exists()) {
file.delete();
}
String exec="java -jar "+dx+" --dex --output="+outName+" "+inName+"";
System.out.println("java to dex:"+exec);
Process process=Runtime.getRuntime().exec(exec);
process.waitFor();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -12,7 +12,7 @@ public class WorldTools {
public static void start(String packName, String managename,Map<String,String> functions) {
try {
BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File("data"+File.separator+"接入文档.txt")), "UTF-8"));
BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(new File("data"+File.separator+"接入文档.txt")), "UTF-8"));
String str="",tmp;
while ((tmp=reader.readLine())!=null) {
tmp=tmp.replace("${GameSDK}", managename);
@ -24,7 +24,7 @@ public class WorldTools {
tmp=tmp.replace("${getSDKManage}", functions.get("getSDKManage"));
str+=tmp+"\n";
}
FileWriter writer=new FileWriter(new File("文档.txt"));
FileWriter writer=new FileWriter(new File("文档.txt"));
writer.write(str);
writer.flush();
writer.close();