如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包

這篇文章主要講解了“如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包”吧!

十年建站經(jīng)驗, 成都網(wǎng)站建設、網(wǎng)站設計客戶的見證與正確選擇。成都創(chuàng)新互聯(lián)提供完善的營銷型網(wǎng)頁建站明細報價表。后期開發(fā)更加便捷高效,我們致力于追求更美、更快、更規(guī)范。

項目背景:做推廣員系統(tǒng),需要把平臺包注入推廣員參數(shù),推廣員拿子包去推廣

安卓子包效果:

如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包

ios子包效果

如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包

package com.qipa.util;import java.io.*;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import java.util.zip.ZipOutputStream;/** * apk文件復制修改注入?yún)?shù)打子包,ipa包注入?yún)?shù)打子包 * author:LiuYunJie */public class SixChannel {private final static String CURSTOM_ID = "curstomId:[ci],platformId:[pi]";public static void main(String[] args) {// public static String curstomId = "SM1";// 盒子編號        // public static int platformId = 1; // 平臺編號        try {//       add_zip_entry("D:/游戲?qū)?母包/666Game-1.0.7-1904161815-release.apk", "d:/222", "D:/游戲?qū)?qq.txt");            add_zip_entry_ios("E:\\盒子\\package\\i\\g\\app0106.ipa", "E:\\盒子\\package\\i\\g\\s", 2323, "cyy2323", "1.0");

        } catch (Exception e) {// TODO Auto-generated catch block            e.printStackTrace();
        }
    }/**     * 增加目錄     *     * @param zip_file  母包文件     * @param file_path 子包目錄     * @param text      text文件,里面有推廣員參數(shù)     * @throws Exception     */    public static void add_zip_entry(String zip_file, String file_path,
                                     String text) throws Exception {
        String entry_name = "META-INF/six_sdk";long time = System.currentTimeMillis();if (zip_file == null)throw new RuntimeException("zip file name is null");if (zip_file.isEmpty())throw new RuntimeException("zip file name is empty");if (file_path == null)throw new RuntimeException("zip file name is null");if (file_path.isEmpty())throw new RuntimeException("zip file name is empty");// if (file_name == null)        // throw new RuntimeException("zip file name is null");        // if (file_name.isEmpty())        // throw new RuntimeException("zip file name is empty");        // if (entry_name == null)        // throw new RuntimeException("zip file name is null");        if (entry_name.isEmpty())throw new RuntimeException("zip file name is empty");
        File file_z = new File(zip_file);if (!file_z.exists())throw new RuntimeException("zip file is not exists");// ZipEntry ze = new ZipEntry(entry_name);        // File file = new File(file_path);        // if (!file.exists())        // file.mkdirs();        // ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(        // file_path + "/" + file_name));        // zos.putNextEntry(ze);        // zos.write(Base64.decode(SDKEncryption.encode(CURSTOM_ID.replace("[ci]",        // "2225").replace("[pi]", "2"), 16), flags));        File file = new File(zip_file);
        String name = file.getName().split("\\.")[0];

        BufferedReader br = new BufferedReader(new InputStreamReader(getInputStream(new FileInputStream(text))));while (true) {
            String channel = br.readLine();if (channel == null)break;
            channel = channel.trim();if (channel.length() == 0)continue;

            ZipEntry ze = new ZipEntry(entry_name);
            File file1 = new File(file_path);if (!file1.exists())
                file1.mkdirs();

            ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
                    file_path + "/" + name + "_" + "ps_" + channel + ".apk"));
            zos.putNextEntry(ze);

            zos.write(CURSTOM_ID.replace("[ci]", channel).replace("[pi]", "1")
                    .getBytes("utf-8"));
            zos.closeEntry();
            ZipInputStream zis = new ZipInputStream(new FileInputStream(
                    zip_file));while ((ze = zis.getNextEntry()) != null) {if (!ze.isDirectory()) {
                    zos.putNextEntry(new ZipEntry(ze.getName()));int len = -1;byte[] b = new byte[1024];while ((len = zis.read(b)) > 0) {
                        zos.write(b, 0, len);
                    }
                    zos.closeEntry();
                    zis.closeEntry();
                }
            }
            zos.flush();
            zos.close();
            zis.close();
        }
        br.close();

        System.out.println("打包成功!");
        System.out.println("time:" + (System.currentTimeMillis() - time));
    }/**     * 安卓通過母包打子包,返回子包文件名,文件里面寫推廣員參數(shù)     *     * @param zip_file    母包文件     * @param file_path   子包目錄     * @param agentParam  推廣員參數(shù)     * @param newFileName 注入的標記文件名     * @param version     包的版本號     * @throws Exception     * @return 返回子包文件名     */    public static String add_zip_entry_Android(String zip_file, String file_path,
                                               Integer agentParam, String newFileName, String version) throws Exception {
        String entry_name = "META-INF/" + newFileName;long time = System.currentTimeMillis();if (zip_file == null)throw new RuntimeException("zip file name is null");if (zip_file.isEmpty())throw new RuntimeException("zip file name is empty");if (file_path == null)throw new RuntimeException("zip file name is null");if (file_path.isEmpty())throw new RuntimeException("zip file name is empty");// if (file_name == null)        // throw new RuntimeException("zip file name is null");        // if (file_name.isEmpty())        // throw new RuntimeException("zip file name is empty");        // if (entry_name == null)        // throw new RuntimeException("zip file name is null");        if (entry_name.isEmpty())throw new RuntimeException("zip file name is empty");
        File file_z = new File(zip_file);if (!file_z.exists())throw new RuntimeException("zip file is not exists");// ZipEntry ze = new ZipEntry(entry_name);        // File file = new File(file_path);        // if (!file.exists())        // file.mkdirs();        // ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(        // file_path + "/" + file_name));        // zos.putNextEntry(ze);        // zos.write(Base64.decode(SDKEncryption.encode(CURSTOM_ID.replace("[ci]",        // "2225").replace("[pi]", "2"), 16), flags));        File file = new File(zip_file);
        String name = file.getName().split("\\.")[0];

        ZipEntry ze = new ZipEntry(entry_name);
        File file1 = new File(file_path);if (!file1.exists())
            file1.mkdirs();//子包母包增加新文件        String subPackageName = name + "_" + "ps_" + agentParam + "_vs_" + version + ".apk";
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
                file_path + "/" + subPackageName));//進入到META-INF        zos.putNextEntry(ze);//寫入?yún)?shù)        zos.write(CURSTOM_ID.replace("[ci]", agentParam.toString()).replace("[pi]", "1")
                .getBytes("utf-8"));
        zos.closeEntry();
        ZipInputStream zis = new ZipInputStream(new FileInputStream(
                zip_file));while ((ze = zis.getNextEntry()) != null) {if (!ze.isDirectory()) {
                zos.putNextEntry(new ZipEntry(ze.getName()));int len = -1;byte[] b = new byte[1024];while ((len = zis.read(b)) > 0) {
                    zos.write(b, 0, len);
                }
                zos.closeEntry();
                zis.closeEntry();
            }
        }
        zos.flush();
        zos.close();
        zis.close();

        System.out.println("安卓打包成功!");
        System.out.println("time:" + (System.currentTimeMillis() - time));return subPackageName;
    }/**     * ios通過母包打子包,返回子包文件名     *     * @param zip_file    母包文件     * @param file_path   子包目錄     * @param agentParam  推廣員參數(shù)     * @param newFileName 注入的標記文件名     * @param version     包的版本號     * @throws Exception     * @return 子包名     */    public static String add_zip_entry_ios(String zip_file, String file_path,
                                           Integer agentParam, String newFileName, String version) throws Exception {
        String entry_name = "Payload/lhtx.app/" + newFileName + "/";//生成目錄        long time = System.currentTimeMillis();if (zip_file == null)throw new RuntimeException("zip file name is null");if (zip_file.isEmpty())throw new RuntimeException("zip file name is empty");if (file_path == null)throw new RuntimeException("zip file name is null");if (file_path.isEmpty())throw new RuntimeException("zip file name is empty");if (entry_name.isEmpty())throw new RuntimeException("zip file name is empty");
        File file_z = new File(zip_file);if (!file_z.exists())throw new RuntimeException("zip file is not exists");
        File file = new File(zip_file);
        String name = file.getName().split("\\.")[0];

        ZipEntry ze = new ZipEntry(entry_name);
        File file1 = new File(file_path);if (!file1.exists())
            file1.mkdirs();//子包母包增加新文件        String subPackageName = name + "_" + "ps_" + agentParam + "_vs_" + version + ".ipa";//輸出流        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(
                file_path + "/" + subPackageName));//寫入一個文件到子包指定位置        //Payload/lhtx.app/        zos.putNextEntry(ze);
        zos.closeEntry();//母包寫入流        ZipInputStream zis = new ZipInputStream(new FileInputStream(
                zip_file));while ((ze = zis.getNextEntry()) != null) {if (!ze.isDirectory()) {
                zos.putNextEntry(new ZipEntry(ze.getName()));int len = -1;byte[] b = new byte[1024];while ((len = zis.read(b)) > 0) {
                    zos.write(b, 0, len);
                }
                zos.closeEntry();
                zis.closeEntry();
            }
        }
        zos.flush();
        zos.close();
        zis.close();

        System.out.println("ios打包成功!");
        System.out.println("time:" + (System.currentTimeMillis() - time));return subPackageName;
    }private static InputStream getInputStream(InputStream in)throws IOException {

        PushbackInputStream testin = new PushbackInputStream(in);int ch = testin.read();if (ch != 0xEF) {
            testin.unread(ch);
        } else if ((ch = testin.read()) != 0xBB) {
            testin.unread(ch);
            testin.unread(0xef);
        } else if ((ch = testin.read()) != 0xBF) {throw new IOException("錯誤的UTF-8格式文件");
        } else {// 不需要做,這里是bom頭被讀完了            // System.out.println("still exist bom");        }return testin;

    }
}

感謝各位的閱讀,以上就是“如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

文章題目:如何實現(xiàn)apk、ipa包修改注入?yún)?shù)打子包
標題路徑:http://bm7419.com/article30/giggso.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設、響應式網(wǎng)站、軟件開發(fā)、App設計全網(wǎng)營銷推廣、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設