java修改某软件.rdata段数据



import Public.Myfile;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Entities;

import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Vector;

class EditNode{
    String strValue;
    int pos;
    int size = 0;
    EditNode(String strValue ,int pos){
        this.strValue = strValue;
        this.pos = pos;
        size = strValue.length();
    }

}
public class Eidte {

    public static void main(String[] args) throws IOException {

        WriteAllData();
    }

    static void WriteAllData() throws IOException {
        String path  = "";
        List<String> f = Myfile.getAllFile(path,false);
        byte[] bytes = Files.readAllBytes(Paths.get(".exe"));
        for (String s :f){
            String file = new File(s).getName();
            file =file.replace(".txt","");
            file =file.replace(".html","");
            int pos =Integer.parseInt(file.split("_")[0],10) ;
            int size =Integer.parseInt(file.split("_")[1],10) ;
            String NewValue = Myfile.readStringKeyData(s);
            if(s.contains(".html")){
                NewValue = HtmlCompressor(NewValue);
            }

            byte[] temp = NewValue.getBytes();
            for (int i = pos,j=0 ;i < pos + size   ;j++, i++){
                if(j < temp.length){
                    bytes[i] = temp[j];
                }else{
                    bytes[i] = ' ';
                }
            }
            System.out.println(file +"\t" +NewValue +"\t" +NewValue.length() );
        }
    }

    static void ReadAllData() throws IOException {
        //读取.rdata 段的所有UTF-8字符串,并记录字符串的起始地址和长度
        byte[] bytes = Files.readAllBytes(Paths.get(".exe"));
        int size = 0x313400;
        int pos = 0x354200;

        Vector<EditNode> v= GetAllString(bytes,pos,size);
        String path = "";
        for (EditNode s : v){
            String tip = ".txt";
            if(s.strValue.contains("html")){
                tip = ".html";
            }
            Myfile.WriteStringValueUTF_8(path +String.format("%d_%d",s.pos,s.size)+tip, s.strValue);
        }

    }

    static Vector<EditNode> GetAllString(byte[] bytes ,int pos ,int size) throws UnsupportedEncodingException {
        Vector<EditNode> result = new Vector<>();
        int max = 0x1000000;
        byte[] buffer = new byte[max];
        int buf = 0;
        int startPos = 0;
        for (int i = pos ; i< pos + size ;i++){
            if(bytes[i] != 0x0){
                buffer[buf] = bytes[i];
                if(buf==0){
                    startPos = i;
                }
                buf++;

            }else{
                if(buf != 0){
                    String temp = new String(buffer,0,buf,"UTF-8");
                    buf = 0;
                    if(temp.contains("html")){
                        result.add(new EditNode(temp,startPos));
                    }

                }
            }

        }
        return  result;
    }



    static String HtmlCompressor(String strValue){
        Document doc = Jsoup.parse(strValue);
        // 压缩HTML为一行
        doc.outputSettings().prettyPrint(false);
        doc.outputSettings().escapeMode(Entities.EscapeMode.xhtml);
        String compressedHtml = doc.html();
        return compressedHtml;
    }





}

使用010查找.rdata段

获得起始地址和大小

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值