从反编译代码的资源文件获得我们需要的color资源

上次说推荐反编译要用jadx 。现在发现他的资源文件都在这个文件夹里


然后效果是这样的



而我们希望的样子是这样的


程序员总不能一个一个的来改吧。偷懒大法好。让我们用程序代码来解决掉他吧。
首先我们将我们需要修改的color的资源文件从我们的这个反编译的这个窗口剪切复制一下
放到我们桌面的txt文件中。然后呢,我们用自己的代码运行一下就是这样的


然后就差不多可以直接用了呢,直接放到自己的color资源文件中,完美。下面是完整的代码。
主类。
   
   
package thinkinjava;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
public class Object {
 
public static void main(String[] args) {
String filePath="C://Users/kingwen/Desktop/changeformat.txt";
String fileContent=getContent(filePath);
ArrayList<FormatBean> beanList=getBeanFormContent(fileContent);
System.out.println(beanList.size());
String filePath1="C://Users/kingwen/Desktop/changeformat1.txt";
writeContent(beanList,filePath1);
}
/**
* 通过文件的读入流读取我们的文件到我们的程序中
* @param fileUrl 我们文件的输入地址
* @return 返回文件的内容
*/
public static String getContent(String fileUrl){
String result="";
File file = new File(fileUrl);
BufferedReader reader = null;
try {
System.out.println("以行为单位读取文件内容,一次读一整行:");
reader = new BufferedReader(new FileReader(file));
String tempString = null;
int line = 1;
// 一次读入一行,直到读入null为文件结束
while ((tempString = reader.readLine()) != null) {
// 显示行号
// System.out.println("line " + line + ": " + tempString);
line++;
result+=tempString;
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
}
}
}
return result;
}
/**
* 对我们读取的一行的数据进行处理,选择出自己想要的东西
* @param s 从文件中读取的所有数据
*/
public static ArrayList<FormatBean> getBeanFormContent(String content) {
// 预定义一个ArrayList来存储结果
ArrayList<FormatBean> results = new ArrayList<FormatBean>();
Pattern pattern = Pattern
.compile("color.(.+?):(.+?)");
Matcher matcher = pattern.matcher(content);
// 是否存在匹配成功的对象
Boolean isFind = matcher.find();
while (isFind) {
// 定义一个对象来存储抓取到的信息
String indexName=matcher.group(1);
String indexColor=content.substring(matcher.end(),matcher.end()+7);
//System.out.println("name="+indexName+" indexColor"+indexColor);
FormatBean temp = new FormatBean(indexName,indexColor);
// 添加成功匹配的结果
results.add(temp);
// 继续查找下一个匹配对象
isFind = matcher.find();
}
return results;
}
/**
* 文件的输出流,将我们处理好的数据进行输出
* @param beans 用于存放我们处理好的数据的链表
* @param filePath 我们要存放的位置
*/
public static void writeContent(ArrayList<FormatBean> beans,String filePath){
FileWriter fw=null;
BufferedWriter bw=null;
try {
fw=new FileWriter(filePath);
bw=new BufferedWriter(fw);
// <color name="colorAccent">#FF4081</color>
for(int i=0;i<beans.size();i++){
bw.write("<color name=\""+beans.get(i).getName()+"\">"+beans.get(i).getColor()+"</color>"+"\n");
// System.out.println("输出"+i);
bw.newLine();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
if(fw!=null||bw!=null){
try {
bw.close();
fw.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}finally{
try {
bw.close();
fw.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
bean类
   
   
package thinkinjava;
 
public class FormatBean {
String name;
String color;
public FormatBean(String n,String c){
this.name=n;
this.color=c;
}
 
public String getName() {
return name;
}
 
public void setName(String name) {
this.name = name;
}
 
public String getColor() {
return color;
}
 
public void setColor(String color) {
this.color = color;
}
public String toString(){
return "name="+name+"color="+color;
}
 
}

如果你想偷懒的话可以尝试一下,嘿嘿~
【写在后面】
有点遗憾就是说这个代码暂时还不能完全的去解析我们的资源文件,这个仅仅能解析我们的color文件。
而我们的String资源 文件由于其独特性和我暂时对正则表达式的理解不是很清晰,所以暂时还不能支持
先写一下我之后处理String的思路,防止以后忘记。
读入→处理→输出
关于处理,就不能和这里的color文件的获取方式一样了,上面的代码是先将我们将整个的文本都读取出来,然后对其进行分析,这样看起来代码会比较规范,有容易理解。但是能力有限的我处理文本的时候正则表达式没有办法使用,可我可以一行一行的处理,比如说读取一行之后查找String,然后subString获取其之后的数据,从而能够得到我们需要的数据,想法先留在这里。要是有时间就去实现它。
ok~

【写在最后,是不是看起来很厉害的样子,忙了一天然后发现,资源文件可以用apktool这个反编译软件来进行获取,有兴趣的可以尝试下,有时间我再写一个apktool的反编译教程,不管怎么样,解决一个问题的感觉还是很赞的,对不对~】


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
反编译exe文件为py文件的过程是将已编译成二进制形式的可执行文件转换回源代码文件的过程。在Python中,有一些第三方工具可以实现这个功能,比如uncompyle6。 下面是一个简单的示例代码,展示如何使用uncompyle6来反编译exe文件为py文件: ```python import uncompyle6 # 定义反编译函数 def decompile_exe(exe_file, py_file): with open(py_file, 'w') as writer: try: uncompyle6.decompile_file(exe_file, writer) print("反编译成功!") except Exception as e: print("反编译过程中出现错误:", str(e)) # 定义exe文件和py文件的路径 exe_file = "path/to/exe_file.exe" py_file = "path/to/py_file.py" # 调用反编译函数 decompile_exe(exe_file, py_file) ``` 以上代码中,我们先导入uncompyle6模块。然后通过定义一个`decompile_exe`函数,该函数接受exe文件和py文件的路径作为参数。在这个函数内部,我们打开py文件以供写入,并使用`uncompyle6.decompile_file()`方法将exe文件内容反编译写入py文件中。 最后我们通过调用`decompile_exe`函数,传入exe文件和py文件的路径来执行反编译过程。如果反编译成功,将打印“反编译成功!”;如果过程出现错误,将打印错误信息。 需要注意的是,使用uncompyle6反编译exe文件为py文件并不能保证100%还原源代码,因为编译器可能对源代码做了一些优化或者对源代码进行了混淆处理。因此,反编译的结果可能不如源代码的原始质量。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值