Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions winappdbg/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@
from .event import Event, EventDispatcher, EventFactory
from .interactive import ConsoleDebugger

from time import time

import warnings
##import traceback

# Cygwin compatibility.
try:
WindowsError
except NameError:
from winappdbg.win32 import WindowsError
from win32 import WindowsError

#==============================================================================

Expand Down Expand Up @@ -505,7 +507,8 @@ def execl(self, lpCmdLine, **kwargs):
# Warn when mixing 32 and 64 bits.
# This also allows the user to stop attaching altogether,
# depending on how the warnings are configured.
if System.bits != aProcess.get_bits():
BITS_WARNING_FLAG = False
if System.bits != aProcess.get_bits() and BITS_WARNING_FLAG:
msg = "Mixture of 32 and 64 bits is considered experimental." \
" Use at your own risk!"
warnings.warn(msg, MixedBitsWarning)
Expand Down Expand Up @@ -1063,7 +1066,7 @@ def stop(self, bIgnoreExceptions = True):
# Close all Win32 handles the Python garbage collector failed to close.
self.force_garbage_collection(bIgnoreExceptions)

def next(self):
def next(self,time_limit_in_seconds = 0):
"""
Handles the next debug event.

Expand All @@ -1079,16 +1082,21 @@ def next(self):
event handler raises an exception nobody catches.
"""
try:
event = self.wait() # NOQA
try:
event = self.wait(time_limit_in_seconds * 1000) # NOQA
except WindowsError:
if time_limit_in_seconds == 0:
pass
else:
raise
except Exception:
self.stop()
raise
try:
self.dispatch()
finally:
self.cont()

def loop(self):
def loop(self,time_limit_in_seconds = 0):
"""
Simple debugging loop.

Expand Down Expand Up @@ -1118,8 +1126,9 @@ def loop(self):
continued before returning. This may happen, for example, if the
event handler raises an exception nobody catches.
"""

while self:
self.next()
self.next(time_limit_in_seconds)

def get_debugee_count(self):
"""
Expand Down
8 changes: 4 additions & 4 deletions winappdbg/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def __init__(self, arch = None):
try:
self.__bug = not isinstance(
list(capstone.cs_disasm_quick(
capstone.CS_ARCH_X86, capstone.CS_MODE_32, "\x90", 1
capstone.CS_ARCH_X86, capstone.CS_MODE_32, b"\x90", 1
))[0],
capstone.capstone.CsInsn
)
Expand Down Expand Up @@ -609,10 +609,10 @@ def decode(self, address, code):
mnemonic = "dcb "
bytes = []
for b in skipped:
if b.isalpha():
bytes.append("'%s'" % b)
if chr(b).isalpha():
bytes.append("'%s'" % chr(b))
else:
bytes.append("0x%x" % ord(b))
bytes.append("0x%x" % b)
op_str = ", ".join(bytes)
disasm = mnemonic + op_str

Expand Down
6 changes: 3 additions & 3 deletions winappdbg/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
try:
WindowsError
except NameError:
from winappdbg.win32 import WindowsError
from win32 import WindowsError

#==============================================================================

Expand Down Expand Up @@ -604,7 +604,7 @@ def get_symbol_at_address(self, address):
result = None
symbols = self.get_symbols()
symbols.sort()
for SymbolAddress, SymbolName, SymbolSize in symbols:
for SymbolName, SymbolAddress, SymbolSize in symbols:
if SymbolAddress > address:
break
result = (SymbolName, SymbolAddress, SymbolSize)
Expand Down Expand Up @@ -1141,7 +1141,7 @@ def parse_label(module = None, function = None, offset = None):
# Validate the parameters.
if module is not None and ('!' in module or '+' in module):
raise ValueError("Invalid module name: %s" % module)
if function is not None and ('!' in function or '+' in function):
if function is not None and ('!' in str(function) or '+' in str(function)):
raise ValueError("Invalid function name: %s" % function)

# Parse the label.
Expand Down
11 changes: 8 additions & 3 deletions winappdbg/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
try:
WindowsError
except NameError:
from winappdbg.win32 import WindowsError, getenv # NOQA
from win32 import WindowsError, getenv # NOQA

# delayed import
System = None
Expand Down Expand Up @@ -1161,7 +1161,10 @@ def get_environment_variables(self):
# renders garbage.

# Read the environment block contents.
data = self.peek( *self.get_environment_block() )

eb_address,eb_size = self.get_environment_block()
data = self.peek(eb_address,eb_size)


# Put them into a Unicode buffer.
tmp = ctypes.create_string_buffer(data)
Expand Down Expand Up @@ -1261,6 +1264,7 @@ def get_environment_data(self, fUnicode = None):
block = [ key + u'=' + value for (key, value) \
in self.get_environment_variables() ]


# Convert the data to ANSI if requested.
if fUnicode is None:
gst = win32.GuessStringType
Expand Down Expand Up @@ -1967,8 +1971,9 @@ def read_string(self, lpBaseAddress, nChars, fUnicode = False):
def __peek_c_type(self, address, format, c_type):
size = ctypes.sizeof(c_type)
packed = self.peek(address, size)

if len(packed) < size:
packed = '\0' * (size - len(packed)) + packed
packed = b'\0' * (size - len(packed)) + packed
elif len(packed) > size:
packed = packed[:size]
return struct.unpack(format, packed)[0]
Expand Down
9 changes: 3 additions & 6 deletions winappdbg/textio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,8 +1357,7 @@ def dump_registers_peek(registers, data, separator = ' ', width = 16):
"""
if None in (registers, data):
return ''
names = data.keys()
names.sort()
names = sorted(data)
result = ''
for reg_name in names:
tag = reg_name.lower()
Expand Down Expand Up @@ -1390,8 +1389,7 @@ def dump_data_peek(data, base = 0,
"""
if data is None:
return ''
pointers = data.keys()
pointers.sort()
pointers = sorted(data)
result = ''
for offset in pointers:
dumped = HexDump.hexline(data[offset], separator, width)
Expand Down Expand Up @@ -1427,8 +1425,7 @@ def dump_stack_peek(data, separator = ' ', width = 16, arch = None):
return ''
if arch is None:
arch = win32.arch
pointers = data.keys()
pointers.sort()
pointers = sorted(data)
result = ''
if pointers:
if arch == win32.ARCH_I386:
Expand Down
3 changes: 2 additions & 1 deletion winappdbg/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
try:
WindowsError
except NameError:
from winappdbg.win32 import WindowsError
from win32 import WindowsError

# delayed imports
Process = None
Expand Down Expand Up @@ -1363,6 +1363,7 @@ def get_stack_frame(self, max_size = None):
or reading data from the process memory.
"""
sp, fp = self.get_stack_frame_range()
print(sp,fp)
size = fp - sp
if max_size and size > max_size:
size = max_size
Expand Down
4 changes: 2 additions & 2 deletions winappdbg/win32/kernel32.py
Original file line number Diff line number Diff line change
Expand Up @@ -3707,8 +3707,8 @@ def ReadProcessMemory(hProcess, lpBaseAddress, nSize):
lpBuffer = ctypes.create_string_buffer(b'', nSize)
lpNumberOfBytesRead = SIZE_T(0)
success = _ReadProcessMemory(hProcess, lpBaseAddress, lpBuffer, nSize, byref(lpNumberOfBytesRead))
if not success and GetLastError() != ERROR_PARTIAL_COPY:
raise ctypes.WinError()
#if not success and GetLastError() != ERROR_PARTIAL_COPY:
# raise ctypes.WinError()
return (lpBuffer.raw)[:lpNumberOfBytesRead.value]

# BOOL WINAPI WriteProcessMemory(
Expand Down