如何实现apk、ipa包修改注入参数打子包
发表于:2025-02-23 作者:千家信息网编辑
千家信息网最后更新 2025年02月23日,这篇文章主要讲解了"如何实现apk、ipa包修改注入参数打子包",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"如何实现apk、ipa包修改注入参数打子包
千家信息网最后更新 2025年02月23日如何实现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包修改注入参数打子包这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
文件
参数
推广
推广员
文件名
目录
成功
盒子
学习
内容
平台
效果
标记
版本
安卓
utf-8
位置
完了
就是
思路
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
怎样做软件开发公司
球探体育比分数据库
软件公司服务器多少钱
简述软件开发的两大类技术
信息安全 网络安全管理规定
金晴云华服务器
国家网络安全局是哪年成立的
永州软件开发有限公司
mts流媒体服务器管理后台
我的世界最先进的红石服务器
域控 数据库
上海虚拟服务器回收价格
以网络安全为论点200字
服务器修改完密码远程连接不上
国家地理国情监测数据库
大厂实习生软件开发工资
商城类软件开发公司排名
数据库中储的是数据吗
国家电网网络安全监测装置
软件开发qc流程
基于防火墙的企业网络安全
国际版的jojo服务器
对象型数据库有哪些特点
网狐数据库 查询已过期
蓬佩奥网络安全局
北京软件开发培训班哪家好
Android数据库建立
腾讯小霸王服务器
计算机网络技术大专生薪资
《网络安全》规定