【发布时间】:2019-02-17 01:30:40
【问题描述】:
我正在尝试生成恶意软件文件的二元组 hexdump,这将帮助我与基于二元组的不同恶意软件文件相关联,我尝试使用计数器、zip 和切片来获得结果,而不是得到一个错误。如果有人可以帮助我,我会很高兴。
import binascii
import re
import collections
try:
from itertools import izip as zip
except ImportError: # will be 3.x series
pass
try:
from itertools import islice as slice
except ImportError: # will be 3.x series
pass
with open('path', 'rb') as f:
for chunk in iter(lambda: f.read(), b''):
s=binascii.hexlify(chunk)
print(collections.Counter(zip(s),slice(s,1,None)))
The result should be like:Counter({(4d5a):200,(5a76):120,(7635):1000...}) but instead i am getting this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-110-d99ed11a1260> in <module>
3 for chunk in iter(lambda: f.read(), b''):
4 s=binascii.hexlify(chunk)
----> 5 print(collections.Counter(zip(s),slice(s,1,None)))
6
~\Anaconda3\lib\collections\__init__.py in __init__(*args, **kwds)
562 self, *args = args
563 if len(args) > 1:
--> 564 raise TypeError('expected at most 1 arguments, got %d' % len(args))
565 super(Counter, self).__init__()
566 self.update(*args, **kwds)
TypeError: expected at most 1 arguments, got 2
【问题讨论】:
-
这是什么语言的?请编辑您的标签以添加语言。
-
做到了。谢谢。
-
Collections() 接受一个参数。我试过这个:
collections.Counter(foo=zip(s), bar=slice(s, 1, None)),但我不知道这是否有帮助。 -
顺便说一句:看起来这些块没有像我想的那样工作。这是我正在查看的内容:pastebin.com/iP8PAscd
-
这里是使用来自 stackoverflow 上另一个问题的 ngrams sn-p 的替代方法:pastebin.com/GzG5FxD3 我不知道这是否能解决您的问题。
标签: python counter binaryfiles hexdump malware-detection