code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
if data is None: return '' if arch is None: arch = win32.arch pointers = compat.keys(data) pointers.sort() result = '' if pointers: if arch == win32.ARCH_I386: spreg = 'esp' elif arch == win32.ARCH_A...
def dump_stack_peek(data, separator = ' ', width = 16, arch = None)
Dump data from pointers guessed within the given stack dump. @type data: str @param data: Dictionary mapping stack offsets to the data they point to. @type separator: str @param separator: Separator between the hexadecimal representation of each character. @type ...
4.204653
4.302927
0.977161
if not stack_trace: return '' table = Table() table.addRow('Frame', 'Origin', 'Module') for (fp, ra, mod) in stack_trace: fp_d = HexDump.address(fp, bits) ra_d = HexDump.address(ra, bits) table.addRow(fp_d, ra_d, mod) retur...
def dump_stack_trace(stack_trace, bits = None)
Dump a stack trace, as returned by L{Thread.get_stack_trace} with the C{bUseLabels} parameter set to C{False}. @type stack_trace: list( int, int, str ) @param stack_trace: Stack trace as a list of tuples of ( return address, frame pointer, module filename ) @type bits: in...
4.250593
3.646839
1.165556
if not stack_trace: return '' table = Table() table.addRow('Frame', 'Origin') for (fp, label) in stack_trace: table.addRow( HexDump.address(fp, bits), label ) return table.getOutput()
def dump_stack_trace_with_labels(stack_trace, bits = None)
Dump a stack trace, as returned by L{Thread.get_stack_trace_with_labels}. @type stack_trace: list( int, int, str ) @param stack_trace: Stack trace as a list of tuples of ( return address, frame pointer, module filename ) @type bits: int @param bits: (O...
6.188745
5.818748
1.063587
if not disassembly: return '' table = Table(sep = ' | ') for (addr, size, code, dump) in disassembly: if bLowercase: code = code.lower() if addr == pc: addr = ' * %s' % HexDump.address(addr, bits) else: ...
def dump_code(disassembly, pc = None, bLowercase = True, bits = None)
Dump a disassembly. Optionally mark where the program counter is. @type disassembly: list of tuple( int, int, str, str ) @param disassembly: Disassembly dump as returned by L{Process.disassemble} or L{Thread.disassemble_around_pc}. @type pc: int @param pc: (Optional) Prog...
3.822675
3.719471
1.027747
if bits is None: address_size = HexDump.address_size else: address_size = bits / 4 (addr, size, code, dump) = disassembly_line dump = dump.replace(' ', '') result = list() fmt = '' if bShowAddress: result.append( HexDum...
def dump_code_line(disassembly_line, bShowAddress = True, bShowDump = True, bLowercase = True, dwDumpWidth = None, ...
Dump a single line of code. To dump a block of code use L{dump_code}. @type disassembly_line: tuple( int, int, str, str ) @param disassembly_line: Single item of the list returned by L{Process.disassemble} or L{Thread.disassemble_around_pc}. @type bShowAddress: bool @para...
2.536261
2.375498
1.067675
if not memoryMap: return '' table = Table() if mappedFilenames: table.addRow("Address", "Size", "State", "Access", "Type", "File") else: table.addRow("Address", "Size", "State", "Access", "Type") # For each memory block in the map......
def dump_memory_map(memoryMap, mappedFilenames = None, bits = None)
Dump the memory map of a process. Optionally show the filenames for memory mapped files as well. @type memoryMap: list( L{win32.MemoryBasicInformation} ) @param memoryMap: Memory map returned by L{Process.get_memory_map}. @type mappedFilenames: dict( int S{->} str ) @param ma...
1.884431
1.826377
1.031787
if text.endswith('\n'): text = text[:-len('\n')] #text = text.replace('\n', '\n\t\t') # text CSV ltime = time.strftime("%X") msecs = (time.time() % 1) * 1000 return '[%s.%04d] %s' % (ltime, msecs, text)
def log_text(text)
Log lines of text, inserting a timestamp. @type text: str @param text: Text to log. @rtype: str @return: Log line.
4.961261
4.858914
1.021064
if not text: if event.get_event_code() == win32.EXCEPTION_DEBUG_EVENT: what = event.get_exception_description() if event.is_first_chance(): what = '%s (first chance)' % what else: what = '%s (second chan...
def log_event(cls, event, text = None)
Log lines of text associated with a debug event. @type event: L{Event} @param event: Event object. @type text: str @param text: (Optional) Text to log. If no text is provided the default is to show a description of the event itself. @rtype: str @return: ...
3.291538
3.471663
0.948116
from sys import stderr msg = "Warning, error writing log file %s: %s\n" msg = msg % (self.logfile, str(e)) stderr.write(DebugLog.log_text(msg)) self.logfile = None self.fd = None
def __logfile_error(self, e)
Shows an error message to standard error if the log file can't be written to. Used internally. @type e: Exception @param e: Exception raised when trying to write to the log file.
6.059569
6.198478
0.97759
if isinstance(text, compat.unicode): text = text.encode('cp1252') if self.verbose: print(text) if self.logfile: try: self.fd.writelines('%s\n' % text) except IOError: e = sys.exc_info()[1] se...
def __do_log(self, text)
Writes the given text verbatim into the log file (if any) and/or standard input (if the verbose flag is turned on). Used internally. @type text: str @param text: Text to print.
3.321849
3.519804
0.94376
self.__do_log( DebugLog.log_event(event, text) )
def log_event(self, event, text = None)
Log lines of text associated with a debug event. @type event: L{Event} @param event: Event object. @type text: str @param text: (Optional) Text to log. If no text is provided the default is to show a description of the event itself.
16.979406
22.440756
0.756633
try: params, method = xmlrpclib.loads(data) # generate response if dispatch_method is not None: response = dispatch_method(method, params) else: response = self._dispatch(method, params) # wrap response in a si...
def _marshaled_dispatch(self, data, dispatch_method=None)
Dispatches an XML-RPC method from marshalled (XML) data. XML-RPC methods are dispatched from the marshalled (XML) data using the _dispatch method and the result is returned as marshalled data. For backwards compatibility, a dispatch function can be provided as an argument (see comment i...
2.950706
2.850152
1.03528
methods = self.funcs.keys() if self.instance is not None: # Instance can implement _listMethod to return a list of # methods if hasattr(self.instance, '_listMethods'): methods = remove_duplicates( methods + self.instan...
def system_listMethods(self)
system.listMethods() => ['add', 'subtract', 'multiple'] Returns a list of the methods supported by the server.
4.588974
4.834699
0.949175
# Check that the path is legal if not self.is_rpc_path_valid(): self.report_404() return try: # Get arguments by reading body of request. # We read this in chunks to avoid straining # socket.read(); around the 10 or 15Mb mark...
def do_POST(self)
Handles the HTTP POST request. Attempts to interpret all HTTP POST requests as XML-RPC calls, which are forwarded to the server's _dispatch method for handling.
3.350973
3.228825
1.037831
if self.server.logRequests: BaseHTTPServer.BaseHTTPRequestHandler.log_request(self, code, size)
def log_request(self, code='-', size='-')
Selectively log an accepted request.
5.167363
4.647738
1.111802
response = self._marshaled_dispatch(request_text) sys.stdout.write('Content-Type: text/xml\n') sys.stdout.write('Content-Length: %d\n' % len(response)) sys.stdout.write('\n') sys.stdout.write(response)
def handle_xmlrpc(self, request_text)
Handle a single XML-RPC request
2.409623
2.317833
1.039602
code = 400 message, explain = \ BaseHTTPServer.BaseHTTPRequestHandler.responses[code] response = BaseHTTPServer.DEFAULT_ERROR_MESSAGE % { #@UndefinedVariable 'code' : code, 'message' : message, 'explain' : explain } ...
def handle_get(self)
Handle a single HTTP GET request. Default implementation indicates an error because XML-RPC uses the POST method.
3.224762
2.976531
1.083396
if request_text is None and \ os.environ.get('REQUEST_METHOD', None) == 'GET': self.handle_get() else: # POST data is normally available through stdin if request_text is None: request_text = sys.stdin.read() self.hand...
def handle_request(self, request_text=None)
Handle a single XML-RPC request passed through a CGI post method. If no XML data is given then it is read from stdin. The resulting XML-RPC response is printed to stdout along with the correct HTTP headers.
4.001236
3.393461
1.179102
''' Return True if running Python is suitable for GUI Event Integration and deeper IPython integration ''' # We require Python 2.6+ ... if sys.hexversion < 0x02060000: return False # Or Python 3.2+ if sys.hexversion >= 0x03000000 and sys.hexversion < 0x03020000: return False # No...
def versionok_for_gui()
Return True if running Python is suitable for GUI Event Integration and deeper IPython integration
4.423306
2.612899
1.692873
if result != ERROR_SUCCESS: raise ctypes.WinError(result) return result
def RaiseIfNotErrorSuccess(result, func = None, arguments = ())
Error checking for Win32 Registry API calls. The function is assumed to return a Win32 error code. If the code is not C{ERROR_SUCCESS} then a C{WindowsError} exception is raised.
4.962661
5.391725
0.920422
@functools.wraps(fn) def wrapper(*argv, **argd): t_ansi = GuessStringType.t_ansi t_unicode = GuessStringType.t_unicode v_types = [ type(item) for item in argv ] v_types.extend( [ type(value) for (key, value) in compat.iteritems(argd) ] ) if t_ansi in v_types: ...
def MakeANSIVersion(fn)
Decorator that generates an ANSI version of a Unicode (wide) only API call. @type fn: callable @param fn: Unicode (wide) version of the API function to call.
2.798136
2.809104
0.996095
".example - This is an example plugin for the command line debugger" print "This is an example command." print "%s.do(%r, %r):" % (__name__, self, arg) print " last event", self.lastEvent print " prefix", self.cmdprefix print " arguments", self.split_tokens(arg)
def do(self, arg)
.example - This is an example plugin for the command line debugger
11.9434
6.989578
1.708744
if process is None: self.dwProcessId = None self.__process = None else: self.__load_Process_class() if not isinstance(process, Process): msg = "Parent process must be a Process instance, " msg += "got %s instead"...
def set_process(self, process = None)
Manually set the parent Process object. Use with care! @type process: L{Process} @param process: (Optional) Process object. Use C{None} for no process.
3.988331
4.068824
0.980217
if self.dwProcessId is None: if self.__process is not None: # Infinite loop if self.__process is None self.dwProcessId = self.get_process().get_pid() else: try: # I wish this had been implemented before Vista......
def get_pid(self)
@rtype: int @return: Parent process global ID. @raise WindowsError: An error occured when calling a Win32 API function. @raise RuntimeError: The parent process ID can't be found.
6.375044
6.109527
1.04346
'Internally used by get_pid().' dwProcessId = None dwThreadId = self.get_tid() with win32.CreateToolhelp32Snapshot(win32.TH32CS_SNAPTHREAD) as hSnapshot: te = win32.Thread32First(hSnapshot) while te is not None: if te.th32ThreadID == dwThreadId: ...
def __get_pid_by_scanning(self)
Internally used by get_pid().
2.870977
2.588083
1.109306
hThread = win32.OpenThread(dwDesiredAccess, win32.FALSE, self.dwThreadId) # In case hThread was set to an actual handle value instead of a Handle # object. This shouldn't happen unless the user tinkered with it. if not hasattr(self.hThread, '__del__'): self.close_ha...
def open_handle(self, dwDesiredAccess = win32.THREAD_ALL_ACCESS)
Opens a new handle to the thread, closing the previous one. The new handle is stored in the L{hThread} property. @warn: Normally you should call L{get_handle} instead, since it's much "smarter" and tries to reuse handles and merge access rights. @type dwDesiredAccess: int ...
5.395032
6.386814
0.844714
try: if hasattr(self.hThread, 'close'): self.hThread.close() elif self.hThread not in (None, win32.INVALID_HANDLE_VALUE): win32.CloseHandle(self.hThread) finally: self.hThread = None
def close_handle(self)
Closes the handle to the thread. @note: Normally you don't need to call this method. All handles created by I{WinAppDbg} are automatically closed when the garbage collector claims them.
2.660498
2.610134
1.019296
if self.hThread in (None, win32.INVALID_HANDLE_VALUE): self.open_handle(dwDesiredAccess) else: dwAccess = self.hThread.dwAccess if (dwAccess | dwDesiredAccess) != dwAccess: self.open_handle(dwAccess | dwDesiredAccess) return self.hThre...
def get_handle(self, dwDesiredAccess = win32.THREAD_ALL_ACCESS)
Returns a handle to the thread with I{at least} the access rights requested. @note: If a handle was previously opened and has the required access rights, it's reused. If not, a new handle is opened with the combination of the old and new access rights. @type...
2.902881
3.186027
0.911129
hThread = self.get_handle(win32.THREAD_TERMINATE) win32.TerminateThread(hThread, dwExitCode) # Ugliest hack ever, won't work if many pieces of code are injected. # Seriously, what was I thinking? Lame! :( if self.pInjectedMemory is not None: try: ...
def kill(self, dwExitCode = 0)
Terminates the thread execution. @note: If the C{lpInjectedMemory} member contains a valid pointer, the memory is freed. @type dwExitCode: int @param dwExitCode: (Optional) Thread exit code.
8.280322
7.70827
1.074213
hThread = self.get_handle(win32.THREAD_SUSPEND_RESUME) if self.is_wow64(): # FIXME this will be horribly slow on XP 64 # since it'll try to resolve a missing API every time try: return win32.Wow64SuspendThread(hThread) except Attri...
def suspend(self)
Suspends the thread execution. @rtype: int @return: Suspend count. If zero, the thread is running.
5.528724
5.643402
0.979679
hThread = self.get_handle(win32.THREAD_SUSPEND_RESUME) return win32.ResumeThread(hThread)
def resume(self)
Resumes the thread execution. @rtype: int @return: Suspend count. If zero, the thread is running.
5.605873
4.793352
1.16951
# Some words on the "strange errors" that lead to the bSuspend # parameter. Peter Van Eeckhoutte and I were working on a fix # for some bugs he found in the 1.5 betas when we stumbled upon # what seemed to be a deadlock in the debug API that caused the # GetThreadContex...
def get_context(self, ContextFlags = None, bSuspend = False)
Retrieves the execution context (i.e. the registers values) for this thread. @type ContextFlags: int @param ContextFlags: Optional, specify which registers to retrieve. Defaults to C{win32.CONTEXT_ALL} which retrieves all registes for the current platform. @typ...
5.052615
5.020725
1.006352
# Get the thread handle. dwAccess = win32.THREAD_SET_CONTEXT if bSuspend: dwAccess = dwAccess | win32.THREAD_SUSPEND_RESUME hThread = self.get_handle(dwAccess) # Suspend the thread if requested. if bSuspend: self.suspend() # ...
def set_context(self, context, bSuspend = False)
Sets the values of the registers. @see: L{get_context} @type context: dict( str S{->} int ) @param context: Dictionary mapping register names to their values. @type bSuspend: bool @param bSuspend: C{True} to automatically suspend the thread before setting its co...
3.728173
3.937723
0.946784
context = self.get_context() context[register] = value self.set_context(context)
def set_register(self, register, value)
Sets the value of a specific register. @type register: str @param register: Register name. @rtype: int @return: Register value.
4.027259
5.632222
0.715039
try: wow64 = self.__wow64 except AttributeError: if (win32.bits == 32 and not win32.wow64): wow64 = False else: wow64 = self.get_process().is_wow64() self.__wow64 = wow64 return wow64
def is_wow64(self)
Determines if the thread is running under WOW64. @rtype: bool @return: C{True} if the thread is running under WOW64. That is, it belongs to a 32-bit application running in a 64-bit Windows. C{False} if the thread belongs to either a 32-bit application r...
3.14844
3.366977
0.935094
try: return self._teb_ptr except AttributeError: try: hThread = self.get_handle(win32.THREAD_QUERY_INFORMATION) tbi = win32.NtQueryInformationThread( hThread, win32.ThreadBasicInformation) ...
def get_teb_address(self)
Returns a remote pointer to the TEB. @rtype: int @return: Remote pointer to the L{TEB} structure. @raise WindowsError: An exception is raised on error.
5.511821
4.983355
1.106046
hThread = self.get_handle(win32.THREAD_QUERY_INFORMATION) selector = self.get_register(segment) ldt = win32.GetThreadSelectorEntry(hThread, selector) BaseLow = ldt.BaseLow BaseMid = ldt.HighWord.Bytes.BaseMid << 16 BaseHi = ldt.HighWord.Bytes.BaseHi <<...
def get_linear_address(self, segment, address)
Translates segment-relative addresses to linear addresses. Linear addresses can be used to access a process memory, calling L{Process.read} and L{Process.write}. @type segment: str @param segment: Segment register name. @type address: int @param address: Segment rela...
4.466239
3.894897
1.14669
if win32.arch != win32.ARCH_I386: raise NotImplementedError( "SEH chain parsing is only supported in 32-bit Windows.") process = self.get_process() address = self.get_linear_address( 'SegFs', 0 ) return process.read_pointer( address )
def get_seh_chain_pointer(self)
Get the pointer to the first structured exception handler block. @rtype: int @return: Remote pointer to the first block of the structured exception handlers linked list. If the list is empty, the returned value is C{0xFFFFFFFF}. @raise NotImplementedError: ...
6.718904
5.760048
1.166467
if win32.arch != win32.ARCH_I386: raise NotImplementedError( "SEH chain parsing is only supported in 32-bit Windows.") process = self.get_process() address = self.get_linear_address( 'SegFs', 0 ) process.write_pointer( address, value )
def set_seh_chain_pointer(self, value)
Change the pointer to the first structured exception handler block. @type value: int @param value: Value of the remote pointer to the first block of the structured exception handlers linked list. To disable SEH set the value C{0xFFFFFFFF}. @raise NotImplementedError: ...
6.537397
5.886761
1.110525
seh_chain = list() try: process = self.get_process() seh = self.get_seh_chain_pointer() while seh != 0xFFFFFFFF: seh_func = process.read_pointer( seh + 4 ) seh_chain.append( (seh, seh_func) ) seh = process.read_...
def get_seh_chain(self)
@rtype: list of tuple( int, int ) @return: List of structured exception handlers. Each SEH is represented as a tuple of two addresses: - Address of this SEH block - Address of the SEH callback function Do not confuse this with the contents of the SEH bloc...
2.91687
2.679642
1.08853
aProcess = self.get_process() arch = aProcess.get_arch() bits = aProcess.get_bits() if arch == win32.ARCH_I386: MachineType = win32.IMAGE_FILE_MACHINE_I386 elif arch == win32.ARCH_AMD64: MachineType = win32.IMAGE_FILE_MACHINE_AMD64 elif ...
def __get_stack_trace(self, depth = 16, bUseLabels = True, bMakePretty = True)
Tries to get a stack trace for the current function using the debug helper API (dbghelp.dll). @type depth: int @param depth: Maximum depth of stack trace. @type bUseLabels: bool @param bUseLabels: C{True} to use labels, C{False} to use addresses. @type bMakePretty: ...
2.652738
2.563813
1.034685
aProcess = self.get_process() st, sb = self.get_stack_range() # top, bottom fp = self.get_fp() trace = list() if aProcess.get_module_count() == 0: aProcess.scan_modules() bits = aProcess.get_bits() while depth > 0: if ...
def __get_stack_trace_manually(self, depth = 16, bUseLabels = True, bMakePretty = True)
Tries to get a stack trace for the current function. Only works for functions with standard prologue and epilogue. @type depth: int @param depth: Maximum depth of stack trace. @type bUseLabels: bool @param bUseLabels: C{True} to use labels, C{False} to use addresses. ...
3.68065
3.565056
1.032424
try: trace = self.__get_stack_trace(depth, False) except Exception: import traceback traceback.print_exc() trace = () if not trace: trace = self.__get_stack_trace_manually(depth, False) return trace
def get_stack_trace(self, depth = 16)
Tries to get a stack trace for the current function. Only works for functions with standard prologue and epilogue. @type depth: int @param depth: Maximum depth of stack trace. @rtype: tuple of tuple( int, int, str ) @return: Stack trace of the thread as a tuple of ...
3.93435
3.984827
0.987333
try: trace = self.__get_stack_trace(depth, True, bMakePretty) except Exception: trace = () if not trace: trace = self.__get_stack_trace_manually(depth, True, bMakePretty) return trace
def get_stack_trace_with_labels(self, depth = 16, bMakePretty = True)
Tries to get a stack trace for the current function. Only works for functions with standard prologue and epilogue. @type depth: int @param depth: Maximum depth of stack trace. @type bMakePretty: bool @param bMakePretty: C{True} for user readable labels, ...
3.404767
3.907794
0.871276
st, sb = self.get_stack_range() # top, bottom sp = self.get_sp() fp = self.get_fp() size = fp - sp if not st <= sp < sb: raise RuntimeError('Stack pointer lies outside the stack') if not st <= fp < sb: raise RuntimeErro...
def get_stack_frame_range(self)
Returns the starting and ending addresses of the stack frame. Only works for functions with standard prologue and epilogue. @rtype: tuple( int, int ) @return: Stack frame range. May not be accurate, depending on the compiler used. @raise RuntimeError: The stack frame is in...
4.623396
4.734306
0.976573
sp, fp = self.get_stack_frame_range() size = fp - sp if max_size and size > max_size: size = max_size return self.get_process().peek(sp, size)
def get_stack_frame(self, max_size = None)
Reads the contents of the current stack frame. Only works for functions with standard prologue and epilogue. @type max_size: int @param max_size: (Optional) Maximum amount of bytes to read. @rtype: str @return: Stack frame data. May not be accurate, depending on t...
5.144859
5.989875
0.858926
aProcess = self.get_process() return aProcess.read(self.get_sp() + offset, size)
def read_stack_data(self, size = 128, offset = 0)
Reads the contents of the top of the stack. @type size: int @param size: Number of bytes to read. @type offset: int @param offset: Offset from the stack pointer to begin reading. @rtype: str @return: Stack data. @raise WindowsError: Could not read the reque...
7.34113
9.304505
0.788987
aProcess = self.get_process() return aProcess.peek(self.get_sp() + offset, size)
def peek_stack_data(self, size = 128, offset = 0)
Tries to read the contents of the top of the stack. @type size: int @param size: Number of bytes to read. @type offset: int @param offset: Offset from the stack pointer to begin reading. @rtype: str @return: Stack data. Returned data may be less than the...
7.350995
10.784776
0.681608
if count > 0: stackData = self.read_stack_data(count * 4, offset) return struct.unpack('<'+('L'*count), stackData) return ()
def read_stack_dwords(self, count, offset = 0)
Reads DWORDs from the top of the stack. @type count: int @param count: Number of DWORDs to read. @type offset: int @param offset: Offset from the stack pointer to begin reading. @rtype: tuple( int... ) @return: Tuple of integers read from the stack. @raise ...
4.130292
5.859174
0.704927
stackData = self.peek_stack_data(count * 4, offset) if len(stackData) & 3: stackData = stackData[:-len(stackData) & 3] if not stackData: return () return struct.unpack('<'+('L'*count), stackData)
def peek_stack_dwords(self, count, offset = 0)
Tries to read DWORDs from the top of the stack. @type count: int @param count: Number of DWORDs to read. @type offset: int @param offset: Offset from the stack pointer to begin reading. @rtype: tuple( int... ) @return: Tuple of integers read from the stack. ...
3.22303
3.926586
0.820822
stackData = self.read_stack_data(count * 8, offset) return struct.unpack('<'+('Q'*count), stackData)
def read_stack_qwords(self, count, offset = 0)
Reads QWORDs from the top of the stack. @type count: int @param count: Number of QWORDs to read. @type offset: int @param offset: Offset from the stack pointer to begin reading. @rtype: tuple( int... ) @return: Tuple of integers read from the stack. @raise ...
4.34023
6.904527
0.628606
aProcess = self.get_process() stackData = aProcess.read_structure(self.get_sp() + offset, structure) return tuple([ stackData.__getattribute__(name) for (name, type) in stackData._fields_ ])
def read_stack_structure(self, structure, offset = 0)
Reads the given structure at the top of the stack. @type structure: ctypes.Structure @param structure: Structure of the data to read from the stack. @type offset: int @param offset: Offset from the stack pointer to begin reading. The stack pointer is the same returned by ...
8.167257
6.084177
1.342377
aProcess = self.get_process() stackData = aProcess.read_structure(self.get_fp() + offset, structure) return tuple([ stackData.__getattribute__(name) for (name, type) in stackData._fields_ ])
def read_stack_frame(self, structure, offset = 0)
Reads the stack frame of the thread. @type structure: ctypes.Structure @param structure: Structure of the stack frame. @type offset: int @param offset: Offset from the frame pointer to begin reading. The frame pointer is the same returned by the L{get_fp} method. ...
7.62001
5.931397
1.284691
return self.get_process().read(self.get_pc() + offset, size)
def read_code_bytes(self, size = 128, offset = 0)
Tries to read some bytes of the code currently being executed. @type size: int @param size: Number of bytes to read. @type offset: int @param offset: Offset from the program counter to begin reading. @rtype: str @return: Bytes read from the process memory. ...
7.761797
9.207753
0.842963
return self.get_process().peek(self.get_pc() + offset, size)
def peek_code_bytes(self, size = 128, offset = 0)
Tries to read some bytes of the code currently being executed. @type size: int @param size: Number of bytes to read. @type offset: int @param offset: Offset from the program counter to begin reading. @rtype: str @return: Bytes read from the process memory. ...
7.862465
9.058769
0.86794
peekable_registers = ( 'Eax', 'Ebx', 'Ecx', 'Edx', 'Esi', 'Edi', 'Ebp' ) if not context: context = self.get_context(win32.CONTEXT_CONTROL | \ win32.CONTEXT_INTEGER) aProcess = self.get_process() data ...
def peek_pointers_in_registers(self, peekSize = 16, context = None)
Tries to guess which values in the registers are valid pointers, and reads some data from them. @type peekSize: int @param peekSize: Number of bytes to read from each pointer found. @type context: dict( str S{->} int ) @param context: (Optional) Dictionary mapping...
3.264289
3.590959
0.90903
aProcess = self.get_process() return aProcess.peek_pointers_in_data(data, peekSize, peekStep)
def peek_pointers_in_data(self, data, peekSize = 16, peekStep = 1)
Tries to guess which values in the given data are valid pointers, and reads some data from them. @type data: str @param data: Binary data to find pointers in. @type peekSize: int @param peekSize: Number of bytes to read from each pointer found. @type peekStep: int ...
3.859207
5.681708
0.679234
aProcess = self.get_process() return aProcess.disassemble_string(lpAddress, code)
def disassemble_string(self, lpAddress, code)
Disassemble instructions from a block of binary code. @type lpAddress: int @param lpAddress: Memory address where the code was read from. @type code: str @param code: Binary code to disassemble. @rtype: list of tuple( long, int, str, str ) @return: List of tuples. E...
4.784173
8.384483
0.570598
aProcess = self.get_process() return aProcess.disassemble(lpAddress, dwSize)
def disassemble(self, lpAddress, dwSize)
Disassemble instructions from the address space of the process. @type lpAddress: int @param lpAddress: Memory address where to read the code from. @type dwSize: int @param dwSize: Size of binary code to disassemble. @rtype: list of tuple( long, int, str, str ) @retu...
5.048124
8.036033
0.628186
aProcess = self.get_process() return aProcess.disassemble_around(lpAddress, dwSize)
def disassemble_around(self, lpAddress, dwSize = 64)
Disassemble around the given address. @type lpAddress: int @param lpAddress: Memory address where to read the code from. @type dwSize: int @param dwSize: Delta offset. Code will be read from lpAddress - dwSize to lpAddress + dwSize. @rtype: list of tuple( long, ...
4.337473
7.236527
0.599386
aProcess = self.get_process() return aProcess.disassemble_around(self.get_pc(), dwSize)
def disassemble_around_pc(self, dwSize = 64)
Disassemble around the program counter of the given thread. @type dwSize: int @param dwSize: Delta offset. Code will be read from pc - dwSize to pc + dwSize. @rtype: list of tuple( long, int, str, str ) @return: List of tuples. Each tuple represents an assembly instructio...
4.8012
7.815172
0.614343
self.__initialize_snapshot() if dwThreadId not in self.__threadDict: msg = "Unknown thread ID: %d" % dwThreadId raise KeyError(msg) return self.__threadDict[dwThreadId]
def get_thread(self, dwThreadId)
@type dwThreadId: int @param dwThreadId: Global ID of the thread to look for. @rtype: L{Thread} @return: Thread object with the given global ID.
4.019858
4.291445
0.936714
found_threads = list() # Find threads with no name. if name is None: for aThread in self.iter_threads(): if aThread.get_name() is None: found_threads.append(aThread) # Find threads matching the given name exactly. elif bE...
def find_threads_by_name(self, name, bExactMatch = True)
Find threads by name, using different search methods. @type name: str, None @param name: Name to look for. Use C{None} to find nameless threads. @type bExactMatch: bool @param bExactMatch: C{True} if the name must be B{exactly} as given, C{False} if the name can be ...
1.916378
2.062699
0.929064
if bSuspended: dwCreationFlags = win32.CREATE_SUSPENDED else: dwCreationFlags = 0 hProcess = self.get_handle( win32.PROCESS_CREATE_THREAD | win32.PROCESS_QUERY_INFORMATION | win32.PROCESS...
def start_thread(self, lpStartAddress, lpParameter=0, bSuspended = False)
Remotely creates a new thread in the process. @type lpStartAddress: int @param lpStartAddress: Start address for the new thread. @type lpParameter: int @param lpParameter: Optional argument for the new thread. @type bSuspended: bool @param bSuspended: C{True} if the...
2.39987
2.740232
0.875791
# Ignore special process IDs. # PID 0: System Idle Process. Also has a special meaning to the # toolhelp APIs (current process). # PID 4: System Integrity Group. See this forum post for more info: # http://tinyurl.com/ycza8jo # (points to so...
def scan_threads(self)
Populates the snapshot with running threads.
4.423561
4.353222
1.016158
for tid in self.get_thread_ids(): aThread = self.get_thread(tid) if not aThread.is_alive(): self._del_thread(aThread)
def clear_dead_threads(self)
Remove Thread objects from the snapshot referring to threads no longer running.
3.607291
3.268841
1.103538
for aThread in compat.itervalues(self.__threadDict): aThread.clear() self.__threadDict = dict()
def clear_threads(self)
Clears the threads snapshot.
7.880703
7.04373
1.118825
for aThread in self.iter_threads(): try: aThread.close_handle() except Exception: try: e = sys.exc_info()[1] msg = "Cannot close thread handle %s, reason: %s" msg %= (aThread.hThread.valu...
def close_thread_handles(self)
Closes all open handles to threads in the snapshot.
3.383332
3.226575
1.048583
## if not isinstance(aThread, Thread): ## if hasattr(aThread, '__class__'): ## typename = aThread.__class__.__name__ ## else: ## typename = str(type(aThread)) ## msg = "Expected Thread, got %s instead" % typename ## raise TypeErro...
def _add_thread(self, aThread)
Private method to add a thread object to the snapshot. @type aThread: L{Thread} @param aThread: Thread object.
2.463362
2.634233
0.935134
try: aThread = self.__threadDict[dwThreadId] del self.__threadDict[dwThreadId] except KeyError: aThread = None msg = "Unknown thread ID %d" % dwThreadId warnings.warn(msg, RuntimeWarning) if aThread: aThread.clear()
def _del_thread(self, dwThreadId)
Private method to remove a thread object from the snapshot. @type dwThreadId: int @param dwThreadId: Global thread ID.
3.151567
3.305398
0.95346
dwThreadId = event.get_tid() hThread = event.get_thread_handle() ## if not self.has_thread(dwThreadId): # XXX this would trigger a scan if not self._has_thread_id(dwThreadId): aThread = Thread(dwThreadId, hThread, self) teb_ptr = event.get_teb() #...
def __add_created_thread(self, event)
Private method to automatically add new thread objects from debug events. @type event: L{Event} @param event: Event object.
4.937882
5.347756
0.923356
dwThreadId = event.get_tid() ## if self.has_thread(dwThreadId): # XXX this would trigger a scan if self._has_thread_id(dwThreadId): self._del_thread(dwThreadId) return True
def _notify_exit_thread(self, event)
Notify the termination of a thread. This is done automatically by the L{Debug} class, you shouldn't need to call it yourself. @type event: L{ExitThreadEvent} @param event: Exit thread event. @rtype: bool @return: C{True} to call the user-defined handle, C{False} othe...
7.512145
9.155831
0.820477
orig_value = getattr(original_code, attribute_name) insert_value = getattr(insert_code, attribute_name) orig_names_len = len(orig_value) code_with_new_values = list(insert_code_list) offset = 0 while offset < len(code_with_new_values): op = code_with_new_values[offset] if op...
def _add_attr_values_from_insert_to_original(original_code, insert_code, insert_code_list, attribute_name, op_list)
This function appends values of the attribute `attribute_name` of the inserted code to the original values, and changes indexes inside inserted code. If some bytecode instruction in the inserted code used to call argument number i, after modification it calls argument n + i, where n - length of the values in ...
2.265712
2.121963
1.067744
# There's a nice overview of co_lnotab in # https://github.com/python/cpython/blob/3.6/Objects/lnotab_notes.txt new_list = list(code_to_modify.co_lnotab) if not new_list: # Could happen on a lambda (in this case, a breakpoint in the lambda should fallback to # tracing). ret...
def _modify_new_lines(code_to_modify, offset, code_to_insert)
Update new lines: the bytecode inserted should be the last instruction of the previous line. :return: bytes sequence of code with updated lines offsets
4.993622
4.962952
1.00618
extended_arg = 0 for i in range(0, len(code), 2): op = code[i] if op >= HAVE_ARGUMENT: if not extended_arg: # in case if we added EXTENDED_ARG, but haven't inserted it to the source code yet. for code_index in range(current_index, len(inserted_cod...
def _unpack_opargs(code, inserted_code_list, current_index)
Modified version of `_unpack_opargs` function from module `dis`. We have to use it, because sometimes code can be in an inconsistent state: if EXTENDED_ARG operator was introduced into the code, but it hasn't been inserted into `code_list` yet. In this case we can't use standard `_unpack_opargs` and we shou...
3.262449
2.881644
1.132149
inserted_code = list() # the list with all inserted pieces of code inserted_code.append((breakpoint_offset, breakpoint_code_list)) code_list = list(code_obj) j = 0 while j < len(inserted_code): current_offset, current_code_list = inserted_code[j] offsets_for_modification = ...
def _update_label_offsets(code_obj, breakpoint_offset, breakpoint_code_list)
Update labels for the relative and absolute jump targets :param code_obj: code to modify :param breakpoint_offset: offset for the inserted code :param breakpoint_code_list: size of the inserted code :return: bytes sequence with modified labels; list of tuples (resulting offset, list of code instructions...
3.251684
3.141782
1.034981
extended_arg_list = [] if jump_arg > MAX_BYTE: extended_arg_list += [EXTENDED_ARG, jump_arg >> 8] jump_arg = jump_arg & MAX_BYTE # remove 'RETURN_VALUE' instruction and add 'POP_JUMP_IF_TRUE' with (if needed) 'EXTENDED_ARG' return list(code_to_insert.co_code[:-RETURN_VALUE_SIZE]) +...
def add_jump_instruction(jump_arg, code_to_insert)
Note: although it's adding a POP_JUMP_IF_TRUE, it's actually no longer used now (we could only return the return and possibly the load of the 'None' before the return -- not done yet because it needs work to fix all related tests).
4.485371
4.062
1.104227
''' :param all_lines_with_breaks: tuple(int) a tuple with all the breaks in the given code object (this method is expected to be called multiple times with different lines to add multiple breakpoints, so, the variable `before_line` should have the current breakpoint an the all_lines_with...
def insert_code(code_to_modify, code_to_insert, before_line, all_lines_with_breaks=())
:param all_lines_with_breaks: tuple(int) a tuple with all the breaks in the given code object (this method is expected to be called multiple times with different lines to add multiple breakpoints, so, the variable `before_line` should have the current breakpoint an the all_lines_with_breaks ...
5.164474
3.141388
1.64401
linestarts = dict(dis.findlinestarts(code_to_modify)) if not linestarts: return False, code_to_modify if code_to_modify.co_name == '<module>': # There's a peculiarity here: if a breakpoint is added in the first line of a module, we # can't replace the code because we require a ...
def _insert_code(code_to_modify, code_to_insert, before_line)
Insert piece of code `code_to_insert` to `code_to_modify` right inside the line `before_line` before the instruction on this line by modifying original bytecode :param code_to_modify: Code to modify :param code_to_insert: Code to insert :param before_line: Number of line for code insertion :return:...
2.577377
2.548188
1.011455
"Internally used by get_pid() and get_tid()." self.dwThreadId, self.dwProcessId = \ win32.GetWindowThreadProcessId(self.get_handle())
def __get_pid_and_tid(self)
Internally used by get_pid() and get_tid().
7.303176
5.645186
1.2937
if thread is None: self.__thread = None else: self.__load_Thread_class() if not isinstance(thread, Thread): msg = "Parent thread must be a Thread instance, " msg += "got %s instead" % type(thread) raise TypeErr...
def set_thread(self, thread = None)
Manually set the thread process. Use with care! @type thread: L{Thread} @param thread: (Optional) Thread object. Use C{None} to autodetect.
4.356902
4.670676
0.932821
window = Window(hWnd) if window.get_pid() == self.get_pid(): window.set_process( self.get_process() ) if window.get_tid() == self.get_tid(): window.set_thread( self.get_thread() ) return window
def __get_window(self, hWnd)
User internally to get another Window from this one. It'll try to copy the parent Process and Thread references if possible.
2.675252
2.004148
1.334858
cr = win32.GetClientRect( self.get_handle() ) cr.left, cr.top = self.client_to_screen(cr.left, cr.top) cr.right, cr.bottom = self.client_to_screen(cr.right, cr.bottom) return cr
def get_client_rect(self)
Get the window's client area coordinates in the desktop. @rtype: L{win32.Rect} @return: Rectangle occupied by the window's client area in the desktop. @raise WindowsError: An error occured while processing this request.
2.827168
2.438085
1.159585
return tuple( win32.ClientToScreen( self.get_handle(), (x, y) ) )
def client_to_screen(self, x, y)
Translates window client coordinates to screen coordinates. @note: This is a simplified interface to some of the functionality of the L{win32.Point} class. @see: {win32.Point.client_to_screen} @type x: int @param x: Horizontal coordinate. @type y: int @pa...
9.703301
8.660357
1.120427
return tuple( win32.ScreenToClient( self.get_handle(), (x, y) ) )
def screen_to_client(self, x, y)
Translates window screen coordinates to client coordinates. @note: This is a simplified interface to some of the functionality of the L{win32.Point} class. @see: {win32.Point.screen_to_client} @type x: int @param x: Horizontal coordinate. @type y: int @pa...
8.756138
8.104836
1.08036
try: if bAllowTransparency: hWnd = win32.RealChildWindowFromPoint( self.get_handle(), (x, y) ) else: hWnd = win32.ChildWindowFromPoint( self.get_handle(), (x, y) ) if hWnd: return self.__get_window(hWnd) except ...
def get_child_at(self, x, y, bAllowTransparency = True)
Get the child window located at the given coordinates. If no such window exists an exception is raised. @see: L{get_children} @type x: int @param x: Horizontal coordinate. @type y: int @param y: Vertical coordinate. @type bAllowTransparency: bool @p...
3.209399
3.409477
0.941317
if bAsync: win32.ShowWindowAsync( self.get_handle(), win32.SW_SHOW ) else: win32.ShowWindow( self.get_handle(), win32.SW_SHOW )
def show(self, bAsync = True)
Make the window visible. @see: L{hide} @type bAsync: bool @param bAsync: Perform the request asynchronously. @raise WindowsError: An error occured while processing this request.
2.339086
2.630045
0.889371
if bAsync: win32.ShowWindowAsync( self.get_handle(), win32.SW_HIDE ) else: win32.ShowWindow( self.get_handle(), win32.SW_HIDE )
def hide(self, bAsync = True)
Make the window invisible. @see: L{show} @type bAsync: bool @param bAsync: Perform the request asynchronously. @raise WindowsError: An error occured while processing this request.
2.425297
2.63748
0.919551
if bAsync: win32.ShowWindowAsync( self.get_handle(), win32.SW_MAXIMIZE ) else: win32.ShowWindow( self.get_handle(), win32.SW_MAXIMIZE )
def maximize(self, bAsync = True)
Maximize the window. @see: L{minimize}, L{restore} @type bAsync: bool @param bAsync: Perform the request asynchronously. @raise WindowsError: An error occured while processing this request.
2.386044
2.60469
0.916057
if bAsync: win32.ShowWindowAsync( self.get_handle(), win32.SW_MINIMIZE ) else: win32.ShowWindow( self.get_handle(), win32.SW_MINIMIZE )
def minimize(self, bAsync = True)
Minimize the window. @see: L{maximize}, L{restore} @type bAsync: bool @param bAsync: Perform the request asynchronously. @raise WindowsError: An error occured while processing this request.
2.396189
2.581246
0.928307
if bAsync: win32.ShowWindowAsync( self.get_handle(), win32.SW_RESTORE ) else: win32.ShowWindow( self.get_handle(), win32.SW_RESTORE )
def restore(self, bAsync = True)
Unmaximize and unminimize the window. @see: L{maximize}, L{minimize} @type bAsync: bool @param bAsync: Perform the request asynchronously. @raise WindowsError: An error occured while processing this request.
2.565284
2.68351
0.955943
if None in (x, y, width, height): rect = self.get_screen_rect() if x is None: x = rect.left if y is None: y = rect.top if width is None: width = rect.right - rect.left if height is None: ...
def move(self, x = None, y = None, width = None, height = None, bRepaint = True)
Moves and/or resizes the window. @note: This is request is performed syncronously. @type x: int @param x: (Optional) New horizontal coordinate. @type y: int @param y: (Optional) New vertical coordinate. @type width: int @param width: (Optional) Desired wind...
1.88374
2.27694
0.827312
if dwTimeout is None: return win32.SendMessage(self.get_handle(), uMsg, wParam, lParam) return win32.SendMessageTimeout( self.get_handle(), uMsg, wParam, lParam, win32.SMTO_ABORTIFHUNG | win32.SMTO_ERRORONEXIT, dwTimeout)
def send(self, uMsg, wParam = None, lParam = None, dwTimeout = None)
Send a low-level window message syncronically. @type uMsg: int @param uMsg: Message code. @param wParam: The type and meaning of this parameter depends on the message. @param lParam: The type and meaning of this parameter depends on the message. @para...
2.859851
2.903006
0.985134
win32.PostMessage(self.get_handle(), uMsg, wParam, lParam)
def post(self, uMsg, wParam = None, lParam = None)
Post a low-level window message asyncronically. @type uMsg: int @param uMsg: Message code. @param wParam: The type and meaning of this parameter depends on the message. @param lParam: The type and meaning of this parameter depends on the message. @rai...
4.722255
6.978583
0.676678
''' Processes a debug adapter protocol json command. ''' DEBUG = False try: request = self.from_json(json_contents, update_ids_from_dap=True) except KeyError as e: request = self.from_json(json_contents, update_ids_from_dap=False) err...
def process_net_command_json(self, py_db, json_contents)
Processes a debug adapter protocol json command.
4.193034
3.937702
1.064843
''' :param ConfigurationDoneRequest request: ''' self.api.run(py_db) configuration_done_response = pydevd_base_schema.build_response(request) return NetCommand(CMD_RETURN, 0, configuration_done_response, is_json=True)
def on_configurationdone_request(self, py_db, request)
:param ConfigurationDoneRequest request:
8.812529
8.015187
1.099479
''' :param ThreadsRequest request: ''' return self.api.list_threads(py_db, request.seq)
def on_threads_request(self, py_db, request)
:param ThreadsRequest request:
10.643572
7.895952
1.347978
''' :param CompletionsRequest request: ''' arguments = request.arguments # : :type arguments: CompletionsArguments seq = request.seq text = arguments.text frame_id = arguments.frameId thread_id = py_db.suspended_frames_manager.get_thread_id_for_variable_r...
def on_completions_request(self, py_db, request)
:param CompletionsRequest request:
5.167008
5.089781
1.015173
''' :param AttachRequest request: ''' self.api.set_enable_thread_notifications(py_db, True) self._set_debug_options(py_db, request.arguments.kwargs) response = pydevd_base_schema.build_response(request) return NetCommand(CMD_RETURN, 0, response, is_json=True)
def on_attach_request(self, py_db, request)
:param AttachRequest request:
10.031368
8.969597
1.118374
''' :param PauseRequest request: ''' arguments = request.arguments # : :type arguments: PauseArguments thread_id = arguments.threadId self.api.request_suspend_thread(py_db, thread_id=thread_id) response = pydevd_base_schema.build_response(request) retur...
def on_pause_request(self, py_db, request)
:param PauseRequest request:
7.862397
6.98273
1.125977