Commits

Skin36  committed 2731c85

fix read base adress

  • Participants
  • Parent commits 9509375

Comments (0)

Files changed (2)

File dfinstancewinddows.py

 THE SOFTWARE.
 """
 
-
 from ctypes import *
 from ctypes.wintypes import *
 from win_structs import *
 from truncatingfilelogger import logger
 from utils import *
 
-
-UBYTE = c_ubyte
-ULONG_PTR = POINTER(ULONG)
-PULONG = ULONG_PTR
-PVOID = LPVOID
-LPCTSTR = LPTSTR = c_wchar_p
-LPBYTE = c_char_p
-SIZE_T = c_uint
-SIZE_T_p = POINTER(SIZE_T)
- 
 PROCESS_QUERY_INFORMATION=0x0400
 PROCESS_VM_READ = 0x0010
 PROCESS_VM_WRITE = 0x0020
 OpenProcess = ctypes.windll.kernel32.OpenProcess
 FindWindow = ctypes.windll.user32.FindWindowA
 GetWindowThreadProcessId=ctypes.windll.user32.GetWindowThreadProcessId
+#удалить
+CloseHandle = windll.kernel32.CloseHandle
 
 ReadProcessMemory = windll.kernel32.ReadProcessMemory
 ReadProcessMemory.argtypes = [HANDLE, LPCVOID, LPVOID, SIZE_T, SIZE_T_p]
         logger.warning("can't find running copy")
         return m_is_ok
     
-    logger.debug("found copy with HWND: %s", hwnd)
+    logger.debug("found copy with HWND: %s", hex(hwnd))
     
     pid = 0
     pid = c_int()
     windll.user32.GetWindowThreadProcessId(hwnd,byref(pid))
     pid=pid.value
-    print("pid=",pid)
     if pid==0:
         return m_is_ok
     logger.debug("PID of process is: %s", pid)
 #    m_hwnd = hwnd
 
     m_proc = OpenProcess(PROCESS_QUERY_INFORMATION| PROCESS_VM_READ| PROCESS_VM_OPERATION| PROCESS_VM_WRITE, False, m_pid)   
-    print("PROC HANDLE=", m_proc)
+    logger.debug("PROC HANDLE: %s", hex(m_proc)) 
     if m_proc==0:
        logger.error("Error opening process! %s", GetLastError())
     
         buttons = QtGui.QMessageBox.Ok)
 
     else:
-        bytes = ctypes.c_double()
-        peb=""
-        bytes=0
-        if ReadProcessMemory(m_proc, c_char_p(peb_addr), peb, sizeof(PEB()), bytes):
-            logger.debug("read %s bytes BASE ADDR is at: %s",bytes,hex(peb().ImageBaseAddress))
-            m_base_addr = peb().ImageBaseAddress
+        peb=PEB()
+        bytes=c_ulong(0)
+        if ReadProcessMemory(m_proc, peb_addr,byref(peb), sizeof(peb), byref(bytes)):
+            logger.debug("read %s bytes BASE ADDR is at: %s",bytes.value,hex(peb.ImageBaseAddress))
+            m_base_addr = peb.ImageBaseAddress
             m_is_ok = True
+            CloseHandle(m_proc)
         else:
-            QtGui.QMessageBox(QtGui.QMessageBox.Critical,
-            connection_error, "unable to read remote PEB!", GetLastError(),
-            buttons = QtGui.QMessageBox.Ok)
-            logger.critical("unable to read remote PEB!",GetLastError())
+#            QtGui.QMessageBox(QtGui.QMessageBox.Critical,
+#            connection_error, "unable to read remote PEB!", GetLastError(),
+#            buttons = QtGui.QMessageBox.Ok)
+#            logger.critical("unable to read remote PEB!",GetLastError())
             m_is_ok = False
 
     logger.debug("base address: %s", hex(m_base_addr))
-    logger.debug("memory correction: %s", hex(m_memory_correction))
+#    logger.debug("memory correction: %s", hex(m_memory_correction))
 
-    logger.debug("GetModuleFileNameEx returned: %s", exe_path)
-    logger.info("Dwarf fortress path: %s", m_df_dir.absolutePath())
+#    logger.debug("GetModuleFileNameEx returned: %s", exe_path)
+#    logger.info("Dwarf fortress path: %s", m_df_dir.absolutePath())
 
     m_is_ok = True
     return m_is_ok

File win_structs.py

 LPBYTE = c_char_p
 SIZE_T = c_uint
 SIZE_T_p = POINTER(SIZE_T)
+BOOL = c_bool
 
 NTSTATUS = DWORD