(self)
| 563 | self.pythonmemorymodule.contents.initialized = 1 |
| 564 | |
| 565 | def load_module(self): |
| 566 | if self.new_command != None and len(self.new_command) != 0: |
| 567 | passed_args=True |
| 568 | self.cmdline_check() |
| 569 | else: |
| 570 | passed_args=False |
| 571 | |
| 572 | if not self.is_exe() and not self.is_dll(): |
| 573 | raise WindowsError('The specified module does not appear to be an exe nor a dll.') |
| 574 | if self.PE_TYPE == pe.OPTIONAL_HEADER_MAGIC_PE and isx64: |
| 575 | raise WindowsError('The exe you attempted to load appears to be an 32-bit exe, but you are using a 64-bit version of Python.') |
| 576 | elif self.PE_TYPE == pe.OPTIONAL_HEADER_MAGIC_PE_PLUS and not isx64: |
| 577 | raise WindowsError('The exe you attempted to load appears to be an 64-bit exe, but you are using a 32-bit version of Python.') |
| 578 | |
| 579 | self._codebaseaddr = VirtualAlloc( |
| 580 | self.OPTIONAL_HEADER.ImageBase, # To test relocations, add some values here i.e. +int(0x030000000) |
| 581 | self.OPTIONAL_HEADER.SizeOfImage, |
| 582 | MEM_RESERVE, |
| 583 | PAGE_READWRITE |
| 584 | ) |
| 585 | |
| 586 | if not bool(self._codebaseaddr): |
| 587 | self._codebaseaddr = VirtualAlloc( |
| 588 | NULL, |
| 589 | self.OPTIONAL_HEADER.SizeOfImage, |
| 590 | MEM_RESERVE, |
| 591 | PAGE_READWRITE |
| 592 | ) |
| 593 | if not bool(self._codebaseaddr): |
| 594 | raise WindowsError('Cannot reserve memory') |
| 595 | |
| 596 | codebase = self._codebaseaddr |
| 597 | self.dbg('Reserved %d bytes for dll at address: 0x%x', self.OPTIONAL_HEADER.SizeOfImage, codebase) |
| 598 | self.pythonmemorymodule = cast(HeapAlloc(GetProcessHeap(), 0, sizeof(MEMORYMODULE)), PMEMORYMODULE) |
| 599 | self.pythonmemorymodule.contents.codeBase = codebase |
| 600 | self.pythonmemorymodule.contents.numModules = 0 |
| 601 | self.pythonmemorymodule.contents.modules = cast(NULL, PHMODULE) |
| 602 | self.pythonmemorymodule.contents.initialized = 0 |
| 603 | |
| 604 | # Committing memory. |
| 605 | VirtualAlloc( |
| 606 | codebase, |
| 607 | self.OPTIONAL_HEADER.SizeOfImage, |
| 608 | MEM_COMMIT, |
| 609 | PAGE_READWRITE |
| 610 | ) |
| 611 | self._headersaddr = VirtualAlloc( |
| 612 | codebase, |
| 613 | self.OPTIONAL_HEADER.SizeOfHeaders, |
| 614 | MEM_COMMIT, |
| 615 | PAGE_READWRITE |
| 616 | ) |
| 617 | if not bool(self._headersaddr): |
| 618 | raise WindowsError('Could not commit memory for PE Headers!') |
| 619 | |
| 620 | szheaders = self.DOS_HEADER.e_lfanew + self.OPTIONAL_HEADER.SizeOfHeaders |
| 621 | tmpheaders = create_unsigned_buffer(szheaders, self.__data__[:szheaders]) |
| 622 | if not memmove(self._headersaddr, cast(tmpheaders, c_void_p), szheaders): |
no test coverage detected