您好,登錄后才能下訂單哦!
這篇文章主要講解了“如何實現apk、ipa包修改注入參數打子包”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“如何實現apk、ipa包修改注入參數打子包”吧!
項目背景:做推廣員系統,需要把平臺包注入推廣員參數,推廣員拿子包去推廣
安卓子包效果:
ios子包效果
package com.qipa.util;import java.io.*;import java.util.zip.ZipEntry;import java.util.zip.ZipInputStream;import java.util.zip.ZipOutputStream;/** * apk文件復制修改注入參數打子包,ipa包注入參數打子包 * 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:/游戲對接/母包/666Game-1.0.7-1904161815-release.apk", "d:/222", "D:/游戲對接/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文件,里面有推廣員參數 * @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)); }/** * 安卓通過母包打子包,返回子包文件名,文件里面寫推廣員參數 * * @param zip_file 母包文件 * @param file_path 子包目錄 * @param agentParam 推廣員參數 * @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);//寫入參數 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 推廣員參數 * @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; } }
感謝各位的閱讀,以上就是“如何實現apk、ipa包修改注入參數打子包”的內容了,經過本文的學習后,相信大家對如何實現apk、ipa包修改注入參數打子包這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。