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

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": "万维",
"ltName": "OnewaySDK_QY.lt",
"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": [
"mobi.oneway.sdk.AdShowActivity"
@ -141,10 +141,75 @@
"isJarLib": true,
"packagerlimit": 3,
"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":[
],
"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/",
"2": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"3": "F:/AndroidStudio_Data/GameSDK/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"4": "/home/yutou/AndroidStudioProjects/ADSDK_v5/sdk_rx/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"5": "/home/yutou/AndroidStudioProjects/ADSDK_v5/qyadsdk/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/",
"6": "/home/yutou/AndroidStudioProjects/ADSDK_v5/Test/build/intermediates/javac/debug/classes/com/",
"switch": "1",
"input": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/com.zip",
"out": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/",
"dx": "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/dx.jar",
@ -16,5 +16,37 @@
"rd_rx",
"qy_rx",
"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.io.File;
import java.io.IOException;
import java.security.Permission;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;
@ -29,6 +30,7 @@ import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import com.sun.javaws.exceptions.ExitException;
import org.json.JSONArray;
import org.json.JSONObject;
@ -66,10 +68,12 @@ public class AppMain extends JFrame {
public static void main(String[] args) {
// TODO Auto-generated method stub
new AppMain();
}
public AppMain() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
json = Tools.loadConfig(new File("config.cfg"));

View File

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

View File

@ -1,71 +1,90 @@
package com.qy.utils;
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.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CsjTools {
private String csj_R_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1\\smali\\com\\bytedance\\sdk\\openadsdk";
private String csj_demo_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1";
private String apk_R_path="E:\\idea\\android_sdk_tools\\app-release-1\\smali\\com\\luckyboy\\mmxing";
private static String csj_res = "D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2\\res\\values";
private static String apk_res = "D:\\IdeaProjects\\android_sdk_tools\\app-release\\res\\values";
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;
public CsjTools() {
}
public void setR() {
r_list=new ArrayList<>();
File apk_R=new File(csj_R_path+File.separator+"R.smali");
if(!apk_R.exists()){
new TextToDalog("找不到文件","穿山甲R文件不存在:"+apk_R);
return;
}
public String loadXml(String path) {
File file = new File(path);
String xml = null;
try {
BufferedReader reader=new BufferedReader(new FileReader(apk_R));
BufferedReader reader = new BufferedReader(new FileReader(file));
String tmp;
while ((tmp = reader.readLine()) != null) {
if(tmp.contains("/R$")){
r_list.add(tmp.split("/")[tmp.split("/").length-1].replace(";,","").replace(";",""));
if (xml == null) {
xml = tmp + "\n";
} else {
xml += tmp + "\n";
}
}
/*for (String fileName : r_list) {
setRData(fileName);
}*/
reader.close();
} catch (Exception e) {
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;
long id=-1;
public long getId(String publicXml) {
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 {
BufferedReader reader=new BufferedReader(new FileReader(apkR));
String tmp;
File apkManifest = new File(apk_Path + File.separator + "AndroidManifest.xml");
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) {
if(tmp.trim().equals("# direct methods")){
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");
manifest += tmp + "\n";
}
FileWriter writer = new FileWriter(demoManifest);
writer.write(manifest);
writer.flush();
writer.close();
@ -73,39 +92,224 @@ public class CsjTools {
e.printStackTrace();
}
}
private List<String> getCSJR(String fileName,long id){
File csjR=new File(csj_R_path+File.separator+fileName+".smali");
List<String> csj=new ArrayList<>();
private void out(String srcFile, String encryptFile, int version) {
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 {
BufferedReader reader=new BufferedReader(new FileReader(csjR));
String tmp;
long nextId=id;
while ((tmp=reader.readLine())!=null){
if(tmp.trim().startsWith(".field public")){
csj.add(tmp.replace(".field public static",".field public static final")+" = 0x"+Long.toHexString(++nextId));
String fileXml = loadXml(file.getAbsolutePath());
String newXml = "";
boolean remove = false;
for (String xml : fileXml.split("\n")) {
for (Object data : item.getJSONArray("data")) {
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) {
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(){
EncryptJar encryptJar=new EncryptJar();
encryptJar.encrypt(new File("E:\\idea\\android_sdk_tools\\csj.apk"),"E:\\idea\\android_sdk_tools\\csj_",13,5600);
if (type != null) {
String nextId = "0x" + Long.toHexString(maxId + 1) + String.format("%.3f", (index++) / 1000f).replace(".", "");
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) {
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.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;
public class SmaliUtils {
private String str = "";
//private String str = "";
public String mainPath =null;
private int mix = 1000;
// private String mainPath = "D:\\反编译\\APK\\rx.jar.out\\smali";
@ -33,14 +33,27 @@ public class SmaliUtils {
}
public void start() {
list=new ArrayList<>();
System.out.println("开始修改:"+mainPath);
File path = new File(mainPath);
recursive(path);
try {
System.out.println(clazzList.size());
for (File file : files) {
loadFile(file);
writerFile(file);
new Thread(new Runnable() {
@Override
public void run() {
String str= null;
try {
str = loadFile(file);
writerFile(file,str);
} catch (Exception e) {
e.printStackTrace();
}
}
}).start();
}
} catch (Exception e) {
// TODO Auto-generated catch block
@ -83,8 +96,14 @@ public class SmaliUtils {
private void readFile(File file, String packName) throws Exception {
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));
str = "";
//String str = "";
String tmp = null;
while ((tmp = reader.readLine()) != null) {
if (isOneLine) {
@ -109,7 +128,9 @@ public class SmaliUtils {
if (newName != null) {
newName = newName.replace(";", "");
//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) {
mix = clazzList.get(newName).length();
}
@ -117,7 +138,7 @@ public class SmaliUtils {
isOneLine = false;
}
// tmp = changeLine(tmp);
str += tmp + "\n";
// str += tmp + "\n";
}
reader.close();
@ -125,7 +146,7 @@ public class SmaliUtils {
private String loadFile(File file) throws Exception {
BufferedReader reader = new BufferedReader(new FileReader(file));
str = "";
String str = "";
String tmp = null;
while ((tmp = reader.readLine()) != null) {
str += tmp + "\n";
@ -134,7 +155,13 @@ public class SmaliUtils {
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 save = "";
i = 1;
@ -169,7 +196,7 @@ public class SmaliUtils {
if(path.exists()&&path.isDirectory()) {
Tools.deleteFiles(path.getAbsolutePath());
}
String args[]=new String[] {"d","-f",jarPath};
String[] args =new String[] {"d","-f",jarPath};
try {
Main.main(args);
File jarFile=new File(jarPath);
@ -177,7 +204,7 @@ public class SmaliUtils {
if(jarFile.getName().contains(".jar")) {
name=jarFile.getName()+".out";
}else if(jarFile.getName().contains(".apk")) {
name=jarFile.getName().split("\\.")[0];
name=jarFile.getName().replace(".apk","");
}else {
name=jarFile.getName();
}
@ -190,15 +217,15 @@ public class SmaliUtils {
public void bale(String path,String smaliPath) {
bale(path,smaliPath,null);
}
public void bale(String path,String smaliPath,SmaliApkToolsPath inter) {
String args[]=new String[] {"b","-f",path,"-o",smaliPath};
public void bale(String smaliPath,String path,SmaliApkToolsPath inter) {
String[] args =new String[] {"b","-f",smaliPath,"-o",path};
for (String string : args) {
System.out.print(string+" ");
}
try {
Main.main(args);
if(inter!=null) {
inter.smaliPath("ok");
inter.smaliPath(path);
}
} catch (Exception e) {
// 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());
}
}
// System.out.println("ɾ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD> "+files.getAbsolutePath());
// System.out.println("删除文件 "+files.getAbsolutePath());
files.delete();
}
}
public static boolean copyFileToName(String srcFileName,String destFileName,String fileName,boolean overlay) {
File srcFile = new File(srcFileName);
// <EFBFBD>ж<EFBFBD>Դ<EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 判断源文件是否存在
if (!srcFile.exists()) {
return false;
} else if (!srcFile.isFile()) {
return false;
}
// <EFBFBD>ж<EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 判断目标文件是否存在
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()) {
// Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// 目标文件所在目录不存在
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;
}
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;
OutputStream out = null;
@ -83,7 +82,7 @@ public class Tools {
fileName=srcFile.getName();
}
in = new FileInputStream(srcFile);
out = new FileOutputStream(destFile);
out = new FileOutputStream(destFile + "/" +fileName );
byte[] buffer = new byte[1024];
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 destFileName Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
* @param overlay <EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD>Ƿ񸲸<EFBFBD>
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƴɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>true<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򷵻<EFBFBD>false
* @param srcFileName 待复制的文件名
* @param destFileName 目标文件名
* @param overlay 如果目标文件存在是否覆盖
* @return 如果复制成功返回true否则返回false
*/
public static boolean copyFile(String srcFileName, String destFileName,
boolean overlay) {
@ -146,4 +145,3 @@ public class Tools {
return json;
}
}