本帖最后由 anysoft 于 2023-5-11 15:26 编辑
其实和语言没关系。
就是一些字符串是直接二进制写在exe里边的,我用16进制方式读取整个exe文件后进行16进制替换,替换完了后写出到exe文件。
代码如下:写的非常粗暴
[JavaScript] 纯文本查看 复制代码 import console;
import crypt;
import crypt.bin;
console.log("开始翻译");
var path = "D:\Development\Softwares\MobaXterm\23.2_preview\zh";
var filename = "MobaXterm_Personal_23.2_Preview1_CHS.exe";
var translatefile = "D:\Development\Softwares\MobaXterm\rdmp\translate.ini";
var data = string.load(path + "\" + filename);
data = crypt.bin.encodeHex(data)
data = string.replace(data," ","");
data = string.replace(data,'\r\n',"");
data = string.replace(data,'\r',"");
data = string.replace(data,'\n',"");
data = string.upper(data);
var file = io.open(translatefile);
var line = "";
var count = 0;
var newfile = "";
while(file.read(0)){
line = file.read("%s");
if(#line > 3){
var tab = string.split(line,"\|");
if(string.find(data,tab[1])){
if(#tab[1]!=#tab[2]){
console.log(tab[1])
continue;
}
count++;
//if(string.find(data,tab[1])){
data = string.replace(data,tab[1],tab[2]);
}else {
newfile = newfile+"\r\n"+line;
}
}
}
//^.*:
//;.*$
// \r\n
string.save(path + "\a.txt", newfile)
string.save(path + "\1" + filename ,crypt.bin.decodeHex(data));
console.log("翻译完成:" + count);
console.pause(true);
至于16进制怎么来的?
用hxd或者winhex等编辑器打开exe搜素关键字,找到对应16进制,然后关键词替换为中文,复制对应的16进制就输出成了 translate.ini文件
刚刚让GPT帮忙写了个python脚本,试了下好用又快
[Python] 纯文本查看 复制代码 import binascii
import os
path = "D:\\Development\\Softwares\\MobaXterm\\23.2_preview\\zh"
input_file_name = "MobaXterm_Personal_23.2_Preview1_CHS.exe"
output_file_name = "2MobaXterm_Personal_23.2_Preview1_CHS.exe"
translate_file_name = "D:\\Development\\Softwares\\MobaXterm\\rdmp\\translate.ini"
# 打开要修改的exe文件
with open(os.path.join(path,input_file_name), 'rb') as f:
data = bytearray(f.read())
# 读取translate.ini文件并进行数据替换
with open(translate_file_name, 'r') as f:
for line in f:
# 按|分隔数据对
src, dest = line.strip().split('|')
# 将16进制字符串转换成字节数组
src_bytes = binascii.unhexlify(src)
dest_bytes = binascii.unhexlify(dest)
# 在data中搜索并替换数据对
offset = 0
while True:
# 在偏移量offset处开始搜索
offset = data.find(src_bytes, offset)
if offset == -1:
# 没有找到,退出循环
break
# 找到了,将原始数据替换为目标数据
print('找到一处,替换中...')
data[offset:offset+len(src_bytes)] = dest_bytes
# 移动偏移量到替换后的位置,避免重复替换
offset += len(dest_bytes)
# 输出修改后的exe文件
with open(os.path.join(path,output_file_name), 'wb') as f:
f.write(data) |