我有一个来自已解析 PE 文件的值列表,其中包括\x00
每个部分末尾的空字节。我希望能够删除\x00
字符串中的字节而不删除所有字节"x"
文件中的 s。我试过做.replace()
and re.sub()
,但并没有取得太大成功。
使用Python 2.6.6
Example.
import re
List = [['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']]
count = 0
while count < len(List):
test = re.sub('\\\\x00', '', str(List[count]))
print test
count += 1
Output:
['.text']
['.data']
['.rsrc']
我想得到以下输出:
.text
.data
.rsrc
关于解决这个问题的最佳方法有什么想法吗?
>>> L = [['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']]
>>> [[x[0]] for x in L]
[['.text\x00\x00\x00'], ['.data\x00\x00\x00'], ['.rsrc\x00\x00\x00']]
>>> [[x[0].replace('\x00', '')] for x in L]
[['.text'], ['.data'], ['.rsrc']]
或者就地修改列表而不是创建新列表:
for x in L:
x[0] = x[0].replace('\x00', '')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)