package com.qy.utils;

import java.awt.Desktop;
import java.io.*;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONArray;
import org.json.JSONObject;

import com.qy.Interfaces.DalogAbs;
/*
 配置JSON格式：
 {
      "title": "趣赢SDK", //标题
      "ltName": "qysdk.jar", //保存文件名
      "manifest": [
        //原始清单配置
      ],
      "class": [ //希望变动的类
        "com.qy.sdk.views.MyActivity",
      ],
      "random": [//修改包名
        "com",//固定包名
        "[random]"//随机包名
      ],
      "rename": {//修改类名
        "MyActivity": "Activity",//指定类名
        "TMProvider":"TProvider[notmover]",//指定类名，但不移动路径
        "BannerView":"[random]"//随机类名（2~6）
        "BannerView":"{+/activity}BannerView"//指定路径  [+表示在random的基础上]
      },
      "isAllPackage":true,//修改所有包名，false的话只修改class指定的包名
      "isReName": true,//重命名类名
      "isJarLib":true,//打出成jar包，false的话则会进行加密
      "packagerlimit": 3,//修改包名长度，需小于或等于random数组
      "isManual": false,//手动修改类文件
      "manual": [
          //需要手动修改的类
        ],
      "dex2jar":"/media/yutou/_dde_data/反编译/dex2jar-2.0/_d2j-dex2jar.sh"//指定dex2jar的路径
    }
 */
import com.qy.Interfaces.SmaliApkToolsPath;
import com.qy.ui.TextToDalog;

public class AutoRandomAdSDK {
    private File sdk;
    private JSONObject config;
    private SmaliUtils smalitools;
    private Map<String, File> adClass;
    private Map<String, File> nowAdClass;
    private Map<String, String> nowAdFile;
    private String rootPath;
    private String dxPath;
    private String version;
    private String sdktype;
    private String packageName;
    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);
        JSONArray array = new JSONArray();

        JSONObject gdt = new JSONObject();
        gdt.put("file", "D:\\IDEA\\android_sdk_tools\\GDTSDK.unionNormal.4.170.1040.jar");
        gdt.put("version", "5700");
        gdt.put("type", "1");
        gdt.put("index", 0);
        gdt.put("packageName", "com.gzlt.tgttaxc.lmd1.tgd");
        array.put(gdt);

        JSONObject unplay = new JSONObject();
        unplay.put("file", "D:\\IDEA\\android_sdk_tools\\JooMobAdSDK_6.1.8.jar");
        unplay.put("version", "5700");
        unplay.put("type", "5");
        unplay.put("index", 1);
        unplay.put("packageName", "com.gzlt.tgttaxc.lmd1.up");
        array.put(unplay);

        JSONObject qy = new JSONObject();
        qy.put("file", "D:\\IDEA\\android_sdk_tools\\classes.jar");
        qy.put("version", "5700");
        qy.put("type", "0");
        qy.put("packageName", "com.gzlt.tgttaxc.lmd1.ww");
        qy.put("index", 3);
        array.put(qy);
        new AutoRandomAdSDK(array, new SmaliApkToolsPath() {
            @Override
            public void smaliPath(String path) {
                //System.out.println("完成：" + path);
            }
        });
    }

    public AutoRandomAdSDK() {

    }
    private  SmaliApkToolsPath batchInter;
    private JSONArray batch;
    public AutoRandomAdSDK(JSONArray batch, SmaliApkToolsPath inter) {
        batchInter=inter;
        this.batch=batch;
        for (Object o : batch) {
            //System.out.println("循环");
            final JSONObject item = (JSONObject) o;
            autoRandomAdSDK(new File(item.getString("file")), item.getString("version"), item
                    .getString("type"), item.getString("packageName"), item.getInt("index"), new SmaliApkToolsPath() {
                public void smaliPath(String path) {
                    JSONArray array = new JSONArray();
                    item.put("path", path);
                    array.put(item);
                    outInter(array);
                    //System.out.println("触发完成事件:"+outIndex+" "+batch.length()+" "+array.toString());
                }
            });
        }
    }
    private int outIndex=0;
    private void outInter(JSONArray array) {
        outIndex++;
        if(batch.length()==outIndex){
            batchInter.smaliPath(batch.toString());
        }
    }

    public void autoRandomAdSDK(File sdk, String version, String type, String packageName, int cfgIndex, SmaliApkToolsPath inster) {
        // TODO Auto-generated constructor stub
        if (inster == null) {
            inster = path -> {

            };
        }
        this.inter = inster;
        this.version = version;
        this.sdktype = type;
        this.packageName = packageName;
        JSONObject cfg = Tools.loadConfig(new File("ad_config.cfg"));
        if (cfg == null) {
            throw new NullPointerException("没有广告配置文件");
        }
        this.sdk = sdk;
        config = cfg.getJSONArray("array").getJSONObject(cfgIndex);
        if (packageName != null) {
            String[] pname = packageName.split("\\.");
            JSONArray random = new JSONArray();
            for (String pn : pname) {
                random.put(pn);
            }
            this.config.put("random", random);
        }
        start();
    }

    public AutoRandomAdSDK(File sdk, String version, String type, int cfgIndex, SmaliApkToolsPath inster) {
        autoRandomAdSDK(sdk, version, type, null, cfgIndex, inster);
    }

    public void start() {
        adClass = new HashMap<String, File>();
        nowAdClass = new HashMap<String, File>();
        nowAdFile = new HashMap<String, String>();
        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");
        }
        Tools.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();
            }
        });
    }

    boolean isPackage = true;

    public void startNotUnPackage(String path, String packagename, 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);
        JSONArray array = new JSONArray();
        for (String str : packagename.split("\\.")) {
            array.put(str);
        }
        config.put("random", array);
        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()) {
              //  System.out.println("key="+clazzs.getString(i)+" value="+clz);
                adClass.put(clazzs.getString(i), clz);
            }
        }
        for (String key : adClass.keySet()) {
           // System.out.println("注入的值：" + key);
        }
        mkdirs();
        update();
        change();

    }

    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.replace(File.separator, ".") + "." + adClass.get(key).getName();
                        array.put(manifest.getString(i).replace(key, newManifest.replace(".smali", "")));
                    } catch (Exception e) {
                        // TODO: handle exception
                        //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");
        File manifest = new File(rootPath + 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 (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private void change() {
        File file;
       /* if (sdk == null) {
            smalitools.setPath(rootPath + File.separator + "smali");
            file = new File(rootPath + File.separator + "smali");
        } else {
            file = new File(sdk.getAbsolutePath() + ".out" + File.separator + "smali");
            if(!file.exists()){
                file=new File(sdk.getAbsolutePath() +File.separator + "smali");
            }
            smalitools.setPath(file.getAbsolutePath());

        }*/
        smalitools.setPath(rootPath + File.separator + "smali");
        file = new File(rootPath + File.separator + "smali");

        try {
            Thread.sleep(200);
            //System.out.println(smalitools.mainPath);


            if (file.exists()) {
                JSONArray array = config.isNull("filter") ? null : 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(new SmaliApkToolsPath() {
                    @Override
                    public void smaliPath(String path) {
                        if (config.getBoolean("isManual")) {
                            manual();
                        } else {
                            out();
                        }
                    }
                });

            } else {
                //System.out.println("没找到对应的文件夹:" + file.getAbsolutePath());
            }
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            inter.smaliPath(e.getMessage());
        }

    }

    private void manual() {
        JSONArray man = config.getJSONArray("manual");
        for (int i = 0; i < man.length(); i++) {
            JSONObject json = man.getJSONObject(i);
            String sdkPath;
            sdkPath = rootPath;
            File file = new File(sdkPath + File.separator + "smali" + File.separator
                    + json.getString("class").replace(".", File.separator) + ".smali");
            if (file.exists()) {
                List<Integer> list = new ArrayList<Integer>();
                try {
                    BufferedReader reader = new BufferedReader(new FileReader(file));
                    String tmp;
                    int index = 1;
                    boolean find = false;
                    boolean end = false;
                    boolean write = false;
                    StringBuilder buffer = new StringBuilder();
                    while ((tmp = reader.readLine()) != null) {
                        if (tmp.contains(json.getString("find"))) {
                            list.add(index);
                            find = true;
                        }
                        if (find && !write) {
                            buffer.append(json.getString("data"));
                            write = true;
                        }
                        if (find && tmp.contains(json.getString("end"))) {
                            end = true;
                            find = false;
                        }
                        if (!find) {
                            buffer.append(tmp).append("\n");
                            if (end) {
                                end = false;
                                write = false;
                            }
                        }
                        index++;
                    }
                    reader.close();
                    FileWriter writer = new FileWriter(file);
                    writer.write(buffer.toString());
                    writer.flush();
                    writer.close();

                    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();
                    }
                });*/

            }
        }
        out();
    }

    private void show(File file) {
        for (File listFile : file.listFiles()) {
            if (listFile.isDirectory()) {
                show(listFile);
            } else {
                //System.out.println(">?" + listFile.getAbsolutePath());
            }

        }
    }

    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();
        }*/
        path = rootPath;
        name = sdk == null ? "tmp.zip" : sdk.getName();
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        smalitools.bale(path,
                path + File.separator + name, new SmaliApkToolsPath() {

                    @Override
                    public void smaliPath(String path) {
                        // TODO Auto-generated method stub
                        try {
                            Thread.sleep(2000);
                            outManifest();
                            File lt;
                            File nLt = null;
                            try {
                                if (!config.getBoolean("isJarLib")) {
                                    Tools.toAJar(dxPath, rootPath + File.separator + sdk.getName(), sdk.getAbsolutePath() + ".out" + File.separator + sdk.getName() + "_dex.jar");
                                    new EncryptJar().encrypt(new File(rootPath + File.separator + sdk.getName())
                                            , rootPath + File.separator + "dexTmp.jar", sdktype, version);
                                    lt = new File(rootPath + File.separator + "dexTmp.jar");
                                } else {
                                    //System.out.println(rootPath + File.separator + sdk.getName());

                                    String exec = config.getString("dex2jar") + " " + rootPath + File.separator + sdk.getName();
                                    //System.out.println("exec:" + exec);
                                    Process process = Runtime.getRuntime().exec(exec);
                                    process.waitFor();

                                    lt = new File(sdk.getName().replace(".jar", "-dex2jar.jar"));
                                }
                                //System.out.println(">>>:" + lt.getAbsolutePath());
                                if (lt.exists()) {
                                    nLt = new File(config.getString("ltName"));
                                    if (nLt.exists()) {
                                        nLt.delete();
                                    }
                                    lt.renameTo(nLt);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            if (inter != null)
                                inter.smaliPath(nLt == null ? rootPath : nLt.getAbsolutePath());
                        } catch (Exception e) {
                            // TODO: handle exception
                            e.printStackTrace();
                        }
                    }
                });


    }

    private void update() {
        //System.out.println("配置：" + config.getBoolean("isAllPackage"));
        File root = null;

        if (config.getBoolean("isAllPackage")) {
            String tmp = nowAdClass.keySet().iterator().next();
            File path = new File((nowAdClass.get(tmp)).getAbsolutePath());
            String packge = path.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
            root = new File(rootPath + File.separator + "smali");
            allpackage(root, packge);


        }
       /* for (String key : nowAdClass.keySet()) {
            System.out.println("key=" + key + " file=" + nowAdClass.get(key) + " oldFile=" + adClass.get(key));
        }*/
        for (String key : adClass.keySet()) {

            File file = new File(adClass.get(key).getAbsolutePath());
            String fileName = file.getName().replace(".smali", "");
            File filePath = new File(nowAdClass.get(key).getAbsolutePath().replace(file.getName(), "").replace(".smali", ""));
            if (!config.getBoolean("isAllPackage")) {
                filePath = new File(file.getAbsolutePath().replace(file.getName(), ""));
            }
           // System.out.println(nowAdClass.get(key)+" "+file.getName()+" "+filePath.getAbsolutePath());
            //System.out.println(key + "  |  " + file.getAbsolutePath() + "  |   " + fileName + " | " + filePath.getAbsolutePath());
            if (filePath.listFiles() == null) {
                //System.out.println("filePath为空：" + filePath.getAbsolutePath());
                //System.out.println(file.getAbsolutePath());
            }
            //moveFile(filePath,key);
            for (File fs : filePath.listFiles()) {
              //  System.out.println(fs.getAbsolutePath());
                if (fs.isDirectory()) {
                    continue;
                }
                if (!fs.getName().startsWith(fileName)) {
                    continue;
                }

                String nName = getNewName(fs.getAbsolutePath());
                //System.out.println(fs.getAbsolutePath().replace(rootPath,"")+"  >  "+nName);
                if (fs.getName().startsWith(fileName.split("\\$")[0] + "$")) {
                    if (getNewName(fs.getAbsolutePath()).endsWith("[notmover]")) {
                       Tools.copyFileToName(fs.getAbsolutePath(), fs.getAbsolutePath(), fs
                                .getName().replace(fs.getName().split("\\$")[0], nName), true);
                        file.delete();
                    } else {

                        moveFile(fs, key, nName+fs.getName().substring(fileName.length()), false);
                    }
                }
            }
            if (getNewNameForSrc(file.getName()).endsWith("[notmover]")) {
                nowAdFile.put(key, file.getAbsolutePath());
                Tools.copyFileToName(file.getAbsolutePath(), file.getAbsolutePath().replace(file.getName(), ""),
                        getNewName(file.getAbsolutePath()) + ".smali", true);
                file.delete();
            } else {
                moveFile(file, key, getNewName(file.getAbsolutePath()) + ".smali", true);
            }


        }
        if (root != null)
            removeNullFile(root);
    }

    private void moveFile(File path, String key) {
        File fileName = nowAdClass.get(key);
        for (File file : path.listFiles()) {
            if (file.isDirectory()) {
                moveFile(file, key);
            } else {
                if (file.getName().startsWith("TMProvider")) {
                    //System.out.println("移动文件：" + file.getName() + " -> " + getNewName(file.getAbsolutePath()) + " | " + fileName);
                }
                //  //System.out.println("移动文件："+path.getName()+" -> "+getNewName(path.getName()));
                moveFile(file, key, getNewName(path.getAbsolutePath()) + ".smali", false);
            }
        }
    }

    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 (!file.exists()) {
            file = new File(nowAdClass.get(key), file.getName());
        }
        if (!file.getName().endsWith(".smali")) {
            file = new File(file.getAbsolutePath() + ".smali");
        }
        if (isAddFile)
            nowAdFile.put(key, nowAdClass.get(key).getAbsolutePath());
        boolean t = Tools.copyFileToName(file.getAbsolutePath(), path,
                nName, true);
        file.delete();
       //System.err.println("移动文件：" + file.getAbsolutePath() + " 到" + path + " 重命名为：" + nName + " 结果" + t);
    }

    private void allpackage(File file, String packge) {
        for (File tmp : file.listFiles()) {
            String pack = tmp.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "");
            if (!packge.contains(pack) && tmp.isDirectory()) {
                movesdk(tmp, File.separator + "smali" + File.separator + packge);
            }
            if (tmp.isDirectory()) {
                allpackage(tmp, packge);
            }
        }

    }

    private void movesdk(File path, String toPath) {
        for (File file : path.listFiles()) {
            if (file.getName().equals("BuildConfig.smali")) {
                file.delete();
                continue;
            }
            if (packageName != null && file.getAbsolutePath().contains(packageName.replace(".", File.separator))) {
                continue;
            }
            String sdkPackageName=config.isNull("regexPackage")?null:config.getString("regexPackage");
            if(sdkPackageName!=null){
                toPath=toPath.replace(sdkPackageName.replace(".",File.separator),"");
            }

            if (file.isDirectory()) {
                String tmp = toPath + File.separator + file.getName();
                new File(rootPath + File.separator + tmp).mkdirs();
                movesdk(file, tmp);
            } else {
                String fileName = file.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator, "")
                        .replace(File.separator, ".")
                        .replace(".smali", "");
                File toPathFile = new File(rootPath + File.separator + toPath);
                if (!toPathFile.exists()) {
                    toPathFile.mkdirs();
                }


                //boolean data = file.renameTo(new File(rootPath + toPath, file.getName()));
                boolean data=Tools.copyFile(file.getAbsolutePath(),rootPath + toPath,true);
                file.delete();
               // System.out.println("移动文件：" + file.getAbsolutePath().replace(rootPath, "") + " 到 " + (rootPath + toPath) + " > " + fileName + " " + nowAdClass.get(fileName) + " >! " + data);
                if (nowAdClass.containsKey(fileName)) {
                 //   System.err.println("移动文件："+file.getAbsolutePath().replace(rootPath, "")+" 到 "+toPath+" > "+fileName+" "+nowAdClass.get(fileName));
                    //  //System.out.println(file.getAbsolutePath().replace(rootPath,"")+"  "+toPath);
                    nowAdClass.put(fileName, new File(rootPath + File.separator + toPath));
                }
            }
        }

    }

    private void removeNullFile(File root) {
        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) {
        File file=new File(name);
        String packageName=file.getAbsolutePath().replace(rootPath + File.separator + "smali" + File.separator,"").replace(file.getName(),"");
        String nName = getNewNameForSrc(packageName.replace(File.separator,".")+file.getName());
        if(nName.equals(packageName.replace(File.separator,".")+file.getName().replace(".smali",""))){
            nName=getNewNameForSrc(file.getName());
        }
        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;
        if (config.getJSONObject("rename").isNull(tmpName.contains("$") ? tmpName.split("\\$")[0] : tmpName)) {
            nName = name;
        } else {
            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(nName.startsWith("{>")){
            nName=nName.split("}")[1];
        }*/
        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 < random.length(); 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()) {
                    boolean t = mkdir.mkdirs();
                }
            }
            nowAdClass.put(clazzs.getString(i), mkdir);
            for (String key : nowAdClass.keySet()) {
              //  System.out.println("key=" + key + " file=" + nowAdClass.get(key) + " oldFile=" + adClass.get(key));
            }
        }
    }
}
