MCPcopy Create free account
hub / github.com/ELMERIKH/PyinMemoryPE / get_imphash

Method get_imphash

pythonmemorymodule/pefile.py:5338–5374  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5336 raise Exception("Invalid hashing algorithm specified")
5337
5338 def get_imphash(self):
5339 impstrs = []
5340 exts = ["ocx", "sys", "dll"]
5341 if not hasattr(self, "DIRECTORY_ENTRY_IMPORT"):
5342 return ""
5343 for entry in self.DIRECTORY_ENTRY_IMPORT:
5344 if isinstance(entry.dll, bytes):
5345 libname = entry.dll.decode().lower()
5346 else:
5347 libname = entry.dll.lower()
5348 parts = libname.rsplit(".", 1)
5349
5350 if len(parts) > 1 and parts[1] in exts:
5351 libname = parts[0]
5352
5353 entry_dll_lower = entry.dll.lower()
5354 for imp in entry.imports:
5355 funcname = None
5356 if not imp.name:
5357 funcname = ordlookup.ordLookup(
5358 entry_dll_lower, imp.ordinal, make_name=True
5359 )
5360 if not funcname:
5361 raise PEFormatError(
5362 f"Unable to look up ordinal {entry.dll}:{imp.ordinal:04x}"
5363 )
5364 else:
5365 funcname = imp.name
5366
5367 if not funcname:
5368 continue
5369
5370 if isinstance(funcname, bytes):
5371 funcname = funcname.decode()
5372 impstrs.append("%s.%s" % (libname.lower(), funcname.lower()))
5373
5374 return md5(",".join(impstrs).encode()).hexdigest()
5375
5376 def parse_import_directory(self, rva, size, dllnames_only=False):
5377 """Walk and parse the import directory."""

Callers

nothing calls this directly

Calls 2

PEFormatErrorClass · 0.85
decodeMethod · 0.80

Tested by

no test coverage detected