如何实现apk、ipa包修改注入参数打子包
这篇文章主要讲解了“如何实现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包修改注入参数打子包这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
本文标题:如何实现apk、ipa包修改注入参数打子包
标题网址:http://scgulin.cn/article/giggso.html