[英]Python reading a PE file and changing resource section
我正在尝试打开Windows PE文件并更改资源部分中的一些字符串。
f = open('c:\test\file.exe', 'rb')
file = f.read()
if b'A'*10 in file:
s = file.replace(b'A'*10, newstring)
在资源部分,我有一个只是的字符串:
AAAAAAAAAA
我想用别的东西代替它。 当我阅读文件时,我得到:
\x00A\x00A\x00A\x00A\x00A\x00A\x00A\x00A\x00A\x00A
我尝试使用UTF-16打开并解码为UTF-16,但随后遇到错误:
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 1604-1605: illegal encoding
我看到的每个人都有通过解码为UTF-16而解决了相同问题的人。 我不确定为什么这对我不起作用。
如果二进制文件中的资源编码为utf-16,则不应更改编码。
尝试这个
f = open('c:\\test\\file.exe', 'rb')
file = f.read()
unicode_str = u'AAAAAAAAAA'
encoded_str = unicode_str.encode('UTF-16')
if encoded_str in file:
s = file.replace(encoded_str, new_utf_string.encode('UTF-16'))
在二进制文件中,所有内容都已编码,请记住
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.