Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deduplicate procmems by sha256 hash #119

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions malduck/procmem/binmem.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from abc import ABCMeta, abstractmethod
from hashlib import sha256
from typing import Iterator, List, Optional, Type, TypeVar

from .procmem import ProcessMemory, ProcessMemoryBuffer
Expand Down Expand Up @@ -78,10 +79,18 @@ def load_binaries_from_memory(cls: Type[T], procmem: ProcessMemory) -> Iterator[
In previous versions it was done by extractor, so it was working only
if memory-aligned version was also "valid".
"""
seen_hashes = set()
if cls.__magic__ is None:
raise NotImplementedError()
for binary_va in procmem.findv(cls.__magic__):
binary_procmem_dmp = cls.from_memory(procmem, base=binary_va)

# Deduplicate procmems by the content hash
next_hash = sha256(binary_procmem_dmp.m).digest()
if next_hash in seen_hashes:
continue
seen_hashes.add(next_hash)

if binary_procmem_dmp.is_valid():
yield binary_procmem_dmp
binary_procmem_img = binary_procmem_dmp.image
Expand Down
Loading