程序六角螺钉(来自代码六角螺钉)以前加载过六角补片包含3项信息的文件 1.要打开的目标文件(在本例中tar=a)windows.exe文件) 2.old(要在exe中找到的数据) 3.new(exe中要替换旧数据的数据)。 旧的/新的将被写为十六进制(64000000或64000000)或文本,谁知道是什么格式的UTF8 UTF16?。 我需要能够看到补丁文件'old'和'new'数据以及tar文件数据的格式与python相同(在python将其翻译给我之前),这样我就可以编写校正因子例程。 六角螺钉地址:
modcwd = os.getcwd() #assign var to modman dir
patch = 'hex.patch' #hardcode patch to var
patlst = [line.strip() for line in open(patch,'rb',1)] #Read Patch start
tar = patlst[patlst.index('TAR:')+1];old = patlst[patlst.index('OLD:')+1];new = patlst[ pat.index('NEW:')+1]
#start sub to determine if data hex or alpha
a = old [:8]
count = lambda l1, l2: len(list(filter(lambda c: c in l2, l1)))
a_chars = count(a, string.ascii_letters)
a_digits = count(a, string.digits)
if (a_chars/a_digits) > .45 : alphex = 'a'
else: alphex = 'h'
if alphex == 'h' : old = ''.join(old.split()); new = ''.join(new.split())
oldlc = [o.lower() for o in old];old = ''.join(oldlc)
newlc = [n.lower() for n in new];new = ''.join(newlc)
#load open exe file
pircwd = os.chdir('..'); pircwd = os.getcwd()
fotar = open(tar,'rb')
data = fotar.read(160)
Hdata = (binascii.hexlify(data))
bus = re.sub(old,new,Hdata)
fobus = open ('newhex','wb')
fobus.write(bus)
fobus.close()
fotar.close()
The complete hex.patch :
TAR:
Hex!.exe
OLD:
2068 6572 652C 2073 7765 6574 6965 2E0A
NEW:
2068 6572 652C 2073 6578 792E 2E2E 2E0A
EOF:
到目前为止,它正在查找正确的数据,即'old'=数据(匹配的子字符串),并正在写入文件'bus',但'bus'文件的第一行不是十六进制,它已将十六进制替换为'new'十六进制,而是将'new'替换为文本值。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐