测试穿山甲资源包工具
This commit is contained in:
111
src/com/qy/utils/CsjTools.java
Normal file
111
src/com/qy/utils/CsjTools.java
Normal file
@@ -0,0 +1,111 @@
|
||||
package com.qy.utils;
|
||||
|
||||
import com.qy.Interfaces.SmaliApkToolsPath;
|
||||
import com.qy.ui.TextToDalog;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CsjTools {
|
||||
private String csj_R_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1\\smali\\com\\bytedance\\sdk\\openadsdk";
|
||||
private String csj_demo_path="E:\\idea\\android_sdk_tools\\demo_2.8.0.1";
|
||||
private String apk_R_path="E:\\idea\\android_sdk_tools\\app-release-1\\smali\\com\\luckyboy\\mmxing";
|
||||
private List<String> r_list;
|
||||
public CsjTools() {
|
||||
}
|
||||
public void setR() {
|
||||
r_list=new ArrayList<>();
|
||||
File apk_R=new File(csj_R_path+File.separator+"R.smali");
|
||||
if(!apk_R.exists()){
|
||||
new TextToDalog("找不到文件","穿山甲R文件不存在:"+apk_R);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
BufferedReader reader=new BufferedReader(new FileReader(apk_R));
|
||||
String tmp;
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
if(tmp.contains("/R$")){
|
||||
r_list.add(tmp.split("/")[tmp.split("/").length-1].replace(";,","").replace(";",""));
|
||||
}
|
||||
}
|
||||
/*for (String fileName : r_list) {
|
||||
setRData(fileName);
|
||||
}*/
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private void setRData(String fileName){
|
||||
File apkR=new File(apk_R_path+File.separator+fileName+".smali");
|
||||
|
||||
List<String> header=new ArrayList<>();
|
||||
List<String> end=new ArrayList<>();
|
||||
|
||||
boolean isHeader=true;
|
||||
long id=-1;
|
||||
try {
|
||||
BufferedReader reader=new BufferedReader(new FileReader(apkR));
|
||||
String tmp;
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
if(tmp.trim().equals("# direct methods")){
|
||||
isHeader=false;
|
||||
}
|
||||
if(isHeader){
|
||||
header.add(tmp);
|
||||
if(tmp.contains(":I = 0x")){
|
||||
id=Long.parseLong(tmp.split("0x")[1],16);
|
||||
}
|
||||
}else{
|
||||
end.add(tmp);
|
||||
}
|
||||
}
|
||||
header.addAll(getCSJR(fileName,id));
|
||||
header.addAll(end);
|
||||
FileWriter writer=new FileWriter(apkR);
|
||||
for (String str : header) {
|
||||
writer.write(str+"\n");
|
||||
}
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private List<String> getCSJR(String fileName,long id){
|
||||
File csjR=new File(csj_R_path+File.separator+fileName+".smali");
|
||||
List<String> csj=new ArrayList<>();
|
||||
try {
|
||||
BufferedReader reader=new BufferedReader(new FileReader(csjR));
|
||||
String tmp;
|
||||
long nextId=id;
|
||||
while ((tmp=reader.readLine())!=null){
|
||||
if(tmp.trim().startsWith(".field public")){
|
||||
csj.add(tmp.replace(".field public static",".field public static final")+" = 0x"+Long.toHexString(++nextId));
|
||||
}
|
||||
}
|
||||
csj.add("\n");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return csj;
|
||||
}
|
||||
private void copyFile(){
|
||||
setR();
|
||||
for (String s : r_list) {
|
||||
Tools.copyFile(apk_R_path+File.separator+s+".smali",csj_R_path+File.separator+s+".smali",true);
|
||||
}
|
||||
|
||||
}
|
||||
private void out(){
|
||||
EncryptJar encryptJar=new EncryptJar();
|
||||
encryptJar.encrypt(new File("E:\\idea\\android_sdk_tools\\csj.apk"),"E:\\idea\\android_sdk_tools\\csj_",13,5600);
|
||||
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
CsjTools tools=new CsjTools();
|
||||
tools.out();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user