完善了穿山甲资源包生成的初始版本

This commit is contained in:
Yutousama 2020-02-21 17:37:20 +08:00
parent 9fa2eb3a02
commit e9e5ba609b
7 changed files with 1114 additions and 683 deletions

View File

@ -84,7 +84,7 @@
"title": "万维", "title": "万维",
"ltName": "OnewaySDK_QY.lt", "ltName": "OnewaySDK_QY.lt",
"manifest": [ "manifest": [
"<activity android:name=\"mobi.oneway.export.AdShowActivity\" android:configChanges=\"fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen\" android:hardwareAccelerated=\"true\" android:launchMode=\"singleTask\" android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\" />", "<activity android:name=\"mobi.oneway.export.AdShowActivity\" android:configChanges=\"fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen\" android:hardwareAccelerated=\"true\" android:launchMode=\"singleTask\" android:theme=\"@android:style/Theme.NoTitleBar.Fullscreen\" />"
], ],
"class": [ "class": [
"mobi.oneway.sdk.AdShowActivity" "mobi.oneway.sdk.AdShowActivity"
@ -141,10 +141,75 @@
"isJarLib": true, "isJarLib": true,
"packagerlimit": 3, "packagerlimit": 3,
"isManual": false, "isManual": false,
"manual": [],
"dex2jar": "D:\\反编译\\dex2jar-2.0\\_d2j-dex2jar.bat"
},
{
"title": "穿山甲",
"ltName": "open_ad_sdk.jar",
"manifest": [
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTLandingPageActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTPlayableLandingPageActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTVideoLandingPageActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTRewardVideoActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTRewardExpressVideoActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTFullScreenVideoActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTFullScreenExpressVideoActivity\" android:configChanges=\"keyboardHidden|orientation|screenSize\" android:launchMode=\"standard\" /> ",
"<activity android:name=\"com.bytedance.sdk.openadsdk.activity.TTDelegateActivity\" android:launchMode=\"singleTask\" android:theme=\"@android:style/Theme.Translucent.NoTitleBar\" /> ",
"<service android:name=\"com.bytedance.sdk.openadsdk.multipro.aidl.BinderPoolService\" /> ",
"<receiver android:name=\"com.bytedance.embedapplog.collector.Collector\" android:enabled=\"true\" android:exported=\"true\" /> ",
"<service android:name=\"com.bytedance.tea.crash.upload.CrashUploadService\" android:process=\":npth\" />"
],
"class":[
"com.bytedance.sdk.openadsdk.activity.TTLandingPageActivity",
"com.bytedance.sdk.openadsdk.activity.TTPlayableLandingPageActivity",
"com.bytedance.sdk.openadsdk.activity.TTVideoLandingPageActivity",
"com.bytedance.sdk.openadsdk.activity.TTRewardVideoActivity",
"com.bytedance.sdk.openadsdk.activity.TTRewardExpressVideoActivity",
"com.bytedance.sdk.openadsdk.activity.TTFullScreenVideoActivity",
"com.bytedance.sdk.openadsdk.activity.TTFullScreenExpressVideoActivity",
"com.bytedance.sdk.openadsdk.activity.TTDelegateActivity",
"com.bytedance.sdk.openadsdk.multipro.aidl.BinderPoolService",
"com.bytedance.embedapplog.collector.Collector",
"com.bytedance.tea.crash.upload.CrashUploadService",
"com.bytedance.sdk.openadsdk.activity.TTBaseVideoActivity"
],
"random":[
"com",
"ww",
"za"
],
"isAllPackage":false,
"isReName":true,
"isJarLib":true,
"packagerlimit":3,
"isManual":false,
"outManifest":false,
"manual":[ "manual":[
], ],
"dex2jar":"/media/yutou/_dde_data/反编译/dex2jar-2.0/_d2j-dex2jar.sh" "rename":{
"TTLandingPageActivity":"{>+/activity}TTLandingPageActivity",
"TTPlayableLandingPageActivity":"{>+/activity}TTPlayableLandingPageActivity",
"TTVideoLandingPageActivity":"{>+/activity}TTVideoLandingPageActivity",
"TTRewardVideoActivity":"{>+/activity}TTRewardVideoActivity",
"TTRewardExpressVideoActivity":"{>+/activity}TTRewardExpressVideoActivity",
"TTFullScreenVideoActivity":"{>+/activity}TTFullScreenVideoActivity",
"TTFullScreenExpressVideoActivity":"{>+/activity}TTFullScreenExpressVideoActivity",
"TTDelegateActivity":"{>+/activity}TTDelegateActivity",
"TTBaseVideoActivity":"{>+/activity}TTBaseVideoActivity",
"BinderPoolService":"BinderPoolService",
"Collector":"Collector",
"CrashUploadService":"CrashUploadService"
},
"filter":[
"com.android",
"com.xandroid",
"com.google",
"com.android",
"com.androidx"
]
} }
] ]
} }

View File

@ -1,11 +1,11 @@
{ {
"switch":"1",
"1": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/", "1": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"2": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/", "2": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"3": "F:/AndroidStudio_Data/GameSDK/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/", "3": "F:/AndroidStudio_Data/GameSDK/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"4": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/", "4": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"5": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/", "5": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"6": "/home/yutou/AndroidStudioProjects/ADSDK_v5/Test/build/intermediates/javac/debug/classes/com/", "6": "/home/yutou/AndroidStudioProjects/ADSDK_v5/Test/build/intermediates/javac/debug/classes/com/",
"switch": "1",
"input": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/com.zip", "input": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/com.zip",
"out": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/", "out": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/",
"dx": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/dx.jar", "dx": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/dx.jar",
@ -16,5 +16,37 @@
"rd_rx", "rd_rx",
"qy_rx", "qy_rx",
"atest" "atest"
],
"csjConfig": {
"xml": {
"data": [
{
"command": "remove",
"name": "${demoRoot}/res/values/public.xml",
"data": [
{
"title": "type",
"value": "raw"
},
{
"title": "type",
"value": "xml"
}
] ]
} }
]
},
"file": {
"data": [
{
"command": "delete",
"name": "${demoRoot}/res/raw/*"
},
{
"command":"delete",
"name":"${demoRoot}/lib/*"
}
]
}
}
}

View File

@ -8,6 +8,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.security.Permission;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.Vector; import java.util.Vector;
@ -29,6 +30,7 @@ import javax.swing.SwingConstants;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.border.LineBorder; import javax.swing.border.LineBorder;
import com.sun.javaws.exceptions.ExitException;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
@ -66,10 +68,12 @@ public class AppMain extends JFrame {
public static void main(String[] args) { public static void main(String[] args) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
new AppMain(); new AppMain();
} }
public AppMain() { public AppMain() {
setResizable(false); setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
json = Tools.loadConfig(new File("config.cfg")); json = Tools.loadConfig(new File("config.cfg"));

View File

@ -7,6 +7,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.sql.SQLOutput;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -34,8 +35,9 @@ import com.qy.Interfaces.DalogAbs;
], ],
"rename": {//修改类名 "rename": {//修改类名
"MyActivity": "Activity",//指定类名 "MyActivity": "Activity",//指定类名
"TMProvider":"TProvider[notmover]",//指定但不移动路径 "TMProvider":"TProvider[notmover]",//指定但不移动路径
"BannerView":"[random]"//随机类名2~6 "BannerView":"[random]"//随机类名2~6
"BannerView":"{+/activity}BannerView"//指定路径 [+表示在random的基础上]
}, },
"isAllPackage":true,//修改所有包名false的话只修改class指定的包名 "isAllPackage":true,//修改所有包名false的话只修改class指定的包名
"isReName": true,//重命名类名 "isReName": true,//重命名类名
@ -71,6 +73,10 @@ public class AutoRandomAdSDK {
// new AutoRandomAdSDK(new File("GDTSDK.unionNormal.4.100.970.jar"), 0, null); // new AutoRandomAdSDK(new File("GDTSDK.unionNormal.4.100.970.jar"), 0, null);
} }
public AutoRandomAdSDK() {
}
public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) { public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
this.inter = inster; this.inter = inster;
@ -119,11 +125,27 @@ public class AutoRandomAdSDK {
}); });
} }
boolean isPackage = true;
public void startNotUnPackage(String path, SmaliApkToolsPath inster) {
this.inter = inster;
isPackage = false;
adClass = new HashMap<String, File>();
nowAdClass = new HashMap<String, File>();
nowAdFile = new HashMap<String, String>();
smalitools = new SmaliUtils();
JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
config = cfg.getJSONArray("array").getJSONObject(4);
rootPath = path;
sdktype = "13";
alter();
}
private void alter() { private void alter() {
JSONArray clazzs = config.getJSONArray("class"); JSONArray clazzs = config.getJSONArray("class");
for (int i = 0; i < clazzs.length(); i++) { for (int i = 0; i < clazzs.length(); i++) {
File clz = new File(rootPath + File.separator + "smali" + File.separator File clz = new File(rootPath + File.separator + "smali" + File.separator
+ clazzs.getString(i).replaceAll("\\.", File.separator) + ".smali"); + clazzs.getString(i).replace(".", File.separator) + ".smali");
if (clz.exists()) { if (clz.exists()) {
adClass.put(clazzs.getString(i), clz); adClass.put(clazzs.getString(i), clz);
} }
@ -138,6 +160,9 @@ public class AutoRandomAdSDK {
} }
private void outManifest() { private void outManifest() {
if (!config.isNull("outManifest") && !config.getBoolean("outManifest")) {
return;
}
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
for (String key : nowAdClass.keySet()) { for (String key : nowAdClass.keySet()) {
JSONArray manifest = config.getJSONArray("manifest"); JSONArray manifest = config.getJSONArray("manifest");
@ -178,13 +203,29 @@ public class AutoRandomAdSDK {
} }
private void change() { private void change() {
File file;
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"); smalitools.setPath(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
}
System.out.println(smalitools.mainPath); System.out.println(smalitools.mainPath);
try { try {
Thread.sleep(200); Thread.sleep(200);
System.out.println(smalitools.mainPath); System.out.println(smalitools.mainPath);
File file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
if (file.exists()) { if (file.exists()) {
JSONArray array = config.getJSONArray("filter");
if (array != null) {
List<String> list = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
list.add(array.getString(i));
}
smalitools.setFilter(list);
}
smalitools.start(); smalitools.start();
if (config.getBoolean("isManual")) { if (config.getBoolean("isManual")) {
manual(); manual();
@ -243,8 +284,23 @@ public class AutoRandomAdSDK {
} }
private void out() { private void out() {
smalitools.bale(sdk.getAbsolutePath() + ".out", if (!isPackage) {
sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName(),new SmaliApkToolsPath() { if (inter != null) {
inter.smaliPath("not package");
return;
}
}
String path;
String name;
if (sdk == null) {
path = rootPath;
name = "tmp.zip";
} else {
path = sdk.getAbsolutePath() + ".out";
name = sdk.getName();
}
smalitools.bale(path,
path + File.separator + name, new SmaliApkToolsPath() {
@Override @Override
public void smaliPath(String path) { public void smaliPath(String path) {
@ -252,6 +308,8 @@ public class AutoRandomAdSDK {
try { try {
outManifest(); outManifest();
File lt; File lt;
File nLt = null;
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"); 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()) new EncryptJar().encrypt(new File(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName())
@ -265,11 +323,17 @@ public class AutoRandomAdSDK {
} }
System.out.println(">>>:" + lt.getAbsolutePath()); System.out.println(">>>:" + lt.getAbsolutePath());
if (lt.exists()) { if (lt.exists()) {
File nLt = new File(config.getString("ltName")); nLt = new File(config.getString("ltName"));
lt.renameTo(nLt); lt.renameTo(nLt);
if (inter != null)
inter.smaliPath(nLt.getAbsolutePath());
} }
} catch (Exception e) {
e.printStackTrace();
}
if (inter != null)
inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath());
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
e.printStackTrace(); e.printStackTrace();
@ -287,17 +351,24 @@ public class AutoRandomAdSDK {
File filePath = new File(file.getAbsolutePath().replace(file.getName(), "")); File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
for (File fs : filePath.listFiles()) { for (File fs : filePath.listFiles()) {
if(fs.isDirectory()){
continue;
}
if(!fs.getName().startsWith(fileName)){
continue;
}
if (fs.getName().equals("BuildConfig.smali")) { if (fs.getName().equals("BuildConfig.smali")) {
fs.delete(); fs.delete();
continue; continue;
} }
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(), Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(),
getNewName(fs.getName()) + "$" + fs.getName().split("\\$")[1], true); nName + "$" + fs.getName().split("\\$")[1], true);
} else { } else {
Tools.copyFileToName(fs.getAbsolutePath(), nowAdClass.get(key).getAbsolutePath(), moveFile(fs, key, nName + "$" + fs.getName().split("\\$")[1],false);
getNewName(fs.getName()) + "$" + fs.getName().split("\\$")[1], true);
} }
fs.delete(); fs.delete();
} }
@ -307,9 +378,7 @@ public class AutoRandomAdSDK {
Tools.copyFileToName(file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), ""), Tools.copyFileToName(file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), ""),
getNewName(file.getName()) + ".smali", true); getNewName(file.getName()) + ".smali", true);
} else { } else {
nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath()); moveFile(file, key, getNewName(file.getName()) + ".smali",true);
Tools.copyFileToName(file.getAbsolutePath(), nowAdClass.get(key).getAbsolutePath(),
getNewName(file.getName()) + ".smali", true);
} }
file.delete(); file.delete();
@ -323,6 +392,30 @@ public class AutoRandomAdSDK {
removeNullFile(root); removeNullFile(root);
} }
} }
private void moveFile(File file, String key, String nName, boolean isAddFile) {
String path;
if (nName.startsWith("{>")) {
nName = nName.replace("{>", "");
String tmp = nName.split("}")[0];
nName = nName.split("}")[1];
tmp = tmp.replace("}", "");// +/activity
tmp = tmp.replace("/", File.separator);
String t = tmp.substring(0, 1);
if (t.equals("+")) {
path = nowAdClass.get(key).getAbsolutePath() + tmp.replace("+","");
} else {
path = rootPath + File.separator + "smali" + tmp;
}
} else {
path = nowAdClass.get(key).getAbsolutePath();
}
if (isAddFile)
nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath());
Tools.copyFileToName(file.getAbsolutePath(), path,
nName, true);
}
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, "");
@ -335,6 +428,7 @@ public class AutoRandomAdSDK {
} }
} }
private void movesdk(File path, String toPath) { private void movesdk(File path, String toPath) {
for (File file : path.listFiles()) { for (File file : path.listFiles()) {
if (file.isDirectory()) { if (file.isDirectory()) {
@ -348,6 +442,7 @@ public class AutoRandomAdSDK {
} }
} }
} }
private void removeNullFile(File root) { private void removeNullFile(File root) {
for (File file : root.listFiles()) { for (File file : root.listFiles()) {
if (file.isDirectory()) { if (file.isDirectory()) {
@ -363,6 +458,7 @@ public class AutoRandomAdSDK {
} }
} }
} }
private String getNewName(String name) { private String getNewName(String name) {
String nName = getNewNameForSrc(name); String nName = getNewNameForSrc(name);
if (nName.endsWith("[notmover]")) { if (nName.endsWith("[notmover]")) {
@ -371,6 +467,7 @@ public class AutoRandomAdSDK {
return nName; return nName;
} }
private String getNewNameForSrc(String name) { private String getNewNameForSrc(String name) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
if (!config.getBoolean("isReName")) { if (!config.getBoolean("isReName")) {

View File

@ -1,71 +1,90 @@
package com.qy.utils; package com.qy.utils;
import com.qy.Interfaces.SmaliApkToolsPath; import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.ui.TextToDalog; import com.qy.ui.EditToDalog;
import org.json.JSONArray;
import org.json.JSONObject;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.*;
import java.util.List; import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CsjTools { public class CsjTools {
private String csj_R_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1\\smali\\com\\bytedance\\sdk\\openadsdk"; private static String csj_res = "D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2\\res\\values";
private String csj_demo_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1"; private static String apk_res = "D:\\IdeaProjects\\android_sdk_tools\\app-release\\res\\values";
private String apk_R_path="E:\\idea\\android_sdk_tools\\app-release-1\\smali\\com\\luckyboy\\mmxing"; private static String apk_Path = "D:\\IdeaProjects\\android_sdk_tools\\app-release";
private static String csj_Path = "D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2";
private List<String> r_list; private List<String> r_list;
public CsjTools() { public CsjTools() {
} }
public void setR() {
r_list=new ArrayList<>(); public String loadXml(String path) {
File apk_R=new File(csj_R_path+File.separator+"R.smali"); File file = new File(path);
if(!apk_R.exists()){ String xml = null;
new TextToDalog("找不到文件","穿山甲R文件不存在:"+apk_R);
return;
}
try { try {
BufferedReader reader=new BufferedReader(new FileReader(apk_R)); BufferedReader reader = new BufferedReader(new FileReader(file));
String tmp; String tmp;
while ((tmp = reader.readLine()) != null) { while ((tmp = reader.readLine()) != null) {
if(tmp.contains("/R$")){ if (xml == null) {
r_list.add(tmp.split("/")[tmp.split("/").length-1].replace(";,","").replace(";","")); xml = tmp + "\n";
} else {
xml += tmp + "\n";
} }
} }
/*for (String fileName : r_list) { reader.close();
setRData(fileName);
}*/
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return xml;
} }
private void setRData(String fileName){
File apkR=new File(apk_R_path+File.separator+fileName+".smali");
List<String> header=new ArrayList<>();
List<String> end=new ArrayList<>();
boolean isHeader=true; public long getId(String publicXml) {
long id=-1; long maxId = 0;
for (String xml : publicXml.split("\n")) {
String id = getXMLValue("id", xml.trim());
if (id != null) {
id = id.substring(2, 6);
if (maxId < Long.parseLong(id, 16)) {
maxId = Long.parseLong(id, 16);
}
}
}
return maxId;
}
public String getXMLValue(String name, String message) {
Pattern p = Pattern.compile(name + "=\"([^\"]+)\"");
Matcher m = p.matcher(message);
if (m.find()) {
String tmp = message.substring(m.start(), m.end()).split("=")[1];
return tmp.substring(1, tmp.length() - 1);
}
return null;
}
private void outManifest() {
try { try {
BufferedReader reader=new BufferedReader(new FileReader(apkR)); File apkManifest = new File(apk_Path + File.separator + "AndroidManifest.xml");
String tmp; File demoManifest = new File(csj_Path + File.separator + "AndroidManifest.xml");
BufferedReader reader = new BufferedReader(new FileReader(apkManifest));
String tmp = reader.readLine();
reader.close();
String apkPackage = getXMLValue("package", tmp);
System.out.println(apkPackage);
reader = new BufferedReader(new FileReader(demoManifest));
tmp = reader.readLine();
String manifest = tmp.replace(getXMLValue("package", tmp), apkPackage) + "\n";
while ((tmp = reader.readLine()) != null) { while ((tmp = reader.readLine()) != null) {
if(tmp.trim().equals("# direct methods")){ manifest += tmp + "\n";
isHeader=false;
}
if(isHeader){
header.add(tmp);
if(tmp.contains(":I = 0x")){
id=Long.parseLong(tmp.split("0x")[1],16);
}
}else{
end.add(tmp);
}
}
header.addAll(getCSJR(fileName,id));
header.addAll(end);
FileWriter writer=new FileWriter(apkR);
for (String str : header) {
writer.write(str+"\n");
} }
FileWriter writer = new FileWriter(demoManifest);
writer.write(manifest);
writer.flush(); writer.flush();
writer.close(); writer.close();
@ -73,39 +92,224 @@ public class CsjTools {
e.printStackTrace(); e.printStackTrace();
} }
} }
private List<String> getCSJR(String fileName,long id){
File csjR=new File(csj_R_path+File.separator+fileName+".smali"); private void out(String srcFile, String encryptFile, int version) {
List<String> csj=new ArrayList<>(); EncryptJar encryptJar = new EncryptJar();
encryptJar.encrypt(new File(srcFile), encryptFile, 13, version);
}
private void commandFile() {
JSONObject config = Tools.loadConfig(new File("config.cfg"));
if (config != null && config.getJSONObject("csjConfig") != null) {
JSONObject _config = config.getJSONObject("csjConfig");
JSONObject fileConfig = _config.getJSONObject("file");
JSONArray data = fileConfig.getJSONArray("data");
for (Object _item : data) {
JSONObject item = (JSONObject) _item;
String path = item.getString("name");
if (item.getString("command").equals("delete")) {
path = path.replace("${demoRoot}", csj_Path)
.replace("${apkRoot}", apk_Path)
.replace("/", File.separator);
File file = new File(path.replace("*", ""));
if (path.endsWith("*")) {
Tools.deleteFiles(file.getAbsolutePath());
} else {
file.delete();
}
}
}
_config = config.getJSONObject("csjConfig").getJSONObject("xml");
if (_config != null) {
data = _config.getJSONArray("data");
for (Object _item : data) {
JSONObject item = (JSONObject) _item;
if (item.getString("command").equals("remove")) {
String path = item.getString("name")
.replace("${demoRoot}", csj_Path)
.replace("${apkRoot}", apk_Path)
.replace("/", File.separator);
File file = new File(path);
commandXml(file, item);
}
}
}
}
}
private void commandXml(File file, JSONObject item) {
try { try {
BufferedReader reader=new BufferedReader(new FileReader(csjR)); String fileXml = loadXml(file.getAbsolutePath());
String tmp; String newXml = "";
long nextId=id; boolean remove = false;
while ((tmp=reader.readLine())!=null){ for (String xml : fileXml.split("\n")) {
if(tmp.trim().startsWith(".field public")){ for (Object data : item.getJSONArray("data")) {
csj.add(tmp.replace(".field public static",".field public static final")+" = 0x"+Long.toHexString(++nextId)); JSONObject _item = (JSONObject) data;
String value = getXMLValue(_item.getString("title"), xml.trim());
if (value != null && value.equals(_item.getString("value"))) {
remove = true;
} }
} }
csj.add("\n"); if (remove) {
remove = false;
continue;
}
newXml += xml + "\n";
}
FileWriter writer = new FileWriter(file);
writer.write(newXml);
writer.flush();
writer.close();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return csj;
}
private void copyFile(){
setR();
for (String s : r_list) {
Tools.copyFile(apk_R_path+File.separator+s+".smali",csj_R_path+File.separator+s+".smali",true);
} }
private void start(SmaliApkToolsPath toolsPath) {
System.out.println("开始制作资源包");
commandFile();
String apkXML = loadXml(apk_res + File.separator + "public.xml");
String demoXML = loadXml(csj_res + File.separator + "public.xml");
long maxId = getId(apkXML);
int index = 0;
String message = "";
String oldType = "";
for (String xml : demoXML.split("\n")) {
String type = getXMLValue("type", xml.trim());
// String name = getXMLValue("name", xml.trim());
String oldId = getXMLValue("id", xml.trim());
if (type != null && !type.equals(oldType)) {
oldType = type;
maxId++;
index = 0;
} }
private void out(){ if (type != null) {
EncryptJar encryptJar=new EncryptJar(); String nextId = "0x" + Long.toHexString(maxId + 1) + String.format("%.3f", (index++) / 1000f).replace(".", "");
encryptJar.encrypt(new File("E:\\idea\\android_sdk_tools\\csj.apk"),"E:\\idea\\android_sdk_tools\\csj_",13,5600); xml = xml.replace(oldId, nextId);
}
message += xml + "\n";
}
try {
FileWriter writer = new FileWriter(new File(csj_res + File.separator + "public.xml"));
writer.write(message);
writer.flush();
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
outManifest();
File csjRes = new File("csj" + File.separator + "csc.apk");
if (!new File("csj/").exists()) {
new File("csj/").mkdirs();
}
SmaliUtils utils = new SmaliUtils();
utils.bale(csj_Path, csjRes.getAbsolutePath(), new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
toolsPath.smaliPath("已出包" + csjRes.getAbsolutePath());
System.out.println("耗时:"+(System.currentTimeMillis()-time)/1000+"");
}
});
}
private long time;
public void build(String csjPath, String apkPath, SmaliApkToolsPath log) {
time=System.currentTimeMillis();
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(apkPath).getName().replace(".apk",File.separator));
new Thread(new Runnable() {
@Override
public void run() {
log.smaliPath("开始反编译目标APK");
utils.unPack(apkPath, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
log.smaliPath("目标APK反编译完成:" + path);
apkUnPackage = true;
System.out.println(path);
apk_Path = path;
apk_res = apk_Path + File.separator + "res" + File.separator + "values";
runStart(log);
}
});
log.smaliPath("开始反编译穿山甲Demo");
utils.unPack(csjPath, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
log.smaliPath("穿山甲Demo反编译完成:" + path);
System.out.println(path);
csj_Path = path;
csj_res = csj_Path + File.separator + "res" + File.separator + "values";
log.smaliPath("开始修改穿山甲清单");
new Thread(new Runnable() {
@Override
public void run() {
new AutoRandomAdSDK().startNotUnPackage(path, new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println("-------" + path);
csjManifest = true;
runStart(log);
}
});
}
}).start();
}
});
} }
}).start();
}
boolean csjManifest = false;
boolean apkUnPackage = false;
private void runStart(SmaliApkToolsPath log) {
if (apkUnPackage && csjManifest) {
start(log);
}
}
//还有最后一个问题穿山甲的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.out(); tools.build("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2.apk",
"D:\\IdeaProjects\\android_sdk_tools\\app-release.apk",
new SmaliApkToolsPath() {
@Override
public void smaliPath(String log) {
System.out.println(log);
if (log.startsWith("已出包")) {
System.out.println("打包完成");
new EditToDalog("成功", "打包完成,请输入版本号", "5600", new SmaliApkToolsPath() {
@Override
public void smaliPath(String path) {
System.out.println(">>" + path);
tools.out(log.replace("已出包", ""),
new File("csj").getAbsolutePath() + File.separator + "csc",
Integer.parseInt(path));
}
});
}
}
});
// tools.outManifest();
// tools.start();
} }
} }

View File

@ -15,7 +15,7 @@ import com.qy.Interfaces.SmaliApkToolsPath;
import brut.apktool.Main; import brut.apktool.Main;
public class SmaliUtils { public class SmaliUtils {
private String str = ""; //private String str = "";
public String mainPath =null; public String mainPath =null;
private int mix = 1000; private int mix = 1000;
// private String mainPath = "D:\\反编译\\APK\\rx.jar.out\\smali"; // private String mainPath = "D:\\反编译\\APK\\rx.jar.out\\smali";
@ -33,14 +33,27 @@ public class SmaliUtils {
} }
public void start() { public void start() {
list=new ArrayList<>();
System.out.println("开始修改:"+mainPath); System.out.println("开始修改:"+mainPath);
File path = new File(mainPath); File path = new File(mainPath);
recursive(path); recursive(path);
try { try {
System.out.println(clazzList.size()); System.out.println(clazzList.size());
for (File file : files) { for (File file : files) {
loadFile(file); new Thread(new Runnable() {
writerFile(file); @Override
public void run() {
String str= null;
try {
str = loadFile(file);
writerFile(file,str);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
} }
} catch (Exception e) { } catch (Exception e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
@ -83,8 +96,14 @@ public class SmaliUtils {
private void readFile(File file, String packName) throws Exception { private void readFile(File file, String packName) throws Exception {
boolean isOneLine = true; boolean isOneLine = true;
for (String filter : list) {
filter=filter.replace(".",File.separator);
if(file.getAbsolutePath().contains(File.separator+filter+File.separator)){
return;
}
}
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
str = ""; //String str = "";
String tmp = null; String tmp = null;
while ((tmp = reader.readLine()) != null) { while ((tmp = reader.readLine()) != null) {
if (isOneLine) { if (isOneLine) {
@ -109,7 +128,9 @@ public class SmaliUtils {
if (newName != null) { if (newName != null) {
newName = newName.replace(";", ""); newName = newName.replace(";", "");
//System.out.println("获取到老包名:" + newName + "新包名:" + (packName + "/" + file.getName().replace(".smali", ""))); //System.out.println("获取到老包名:" + newName + "新包名:" + (packName + "/" + file.getName().replace(".smali", "")));
clazzList.put(newName, (packName + File.separator + file.getName().replace(".smali", ""))); clazzList.put(newName, (packName + "/"+ file.getName()
.replace(".smali", "")
.replace("#","")));
if (clazzList.get(newName).length() < mix) { if (clazzList.get(newName).length() < mix) {
mix = clazzList.get(newName).length(); mix = clazzList.get(newName).length();
} }
@ -117,7 +138,7 @@ public class SmaliUtils {
isOneLine = false; isOneLine = false;
} }
// tmp = changeLine(tmp); // tmp = changeLine(tmp);
str += tmp + "\n"; // str += tmp + "\n";
} }
reader.close(); reader.close();
@ -125,7 +146,7 @@ public class SmaliUtils {
private String loadFile(File file) throws Exception { private String loadFile(File file) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file)); BufferedReader reader = new BufferedReader(new FileReader(file));
str = ""; String str = "";
String tmp = null; String tmp = null;
while ((tmp = reader.readLine()) != null) { while ((tmp = reader.readLine()) != null) {
str += tmp + "\n"; str += tmp + "\n";
@ -134,7 +155,13 @@ public class SmaliUtils {
return str; return str;
} }
private void writerFile(File file) throws Exception { private void writerFile(File file,String str) throws Exception {
for (String filter : list) {
filter=filter.replace(".",File.separator);
if(file.getAbsolutePath().contains(File.separator+filter+File.separator)){
return;
}
}
String[] datas = str.split("\n"); String[] datas = str.split("\n");
String save = ""; String save = "";
i = 1; i = 1;
@ -169,7 +196,7 @@ public class SmaliUtils {
if(path.exists()&&path.isDirectory()) { if(path.exists()&&path.isDirectory()) {
Tools.deleteFiles(path.getAbsolutePath()); Tools.deleteFiles(path.getAbsolutePath());
} }
String args[]=new String[] {"d","-f",jarPath}; String[] args =new String[] {"d","-f",jarPath};
try { try {
Main.main(args); Main.main(args);
File jarFile=new File(jarPath); File jarFile=new File(jarPath);
@ -177,7 +204,7 @@ public class SmaliUtils {
if(jarFile.getName().contains(".jar")) { if(jarFile.getName().contains(".jar")) {
name=jarFile.getName()+".out"; name=jarFile.getName()+".out";
}else if(jarFile.getName().contains(".apk")) { }else if(jarFile.getName().contains(".apk")) {
name=jarFile.getName().split("\\.")[0]; name=jarFile.getName().replace(".apk","");
}else { }else {
name=jarFile.getName(); name=jarFile.getName();
} }
@ -190,15 +217,15 @@ public class SmaliUtils {
public void bale(String path,String smaliPath) { public void bale(String path,String smaliPath) {
bale(path,smaliPath,null); bale(path,smaliPath,null);
} }
public void bale(String path,String smaliPath,SmaliApkToolsPath inter) { public void bale(String smaliPath,String path,SmaliApkToolsPath inter) {
String args[]=new String[] {"b","-f",path,"-o",smaliPath}; String[] args =new String[] {"b","-f",smaliPath,"-o",path};
for (String string : args) { for (String string : args) {
System.out.print(string+" "); System.out.print(string+" ");
} }
try { try {
Main.main(args); Main.main(args);
if(inter!=null) { if(inter!=null) {
inter.smaliPath("ok"); inter.smaliPath(path);
} }
} catch (Exception e) { } catch (Exception e) {
// TODO: handle exception // TODO: handle exception
@ -208,4 +235,8 @@ public class SmaliUtils {
} }
} }
} }
List<String> list;
public void setFilter(List<String> list){
this.list=list;
}
} }

View File

@ -47,34 +47,33 @@ public class Tools {
deleteFiles(file.getAbsolutePath()); deleteFiles(file.getAbsolutePath());
} }
} }
// System.out.println("ɾ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> "+files.getAbsolutePath()); // System.out.println("删除文件 "+files.getAbsolutePath());
files.delete(); files.delete();
} }
} }
public static boolean copyFileToName(String srcFileName,String destFileName,String fileName,boolean overlay) { public static boolean copyFileToName(String srcFileName,String destFileName,String fileName,boolean overlay) {
File srcFile = new File(srcFileName); File srcFile = new File(srcFileName);
// <EFBFBD>ж<EFBFBD>Դ<EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> // 判断源文件是否存在
if (!srcFile.exists()) { if (!srcFile.exists()) {
return false; return false;
} else if (!srcFile.isFile()) { } else if (!srcFile.isFile()) {
return false; return false;
} }
// <EFBFBD>ж<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> // 判断目标文件是否存在
File destFile = new File(destFileName); File destFile = new File(destFileName);
// <EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>򴴽<EFBFBD>Ŀ¼ // 如果目标文件所在目录不存在则创建目录
if (!destFile.exists()) { if (!destFile.exists()) {
// Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> // 目标文件所在目录不存在
if (!destFile.mkdirs()) { if (!destFile.mkdirs()) {
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼ʧ<EFBFBD><EFBFBD> // 复制文件失败创建目标文件所在目录失败
return false; return false;
} }
destFile.delete();
} }
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> // 复制文件
int byteread = 0; // <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD> int byteread = 0; // 读取的字节数
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
@ -83,7 +82,7 @@ public class Tools {
fileName=srcFile.getName(); fileName=srcFile.getName();
} }
in = new FileInputStream(srcFile); in = new FileInputStream(srcFile);
out = new FileOutputStream(destFile); out = new FileOutputStream(destFile + "/" +fileName );
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
while ((byteread = in.read(buffer)) != -1) { while ((byteread = in.read(buffer)) != -1) {
@ -108,12 +107,12 @@ public class Tools {
} }
} }
/** /**
* <EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> * 复制单个文件
* *
* @param srcFileName <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƶ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD> * @param srcFileName 待复制的文件名
* @param destFileName Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD> * @param destFileName 目标文件名
* @param overlay <EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>Ƿ񸲸<EFBFBD> * @param overlay 如果目标文件存在是否覆盖
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>true<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD>false * @return 如果复制成功返回true否则返回false
*/ */
public static boolean copyFile(String srcFileName, String destFileName, public static boolean copyFile(String srcFileName, String destFileName,
boolean overlay) { boolean overlay) {
@ -146,4 +145,3 @@ public class Tools {
return json; return json;
} }
} }