From e9e5ba609b4aed6cf34c5be2479d21e05ff73f11 Mon Sep 17 00:00:00 2001
From: Yutousama <583819556@qq.com>
Date: Fri, 21 Feb 2020 17:37:20 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E7=A9=BF=E5=B1=B1?=
=?UTF-8?q?=E7=94=B2=E8=B5=84=E6=BA=90=E5=8C=85=E7=94=9F=E6=88=90=E7=9A=84?=
=?UTF-8?q?=E5=88=9D=E5=A7=8B=E7=89=88=E6=9C=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ad_config.cfg | 357 ++++++-----
config.cfg | 68 ++-
src/com/qy/ui/AppMain.java | 4 +
src/com/qy/utils/AutoRandomAdSDK.java | 823 ++++++++++++++------------
src/com/qy/utils/CsjTools.java | 340 ++++++++---
src/com/qy/utils/SmaliUtils.java | 57 +-
src/com/qy/utils/Tools.java | 148 +++--
7 files changed, 1114 insertions(+), 683 deletions(-)
diff --git a/ad_config.cfg b/ad_config.cfg
index 068a610..d8a8e26 100644
--- a/ad_config.cfg
+++ b/ad_config.cfg
@@ -1,150 +1,215 @@
{
- "array": [
- {
- "title": "广点通",
- "ltName": "GDTUnionSDK_QY.lt",
- "manifest": [
- "",
- "",
- "",
- ""
- ],
- "class": [
- "com.qq.e.ads.ADActivity",
- "com.qq.e.ads.PortraitADActivity",
- "com.qq.e.ads.LandscapeADActivity",
- "com.qq.e.comm.DownloadService"
- ],
- "random": [
- "com",
- "ww",
- "dt"
- ],
- "rename": {
- "ADActivity": "Activity",
- "PortraitADActivity": "PortraitActivity",
- "LandscapeADActivity": "LandscapeActivity",
- "DownloadService": "DownloadService"
- },
- "isAllPackage":false,
- "isReName": true,
- "isJarLib":false,
- "packagerlimit": 3,
- "isManual": false,
- "manual": [
+ "array": [
{
- "class": "com.qq.e.comm.a",
- "find": "com/qq/e/ads/ADActivity"
+ "title": "广点通",
+ "ltName": "GDTUnionSDK_QY.lt",
+ "manifest": [
+ "",
+ "",
+ "",
+ ""
+ ],
+ "class": [
+ "com.qq.e.ads.ADActivity",
+ "com.qq.e.ads.PortraitADActivity",
+ "com.qq.e.ads.LandscapeADActivity",
+ "com.qq.e.comm.DownloadService"
+ ],
+ "random": [
+ "com",
+ "ww",
+ "dt"
+ ],
+ "rename": {
+ "ADActivity": "Activity",
+ "PortraitADActivity": "PortraitActivity",
+ "LandscapeADActivity": "LandscapeActivity",
+ "DownloadService": "DownloadService"
+ },
+ "isAllPackage": false,
+ "isReName": true,
+ "isJarLib": false,
+ "packagerlimit": 3,
+ "isManual": false,
+ "manual": [
+ {
+ "class": "com.qq.e.comm.a",
+ "find": "com/qq/e/ads/ADActivity"
+ }
+ ]
+ },
+ {
+ "title": "聚量",
+ "ltName": "jla",
+ "manifest": [
+ "/>",
+ "",
+ "",
+ "",
+ ""
+ ],
+ "class": [
+ "com.uniplay.adsdk.AdActivity",
+ "com.uniplay.adsdk.InterstitialAdActivity",
+ "com.uniplay.adsdk.NetworkChangeActivity",
+ "com.joomob.activity.AdVideoActivity",
+ "com.uniplay.adsdk.DownloadService"
+ ],
+ "random": [
+ "com",
+ "ww",
+ "ut"
+ ],
+ "rename": {
+ "AdActivity": "Activity",
+ "InterstitialAdActivity": "InterstitialActivity",
+ "NetworkChangeActivity": "NetworkChangeActivity",
+ "AdVideoActivity": "VideoActivity",
+ "DownloadService": "DownloadService"
+ },
+ "isAllPackage": false,
+ "isReName": true,
+ "isJarLib": false,
+ "packagerlimit": 3,
+ "isManual": true,
+ "manual": [
+ {
+ "class": "com.uniplay.adsdk.basic.RuleManage",
+ "find": ".method public configRight",
+ "msg": "仅保留const-string v0, \"\" return-object v0"
+ }
+ ]
+ },
+ {
+ "title": "万维",
+ "ltName": "OnewaySDK_QY.lt",
+ "manifest": [
+ ""
+ ],
+ "class": [
+ "mobi.oneway.sdk.AdShowActivity"
+ ],
+ "random": [
+ "com",
+ "ww",
+ "wt"
+ ],
+ "rename": {
+ "AdShowActivity": "ShowActivity"
+ },
+ "isAllPackage": false,
+ "isReName": true,
+ "isJarLib": false,
+ "packagerlimit": 3,
+ "isManual": true,
+ "manual": [
+ {
+ "class": "mobi.oneway.sdk.port.Unit",
+ "find": "const-string v0, \"mobi.oneway.export.AdShowActivity\""
+ },
+ {
+ "class": "mobi.oneway.sdk.b.c",
+ "find": "const-string v1, \"mobi.oneway.export.OWProvider\""
+ }
+ ]
+ },
+ {
+ "title": "趣赢SDK",
+ "ltName": "qysdk.jar",
+ "manifest": [
+ "",
+ " ",
+ " "
+ ],
+ "class": [
+ "com.qy.sdk.views.MyActivity",
+ "com.qy.sdk_rx.listeners.QyReceiver",
+ "com.qy.sdk.TMProvider"
+ ],
+ "random": [
+ "com",
+ "wq",
+ "rx"
+ ],
+ "rename": {
+ "MyActivity": "Activity",
+ "QyReceiver": "Receiver",
+ "TMProvider": "TProvider"
+ },
+ "isAllPackage": true,
+ "isReName": true,
+ "isJarLib": true,
+ "packagerlimit": 3,
+ "isManual": false,
+ "manual": [],
+ "dex2jar": "D:\\反编译\\dex2jar-2.0\\_d2j-dex2jar.bat"
+ },
+ {
+ "title": "穿山甲",
+ "ltName": "open_ad_sdk.jar",
+ "manifest": [
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ " ",
+ ""
+ ],
+ "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":[
+
+ ],
+ "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"
+ ]
+
}
- ]
- },
- {
- "title": "聚量",
- "ltName": "jla",
- "manifest": [
- "/>",
- "",
- "",
- "",
- ""
- ],
- "class": [
- "com.uniplay.adsdk.AdActivity",
- "com.uniplay.adsdk.InterstitialAdActivity",
- "com.uniplay.adsdk.NetworkChangeActivity",
- "com.joomob.activity.AdVideoActivity",
- "com.uniplay.adsdk.DownloadService"
- ],
- "random": [
- "com",
- "ww",
- "ut"
- ],
- "rename": {
- "AdActivity": "Activity",
- "InterstitialAdActivity": "InterstitialActivity",
- "NetworkChangeActivity": "NetworkChangeActivity",
- "AdVideoActivity": "VideoActivity",
- "DownloadService": "DownloadService"
- },
- "isAllPackage":false,
- "isReName": true,
- "isJarLib":false,
- "packagerlimit": 3,
- "isManual": true,
- "manual": [
- {
- "class":"com.uniplay.adsdk.basic.RuleManage",
- "find":".method public configRight",
- "msg":"仅保留const-string v0, \"\" return-object v0"
- }
- ]
- },
- {
- "title": "万维",
- "ltName": "OnewaySDK_QY.lt",
- "manifest": [
- "",
- ],
- "class": [
- "mobi.oneway.sdk.AdShowActivity"
- ],
- "random": [
- "com",
- "ww",
- "wt"
- ],
- "rename": {
- "AdShowActivity": "ShowActivity"
- },
- "isAllPackage":false,
- "isReName": true,
- "isJarLib":false,
- "packagerlimit": 3,
- "isManual": true,
- "manual": [
- {
- "class":"mobi.oneway.sdk.port.Unit",
- "find":"const-string v0, \"mobi.oneway.export.AdShowActivity\""
- },
- {
- "class":"mobi.oneway.sdk.b.c",
- "find":"const-string v1, \"mobi.oneway.export.OWProvider\""
- }
- ]
- },
- {
- "title": "趣赢SDK",
- "ltName": "qysdk.jar",
- "manifest": [
- "",
- " ",
- " "
- ],
- "class": [
- "com.qy.sdk.views.MyActivity",
- "com.qy.sdk_rx.listeners.QyReceiver",
- "com.qy.sdk.TMProvider"
- ],
- "random": [
- "com",
- "wq",
- "rx"
- ],
- "rename": {
- "MyActivity": "Activity",
- "QyReceiver":"Receiver",
- "TMProvider":"TProvider"
- },
- "isAllPackage":true,
- "isReName": true,
- "isJarLib":true,
- "packagerlimit": 3,
- "isManual": false,
- "manual": [
-
- ],
- "dex2jar":"/media/yutou/_dde_data/反编译/dex2jar-2.0/_d2j-dex2jar.sh"
- }
- ]
+ ]
}
\ No newline at end of file
diff --git a/config.cfg b/config.cfg
index fabff27..6e15f86 100755
--- a/config.cfg
+++ b/config.cfg
@@ -1,20 +1,52 @@
{
-"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/",
-"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",
-"array":[
- "rd_rx",
- "qy_rx",
- "rx",
- "rd_rx",
- "qy_rx",
- "atest"
- ]
+ "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",
+ "array": [
+ "rd_rx",
+ "qy_rx",
+ "rx",
+ "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/*"
+ }
+ ]
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/qy/ui/AppMain.java b/src/com/qy/ui/AppMain.java
index 90f2fa4..b67d51b 100755
--- a/src/com/qy/ui/AppMain.java
+++ b/src/com/qy/ui/AppMain.java
@@ -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"));
diff --git a/src/com/qy/utils/AutoRandomAdSDK.java b/src/com/qy/utils/AutoRandomAdSDK.java
index 8a014b3..580006d 100644
--- a/src/com/qy/utils/AutoRandomAdSDK.java
+++ b/src/com/qy/utils/AutoRandomAdSDK.java
@@ -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,//重命名类名
@@ -52,380 +54,475 @@ import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.ui.TextToDalog;
public class AutoRandomAdSDK {
- private File sdk;
- private JSONObject config;
- private SmaliUtils smalitools;
- private Map adClass;
- private Map nowAdClass;
- private Map nowAdFile;
- private String rootPath;
- private String dxPath;
- private String version;
- private String sdktype;
- private SmaliApkToolsPath inter;
- private boolean isDev = false;
+ private File sdk;
+ private JSONObject config;
+ private SmaliUtils smalitools;
+ private Map adClass;
+ private Map nowAdClass;
+ private Map nowAdFile;
+ private String rootPath;
+ private String dxPath;
+ private String version;
+ private String sdktype;
+ private SmaliApkToolsPath inter;
+ private boolean isDev = false;
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- new AutoRandomAdSDK(new File("JooMobAdSDK_6.1.8.jar"), "5600","5",1,null);
- // new AutoRandomAdSDK(new File("GDTSDK.unionNormal.4.100.970.jar"), 0, null);
- }
+ public static void main(String[] args) {
+ // TODO Auto-generated method stub
+ new AutoRandomAdSDK(new File("JooMobAdSDK_6.1.8.jar"), "5600", "5", 1, null);
+ // new AutoRandomAdSDK(new File("GDTSDK.unionNormal.4.100.970.jar"), 0, null);
+ }
- public AutoRandomAdSDK(File sdk,String version,String type, int cfgIndex, SmaliApkToolsPath inster) {
- // TODO Auto-generated constructor stub
- this.inter = inster;
- this.version=version;
- this.sdktype=type;
- JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
- if (cfg == null) {
- throw new NullPointerException("没有广告配置文件");
- }
- this.sdk = sdk;
- config = cfg.getJSONArray("array").getJSONObject(cfgIndex);
- start();
- }
+ public AutoRandomAdSDK() {
- public void start() {
- adClass = new HashMap();
- nowAdClass = new HashMap();
- nowAdFile = new HashMap();
- smalitools = new SmaliUtils();
- File tmpSdk = new File(sdk.getAbsolutePath().replace(sdk.getName(), "new_" + sdk.getName()));
- if (isDev) {
- dxPath="/media/yutou/_dde_data/AndroidStudio_Data/buildTools/dx.jar";
- sdktype="3";
- version="1000";
- } else {
- JSONObject json = Tools.loadConfig(new File("config.cfg"));
- dxPath=json.getString("dx");
- }
- JarToAJar.toAJar(dxPath, sdk.getAbsolutePath(),
- tmpSdk.getAbsolutePath());
- sdk = new File(tmpSdk.getAbsolutePath());
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- smalitools.unPack(sdk.getAbsolutePath(), new SmaliApkToolsPath() {
+ }
- @Override
- public void smaliPath(String path) {
- // TODO Auto-generated method stub
- rootPath = path;
- alter();
- }
- });
- }
+ public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) {
+ // TODO Auto-generated constructor stub
+ this.inter = inster;
+ this.version = version;
+ this.sdktype = type;
+ JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
+ if (cfg == null) {
+ throw new NullPointerException("没有广告配置文件");
+ }
+ this.sdk = sdk;
+ config = cfg.getJSONArray("array").getJSONObject(cfgIndex);
+ start();
+ }
- 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");
- if (clz.exists()) {
- adClass.put(clazzs.getString(i), clz);
- }
- }
- for (String key : adClass.keySet()) {
- System.out.println("注入的值:" + key);
- }
- mkdirs();
- update();
- change();
+ public void start() {
+ adClass = new HashMap();
+ nowAdClass = new HashMap();
+ nowAdFile = new HashMap();
+ smalitools = new SmaliUtils();
+ File tmpSdk = new File(sdk.getAbsolutePath().replace(sdk.getName(), "new_" + sdk.getName()));
+ if (isDev) {
+ dxPath = "/media/yutou/_dde_data/AndroidStudio_Data/buildTools/dx.jar";
+ sdktype = "3";
+ version = "1000";
+ } else {
+ JSONObject json = Tools.loadConfig(new File("config.cfg"));
+ dxPath = json.getString("dx");
+ }
+ JarToAJar.toAJar(dxPath, sdk.getAbsolutePath(),
+ tmpSdk.getAbsolutePath());
+ sdk = new File(tmpSdk.getAbsolutePath());
+ try {
+ Thread.sleep(2000);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ smalitools.unPack(sdk.getAbsolutePath(), new SmaliApkToolsPath() {
- }
+ @Override
+ public void smaliPath(String path) {
+ // TODO Auto-generated method stub
+ rootPath = path;
+ alter();
+ }
+ });
+ }
- private void outManifest() {
- JSONArray array = new JSONArray();
- for (String key : nowAdClass.keySet()) {
- JSONArray manifest = config.getJSONArray("manifest");
- for (int i = 0; i < manifest.length(); i++) {
- if (manifest.getString(i).contains(key)) {
- String path = nowAdClass.get(key).getAbsolutePath();
- String newManifest = path
- .replace(sdk.getAbsolutePath() + ".out" + File.separator + "smali" + File.separator, "");
- try {
- newManifest = newManifest.replaceAll(File.separator, ".") + "." + adClass.get(key).getName();
- array.put(manifest.getString(i).replace(key, newManifest.replace(".smali", "")));
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- System.out.println("-------->"+adClass.size());
- for(String keys:adClass.keySet()) {
- System.out.println(keys+" "+adClass.get(keys));
- }
- }
-
- break;
- }
- }
- }
- File manifest = new File(sdk.getAbsolutePath() + ".out" + File.separator + "manifest.xml");
- PrintWriter writer;
- try {
- writer = new PrintWriter(manifest);
- for (int i = 0; i < array.length(); i++) {
- writer.write(array.getString(i).toString() + "\n");
- writer.flush();
- }
- writer.close();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
+ boolean isPackage = true;
- private void change() {
- smalitools.setPath(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()) {
- smalitools.start();
- if (config.getBoolean("isManual")) {
- manual();
- } else {
- out();
- }
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ public void startNotUnPackage(String path, SmaliApkToolsPath inster) {
+ this.inter = inster;
+ isPackage = false;
+ adClass = new HashMap();
+ nowAdClass = new HashMap();
+ nowAdFile = new HashMap();
+ 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).replace(".", File.separator) + ".smali");
+ if (clz.exists()) {
+ adClass.put(clazzs.getString(i), clz);
+ }
+ }
+ for (String key : adClass.keySet()) {
+ System.out.println("注入的值:" + key);
+ }
+ mkdirs();
+ update();
+ change();
- private void manual() {
- JSONArray man = config.getJSONArray("manual");
- for (int i = 0; i < man.length(); i++) {
- JSONObject json = man.getJSONObject(i);
- File file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali" + File.separator
- + json.getString("class").replace(".", File.separator) + ".smali");
- if (file.exists()) {
- List list = new ArrayList();
- try {
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String tmp;
- int index = 1;
- while ((tmp = reader.readLine()) != null) {
- if (tmp.contains(json.getString("find"))) {
- list.add(index);
- }
- index++;
- }
- reader.close();
- Desktop.getDesktop().open(file);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
- }
- String index="";
- for (Integer integer : list) {
- System.out.println("请修改第:" + integer + " 行附近的代码");
- index+=integer+",";
- }
- new TextToDalog("提示", "请修改第:" + index + " 行附近的代码,备注:"+json.getString("msg"),new DalogAbs() {
-
- @Override
- public void onSuccess() {
- // TODO Auto-generated method stub
- out();
- }
- });
-
- }
- }
- }
+ }
- private void out() {
- smalitools.bale(sdk.getAbsolutePath() + ".out",
- sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName(),new SmaliApkToolsPath() {
-
- @Override
- public void smaliPath(String path) {
- // TODO Auto-generated method stub
- try {
- outManifest();
- File lt;
- if (!config.getBoolean("isJarLib")) {
- JarToAJar.toAJar(dxPath, sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName(), sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName()+"_dex.jar");
- new EncryptJar().encrypt(new File(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName())
- ,sdk.getAbsolutePath() + ".out" + File.separator +"dexTmp.jar", sdktype, version);
- lt = new File(sdk.getAbsolutePath() + ".out" + File.separator +"dexTmp.jar");
- }else {
- System.out.println(sdk.getAbsolutePath()+".out"+File.separator+sdk.getName());
- Process process=Runtime.getRuntime().exec(config.getString("dex2jar")+" "+sdk.getAbsolutePath()+".out"+File.separator+sdk.getName());
- process.waitFor();
- lt = new File(sdk.getAbsolutePath().split(sdk.getName())[0],sdk.getName().replace(".jar", "-dex2jar.jar"));
- }
- System.out.println(">>>:" + lt.getAbsolutePath());
- if (lt.exists()) {
- File nLt = new File(config.getString("ltName"));
- lt.renameTo(nLt);
- if (inter != null)
- inter.smaliPath(nLt.getAbsolutePath());
- }
- } catch (Exception e) {
- // TODO: handle exception
- e.printStackTrace();
- }
- }
- });
-
-
- }
+ 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");
+ for (int i = 0; i < manifest.length(); i++) {
+ if (manifest.getString(i).contains(key)) {
+ String path = nowAdClass.get(key).getAbsolutePath();
+ String newManifest = path
+ .replace(sdk.getAbsolutePath() + ".out" + File.separator + "smali" + File.separator, "");
+ try {
+ newManifest = newManifest.replaceAll(File.separator, ".") + "." + adClass.get(key).getName();
+ array.put(manifest.getString(i).replace(key, newManifest.replace(".smali", "")));
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ System.out.println("-------->" + adClass.size());
+ for (String keys : adClass.keySet()) {
+ System.out.println(keys + " " + adClass.get(keys));
+ }
+ }
- private void update() {
- for (String key : adClass.keySet()) {
- File file = adClass.get(key);
- String fileName = file.getName().replace(".smali", "");
- File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
+ break;
+ }
+ }
+ }
+ File manifest = new File(sdk.getAbsolutePath() + ".out" + File.separator + "manifest.xml");
+ PrintWriter writer;
+ try {
+ writer = new PrintWriter(manifest);
+ for (int i = 0; i < array.length(); i++) {
+ writer.write(array.getString(i).toString() + "\n");
+ writer.flush();
+ }
+ writer.close();
+ } catch (FileNotFoundException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
- for (File fs : filePath.listFiles()) {
- if(fs.getName().equals("BuildConfig.smali")) {
- fs.delete();
- continue;
- }
- 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);
- }else {
- Tools.copyFileToName(fs.getAbsolutePath(), nowAdClass.get(key).getAbsolutePath(),
- getNewName(fs.getName()) + "$" + fs.getName().split("\\$")[1], true);
- }
- fs.delete();
- }
- }
- if(getNewNameForSrc(file.getName()).endsWith("[notmover]")) {
- nowAdFile.put(key,file.getAbsolutePath());
- 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);
- }
-
- file.delete();
- }
- 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);
- }
- }
- private void allpackage(File file,String packge) {
- for(File tmp:file.listFiles()) {
- String pack=tmp.getAbsolutePath().replace(rootPath+File.separator+"smali"+File.separator,"");
- if(!packge.contains(pack)&&tmp.isDirectory()) {
- movesdk(tmp, File.separator+"smali"+File.separator+packge);
- }
- if(tmp.isDirectory()) {
- allpackage(tmp, packge);
- }
- }
-
- }
- private void movesdk(File path,String toPath) {
- for(File file:path.listFiles()) {
- if(file.isDirectory()) {
- String tmp=toPath+File.separator+file.getName();
- //System.out.println("创建文件夹:"+tmp);
- new File(rootPath+File.separator+tmp).mkdirs();
- movesdk(file, tmp);
- }else {
- // System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+" 到"+toPath);
- file.renameTo(new File(rootPath+File.separator+toPath,file.getName()));
- }
- }
- }
- private void removeNullFile(File root) {
- for(File file:root.listFiles()) {
- if(file.isDirectory()) {
- if(file.listFiles().length==0) {
- file.delete();
- }else {
- removeNullFile(file);
- if(file.listFiles().length==0) {
- file.delete();
- }
- }
-
- }
- }
- }
- private String getNewName(String name) {
- String nName=getNewNameForSrc(name);
- if(nName.endsWith("[notmover]")) {
- nName=nName.replace("[notmover]", "");
- }
-
- return nName;
- }
- private String getNewNameForSrc(String name) {
- // TODO Auto-generated method stub
- if (!config.getBoolean("isReName")) {
- return name;
- }
- String tmpName;
- String wName = null;
- name = name.replace(".smali", "");
- if (name.contains("$")) {
- tmpName = name.split("$")[0];
- for (String t : name.split("$")) {
- if (!t.equals(tmpName)) {
- wName += t;
- }
- }
- } else {
- tmpName = name;
- }
-
- String nName = config.getJSONObject("rename")
- .getString(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName);
- if(nName.contains("[random]")) {
- String tName=Tools.getRandomString(new Random().nextInt(6)+2);
- nName=nName.replace("[random]", tName);
- config.getJSONObject("rename").put(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName,nName);
- }
- if (wName != null) {
- nName += wName;
- }
- return nName;
- }
+ 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);
- private void mkdirs() {
- JSONArray clazzs = config.getJSONArray("class");
- JSONArray random = config.getJSONArray("random");
- for (int i = 0; i < clazzs.length(); i++) {
- File path = new File(rootPath + File.separator + "smali");
- File mkdir = null;
- for (int j = 0; j < config.getInt("packagerlimit"); j++) {
- String packageName;
- if (random.getString(j).equals("[random]")) {
- packageName = Tools.getRandomString(3);
- } else {
- packageName = random.getString(j);
- }
- if (mkdir == null) {
- mkdir = new File(path.getAbsolutePath() + File.separator + packageName);
- } else {
- mkdir = new File(mkdir.getAbsolutePath() + File.separator + packageName);
- }
- if (!mkdir.exists()) {
- mkdir.mkdirs();
- }
- }
- nowAdClass.put(clazzs.getString(i), mkdir);
- }
- }
+
+ if (file.exists()) {
+ JSONArray array = config.getJSONArray("filter");
+ if (array != null) {
+ List 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();
+ } else {
+ out();
+ }
+ }
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+ private void manual() {
+ JSONArray man = config.getJSONArray("manual");
+ for (int i = 0; i < man.length(); i++) {
+ JSONObject json = man.getJSONObject(i);
+ File file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali" + File.separator
+ + json.getString("class").replace(".", File.separator) + ".smali");
+ if (file.exists()) {
+ List list = new ArrayList();
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ String tmp;
+ int index = 1;
+ while ((tmp = reader.readLine()) != null) {
+ if (tmp.contains(json.getString("find"))) {
+ list.add(index);
+ }
+ index++;
+ }
+ reader.close();
+ Desktop.getDesktop().open(file);
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ System.out.println("请手动打开:" + file.getAbsolutePath() + " 文件");
+ }
+ String index = "";
+ for (Integer integer : list) {
+ System.out.println("请修改第:" + integer + " 行附近的代码");
+ index += integer + ",";
+ }
+ new TextToDalog("提示", "请修改第:" + index + " 行附近的代码,备注:" + json.getString("msg"), new DalogAbs() {
+
+ @Override
+ public void onSuccess() {
+ // TODO Auto-generated method stub
+ out();
+ }
+ });
+
+ }
+ }
+ }
+
+ private void out() {
+ 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) {
+ // TODO Auto-generated method stub
+ 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())
+ , sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar", sdktype, version);
+ lt = new File(sdk.getAbsolutePath() + ".out" + File.separator + "dexTmp.jar");
+ } else {
+ System.out.println(sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName());
+ Process process = Runtime.getRuntime().exec(config.getString("dex2jar") + " " + sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName());
+ process.waitFor();
+ lt = new File(sdk.getAbsolutePath().split(sdk.getName())[0], sdk.getName().replace(".jar", "-dex2jar.jar"));
+ }
+ System.out.println(">>>:" + lt.getAbsolutePath());
+ if (lt.exists()) {
+ nLt = new File(config.getString("ltName"));
+ lt.renameTo(nLt);
+
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+
+ if (inter != null)
+ inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath());
+ } catch (Exception e) {
+ // TODO: handle exception
+ e.printStackTrace();
+ }
+ }
+ });
+
+
+ }
+
+ private void update() {
+ for (String key : adClass.keySet()) {
+ File file = adClass.get(key);
+ String fileName = file.getName().replace(".smali", "");
+ File filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
+
+ 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(),
+ nName + "$" + fs.getName().split("\\$")[1], true);
+ } else {
+ moveFile(fs, key, nName + "$" + fs.getName().split("\\$")[1],false);
+ }
+ fs.delete();
+ }
+ }
+ if (getNewNameForSrc(file.getName()).endsWith("[notmover]")) {
+ nowAdFile.put(key, file.getAbsolutePath());
+ Tools.copyFileToName(file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), ""),
+ getNewName(file.getName()) + ".smali", true);
+ } else {
+ moveFile(file, key, getNewName(file.getName()) + ".smali",true);
+ }
+
+ file.delete();
+ }
+ 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);
+ }
+ }
+
+ 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, "");
+ if (!packge.contains(pack) && tmp.isDirectory()) {
+ movesdk(tmp, File.separator + "smali" + File.separator + packge);
+ }
+ if (tmp.isDirectory()) {
+ allpackage(tmp, packge);
+ }
+ }
+
+ }
+
+ private void movesdk(File path, String toPath) {
+ for (File file : path.listFiles()) {
+ if (file.isDirectory()) {
+ String tmp = toPath + File.separator + file.getName();
+ //System.out.println("创建文件夹:"+tmp);
+ new File(rootPath + File.separator + tmp).mkdirs();
+ movesdk(file, tmp);
+ } else {
+ // System.out.println("移动文件:"+file.getAbsolutePath().replace(rootPath, "")+" 到"+toPath);
+ file.renameTo(new File(rootPath + File.separator + toPath, file.getName()));
+ }
+ }
+ }
+
+ private void removeNullFile(File root) {
+ for (File file : root.listFiles()) {
+ if (file.isDirectory()) {
+ if (file.listFiles().length == 0) {
+ file.delete();
+ } else {
+ removeNullFile(file);
+ if (file.listFiles().length == 0) {
+ file.delete();
+ }
+ }
+
+ }
+ }
+ }
+
+ private String getNewName(String name) {
+ String nName = getNewNameForSrc(name);
+ if (nName.endsWith("[notmover]")) {
+ nName = nName.replace("[notmover]", "");
+ }
+
+ return nName;
+ }
+
+ private String getNewNameForSrc(String name) {
+ // TODO Auto-generated method stub
+ if (!config.getBoolean("isReName")) {
+ return name;
+ }
+ String tmpName;
+ String wName = null;
+ name = name.replace(".smali", "");
+ if (name.contains("$")) {
+ tmpName = name.split("$")[0];
+ for (String t : name.split("$")) {
+ if (!t.equals(tmpName)) {
+ wName += t;
+ }
+ }
+ } else {
+ tmpName = name;
+ }
+
+ String nName = config.getJSONObject("rename")
+ .getString(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName);
+ if (nName.contains("[random]")) {
+ String tName = Tools.getRandomString(new Random().nextInt(6) + 2);
+ nName = nName.replace("[random]", tName);
+ config.getJSONObject("rename").put(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName, nName);
+ }
+ if (wName != null) {
+ nName += wName;
+ }
+ return nName;
+ }
+
+ private void mkdirs() {
+ JSONArray clazzs = config.getJSONArray("class");
+ JSONArray random = config.getJSONArray("random");
+ for (int i = 0; i < clazzs.length(); i++) {
+ File path = new File(rootPath + File.separator + "smali");
+ File mkdir = null;
+ for (int j = 0; j < config.getInt("packagerlimit"); j++) {
+ String packageName;
+ if (random.getString(j).equals("[random]")) {
+ packageName = Tools.getRandomString(3);
+ } else {
+ packageName = random.getString(j);
+ }
+ if (mkdir == null) {
+ mkdir = new File(path.getAbsolutePath() + File.separator + packageName);
+ } else {
+ mkdir = new File(mkdir.getAbsolutePath() + File.separator + packageName);
+ }
+ if (!mkdir.exists()) {
+ mkdir.mkdirs();
+ }
+ }
+ nowAdClass.put(clazzs.getString(i), mkdir);
+ }
+ }
}
diff --git a/src/com/qy/utils/CsjTools.java b/src/com/qy/utils/CsjTools.java
index faf6dda..c50a3f9 100644
--- a/src/com/qy/utils/CsjTools.java
+++ b/src/com/qy/utils/CsjTools.java
@@ -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 List r_list;
+ 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 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(";",""));
+ while ((tmp = reader.readLine()) != null) {
+ 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 header=new ArrayList<>();
- List 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;
- 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");
+ 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) {
+ 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 getCSJR(String fileName,long id){
- File csjR=new File(csj_R_path+File.separator+fileName+".smali");
- List csj=new ArrayList<>();
- 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));
+
+ 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();
+ }
}
}
- csj.add("\n");
+ _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 {
+ 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;
+ }
+ }
+ 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;
+ }
+ 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();
}
- 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);
+ boolean csjManifest = false;
+ boolean apkUnPackage = false;
+
+ private void runStart(SmaliApkToolsPath log) {
+ if (apkUnPackage && csjManifest) {
+ start(log);
+ }
}
+
+ //还有最后一个问题,穿山甲的Activity没改
public static void main(String[] args) {
- CsjTools tools=new CsjTools();
- tools.out();
+ if (false) {
+ new AutoRandomAdSDK().startNotUnPackage("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2", new SmaliApkToolsPath() {
+ @Override
+ public void smaliPath(String path) {
+ System.out.println("-------" + path);
+ }
+ });
+ return;
+ }
+ CsjTools tools = new CsjTools();
+ tools.build("D:\\IdeaProjects\\android_sdk_tools\\demo_2.8.0.2.apk",
+ "D:\\IdeaProjects\\android_sdk_tools\\app-release.apk",
+ 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();
}
}
diff --git a/src/com/qy/utils/SmaliUtils.java b/src/com/qy/utils/SmaliUtils.java
index 1d9cfa1..edff8f4 100755
--- a/src/com/qy/utils/SmaliUtils.java
+++ b/src/com/qy/utils/SmaliUtils.java
@@ -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 list;
+ public void setFilter(List list){
+ this.list=list;
+ }
}
diff --git a/src/com/qy/utils/Tools.java b/src/com/qy/utils/Tools.java
index 437be78..cac2b49 100755
--- a/src/com/qy/utils/Tools.java
+++ b/src/com/qy/utils/Tools.java
@@ -21,7 +21,7 @@ public class Tools {
}
return false;
}
-
+
public static String getRandomString(int length) {
String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
Random random = new Random();
@@ -40,87 +40,86 @@ public class Tools {
return i;
}
public static void deleteFiles(String path) {
- File files = new File(path);
- if (files.exists()) {
- if (files.isDirectory()) {
- for (File file : files.listFiles()) {
- deleteFiles(file.getAbsolutePath());
- }
- }
- // System.out.println("ɾ���ļ� "+files.getAbsolutePath());
- files.delete();
- }
- }
+ File files = new File(path);
+ if (files.exists()) {
+ if (files.isDirectory()) {
+ for (File file : files.listFiles()) {
+ deleteFiles(file.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);
- // �ж�Դ�ļ��Ƿ����
- if (!srcFile.exists()) {
- return false;
- } else if (!srcFile.isFile()) {
- return false;
- }
+ File srcFile = new File(srcFileName);
+ // 判断源文件是否存在
+ if (!srcFile.exists()) {
+ return false;
+ } else if (!srcFile.isFile()) {
+ return false;
+ }
- // �ж�Ŀ���ļ��Ƿ����
- File destFile = new File(destFileName);
- // ���Ŀ���ļ�����Ŀ¼�����ڣ���Ŀ¼
- if (!destFile.exists()) {
- // Ŀ���ļ�����Ŀ¼������
- if (!destFile.mkdirs()) {
- // �����ļ�ʧ�ܣ�����Ŀ���ļ�����Ŀ¼ʧ��
- return false;
- }
- destFile.delete();
+ // 判断目标文件是否存在
+ File destFile = new File(destFileName);
+ // 如果目标文件所在目录不存在,则创建目录
+ if (!destFile.exists()) {
+ // 目标文件所在目录不存在
+ if (!destFile.mkdirs()) {
+ // 复制文件失败:创建目标文件所在目录失败
+ return false;
+ }
- }
+ }
- // �����ļ�
- int byteread = 0; // ��ȡ���ֽ���
- InputStream in = null;
- OutputStream out = null;
+ // 复制文件
+ int byteread = 0; // 读取的字节数
+ InputStream in = null;
+ OutputStream out = null;
- try {
- if(fileName==null) {
- fileName=srcFile.getName();
- }
- in = new FileInputStream(srcFile);
- out = new FileOutputStream(destFile);
- byte[] buffer = new byte[1024];
+ try {
+ if(fileName==null) {
+ fileName=srcFile.getName();
+ }
+ in = new FileInputStream(srcFile);
+ out = new FileOutputStream(destFile + "/" +fileName );
+ byte[] buffer = new byte[1024];
- while ((byteread = in.read(buffer)) != -1) {
- out.write(buffer, 0, byteread);
- }
- return true;
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- return false;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- } finally {
- try {
- if (out != null)
- out.close();
- if (in != null)
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
+ while ((byteread = in.read(buffer)) != -1) {
+ out.write(buffer, 0, byteread);
+ }
+ return true;
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ return false;
+ } catch (IOException e) {
+ e.printStackTrace();
+ return false;
+ } finally {
+ try {
+ if (out != null)
+ out.close();
+ if (in != null)
+ in.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
}
/**
- * ���Ƶ����ļ�
- *
- * @param srcFileName �����Ƶ��ļ���
- * @param destFileName Ŀ���ļ���
- * @param overlay ���Ŀ���ļ����ڣ��Ƿ�
- * @return ������Ƴɹ�����true������false
- */
- public static boolean copyFile(String srcFileName, String destFileName,
- boolean overlay) {
- return copyFileToName(srcFileName, destFileName, null, overlay);
- }
-
- public static JSONObject loadConfig(File file) {
+ * 复制单个文件
+ *
+ * @param srcFileName 待复制的文件名
+ * @param destFileName 目标文件名
+ * @param overlay 如果目标文件存在,是否覆盖
+ * @return 如果复制成功返回true,否则返回false
+ */
+ public static boolean copyFile(String srcFileName, String destFileName,
+ boolean overlay) {
+ return copyFileToName(srcFileName, destFileName, null, overlay);
+ }
+
+ public static JSONObject loadConfig(File file) {
JSONObject json = null;
BufferedReader reader;
if (!file.exists()) {
@@ -146,4 +145,3 @@ public class Tools {
return json;
}
}
-