我正在从C#重写库,它会扫描内存中的模式。我需要从起始地址到结尾扫描进程内存,它在列表中占用大约13+百万字节。接下来,我需要通过条件在这个列表中找到一个模式,其中'offset‘是来自迭代器的字节值。
在C#中,我只使用了for-loop for 1 pattern,扫描花费了大约800ms,但在python中,我没有完全学习这门语言,但我尝试了for-range,花了大约35分钟!几秒钟后,我发现唯一的东西是numpy.where,但我不能将它应用于我的情况。
我尝试过的:
loop_len = range(len(self.exe_image) - pattern_length)
for offset in filter(lambda o: self.__compare_data(pattern, o), loop_len):我需要对偏移量做什么:
def __compare_data(self, pattern: Pattern, offset: int):
return not any(filter(lambda i: pattern.mask[i] == 'x' and pattern.bytes[i] != self.exe_image[offset + i],
range(len(pattern.bytes))))有什么建议吗?
发布于 2019-07-07 02:44:46
发布于 2019-07-07 19:07:58
如果有人感兴趣,那么我使用正则表达式+ bytearray.index代替了JIT。我将exe-bytearray转换为一串int值并通过regex.search找到模式,然后将其转换为bytearray并通过bytearray.index找到索引
我的例子:
search_for = str(pattern.bytes)[1:-1].replace('-1', '.{1,3}') # -1 it's unknown byte
match = re.search(search_for, exe_image_as_str)然后:
offset = exe_image.index(bytearray(int(i) for i in match.group(0).split(', ')))https://stackoverflow.com/questions/56916507
复制相似问题