Reads the memory of the process. @see: L{read} @type lpBaseAddress: int @param lpBaseAddress: Memory address to begin reading. @type nSize: int @param nSize: Number of bytes to read. @rtype: str @return: Bytes read from the proc
(self, lpBaseAddress, nSize)
| 1955 | return self.poke(address, packed) |
| 1956 | |
| 1957 | def peek(self, lpBaseAddress, nSize): |
| 1958 | """ |
| 1959 | Reads the memory of the process. |
| 1960 | |
| 1961 | @see: L{read} |
| 1962 | |
| 1963 | @type lpBaseAddress: int |
| 1964 | @param lpBaseAddress: Memory address to begin reading. |
| 1965 | |
| 1966 | @type nSize: int |
| 1967 | @param nSize: Number of bytes to read. |
| 1968 | |
| 1969 | @rtype: str |
| 1970 | @return: Bytes read from the process memory. |
| 1971 | Returns an empty string on error. |
| 1972 | """ |
| 1973 | # XXX TODO |
| 1974 | # + Maybe change page permissions before trying to read? |
| 1975 | # + Maybe use mquery instead of get_memory_map? |
| 1976 | # (less syscalls if we break out of the loop earlier) |
| 1977 | data = "" |
| 1978 | if nSize > 0: |
| 1979 | try: |
| 1980 | hProcess = self.get_handle(win32.PROCESS_VM_READ | win32.PROCESS_QUERY_INFORMATION) |
| 1981 | for mbi in self.get_memory_map(lpBaseAddress, lpBaseAddress + nSize): |
| 1982 | if not mbi.is_readable(): |
| 1983 | nSize = mbi.BaseAddress - lpBaseAddress |
| 1984 | break |
| 1985 | if nSize > 0: |
| 1986 | data = win32.ReadProcessMemory(hProcess, lpBaseAddress, nSize) |
| 1987 | except WindowsError: |
| 1988 | e = sys.exc_info()[1] |
| 1989 | msg = "Error reading process %d address %s: %s" |
| 1990 | msg %= (self.get_pid(), HexDump.address(lpBaseAddress), e.strerror) |
| 1991 | warnings.warn(msg) |
| 1992 | return data |
| 1993 | |
| 1994 | def poke(self, lpBaseAddress, lpBuffer): |
| 1995 | """ |
no test coverage detected