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

Method execPE

pythonmemorymodule/__init__.py:525–563  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

523
524
525 def execPE(self):
526 codebase = self._codebaseaddr
527 entryaddr = self.pythonmemorymodule.contents.headers.contents.OptionalHeader.AddressOfEntryPoint
528
529 self.dbg('Checking for entry point.')
530 if entryaddr != 0:
531 entryaddr += codebase
532
533 if self.is_exe():
534 ExeEntry = ExeEntryProc(entryaddr)
535 if not bool(ExeEntry):
536 self.free_library()
537 raise WindowsError('exe has no entry point.\n')
538 try:
539 self.dbg("Calling exe entrypoint 0x%x", entryaddr)
540 success = ExeEntry(entryaddr)
541 except Exception as e:
542 print(e)
543
544 elif self.is_dll():
545 DllEntry = DllEntryProc(entryaddr)
546 if not bool(DllEntry):
547 self.free_library()
548 raise WindowsError('dll has no entry point.\n')
549
550 try:
551 self.dbg("Calling dll entrypoint 0x%x with DLL_PROCESS_ATTACH", entryaddr)
552 success = DllEntry(codebase, DLL_PROCESS_ATTACH, 0)
553 except Exception as e:
554 print(e)
555
556 if not bool(success):
557 if self.is_dll():
558 self.free_library()
559 raise WindowsError('dll could not be loaded.')
560 else:
561 self.free_exe()
562 raise WindowsError('exe could not be loaded')
563 self.pythonmemorymodule.contents.initialized = 1
564
565 def load_module(self):
566 if self.new_command != None and len(self.new_command) != 0:

Callers

nothing calls this directly

Calls 5

dbgMethod · 0.95
free_libraryMethod · 0.95
free_exeMethod · 0.95
is_exeMethod · 0.80
is_dllMethod · 0.80

Tested by

no test coverage detected