diff --git a/windows/debug.py b/windows/debug.py index 21e9e8d..068cb77 100644 --- a/windows/debug.py +++ b/windows/debug.py @@ -1,19 +1,18 @@ import os.path +from collections import defaultdict import windows -import windows.winproxy as winproxy - -from windows.winobject import WinProcess, WinThread -from windows.dbgprint import dbgprint - import windows.native_exec.simple_x86 as x86 import windows.native_exec.simple_x64 as x64 +from windows.winobject import WinProcess, WinThread +from windows.dbgprint import dbgprint +from windows import winproxy from windows.generated_def.winstructs import * from .generated_def import windef from windows.exception import VectoredException -from collections import defaultdict + STANDARD_BP = "BP" HARDWARE_EXEC_BP = "HXBP" @@ -484,6 +483,7 @@ class Breakpoint(object): """Called when breakpoint is hit""" pass + class ProxyBreakpoint(Breakpoint): def __init__(self, target, addr, type): self.target = target @@ -493,6 +493,7 @@ class ProxyBreakpoint(Breakpoint): def trigger(self, dbg, exception): return self.target(dbg, exception) + class HXBreakpoint(Breakpoint): """An hardware-execution breakpoint (type == ``HARDWARE_EXEC_BP``)""" type = HARDWARE_EXEC_BP @@ -501,9 +502,6 @@ class HXBreakpoint(Breakpoint): return isinstance(target, WinThread) - -import ctypes - class LocalDebugger(object): """A debugger interface around :func:`AddVectoredExceptionHandler`""" def __init__(self): @@ -513,7 +511,7 @@ class LocalDebugger(object): self._hxbp_breakpoint = defaultdict(dict) self.callback_vectored = VectoredException(self.callback) - windows.winproxy.AddVectoredExceptionHandler(0, self.callback_vectored) + winproxy.AddVectoredExceptionHandler(0, self.callback_vectored) self.setup_hxbp_callback_vectored = VectoredException(self.setup_hxbp_callback) self.hxbp_info = None self.code = windows.native_exec.create_function("\xcc\xc3", [PVOID]) diff --git a/windows/network.py b/windows/network.py index a300018..ab0c90d 100644 --- a/windows/network.py +++ b/windows/network.py @@ -1,9 +1,9 @@ import windows -from windows import winproxy import ctypes import socket import struct +from windows import winproxy from windows.generated_def.winstructs import * from windows.generated_def.windef import * @@ -76,7 +76,7 @@ class TCP4Connection(MIB_TCPROW_OWNER_PID): closing.dwLocalPort = self.dwLocalPort closing.dwRemoteAddr = self.dwRemoteAddr closing.dwRemotePort = self.dwRemotePort - return windows.winproxy.SetTcpEntry(ctypes.byref(closing)) + return winproxy.SetTcpEntry(ctypes.byref(closing)) def __repr__(self): if not self.established: @@ -175,11 +175,11 @@ class Network(object): def _get_tcp_ipv4_sockets(): size = ctypes.c_uint(0) try: - windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET) - except windows.winproxy.IphlpapiError: + winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET) + except winproxy.IphlpapiError: pass # Allow us to set size to the needed value buffer = (ctypes.c_char * size.value)() - windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET) + winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET) t = get_MIB_TCPTABLE_OWNER_PID_from_buffer(buffer) return list(t.table) @@ -187,11 +187,11 @@ class Network(object): def _get_tcp_ipv6_sockets(): size = ctypes.c_uint(0) try: - windows.winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET6) - except windows.winproxy.IphlpapiError: + winproxy.GetExtendedTcpTable(None, ctypes.byref(size), ulAf=AF_INET6) + except winproxy.IphlpapiError: pass # Allow us to set size to the needed value buffer = (ctypes.c_char * size.value)() - windows.winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET6) + winproxy.GetExtendedTcpTable(buffer, ctypes.byref(size), ulAf=AF_INET6) t = get_MIB_TCP6TABLE_OWNER_PID_from_buffer(buffer) return list(t.table)