rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
szString = unicode(szString, 'U16', 'ignore') szString = ctypes.create_unicode_buffer(szString).value | szString = unicode(szString, 'U16', 'replace') szString = szString[ : szString.find(u'\0') ] | def peek_string(self, lpBaseAddress, fUnicode = False, dwMaxSize = 0x1000): """ Tries to read an ASCII or Unicode string from the address space of the process. |
szString = ctypes.create_string_buffer(szString).value | szString = szString[ : szString.find('\0') ] | def peek_string(self, lpBaseAddress, fUnicode = False, dwMaxSize = 0x1000): """ Tries to read an ASCII or Unicode string from the address space of the process. |
for ((pid, address), bp) in self.__pageBP.itervalues(): | for ((pid, address), bp) in self.__pageBP.iteritems(): | def get_all_page_breakpoints(self): """ @rtype: list of tuple( int, L{PageBreakpoint} ) @return: All page breakpoints as a list of tuples (pid, bp). """ |
return [ bp for ((pid, address), bp) in self.__codeBP.itervalues() \ | return [ bp for ((pid, address), bp) in self.__codeBP.iteritems() \ | def get_process_code_breakpoints(self, dwProcessId): """ @type dwProcessId: int @param dwProcessId: Process global ID. |
return [ bp for ((pid, address), bp) in self.__pageBP.itervalues() \ | return [ bp for ((pid, address), bp) in self.__pageBP.iteritems() \ | def get_process_page_breakpoints(self, dwProcessId): """ @type dwProcessId: int @param dwProcessId: Process global ID. |
elif win32.CONTEXT.arch == 'i386': | elif win32.CONTEXT.arch == 'amd64': | def dump_stack_peek(data, separator = ' ', width = 16): """ Dump data from pointers guessed within the given stack dump. |
if callable(HandlerRoutine): HandlerRoutine = PHANDLER_ROUTINE(HandlerRoutine) elif not HandlerRoutine: HandlerRoutine = None else: raise ValueError, "Bad argument for HandlerRoutine: %r" % HandlerRoutine | def SetConsoleCtrlHandler(HandlerRoutine = None, Add = True): _SetConsoleCtrlHandler = windll.kernel32.SetConsoleCtrlHandler _SetConsoleCtrlHandler.argtypes = [PHANDLER_ROUTINE, BOOL] _SetConsoleCtrlHandler.restype = bool _SetConsoleCtrlHandler.errcheck = RaiseIfZero if callable(HandlerRoutine): HandlerRoutine = PHAN... | |
def SetDllDirectoryA(lpPathName): | def SetDllDirectoryA(lpPathName = None): | def SetDllDirectoryA(lpPathName): _SetDllDirectoryA = windll.kernel32.SetDllDirectoryA _SetDllDirectoryA.argytpes = [LPSTR] _SetDllDirectoryA.restype = bool _SetDllDirectoryA.errcheck = RaiseIfZero _SetDllDirectoryA(lpPathName) |
elif type(lpProcName) == type("") | elif type(lpProcName) == type(""): | def GetProcAddress(hModule, lpProcName): _GetProcAddress = windll.kernel32.GetProcAddress _GetProcAddress.argtypes = [HMODULE, LPVOID] _GetProcAddress.restype = LPVOID if type(lpProcName) in (type(0), type(0L)): lpProcName = LPVOID(lpProcName) if lpProcName.value & (~0xFFFF): raise ValueError, 'Ordinal number too lar... |
_LoadLibraryA.argtypes = LPSTR | _LoadLibraryA.argtypes = [LPSTR] | def LoadLibraryA(pszLibrary): _LoadLibraryA = windll.kernel32.LoadLibraryA _LoadLibraryA.argtypes = LPSTR _LoadLibraryA.restype = HMODULE hModule = _LoadLibraryA(pszLibrary) if hModule == NULL: raise ctypes.WinError() return hModule |
_LoadLibraryW.argtypes = LPWSTR | _LoadLibraryW.argtypes = [LPWSTR] | def LoadLibraryW(pszLibrary): _LoadLibraryW = windll.kernel32.LoadLibraryW _LoadLibraryW.argtypes = LPWSTR _LoadLibraryW.restype = HMODULE hModule = _LoadLibraryW(pszLibrary) if hModule == NULL: raise ctypes.WinError() return hModule |
_LoadLibraryExA.argtypes = LPSTR, HANDLE, DWORD | _LoadLibraryExA.argtypes = [LPSTR, HANDLE, DWORD] | def LoadLibraryExA(pszLibrary, dwFlags = 0): _LoadLibraryExA = windll.kernel32.LoadLibraryExA _LoadLibraryExA.argtypes = LPSTR, HANDLE, DWORD _LoadLibraryExA.restype = HMODULE hModule = _LoadLibraryExA(pszLibrary, NULL, dwFlags) if hModule == NULL: raise ctypes.WinError() return hModule |
_LoadLibraryExW.argtypes = LPWSTR, HANDLE, DWORD | _LoadLibraryExW.argtypes = [LPWSTR, HANDLE, DWORD] | def LoadLibraryExW(pszLibrary, dwFlags = 0): _LoadLibraryExW = windll.kernel32.LoadLibraryExW _LoadLibraryExW.argtypes = LPWSTR, HANDLE, DWORD _LoadLibraryExW.restype = HMODULE hModule = _LoadLibraryExW(pszLibrary, NULL, dwFlags) if hModule == NULL: raise ctypes.WinError() return hModule |
else: if begin < end: step = 1 else: begin, end = end, begin step = -1 for page in xrange(begin, end, step): if page in valid_addresses: yield page else: logger.log_text("invalid address: %s" % HexDump.address(page)) | def next(self): valid_addresses = set(ExecutableAddressIterator(self.process.get_memory_map())) for current_range in self.ranges_list: try: begin, end = current_range.split('-') except ValueError: logger.log_text("can't parse range: %s" % current_range) continue try: begin = process.resolve_label(begin) except Exceptio... | |
lpdwSize = DWORD(0) _QueryFullProcessImageNameA(hProcess, dwFlags, None, ctypes.byref(lpdwSize)) if lpdwSize.value == 0: raise ctypes.WinError() lpExeName = ctypes.create_string_buffer('', lpdwSize.value + 1) success = _QueryFullProcessImageNameA(hProcess, dwFlags, lpExeName, ctypes.byref(lpdwSize)) if not success: rai... | dwSize = MAX_PATH while 1: lpdwSize = DWORD(dwSize) lpExeName = ctypes.create_string_buffer('', lpdwSize.value + 1) success = _QueryFullProcessImageNameA(hProcess, dwFlags, lpExeName, ctypes.byref(lpdwSize)) if success and 0 < lpdwSize.value < dwSize: break error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER: ... | def QueryFullProcessImageNameA(hProcess, dwFlags = 0): _QueryFullProcessImageNameA = windll.kernel32.QueryFullProcessImageNameA _QueryFullProcessImageNameA.argtypes = [HANDLE, DWORD, LPSTR, PDWORD] _QueryFullProcessImageNameA.restype = bool lpdwSize = DWORD(0) _QueryFullProcessImageNameA(hProcess, dwFlags, None, ctyp... |
lpdwSize = DWORD(0) _QueryFullProcessImageNameW(hProcess, dwFlags, None, ctypes.byref(lpdwSize)) if lpdwSize.value == 0: raise ctypes.WinError() lpExeName = ctypes.create_unicode_buffer(u'', lpdwSize.value + 1) success = _QueryFullProcessImageNameW(hProcess, dwFlags, lpExeName, ctypes.byref(lpdwSize)) if not success: r... | dwSize = MAX_PATH while 1: lpdwSize = DWORD(dwSize) lpExeName = ctypes.create_unicode_buffer('', lpdwSize.value + 1) success = _QueryFullProcessImageNameW(hProcess, dwFlags, lpExeName, ctypes.byref(lpdwSize)) if success and 0 < lpdwSize.value < dwSize: break error = GetLastError() if error != ERROR_INSUFFICIENT_BUFFER:... | def QueryFullProcessImageNameW(hProcess, dwFlags = 0): _QueryFullProcessImageNameW = windll.kernel32.QueryFullProcessImageNameW _QueryFullProcessImageNameW.argtypes = [HANDLE, DWORD, LPWSTR, PDWORD] _QueryFullProcessImageNameW.restype = bool lpdwSize = DWORD(0) _QueryFullProcessImageNameW(hProcess, dwFlags, None, cty... |
_GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA | _GetLogicalDriveStringsA = ctypes.windll.kernel32.GetLogicalDriveStringsA | def GetLogicalDriveStringsA(): _GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] _GetLogicalDriveStringsA.restype = DWORD _GetLogicalDriveStringsA.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_string_buffer('', nBufferLength)... |
nBufferLength = 0x1000 | nBufferLength = (4 * 26) + 1 | def GetLogicalDriveStringsA(): _GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] _GetLogicalDriveStringsA.restype = DWORD _GetLogicalDriveStringsA.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_string_buffer('', nBufferLength)... |
return lpBuffer.value | drive_strings = list() string_p = ctypes.addressof(lpBuffer) sizeof_char = ctypes.sizeof(ctypes.c_char) while True: string_v = ctypes.string_at(string_p) if string_v == '': break drive_strings.append(string_v) string_p += len(string_v) + sizeof_char return drive_strings | def GetLogicalDriveStringsA(): _GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] _GetLogicalDriveStringsA.restype = DWORD _GetLogicalDriveStringsA.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_string_buffer('', nBufferLength)... |
_GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW | _GetLogicalDriveStringsW = ctypes.windll.kernel32.GetLogicalDriveStringsW | def GetLogicalDriveStringsW(): _GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] _GetLogicalDriveStringsW.restype = DWORD _GetLogicalDriveStringsW.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_unicode_buffer('', nBufferLengt... |
nBufferLength = 0x1000 lpBuffer = ctypes.create_unicode_buffer('', nBufferLength) | nBufferLength = (4 * 26) + 1 lpBuffer = ctypes.create_unicode_buffer(u'', nBufferLength) | def GetLogicalDriveStringsW(): _GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] _GetLogicalDriveStringsW.restype = DWORD _GetLogicalDriveStringsW.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_unicode_buffer('', nBufferLengt... |
return lpBuffer.value | drive_strings = list() string_p = ctypes.addressof(lpBuffer) sizeof_wchar = ctypes.sizeof(ctypes.c_wchar) while True: string_v = ctypes.wstring_at(string_p) if string_v == u'': break drive_strings.append(string_v) string_p += (len(string_v) * sizeof_wchar) + sizeof_wchar return drive_strings | def GetLogicalDriveStringsW(): _GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] _GetLogicalDriveStringsW.restype = DWORD _GetLogicalDriveStringsW.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_unicode_buffer('', nBufferLengt... |
useHardwareBreakpoints = True | useHardwareBreakpoints = False | def running(self, aProcess, aThread): self.__clear_bp(aThread) super(HardwareBreakpoint, self).running(aProcess, aThread) aThread.set_tf() |
is_buffer_mapped, | is_buffer, | def notify_exit_process(self, event): """ Notify the termination of a process. |
def is_buffer_writeable_and_executable(self, address, size): | def is_buffer_executable_and_writeable(self, address, size): | def is_buffer_writeable_and_executable(self, address, size): """ Determines if the given memory area is writeable and executable. |
@see: L{http://msdn.microsoft.com/en-us/library/ms679294(VS.85).aspx} | @see: U{http://msdn.microsoft.com/en-us/library/ms679294(VS.85).aspx} | def simple_debugger( argv ): |
def log_event(self, event, text): | def log_event(self, event, text = None): | def log_event(self, event, text): """ Log lines of text associated with a debug event. |
@param text: Text to log. | @param text: (Optional) Text to log. If no text is provided the default is to show a description of the event itself. | def log_event(self, event, text): """ Log lines of text associated with a debug event. |
if debug_prints: print "updated snapshot" | logger.log_text("updated snapshot") | def exception(self, event): if event.is_first_chance(): event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED if self.testing: if self.checkSnapshotPage(event): if debug_prints: print "updated snapshot" event.continueStatus = win32.DBG_CONTINUE elif hasattr(event, 'get_fault_type') and event.get_fault_type() == win32.... |
if debug_prints: print "dep fault, aborting" | logger.log_text("dep fault, aborting") | def exception(self, event): if event.is_first_chance(): event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED if self.testing: if self.checkSnapshotPage(event): if debug_prints: print "updated snapshot" event.continueStatus = win32.DBG_CONTINUE elif hasattr(event, 'get_fault_type') and event.get_fault_type() == win32.... |
if debug_prints: print "found attacker seh" | logger.log_text("found attacker seh") | def exception(self, event): if event.is_first_chance(): event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED if self.testing: if self.checkSnapshotPage(event): if debug_prints: print "updated snapshot" event.continueStatus = win32.DBG_CONTINUE elif hasattr(event, 'get_fault_type') and event.get_fault_type() == win32.... |
if debug_prints: print "got a crash but seh is intact, aborting" | logger.log_text("got a crash but seh is intact, aborting") | def exception(self, event): if event.is_first_chance(): event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED if self.testing: if self.checkSnapshotPage(event): if debug_prints: print "updated snapshot" event.continueStatus = win32.DBG_CONTINUE elif hasattr(event, 'get_fault_type') and event.get_fault_type() == win32.... |
if debug_prints: print "ignored second chance" | logger.log_text("ignored second chance") | def exception(self, event): if event.is_first_chance(): event.continueStatus = win32.DBG_EXCEPTION_NOT_HANDLED if self.testing: if self.checkSnapshotPage(event): if debug_prints: print "updated snapshot" event.continueStatus = win32.DBG_CONTINUE elif hasattr(event, 'get_fault_type') and event.get_fault_type() == win32.... |
if debug_prints: print "begin testing" | logger.log_text("begin testing") | def beginTesting(self, event): if debug_prints: print "begin testing" |
self.iter = ExecutableAddressIterator(self.process.get_memory_map()) | def beginTesting(self, event): if debug_prints: print "begin testing" | |
if debug_prints: print "stop testing" | logger.log_text("stop testing") | def stopTesting(self): if debug_prints: print "stop testing" |
if debug_prints: print "continue testing" | def nextAddress(self): if debug_prints: print "continue testing" self.removeBreakpoint() try: self.current_target = self.iter.next() if debug_prints: print "next target is %s" % HexDump.address(self.current_target) if self.options.output: print "Trying: %s" % HexDump.address(self.current_target) except StopIteration: s... | |
try: self.current_target = self.iter.next() if debug_prints: print "next target is %s" % HexDump.address(self.current_target) if self.options.output: print "Trying: %s" % HexDump.address(self.current_target) except StopIteration: self.stopTesting() return | def nextAddress(self): if debug_prints: print "continue testing" self.removeBreakpoint() try: self.current_target = self.iter.next() if debug_prints: print "next target is %s" % HexDump.address(self.current_target) if self.options.output: print "Trying: %s" % HexDump.address(self.current_target) except StopIteration: s... | |
self.setBreakpoint() | def nextAddress(self): if debug_prints: print "continue testing" self.removeBreakpoint() try: self.current_target = self.iter.next() if debug_prints: print "next target is %s" % HexDump.address(self.current_target) if self.options.output: print "Trying: %s" % HexDump.address(self.current_target) except StopIteration: s... | |
if debug_prints: print "found valid target" | logger.log_text("found valid target") | def foundValidTarget(self, event): if debug_prints: print "found valid target" printable_address = HexDump.address(self.current_target) if self.options.output: print "FOUND: %s" % printable_address print >> self.output_file, printable_address self.output_file.flush() else: print printable_address self.nextAddress() |
if debug_prints: print "looking for attacker seh" attacker_seh = self.process.resolve_label(self.options.seh) if debug_prints: print "attacker seh would be %s (%s)" % (self.options.seh, HexDump.address(attacker_seh)) | logger.log_text("looking for attacker seh") try: attacker_seh = self.process.resolve_label(self.options.seh) except Exception: logger.log_text("failed to resolve: %s" % self.options.seh) return False logger.log_text("attacker seh would be %s (%s)" % (self.options.seh, HexDump.address(attacker_seh))) | def findAttackerExceptionHandler(self, event): if debug_prints: print "looking for attacker seh" attacker_seh = self.process.resolve_label(self.options.seh) if debug_prints: print "attacker seh would be %s (%s)" % (self.options.seh, HexDump.address(attacker_seh)) sizeof_pvoid = win32.sizeof(win32.PVOID) pfirst = even... |
if debug_prints: print "looking at seh %s" % HexDump.address(pseh) | logger.log_text("looking at seh %s" % HexDump.address(pseh)) | def findAttackerExceptionHandler(self, event): if debug_prints: print "looking for attacker seh" attacker_seh = self.process.resolve_label(self.options.seh) if debug_prints: print "attacker seh would be %s (%s)" % (self.options.seh, HexDump.address(attacker_seh)) sizeof_pvoid = win32.sizeof(win32.PVOID) pfirst = even... |
if debug_prints: print "current (%s) -> next (%s)" % (HexDump.address(pcurrent), HexDump.address(pnext)) | logger.log_text("current (%s) -> next (%s)" % (HexDump.address(pcurrent), HexDump.address(pnext))) | def findAttackerExceptionHandler(self, event): if debug_prints: print "looking for attacker seh" attacker_seh = self.process.resolve_label(self.options.seh) if debug_prints: print "attacker seh would be %s (%s)" % (self.options.seh, HexDump.address(attacker_seh)) sizeof_pvoid = win32.sizeof(win32.PVOID) pfirst = even... |
if debug_prints: print "set breakpoint" | logger.log_text("set breakpoint") | def setBreakpoint(self): if debug_prints: print "set breakpoint" self.debug.stalk_at(self.pid, self.current_target, self.foundValidTarget) |
if debug_prints: print "remove breakpoint" | logger.log_text("remove breakpoint") | def removeBreakpoint(self): if debug_prints: print "remove breakpoint" if self.current_target is not None: self.debug.dont_stalk_at(self.pid, self.current_target) |
if debug_prints: print "remember exception handler" | logger.log_text("remember exception handler") | def rememberExceptionHandler(self): if debug_prints: print "remember exception handler" self.first_seh = self.thread.get_seh_chain_pointer() self.next_seh = self.process.read_pointer(self.first_seh) self.ptr_function_seh = self.first_seh + win32.sizeof(win32.LPVOID) self.function_seh = self.process.r... |
if debug_prints: print "change exception handler" | logger.log_text("change exception handler") | def changeExceptionHandler(self): if debug_prints: print "change exception handler" self.process.write_pointer(self.first_seh, win32.LPVOID(-1).value) self.process.write_pointer(self.ptr_function_seh, self.current_target) |
if debug_prints: print "restore exception handler" | logger.log_text("restore exception handler") | def restoreExceptionHandler(self): if debug_prints: print "restore exception handler" self.process.write_pointer(self.first_seh, self.next_seh) self.process.write_pointer(self.ptr_function_seh, self.function_seh) |
if debug_prints: print "suspend other threads" | logger.log_text("suspend other threads") | def suspendOtherThreads(self): if debug_prints: print "suspend other threads" for thread in self.process.iter_threads(): if thread.get_tid() != self.tid: thread.suspend() |
if debug_prints: print "resume other threads" | logger.log_text("resume other threads") | def resumeOtherThreads(self): if debug_prints: print "resume other threads" for thread in self.process.iter_threads(): if thread.get_tid() != self.tid: thread.resume() |
if debug_prints: print "take snapshot" | logger.log_text("take snapshot") | def takeSnapshot(self): if debug_prints: print "take snapshot" self.context = self.thread.get_context() |
if debug_prints: print "unexpected special page %s" % HexDump.address(page) | logger.log_text("unexpected special page %s" % HexDump.address(page)) | def takeSnapshot(self): if debug_prints: print "take snapshot" self.context = self.thread.get_context() |
if debug_prints: print "restore snapshot" | logger.log_text("restore snapshot") | def restoreSnapshot(self): if debug_prints: print "restore snapshot" self.thread.set_context(self.context) pageSize = System.pageSize process = self.process tainted = self.tainted for page, content in self.special_pages.iteritems(): process.write(page, content) for page, (content, protect, new_protect) in self.memory.i... |
def log_event(self, event): if debug_prints: try: print HexDump.address(event.get_exception_address()), event.get_exception_description(), event.is_first_chance() except AttributeError: print HexDump.address(event.get_thread().get_pc()), event.get_event_name() | def log_event(self, event): if debug_prints: try: print HexDump.address(event.get_exception_address()), event.get_exception_description(), event.is_first_chance() except AttributeError: print HexDump.address(event.get_thread().get_pc()), event.get_event_name() | |
self.log_event(event) | logger.log_event(event) | def event(self, event): self.log_event(event) pid = event.get_pid() if self.forward.has_key(pid): return self.forward[pid](event) |
self.log_event(event) | logger.log_event(event) | def create_process(self, event): self.log_event(event) handler = self.cls(self.options) self.forward[event.get_pid()] = handler return handler(event) |
self.log_event(event) | logger.log_event(event) | def exit_process(self, event): self.log_event(event) pid = event.get_pid() if self.forward.has_key(pid): retval = self.forward[pid](event) del self.forward[pid] return retval |
self.log_event(event) | logger.log_event(event) | def breakpoint(self, event): event.continueStatus = win32.DBG_EXCEPTION_HANDLED self.log_event(event) |
self.log_event(event) | logger.log_event(event) | def wow64_breakpoint(self, event): event.continueStatus = win32.DBG_EXCEPTION_HANDLED self.log_event(event) |
self.log_event(event) | logger.log_event(event) | def debug_control_c(self, event): event.continueStatus = win32.DBG_EXCEPTION_HANDLED self.log_event(event) |
self.log_event(event) | logger.log_event(event) | def invalid_handle(self, event): event.continueStatus = win32.DBG_EXCEPTION_HANDLED self.log_event(event) |
self.log_event(event) | logger.log_event(event) | def possible_deadlock(self, event): event.continueStatus = win32.DBG_EXCEPTION_HANDLED self.log_event(event) |
return Handle(lpTargetHandle.value) | if isinstance(hSourceHandle, Handle): HandleClass = hSourceHandle.__class__ else: HandleClass = Handle return HandleClass(lpTargetHandle.value) | def DuplicateHandle(hSourceHandle, hSourceProcessHandle = None, hTargetProcessHandle = None, dwDesiredAccess = STANDARD_RIGHTS_ALL, bInheritHandle = False, dwOptions = DUPLICATE_SAME_ACCESS): _DuplicateHandle = windll.kernel32.DuplicateHandle _DuplicateHandle.argtypes = [HANDLE, HANDLE, HANDLE, LPHANDLE, DWORD, BOOL, D... |
_GetDllDirectoryW.argytpes = [DWORD, LPSTR] | _GetDllDirectoryW.argytpes = [DWORD, LPWSTR] | def GetDllDirectoryW(): _GetDllDirectoryW = windll.kernel32.GetDllDirectoryW _GetDllDirectoryW.argytpes = [DWORD, LPSTR] _GetDllDirectoryW.restype = DWORD _GetDllDirectoryW.errcheck = RaiseIfZero nBufferLength = _GetDllDirectoryW(0, None) if nBufferLength == 0: return None lpBuffer = ctypes.create_unicode_buffer(u"",... |
_GetDllDirectoryW.errcheck = RaiseIfZero | def GetDllDirectoryW(): _GetDllDirectoryW = windll.kernel32.GetDllDirectoryW _GetDllDirectoryW.argytpes = [DWORD, LPSTR] _GetDllDirectoryW.restype = DWORD _GetDllDirectoryW.errcheck = RaiseIfZero nBufferLength = _GetDllDirectoryW(0, None) if nBufferLength == 0: return None lpBuffer = ctypes.create_unicode_buffer(u"",... | |
_GetLogicalDriveStringsA(nBufferLength, ctypes.byref(lpBuffer)) | _GetLogicalDriveStringsA(nBufferLength, lpBuffer) | def GetLogicalDriveStringsA(): _GetLogicalDriveStringsA = windll.kernel32.GetLogicalDriveStringsA _GetLogicalDriveStringsA.argtypes = [DWORD, LPSTR] _GetLogicalDriveStringsA.restype = DWORD _GetLogicalDriveStringsA.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_string_buffer('', nBufferLength)... |
_GetLogicalDriveStringsW(nBufferLength, ctypes.byref(lpBuffer)) | _GetLogicalDriveStringsW(nBufferLength, lpBuffer) | def GetLogicalDriveStringsW(): _GetLogicalDriveStringsW = windll.kernel32.GetLogicalDriveStringsW _GetLogicalDriveStringsW.argtypes = [DWORD, LPWSTR] _GetLogicalDriveStringsW.restype = DWORD _GetLogicalDriveStringsW.errcheck = RaiseIfZero nBufferLength = 0x1000 lpBuffer = ctypes.create_unicode_buffer('', nBufferLengt... |
if hFileMappingObject == INVALID_HANDLE_VALUE: raise ctypes.WinError() return Handle(hFileMappingObject) | return FileMappingHandle(hFileMappingObject) | def OpenFileMappingA(dwDesiredAccess, bInheritHandle, lpName): _OpenFileMappingA = windll.kernel32.OpenFileMappingA _OpenFileMappingA.argtypes = [DWORD, BOOL, LPSTR] _OpenFileMappingA.restype = HANDLE hFileMappingObject = _OpenFileMappingA(dwDesiredAccess, bool(bInheritHandle), lpName) if hFileMappingObject == INVALID... |
if hFileMappingObject == INVALID_HANDLE_VALUE: raise ctypes.WinError() return Handle(hFileMappingObject) | return FileMappingHandle(hFileMappingObject) | def OpenFileMappingW(dwDesiredAccess, bInheritHandle, lpName): _OpenFileMappingW = windll.kernel32.OpenFileMappingW _OpenFileMappingW.argtypes = [DWORD, BOOL, LPWSTR] _OpenFileMappingW.restype = HANDLE hFileMappingObject = _OpenFileMappingW(dwDesiredAccess, bool(bInheritHandle), lpName) if hFileMappingObject == INVALI... |
if hFileMappingObject == INVALID_HANDLE_VALUE: raise ctypes.WinError() return Handle(hFileMappingObject) | return FileMappingHandle(hFileMappingObject) | def CreateFileMappingA(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None): _CreateFileMappingA = windll.kernel32.CreateFileMappingA _CreateFileMappingA.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPSTR] _CreateFileMappingA.restype = HANDLE ... |
if hFileMappingObject == INVALID_HANDLE_VALUE: raise ctypes.WinError() return Handle(hFileMappingObject) | return FileMappingHandle(hFileMappingObject) | def CreateFileMappingW(hFile, lpAttributes = None, flProtect = PAGE_EXECUTE_READWRITE, dwMaximumSizeHigh = 0, dwMaximumSizeLow = 0, lpName = None): _CreateFileMappingW = windll.kernel32.CreateFileMappingW _CreateFileMappingW.argtypes = [HANDLE, LPVOID, DWORD, DWORD, DWORD, LPWSTR] _CreateFileMappingW.restype = HANDLE ... |
return Handle(hFile) | return FileHandle(hFile) | def CreateFileA(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None): _CreateFileA = windll.kernel32.CreateFileA _CreateFileA.argtypes = [LPSTR, DWORD, DWORD, LPVOID, DWORD, DWORD... |
return Handle(hFile) | return FileHandle(hFile) | def CreateFileW(lpFileName, dwDesiredAccess = GENERIC_ALL, dwShareMode = 0, lpSecurityAttributes = None, dwCreationDisposition = OPEN_ALWAYS, dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL, hTemplateFile = None): _CreateFileW = windll.kernel32.CreateFileW _CreateFileW.argtypes = [LPWSTR, DWORD, DWORD, LPVOID, DWORD, DWOR... |
while hWnd: | while hWnd and hWnd not in history: history.add(hWnd) | def get_root(self): """ @see: L{get_tree} @rtype: L{Window} @return: Root window for this tree. @raise WindowsError: An error occured while processing this request. """ hWnd = self.get_handle() hPrevWnd = hWnd while hWnd: hPrevWnd = hWnd hWnd = win32.GetParent(hWnd) if hPrevWnd != self.hWnd: return self.__g... |
'http://svn.edgewall.com/repos/trac/sandbox/mercurial-plugin-0.11 | 'http://svn.edgewall.org/repos/trac/plugins/0.11/mercurial-plugin | def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() |
for mil_name in cleanMultiParams(options.get('milestones', '')): | for mil_data in cleanMultiParams(options.get('milestones', '')): mil_name = mil_data[0] | def cleanMultiParams(v): params = [s.split('|') for s in [l.strip() for l in v.split('\n')] if len(s) > 0] cleaned_params = [] for line in params: cleaned_params.append([row.strip() for row in line]) return cleaned_params |
comp.name = comp_data[0] | comp.name = comp_name | def cleanMultiParams(v): params = [s.split('|') for s in [l.strip() for l in v.split('\n')] if len(s) > 0] cleaned_params = [] for line in params: cleaned_params.append([row.strip() for row in line]) return cleaned_params |
assert profiler.memory_grow(stable) <= 500 | assert profiler.memory_grow(stable) <= 700 | def unstable(): growing.append(stable()) |
start_time = timer() | def __profile(*args, **kw): start_time = timer() profiler = hpy() profiler.setref() start = profiler.heap().size + 12 try: return function(*args, **kw) finally: total = timer() - start_time kstones = secs_to_kstones(total) memory = profiler.heap().size - start stats[name] = {'time': total, 'stones': kstones, 'memory': ... | |
'memory': profiler.heap().size} | 'memory': memory} | def __profile(*args, **kw): start_time = timer() profiler = hpy() profiler.setref() start = profiler.heap().size + 12 try: return function(*args, **kw) finally: total = timer() - start_time kstones = secs_to_kstones(total) memory = profiler.heap().size - start stats[name] = {'time': total, 'stones': kstones, 'memory': ... |
env = trac.env_open() | def install(self): """Installer""" | |
rospy.Subscriber('image', sensor_msgs.msg.Image, self.queue_monocular) | msub = message_filters.Subscriber('image', sensor_msgs.msg.Image) msub.registerCallback(self.queue_monocular) | def __init__(self, chess_size, dim, service_check): |
self.font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.20, 1, thickness = 2, line_type = cv.CV_AA) | self.font = cv.InitFont(cv.CV_FONT_HERSHEY_SIMPLEX, 0.20, 1, thickness = 2) | def __init__(self, *args): |
display = cv.CreateMat(height, width + 100, cv.CV_8UC3) | display = cv.CreateMat(max(480, height), width + 100, cv.CV_8UC3) | def redraw_monocular(self, scrib, _): width, height = cv.GetSize(scrib) |
display = cv.CreateMat(self.height, 2 * self.width + 100, cv.CV_8UC3) | display = cv.CreateMat(max(480, self.height), 2 * self.width + 100, cv.CV_8UC3) | def redraw_stereo(self, lscrib, rscrib, lrgb, rrgb): display = cv.CreateMat(self.height, 2 * self.width + 100, cv.CV_8UC3) cv.Copy(lscrib, cv.GetSubRect(display, (0,0,self.width,self.height))) cv.Copy(rscrib, cv.GetSubRect(display, (self.width,0,self.width,self.height))) cv.Set(cv.GetSubRect(display, (2 * self.width,0,... |
scale = int(math.ceil(self.width / 640)) | scale = math.ceil(self.width / 640.) | def handle_monocular(self, msg): |
scrib = cv.CreateMat(self.height / scale, self.width / scale, cv.GetElemType(rgb)) | scrib = cv.CreateMat(int(self.height / scale), int(self.width / scale), cv.GetElemType(rgb)) | def handle_monocular(self, msg): |
cv.DrawChessboardCorners(scrib, self.chess_size, [ (x/scale, y/scale) for (x, y) in cvmat_iterator(src)], True) | cv.DrawChessboardCorners(scrib, self.chess_size, [ (int(x/scale), int(y/scale)) for (x, y) in cvmat_iterator(src)], True) | def handle_monocular(self, msg): |
mc = MonoCalibrator() | mc = MonoCalibrator((8,6), .108) | def test_monocular(self): mc = MonoCalibrator() mc.cal(self.limages) if 0: cv.NamedWindow("display") for im in images: (ok, corners) = get_corners(im) if ok: src = cv.Reshape(mk_image_points([corners]), 2) rm = mc.remap(cv.GetMat(im)) |
mc = StereoCalibrator((8, 6)) | mc = StereoCalibrator((8, 6), .108) | def test_stereo(self): print self.image_from_archive('wide/left0003.pgm') limages = [self.image_from_archive("wide/left%04d.pgm" % i) for i in range(3, 15)] rimages = [self.image_from_archive("wide/right%04d.pgm" % i) for i in range(3, 15)] mc = StereoCalibrator((8, 6)) mc.cal(self.limages, self.rimages) |
sc = StereoCalibrator(size) | sc = StereoCalibrator(size, .108) | def test_nochecker(self): |
mc = MonoCalibrator(size) | mc = MonoCalibrator(size, .108) | def test_nochecker(self): |
self.chess_size = chess_size self.dim = dim | self.board = ChessboardInfo() self.board.n_cols = chess_size[0] self.board.n_rows = chess_size[1] self.board.dim = dim | def __init__(self, chess_size, dim): self.chess_size = chess_size self.dim = dim |
self.mc = MonoCalibrator(self.chess_size, self.dim) | self.mc = MonoCalibrator([self.board]) | def __init__(self, chess_size, dim): self.chess_size = chess_size self.dim = dim |
(ok, corners) = self.mc.get_corners(im) | (ok, corners, b) = self.mc.get_corners(im) | def image_corners(self, im): (ok, corners) = self.mc.get_corners(im) if ok: return list(cvmat_iterator(cv.Reshape(self.mc.mk_image_points([corners]), 2))) else: return None |
return list(cvmat_iterator(cv.Reshape(self.mc.mk_image_points([corners]), 2))) | return list(cvmat_iterator(cv.Reshape(self.mc.mk_image_points([(corners, b)]), 2))) | def image_corners(self, im): (ok, corners) = self.mc.get_corners(im) if ok: return list(cvmat_iterator(cv.Reshape(self.mc.mk_image_points([corners]), 2))) else: return None |
cc = self.mc.chessboard_n_cols cr = self.mc.chessboard_n_rows | cc = self.board.n_cols cr = self.board.n_rows | def pt2line(x0, y0, x1, y1, x2, y2): """ point is (x0, y0), line is (x1, y1, x2, y2) """ return abs((x2 - x1) * (y1 - y0) - (x1 - x0) * (y2 - y1)) / math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) |
sc = StereoCalibrator(self.chess_size, self.dim) | sc = StereoCalibrator([self.board]) | def handle_stereo(self, msg): |
cc = self.mc.chessboard_n_cols cr = self.mc.chessboard_n_rows | cc = self.board.n_cols cr = self.board.n_rows | def l2(p0, p1): return math.sqrt(sum([(c0 - c1) ** 2 for (c0, c1) in zip(p0, p1)])) |
m.width = 320 m.height = 240 self.callback(m, *self.args) | br = cv_bridge.CvBridge() m.encoding = "mono8" raw = br.imgmsg_to_cv(m) rgb = cv.CreateMat(raw.rows, raw.cols, cv.CV_8UC3) mono = cv.CreateMat(raw.rows, raw.cols, cv.CV_8UC1) cv.CvtColor(raw, rgb, cv.CV_BayerRG2BGR) cv.CvtColor(rgb, mono, cv.CV_BGR2GRAY) cv.CvtColor(mono, rgb, cv.CV_GRAY2BGR) smaller = cv.CreateMat(r... | def incoming(self, m): m.width = 320 m.height = 240 self.callback(m, *self.args) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.