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段
获得起始地址和大小