新增自动打包程序

修复穿山甲打资源包问题
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" "bh"
], ],
"rename": { "rename": {
"MyActivity": "Activity", "MyActivity": "{>+}Activity",
"QyReceiver": "Receiver", "QyReceiver": "{>+}Receiver",
"TMProvider": "TProvider" "TMProvider": "TProvider"
}, },
"isAllPackage": true, "isAllPackage": true,
@ -179,16 +179,23 @@
"random":[ "random":[
"com", "com",
"ww", "ww",
"za" "za",
"csc"
], ],
"isAllPackage":false, "isAllPackage":false,
"isReName":true, "isReName":true,
"isJarLib":true, "isJarLib":true,
"packagerlimit":3, "packagerlimit":3,
"isManual":false, "isManual":true,
"outManifest":false, "outManifest":false,
"manual":[ "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":{ "rename":{
"TTLandingPageActivity":"{>+/activity}TTLandingPageActivity", "TTLandingPageActivity":"{>+/activity}TTLandingPageActivity",

View File

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

View File

@ -378,8 +378,13 @@ public class SmaliUi extends JFrame {
@Override @Override
public void run() { public void run() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
utils.start(); utils.start(new SmaliApkToolsPath() {
lblInfo.setText("完成"); @Override
public void smaliPath(String path) {
lblInfo.setText("完成");
}
});
} }
}, 100); }, 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 dxPath;
private String version; private String version;
private String sdktype; private String sdktype;
private String packageName;
private SmaliApkToolsPath inter; private SmaliApkToolsPath inter;
private boolean isDev = false; private boolean isDev = false;
@ -94,7 +95,7 @@ public class AutoRandomAdSDK {
new AutoRandomAdSDK(array, new SmaliApkToolsPath() { new AutoRandomAdSDK(array, new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
System.out.println("完成:"+path); //System.out.println("完成:" + path);
} }
}); });
} }
@ -102,20 +103,32 @@ public class AutoRandomAdSDK {
public AutoRandomAdSDK() { public AutoRandomAdSDK() {
} }
private SmaliApkToolsPath batchInter;
private JSONArray batch;
public AutoRandomAdSDK(JSONArray batch, SmaliApkToolsPath inter) { public AutoRandomAdSDK(JSONArray batch, SmaliApkToolsPath inter) {
final JSONArray array = new JSONArray(); batchInter=inter;
this.batch=batch;
for (Object o : batch) { for (Object o : batch) {
//System.out.println("循环");
final JSONObject item = (JSONObject) o; final JSONObject item = (JSONObject) o;
autoRandomAdSDK(new File(item.getString("file")), item.getString("version"), item autoRandomAdSDK(new File(item.getString("file")), item.getString("version"), item
.getString("type"), item.getString("packageName"), item.getInt("index"), new SmaliApkToolsPath() { .getString("type"), item.getString("packageName"), item.getInt("index"), new SmaliApkToolsPath() {
public void smaliPath(String path) { public void smaliPath(String path) {
JSONArray array = new JSONArray();
item.put("path", path); item.put("path", path);
array.put(item); 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) { 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.inter = inster;
this.version = version; this.version = version;
this.sdktype = type; this.sdktype = type;
this.packageName = packageName;
JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg")); JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
if (cfg == null) { if (cfg == null) {
throw new NullPointerException("没有广告配置文件"); throw new NullPointerException("没有广告配置文件");
@ -163,7 +177,7 @@ public class AutoRandomAdSDK {
JSONObject json = Tools.loadConfig(new File("config.cfg")); JSONObject json = Tools.loadConfig(new File("config.cfg"));
dxPath = json.getString("dx"); dxPath = json.getString("dx");
} }
JarToAJar.toAJar(dxPath, sdk.getAbsolutePath(), Tools.toAJar(dxPath, sdk.getAbsolutePath(),
tmpSdk.getAbsolutePath()); tmpSdk.getAbsolutePath());
sdk = new File(tmpSdk.getAbsolutePath()); sdk = new File(tmpSdk.getAbsolutePath());
try { try {
@ -185,7 +199,7 @@ public class AutoRandomAdSDK {
boolean isPackage = true; boolean isPackage = true;
public void startNotUnPackage(String path, SmaliApkToolsPath inster) { public void startNotUnPackage(String path, String packagename, SmaliApkToolsPath inster) {
this.inter = inster; this.inter = inster;
isPackage = false; isPackage = false;
adClass = new HashMap<String, File>(); adClass = new HashMap<String, File>();
@ -194,6 +208,12 @@ public class AutoRandomAdSDK {
smalitools = new SmaliUtils(); smalitools = new SmaliUtils();
JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg")); JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
config = cfg.getJSONArray("array").getJSONObject(4); 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; rootPath = path;
sdktype = "13"; sdktype = "13";
alter(); alter();
@ -210,7 +230,7 @@ public class AutoRandomAdSDK {
} }
} }
for (String key : adClass.keySet()) { for (String key : adClass.keySet()) {
System.out.println("注入的值:" + key); //System.out.println("注入的值:" + key);
} }
mkdirs(); mkdirs();
update(); update();
@ -236,9 +256,9 @@ public class AutoRandomAdSDK {
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); e.printStackTrace();
System.out.println("-------->" + adClass.size()); //System.out.println("-------->" + adClass.size());
for (String keys : adClass.keySet()) { 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; PrintWriter writer;
try { try {
writer = new PrintWriter(manifest); writer = new PrintWriter(manifest);
@ -263,17 +284,24 @@ public class AutoRandomAdSDK {
private void change() { private void change() {
File file; File file;
if (sdk == null) { /* if (sdk == null) {
smalitools.setPath(rootPath + File.separator + "smali"); smalitools.setPath(rootPath + File.separator + "smali");
file = new File(rootPath + File.separator + "smali"); file = new File(rootPath + File.separator + "smali");
} else { } else {
smalitools.setPath(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali"); file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
} if(!file.exists()){
System.out.println(smalitools.mainPath); 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 { try {
Thread.sleep(200); Thread.sleep(200);
System.out.println(smalitools.mainPath); //System.out.println(smalitools.mainPath);
if (file.exists()) { if (file.exists()) {
@ -285,16 +313,24 @@ public class AutoRandomAdSDK {
} }
smalitools.setFilter(list); smalitools.setFilter(list);
} }
smalitools.start(); smalitools.start(new SmaliApkToolsPath() {
if (config.getBoolean("isManual")) { @Override
manual(); public void smaliPath(String path) {
} else { if (config.getBoolean("isManual")) {
out(); manual();
} } else {
out();
}
}
});
} else {
//System.out.println("没找到对应的文件夹:" + file.getAbsolutePath());
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
inter.smaliPath(e.getMessage());
} }
} }
@ -303,7 +339,9 @@ public class AutoRandomAdSDK {
JSONArray man = config.getJSONArray("manual"); JSONArray man = config.getJSONArray("manual");
for (int i = 0; i < man.length(); i++) { for (int i = 0; i < man.length(); i++) {
JSONObject json = man.getJSONObject(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"); + json.getString("class").replace(".", File.separator) + ".smali");
if (file.exists()) { if (file.exists()) {
List<Integer> list = new ArrayList<Integer>(); List<Integer> list = new ArrayList<Integer>();
@ -348,11 +386,11 @@ public class AutoRandomAdSDK {
} catch (IOException e) { } catch (IOException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件"); //System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
} }
/* String index = ""; /* String index = "";
for (Integer integer : list) { for (Integer integer : list) {
System.out.println("请修改第:" + integer + " 行附近的代码"); //System.out.println("请修改第:" + integer + " 行附近的代码");
index += integer + ","; index += integer + ",";
} }
new TextToDalog("提示", "请修改第:" + index + " 行附近的代码,备注:" + json.getString("msg"), new DalogAbs() { new TextToDalog("提示", "请修改第:" + index + " 行附近的代码,备注:" + json.getString("msg"), new DalogAbs() {
@ -373,7 +411,7 @@ public class AutoRandomAdSDK {
if (listFile.isDirectory()) { if (listFile.isDirectory()) {
show(listFile); show(listFile);
} else { } else {
System.out.println(">?" + listFile.getAbsolutePath()); //System.out.println(">?" + listFile.getAbsolutePath());
} }
} }
@ -388,13 +426,15 @@ public class AutoRandomAdSDK {
} }
String path; String path;
String name; String name;
if (sdk == null) { /* if (sdk == null) {
path = rootPath; path = rootPath;
name = "tmp.zip"; name = "tmp.zip";
} else { } else {
path = sdk.getAbsolutePath() + ".out"; path = sdk.getAbsolutePath() + ".out";
name = sdk.getName(); name = sdk.getName();
} }*/
path = rootPath;
name = sdk == null ? "tmp.zip" : sdk.getName();
try { try {
Thread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -413,36 +453,31 @@ public class AutoRandomAdSDK {
File nLt = null; File nLt = null;
try { try {
if (!config.getBoolean("isJarLib")) { if (!config.getBoolean("isJarLib")) {
JarToAJar.toAJar(dxPath, sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName(), sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName() + "_dex.jar"); Tools.toAJar(dxPath, rootPath + 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()) new EncryptJar().encrypt(new File(rootPath + File.separator + sdk.getName())
, sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar", sdktype, version); , rootPath + File.separator + "dexTmp.jar", sdktype, version);
lt = new File(sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar"); lt = new File(rootPath + File.separator + "dexTmp.jar");
} else { } 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(); String exec = config.getString("dex2jar") + " " + rootPath + File.separator + sdk.getName();
System.out.println("exec:" + exec); //System.out.println("exec:" + exec);
Process process = Runtime.getRuntime().exec(exec); Process process = Runtime.getRuntime().exec(exec);
process.waitFor(); process.waitFor();
Thread.sleep(100);
process = Runtime.getRuntime().exec(exec); lt = new File(sdk.getName().replace(".jar", "-dex2jar.jar"));
process.waitFor();
lt = new File(sdk.getAbsolutePath().split(sdk.getName())[0], sdk.getName().replace(".jar", "-dex2jar.jar"));
} }
System.out.println(">>>:" + lt.getAbsolutePath()); //System.out.println(">>>:" + lt.getAbsolutePath());
if (lt.exists()) { if (lt.exists()) {
nLt = new File(config.getString("ltName")); nLt = new File(config.getString("ltName"));
if (nLt.exists()) { if (nLt.exists()) {
nLt.delete(); nLt.delete();
} }
lt.renameTo(nLt); lt.renameTo(nLt);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
if (inter != null) if (inter != null)
inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath()); inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath());
} catch (Exception e) { } catch (Exception e) {
@ -456,22 +491,46 @@ public class AutoRandomAdSDK {
} }
private void update() { private void update() {
for (String key : adClass.keySet()) { //System.out.println("配置:" + config.getBoolean("isAllPackage"));
File file = adClass.get(key); File root = null;
String fileName = file.getName().replace(".smali", "");
File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
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()) { for (File fs : filePath.listFiles()) {
System.out.println(fs.getAbsolutePath().replace(new File("").getAbsolutePath(), "")); // //System.out.println(fs.getAbsolutePath().replace(rootPath, ""));
if (fs.isDirectory()) { if (fs.isDirectory()) {
continue; continue;
} }
if (!fs.getName().startsWith(fileName)) { if (!fs.getName().startsWith(fileName)) {
continue; continue;
} }
String nName = getNewName(fs.getName()); String nName = getNewName(fs.getName());
if (fs.getName().startsWith(fileName + "$")) { if (fs.getName().startsWith(fileName + "$")) {
if (getNewName(fs.getName()).endsWith("[notmover]")) { if (getNewName(fs.getName()).endsWith("[notmover]")) {
Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(), fs Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(), fs
.getName().replace(fs.getName().split("\\$")[0], nName), true); .getName().replace(fs.getName().split("\\$")[0], nName), true);
@ -491,14 +550,22 @@ public class AutoRandomAdSDK {
file.delete(); file.delete();
} }
System.out.println("配置:" + config.getBoolean("isAllPackage")); if (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, "");
File root = new File(rootPath + File.separator + "smali");
allpackage(root, packge);
removeNullFile(root); 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 { } else {
path = nowAdClass.get(key).getAbsolutePath(); 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) if (isAddFile)
nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath()); nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath());
Tools.copyFileToName(file.getAbsolutePath(), path, boolean t = Tools.copyFileToName(file.getAbsolutePath(), path,
nName, true); nName, true);
file.delete();
////System.out.println("移动文件:" + file.getAbsolutePath() + "" + path + " 重命名为:" + nName + " 结果" + t);
} }
private void allpackage(File file, String packge) { private void allpackage(File file, String packge) {
for (File tmp : file.listFiles()) { for (File tmp : file.listFiles()) {
String pack = tmp.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, ""); String pack = tmp.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
if (!packge.contains(pack) && tmp.isDirectory()) { if (!packge.contains(pack) && tmp.isDirectory()) {
movesdk(tmp, File.separator + "smali" + File.separator + packge); movesdk(tmp, File.separator + "smali" + File.separator + packge);
@ -545,17 +619,34 @@ public class AutoRandomAdSDK {
file.delete(); file.delete();
continue; continue;
} }
if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) {
continue;
}
if (file.isDirectory()) { if (file.isDirectory()) {
String tmp = toPath + File.separator + file.getName(); String tmp = toPath + File.separator + file.getName();
//System.out.println("创建文件夹:"+tmp); ////System.out.println("创建文件夹:"+tmp);
new File(rootPath + File.separator + tmp).mkdirs(); new File(rootPath + File.separator + tmp).mkdirs();
movesdk(file, tmp); movesdk(file, tmp);
} else { } else {
boolean data = file.renameTo(new File(rootPath + File.separator + toPath, file.getName())); String fileName = file.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "")
// System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+""+(rootPath + File.separator + toPath)+" "+data); .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) { private void removeNullFile(File root) {
@ -579,7 +670,6 @@ public class AutoRandomAdSDK {
if (nName.endsWith("[notmover]")) { if (nName.endsWith("[notmover]")) {
nName = nName.replace("[notmover]", ""); nName = nName.replace("[notmover]", "");
} }
return nName; return nName;
} }
@ -613,6 +703,9 @@ public class AutoRandomAdSDK {
nName = nName.replace("[random]", tName); nName = nName.replace("[random]", tName);
config.getJSONObject("rename").put(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName, nName); config.getJSONObject("rename").put(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName, nName);
} }
/*if(nName.startsWith("{>")){
nName=nName.split("}")[1];
}*/
if (wName != null) { if (wName != null) {
nName += wName; nName += wName;
} }
@ -625,7 +718,7 @@ public class AutoRandomAdSDK {
for (int i = 0; i < clazzs.length(); i++) { for (int i = 0; i < clazzs.length(); i++) {
File path = new File(rootPath + File.separator + "smali"); File path = new File(rootPath + File.separator + "smali");
File mkdir = null; File mkdir = null;
for (int j = 0; j < config.getInt("packagerlimit"); j++) { for (int j = 0; j < random.length(); j++) {
String packageName; String packageName;
if (random.getString(j).equals("[random]")) { if (random.getString(j).equals("[random]")) {
packageName = Tools.getRandomString(3); packageName = Tools.getRandomString(3);
@ -638,10 +731,13 @@ public class AutoRandomAdSDK {
mkdir = new File(mkdir.getAbsolutePath() + File.separator + packageName); mkdir = new File(mkdir.getAbsolutePath() + File.separator + packageName);
} }
if (!mkdir.exists()) { if (!mkdir.exists()) {
mkdir.mkdirs(); boolean t = mkdir.mkdirs();
} }
} }
nowAdClass.put(clazzs.getString(i), mkdir); 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; 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() { private void outManifest() {
try { try {
@ -77,7 +89,7 @@ public class CsjTools {
reader.close(); reader.close();
String apkPackage = getXMLValue("package", tmp); String apkPackage = getXMLValue("package", tmp);
System.out.println(apkPackage); System.out.println(apkPackage);
_log.smaliPath("获取到APK包名"+apkPackage); _log.smaliPath("获取到APK包名" + apkPackage);
reader = new BufferedReader(new FileReader(demoManifest)); reader = new BufferedReader(new FileReader(demoManifest));
tmp = reader.readLine(); tmp = reader.readLine();
String manifest = tmp.replace(getXMLValue("package", tmp), apkPackage) + "\n"; String manifest = tmp.replace(getXMLValue("package", tmp), apkPackage) + "\n";
@ -204,8 +216,8 @@ public class CsjTools {
} }
outManifest(); outManifest();
File csjRes = new File("csj" + File.separator + "csc.apk"); File csjRes = new File("csj" + File.separator + "csc.apk");
if (!new File("csj/").exists()) { if (!new File("csj").exists()) {
new File("csj/").mkdirs(); new File("csj").mkdirs();
} }
SmaliUtils utils = new SmaliUtils(); SmaliUtils utils = new SmaliUtils();
_log.smaliPath("资源包制作完成开始打包为apk"); _log.smaliPath("资源包制作完成开始打包为apk");
@ -225,17 +237,17 @@ public class CsjTools {
public void build(String csjPath, String apkPath, SmaliApkToolsPath log) { public void build(String csjPath, String apkPath, SmaliApkToolsPath log) {
time = System.currentTimeMillis(); time = System.currentTimeMillis();
_log=log; _log = log;
unPackageCSJ=false; unPackageCSJ = false;
File csjFile = new File(csjPath); File csjFile = new File(csjPath);
if (new File(csjFile.getName().replace(".apk", "")).exists()) { 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; unPackageCSJ = true;
csj_Path = new File(csjFile.getName().replace(".apk", "")).getAbsolutePath(); csj_Path = new File(csjFile.getName().replace(".apk", "")).getAbsolutePath();
csj_res = csj_Path + File.separator + "res" + File.separator + "values"; csj_res = csj_Path + File.separator + "res" + File.separator + "values";
} }
SmaliUtils utils = new SmaliUtils(); 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)); Tools.deleteFiles(new File("").getAbsolutePath() + File.separator + new File(apkPath).getName().replace(".apk", File.separator));
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
@ -272,7 +284,7 @@ public class CsjTools {
new Thread(new Runnable() { new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
new AutoRandomAdSDK().startNotUnPackage(path, new SmaliApkToolsPath() { new AutoRandomAdSDK().startNotUnPackage(path, getPackageName(), new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
_log.smaliPath("穿山甲修改完成"); _log.smaliPath("穿山甲修改完成");
@ -303,15 +315,6 @@ public class CsjTools {
//还有最后一个问题穿山甲的Activity没改 //还有最后一个问题穿山甲的Activity没改
public static void main(String[] args) { 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(); CsjTools tools = new CsjTools();
tools.build("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2.apk", tools.build("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2.apk",
"D:\\IdeaProjects\\android_sdk_tools\\app-release.apk", "D:\\IdeaProjects\\android_sdk_tools\\app-release.apk",

View File

@ -16,14 +16,14 @@ import com.qy.ui.AppMain;
public class JarToAJar { public class JarToAJar {
private static JSONObject json; private static JSONObject json;
private final int BUFFER_SIZE = 2 * 1024;
public static void start(JSONObject json) { public static void start(JSONObject json) {
JarToAJar.json=json; JarToAJar.json=json;
JSONArray array=json.getJSONArray("array"); JSONArray array=json.getJSONArray("array");
String inName=json.isNull("input")?"com.zip":json.getString("input"); 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); new JarToAJar(inName,outName);
} }
@ -36,95 +36,16 @@ public class JarToAJar {
outFile.delete(); outFile.delete();
OutputStream outputStream = new FileOutputStream( OutputStream outputStream = new FileOutputStream(
new File(inName)); new File(inName));
toZip(json.getString(json.getString("switch")), outputStream, true); Tools.toZip(json.getString(json.getString("switch")), outputStream, true,true);
toAJar(dx,inName, outName); Tools.toAJar(dx,inName, outName);
System.out.println(outName); System.out.println(outName);
if(AppMain.isOpenWindows) if(AppMain.isOpenWindows)
Desktop.getDesktop().open(new File(json.getString("out"))); Desktop.getDesktop().open(new File(json.getString("out")));
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); 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; mainPath=uPath;
} }
public void start() { private SmaliApkToolsPath inter;
public void start(SmaliApkToolsPath inter) {
this.inter=inter;
list=new ArrayList<>(); list=new ArrayList<>();
System.out.println("开始修改:"+mainPath); System.out.println("开始修改:"+mainPath);
File path = new File(mainPath); File path = new File(mainPath);
@ -40,26 +42,23 @@ public class SmaliUtils {
try { try {
System.out.println(clazzList.size()); System.out.println(clazzList.size());
for (File file : files) { for (File file : files) {
new Thread(new Runnable() { String str = loadFile(file);
@Override writerFile(file,str);
public void run() {
String str= null;
try {
str = loadFile(file);
writerFile(file,str);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} }
inter.smaliPath("ok");
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} }
private int writerIndex=0;
private void test(){
writerIndex++;
if(files.size()==writerIndex){
inter.smaliPath("ok");
}
}
private void recursive(File file) { private void recursive(File file) {
String packname = null; String packname = null;
if (file.isFile()) { if (file.isFile()) {
@ -86,7 +85,7 @@ public class SmaliUtils {
e.printStackTrace(); e.printStackTrace();
} }
} else { } else {
System.out.println(file.getAbsolutePath()+" > "+file.exists()); //System.out.println(file.getAbsolutePath()+" > "+file.exists());
for (int i = 0; i < file.listFiles().length; i++) { for (int i = 0; i < file.listFiles().length; i++) {
recursive(file.listFiles()[i]); recursive(file.listFiles()[i]);
} }
@ -198,6 +197,9 @@ public class SmaliUtils {
} }
String[] args =new String[] {"d","-f",jarPath}; String[] args =new String[] {"d","-f",jarPath};
try { try {
for (String arg : args) {
System.out.print(arg+" ");
}
Main.main(args); Main.main(args);
File jarFile=new File(jarPath); File jarFile=new File(jarPath);
String name; String name;
@ -208,6 +210,7 @@ public class SmaliUtils {
}else { }else {
name=jarFile.getName(); name=jarFile.getName();
} }
//jarFile.delete();
smaliApkToolsPath.smaliPath(new File("").getAbsolutePath()+File.separator+name); smaliApkToolsPath.smaliPath(new File("").getAbsolutePath()+File.separator+name);
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block

View File

@ -3,9 +3,15 @@ package com.qy.utils;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Random; 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 org.json.JSONObject;
import static java.util.zip.ZipEntry.STORED;
public class Tools { public class Tools {
public static boolean stringIsNull(String string) { public static boolean stringIsNull(String string) {
@ -48,6 +54,7 @@ public class Tools {
File srcFile = new File(srcFileName); File srcFile = new File(srcFileName);
// 判断源文件是否存在 // 判断源文件是否存在
if (!srcFile.exists()) { if (!srcFile.exists()) {
return false; return false;
} else if (!srcFile.isFile()) { } else if (!srcFile.isFile()) {
return false; return false;
@ -58,11 +65,19 @@ public class Tools {
// 如果目标文件所在目录不存在则创建目录 // 如果目标文件所在目录不存在则创建目录
if (!destFile.exists()) { if (!destFile.exists()) {
// 目标文件所在目录不存在 // 目标文件所在目录不存在
boolean t=destFile.mkdirs();
if(srcFileName.equals("Activity.smali")){
System.out.println("创建文件夹:"+destFileName+" "+t);
}
if (!destFile.mkdirs()) { if (!destFile.mkdirs()) {
// 复制文件失败创建目标文件所在目录失败 // 复制文件失败创建目标文件所在目录失败
return false; 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, public static boolean copyFile(String srcFileName, String destFileName,
boolean overlay) { 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) { public static JSONObject loadConfig(File file) {
@ -138,4 +203,112 @@ public class Tools {
} }
return json; 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) { public static void start(String packName, String managename,Map<String,String> functions) {
try { 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; String str="",tmp;
while ((tmp=reader.readLine())!=null) { while ((tmp=reader.readLine())!=null) {
tmp=tmp.replace("${GameSDK}", managename); tmp=tmp.replace("${GameSDK}", managename);
@ -24,7 +24,7 @@ public class WorldTools {
tmp=tmp.replace("${getSDKManage}", functions.get("getSDKManage")); tmp=tmp.replace("${getSDKManage}", functions.get("getSDKManage"));
str+=tmp+"\n"; str+=tmp+"\n";
} }
FileWriter writer=new FileWriter(new File("文档.txt")); FileWriter writer=new FileWriter(new File("文档.txt"));
writer.write(str); writer.write(str);
writer.flush(); writer.flush();
writer.close(); writer.close();