def _find_function_address(self, search_tuple): name, handle = search_tuple dprint("PupyCDLL._find_function_address: {}".format(name)) if not type(name) in (str, unicode): return self._FuncPtr_orig(search_tuple) else: addr = pupy.find_function_address(self._name, name) dprint("PupyCDLL._find_function_address: {} = {}".format(name, addr)) if addr: return self._FuncPtr_orig(addr) else: return self._FuncPtr_orig(search_tuple)
def __init__(self): _functions = { 'winpty_error_code': CFUNCTYPE(DWORD, c_void_p), 'winpty_error_msg': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_error_free': CFUNCTYPE(None, c_void_p), 'winpty_config_new': CFUNCTYPE(c_void_p, c_ulonglong, c_void_p), 'winpty_config_free': CFUNCTYPE(None, c_void_p), 'winpty_config_set_initial_size': CFUNCTYPE(None, c_void_p, c_int, c_int), 'winpty_config_set_mouse_mode': CFUNCTYPE(None, c_void_p, c_int), 'winpty_config_set_htoken': CFUNCTYPE(None, c_void_p, c_void_p), 'winpty_config_set_agent_timeout': CFUNCTYPE(None, c_void_p, c_uint), 'winpty_open': CFUNCTYPE(c_void_p, c_void_p, c_void_p), 'winpty_free': CFUNCTYPE(None, c_void_p), 'winpty_agent_process': CFUNCTYPE(HWND, c_void_p), 'winpty_spawn_config_new': CFUNCTYPE(c_void_p, c_ulonglong, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, c_void_p), 'winpty_spawn_config_free': CFUNCTYPE(None, c_void_p), 'winpty_spawn': CFUNCTYPE(c_int, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p), 'winpty_set_size': CFUNCTYPE(c_int, c_void_p, c_int, c_int, c_void_p), 'winpty_conin_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conout_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conerr_name': CFUNCTYPE(LPCWSTR, c_void_p) } _new_api = set(['winpty_config_set_htoken']) for funcname, definition in _functions.iteritems(): funcaddr = pupy.find_function_address(DLLNAME, funcname) if not funcaddr and funcname not in _new_api: raise ImportError( "Couldn't find function {} at winpty.dll".format(funcname)) setattr(self, funcname[len('winpty_'):], definition(funcaddr))
CFUNCTYPE(None, c_void_p), 'winpty_spawn': CFUNCTYPE(c_int, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p), 'winpty_set_size': CFUNCTYPE(c_int, c_void_p, c_int, c_int, c_void_p), 'winpty_conin_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conout_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conerr_name': CFUNCTYPE(LPCWSTR, c_void_p) } for funcname, definition in _functions.iteritems(): funcaddr = pupy.find_function_address(DLLNAME, funcname) if not funcaddr: raise ImportError( "Couldn't find function {} at winpty.dll".format(funcname)) globals()[funcname] = definition(funcaddr) class WinPTYException(Exception): def __init__(self, code, message): Exception.__init__(self, message) self.code = code @contextmanager def winpty_error(): error = c_void_p(None)
'winpty_config_set_agent_timeout': CFUNCTYPE(None, c_void_p, c_uint), 'winpty_open': CFUNCTYPE(c_void_p, c_void_p, c_void_p), 'winpty_free': CFUNCTYPE(None, c_void_p), 'winpty_agent_process': CFUNCTYPE(HWND, c_void_p), 'winpty_spawn_config_new': CFUNCTYPE( c_void_p, c_ulonglong, LPCWSTR, LPCWSTR, LPCWSTR, LPCWSTR, c_void_p), 'winpty_spawn_config_free': CFUNCTYPE(None, c_void_p), 'winpty_spawn': CFUNCTYPE(c_int, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p, c_void_p), 'winpty_set_size': CFUNCTYPE(c_int, c_void_p, c_int, c_int, c_void_p), 'winpty_conin_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conout_name': CFUNCTYPE(LPCWSTR, c_void_p), 'winpty_conerr_name': CFUNCTYPE(LPCWSTR, c_void_p) } for funcname, definition in _functions.iteritems(): funcaddr = pupy.find_function_address(DLLNAME, funcname) if not funcaddr: raise ImportError("Couldn't find function {} at winpty.dll".format(funcname)) globals()[funcname] = definition(funcaddr) class WinPTYException(Exception): def __init__(self, code, message): Exception.__init__(self, message) self.code = code @contextmanager def winpty_error(): error = c_void_p(None) try: yield pointer(error) code = winpty_error_code(error)