import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ReplaceStr {
static String replaceStr;
static String channel;//渠道号数字部分
static String channelPre;//渠道号前缀
static int channelMax;//渠道数量
static String unpacked="unpacked";
static String packed="packed";
static String signed="signed";
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
channelPre= PropertyHelper.getKeyValue("channelPre");
channelMax=Integer.parseInt(PropertyHelper.getKeyValue("channelMax"));
step1();
step2();
step3();
step4();
}
private static void step4() {
// TODO Auto-generated method stub
System.out.println("清空临时文件夹→→→→→");
Utils.deleteFolder(unpacked);
List<String> strings= readFiles(packed);
for(String string:strings){
System.out.println("当前文件名:"+string);
if(string.contains(".apk")){
new File("packed\\"+string).delete();
}
}
System.out.println("临时文件清理完成!");
}
private static void step1() {
Utils.createFolder(unpacked);
Utils.createFolder(signed);
System.out.println("第一步:批量解包→→→→→");
String dir="apk";
List<String> strings= readFiles(dir);
for(String string : strings){
String temp="cmd /c apktool d \"apk\\"+string+"\" \"unpacked\\"+string.split("\\.")[0]+"\"";
System.out.println("执行的cmd语句:"+temp);
runbat(temp);
}
}
private static void step2() {
System.out.println("第二步:批量替换并打包中→→→→→");
for (int i = 1; i <= channelMax; i++) {
if(i<10){
channel="0"+i;
}else{
channel=String.valueOf(i);
}
System.out.println("正在操作渠道"+channelPre+channel+"→→→→→");
System.out.println("批量替换Strings.xml的fuid中→→→→→");
// PropertyHelper.writeProperties("anqu", "anqu01");
String dirs = "unpacked";
List<String> stringss = readAbFiles(dirs);
for (String temp : stringss) {
File file = new File(temp + "\\res\\values\\strings.xml");
//正则替换
regularExp("", "<string name=\"fuid\">"+channelPre+channel+"</string>", file);
}
System.out.println("批量打包中→→→→→");
List<String> s_unpacks = readFiles("unpacked");
for (String string : s_unpacks) {
String temp = "cmd /c apktool b \"unpacked\\" + string + "\" \"packed\\" + string +channelPre+channel+ ".apk\"";
System.out.println("执行的cmd语句:" + temp);
runbat(temp);
}
}
}
private static void step3() {
System.out.println("第四步:批量签名中→→→→→");
List<String> s_packedApks= readFiles("packed");
for(String string : s_packedApks){
if(!string.contains(".apk")){
continue;
}
String temp="cmd /c java -jar packed\\signapk.jar packed\\testkey.x509.pem packed\\testkey.pk8 \"packed\\"+string+"\" \"signed\\"+string+"\"";
System.out.println("执行的cmd语句:"+temp);
runbat(temp);
}
System.out.println("签名完成,存放于signed文件夹中。");
}
private static void replace(File file,String searchStr,String replaceStr) {
// TODO Auto-generated method stub
if(searchStr == null){
return;
}
try{
/* FileReader reader = new FileReader(file);
char[] dates = new char[1024];
int count = 0;
StringBuilder sb = new StringBuilder();
while((count = reader.read(dates)) > 0){
String str = String.valueOf(dates, 0, count);
sb.append(str);
}
reader.close();*/
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
StringBuffer sbread = new StringBuffer();
while (isr.ready()) {
sbread.append((char) isr.read());
}
isr.close();
// 从构造器中生成字符串,并替换搜索文本
String str = sbread.toString().replace(searchStr, replaceStr);
/* FileWriter writer = new FileWriter(file);
writer.write(str.toCharArray());
writer.close();*/
OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(file),"UTF-8");
out.write(str.toCharArray());
out.flush();
out.close();
}catch(Exception e){
e.printStackTrace();
}
System.out.println("替换完成!");
}
/**
* 运行cmd命令
*/
public static boolean exec(String[] cmdAry) throws Exception {
Runtime rt = Runtime.getRuntime();
Process proc = null;
try {
proc = rt.exec(cmdAry);
/*
* Runtime的exec()方法类似线程,不会在cmd命令执行完成后再继续运行下面的代码,
* 所以导致可能cmd命令还没执行完毕,程序就运行到了Process的destroy()方法,因
* 此需要一个方法去等待cmd命令执行完毕后,再运行exec()之后的方法
*/
return waitForProcess(proc) > 0;
} finally {
if (proc != null) {
proc.destroy();
proc = null;
}
}
}
/**
* 得到cmd命令返回的信息数据流,该流的运行周期与cmd命令的实行时间相同
*/
public static int waitForProcess(Process proc) throws Exception {
// cmd命令有返回正确的信息流,和错误信息流,不过不能绝对表示cmd命令是否执行正确
BufferedReader in = null;
BufferedReader err = null;
String msg = null;
int exitValue = -1;
try {
in = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((msg = in.readLine()) != null) {
System.out.println(msg);
if (1 != exitValue) {
exitValue = 1;
}
}
err = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
while ((msg = err.readLine()) != null) {
System.out.println(msg);
if (0 != exitValue) {
exitValue = 0;
}
}
return exitValue;
} finally {
if (null != in) {
in.close();
in = null;
}
if (null != err) {
err.close();
err = null;
}
}
}
public static void runbat(String bat) {
try {
Process process = Runtime.getRuntime().exec(bat);
process.waitFor( );
// System.out.println(ps.getInputStream());
} catch(IOException ioe) {
ioe.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static List<String> readFiles(String filePath) {
File f = null;
f = new File(filePath);
File[] files = f.listFiles(); // 得到f文件夹下面的所有文件。
List<File> list = new ArrayList<File>();
List<String> strings=new ArrayList<String>();
for (File file : files) {
list.add(file);
}
for(File file : files) {
System.out.println(file.getName());
strings.add(file.getName());
}
return strings;
}
public static List<String> readAbFiles(String filePath) {
File f = null;
f = new File(filePath);
File[] files = f.listFiles(); // 得到f文件夹下面的所有文件。
List<File> list = new ArrayList<File>();
List<String> strings=new ArrayList<String>();
for (File file : files) {
list.add(file);
}
for(File file : files) {
strings.add(file.getAbsolutePath());
}
return strings;
}
/**
* @param regex 正则
* @param to 要替换成的内容
* @param file 被替换的文件
*/
public static void regularExp(String regex,String to,File file){
// regex = "^\"fuid\">(.*)</string>$";
regex = "<string name=\"fuid\">(.*?)</string>";
/* source = "<a href=\"http://***.***.***" onclick=\"co('**')\" class=\"lr\">***</a>";*/
String source=Utils.read_UTF8_FileContent(file);
Matcher matcher = Pattern.compile(regex).matcher(source);
while (matcher.find()) {
System.out.println("匹配的group():"+matcher.group());
replace(file, matcher.group(),to);
}
/*output:
href="http://***.***.*" onclick="co('**')" class="lr">***
*/
}
}
分享到:
相关推荐
apk zip格式加密 签名 高通机型镜像合并 QSB格式解包 ozip转换zip格式 华为机型官方固件Updata。app格式解包 开机第一屏制作logo ofp格式解包 等等功能选项较多 是你入手编译第三方rom的工具 需要的友友下载使用 ...
ROM签名 盒子刷机解包打包签名工具
适用于非高安版的海思Hi3798_Mv100系列机顶盒固件解包打包签名的工具,解包后自由修改后再打包刷机的。比如M100、HG680J、EC6108V9系列、E900系列,只要不是高安版的Hi3798_MV100芯片的都可以,高安的肯定不行,其他...
网上搬运的瑞芯微固件解包打包工具_20140513_v5.0.exe_Beat3 1.瑞芯微跟全志平板的固件解包打包 2.平板电脑的管理工具 -平板电脑ROOT -平板电脑第三方API定制固件 ...-APK解包打包 -APK优化 -APK汉化
把需要解包的APK文件放入文件夹。点击启动-分解,后面的就根据提示操作就可以了。集APK文件解包,打包,签名。源文件备份为一体。需要修改的APK文件不需要修改文件名。
该文件为apk文件解包打包工具。将所需解包xxx.apk文件复制到压缩包解压后apktool.bat所在目录,打开cmd.exe定位到该目录,输入“apktool d xxx.apk”,解包后文件在该目录中xxx文件夹中;输入“apktool b xxx“,...
2022rom解包打包做第三方rom工具 支持super格式解包打包 提示:请下载解压后改名英文短目录后在操作 简单说明 支持目前机型的解包打包 支持img格式解包打包 支持super格式的解包打包 支持任意BR后缀解包打包 支持...
晶晨固件解包打包工具
帮助您解包打包和修改APK文件
改工具就有android apk 解包、打包、签名所需的所以工具一次下载即可,下载后可以参考http://blog.csdn.net/changcsw/article/details/17420641 这里有使用的详细步骤
安卓rom解包打包制作修改rom软件 支持解包super-CRB 工具支持一键分解/合成Img、Super、Raw、Ext镜像(包括三星、索尼等定制格式)、一键编辑Build.prop、内核编辑修改、Apk反编译 中文语言操作 图形化界面 有需要...
ubuntu 解包打包 img
安卓机型一键解包打包工具 做rom的工具 解包 打包系统 解包rec 解包boot 打包rec 打包boot 解包系统 解包其他分区img等 对应到解包打包选项较多 资源自测较好 建议win7以上机型使用 资源较大。建议留有空间解压
win下工具:免费交流群:566781254。...兼容海思盒子uboot格式rec解压打包(非高安),比如hi3798芯片系列的盒子,拖入一键解压,一键打包,包含keys生成工具和视频教程。玩海思盒子改私签必备工具。
用于img格式镜像文件解包和打包的好工具!
rom解包 打包修改 做包工具-推荐版 资源将近1G大小。功能非常齐全 适合做第三方rom的工具 解包img 解包其他格式 打包卡刷包 打包其他格式 资源对miui兼容性发行好。...签名zip和apk等等功能 有需要的友友可以下载使用
安卓机型ROM解包打包工具MIK解压版 说明: 是一个允许用户使用 Windows 重新打包 Android 分区的工具。该工具支持 更多功能,您可以在下面查看。 特征: 拆包和打包分区:System、Vendor、Product、ODM、SOCKO、...
apk解包打包修改汉化工具软件,解压出包里面的资源来是不成问题的,不过如果要去修改程序的一些参数就要静下心来好好学习了,我反正是没静下心来,不过如果单纯只是想解包的话,很简单,直接用winrar就行了
用于linux下 解包打包APK文件,同样带有签名工具
固件解包打包工具_2014固件解包打包固件解包打包工具_20140420_v5.0.exe工具_20140420_v5.0.exe0420_v5.0.exe固件解包打包工具_20140420_v5.0.exe