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

Method load_module

windows/debug/symbols.py:328–363  ·  view source on GitHub ↗

Load a module at a given ``addr``. The module to load can be pass via a ``file_handle`` or the direct ``path`` of the file to load. :return: :class:`SymbolModule` -- The loaded module .. note:: The logic of ``SymLoadModuleEx`` seems somewhat strange about the n

(self, file_handle=None, path=None, name=None, addr=0, size=0, data=None, flags=0)

Source from the content-addressed store, hash-verified

326
327
328 def load_module(self, file_handle=None, path=None, name=None, addr=0, size=0, data=None, flags=0):
329 """Load a module at a given ``addr``. The module to load can be pass via a ``file_handle``
330 or the direct ``path`` of the file to load.
331
332 :return: :class:`SymbolModule` -- The loaded module
333
334 .. note::
335
336 The logic of ``SymLoadModuleEx`` seems somewhat strange about the naming of the loaded module.
337 A custom module ``name`` is only taken into account if the file is passed via a File handle.
338 To make it more intuitive, if this function is call with a ``path`` and ``name`` and no ``file_handle``,
339 it will open the path and directly call ``SymLoadModuleEx`` with a file handle and a name.
340 """
341
342 # Is that a bug in SymLoadModuleEx ?
343 # To get a custom name for a module it use "path"
344 # So we need to use file_handle and set a custom path
345 # ! BUT it means we cannot get a custom name for a module where the path is not explicit and need to be searched
346 if name is not None and file_handle is None and os.path.exists(path):
347 try:
348 f = open(path)
349 file_handle = windows.utils.get_handle_from_file(f)
350 path = name
351 except Exception as e:
352 pass
353 # Expect a-string
354 path = windows.pycompat.raw_encode(path)
355 try:
356 load_addr = winproxy.SymLoadModuleEx(self.handle, file_handle, path, name, addr, size, data, flags)
357 except WindowsError as e:
358 # if e.winerror == 0:
359 # Already loaded ?
360 # What if someone try to load another PE at the same BaseOfDll ?
361 # return BaseOfDll
362 raise
363 return self.get_module(load_addr)
364
365 def load_file(self, path, name=None, addr=0, size=0, data=None, flags=0):
366 """Load the module ``path`` at ``addr``

Callers 3

load_fileMethod · 0.95
loadMethod · 0.45
_internal_on_load_dllMethod · 0.45

Calls 2

get_moduleMethod · 0.95
existsMethod · 0.45

Tested by

no test coverage detected