当前位置: 首页>>代码示例>>Python>>正文


Python ctypes.c_wchar方法代码示例

本文整理汇总了Python中ctypes.c_wchar方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_wchar方法的具体用法?Python ctypes.c_wchar怎么用?Python ctypes.c_wchar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


在下文中一共展示了ctypes.c_wchar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clear_screen

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def clear_screen(self,param):
			mode=to_int(param,0)
			sbinfo=self.screen_buffer_info()
			if mode==1:
				clear_start=COORD(0,0)
				clear_length=sbinfo.CursorPosition.X*sbinfo.CursorPosition.Y
			elif mode==2:
				clear_start=COORD(0,0)
				clear_length=sbinfo.Size.X*sbinfo.Size.Y
				windll.kernel32.SetConsoleCursorPosition(self.hconsole,clear_start)
			else:
				clear_start=sbinfo.CursorPosition
				clear_length=((sbinfo.Size.X-sbinfo.CursorPosition.X)+sbinfo.Size.X*(sbinfo.Size.Y-sbinfo.CursorPosition.Y))
			chars_written=c_ulong()
			windll.kernel32.FillConsoleOutputCharacterW(self.hconsole,c_wchar(' '),clear_length,clear_start,byref(chars_written))
			windll.kernel32.FillConsoleOutputAttribute(self.hconsole,sbinfo.Attributes,clear_length,clear_start,byref(chars_written)) 
开发者ID:MOSAIC-UA,项目名称:802.11ah-ns3,代码行数:18,代码来源:ansiterm.py

示例2: _get_image_base_by_name

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _get_image_base_by_name(self, name):
		peb_ldr_data = self.get_proc_attribute('peb_ldr_data')

		firstFLink = 0
		fLink = peb_ldr_data.InLoadOrderModuleList.Flink
		while fLink != firstFLink:
			firstFLink = peb_ldr_data.InLoadOrderModuleList.Flink
			module = wintypes.LDR_MODULE()

			m_k32.ReadProcessMemory(self.handle, fLink, ctypes.byref(module), ctypes.sizeof(module), 0)

			_base_dll_name = (ctypes.c_wchar * module.BaseDllName.MaximumLength)
			base_dll_name = _base_dll_name()

			m_k32.ReadProcessMemory(self.handle, module.BaseDllName.Buffer, base_dll_name, module.BaseDllName.Length + 2, 0)
			base_dll_name = base_dll_name[:(module.BaseDllName.Length / 2)]
			if name == base_dll_name:
				return module
			fLink = module.InLoadOrderModuleList.Flink
		return None 
开发者ID:zeroSteiner,项目名称:mayhem,代码行数:22,代码来源:windows.py

示例3: test_aswidecharstring

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def test_aswidecharstring(self):
        from _testcapi import unicode_aswidecharstring
        support.import_module('ctypes')
        from ctypes import c_wchar, sizeof

        wchar, size = unicode_aswidecharstring('abc')
        self.assertEqual(size, 3)
        self.assertEqual(wchar, 'abc\0')

        wchar, size = unicode_aswidecharstring('abc\0def')
        self.assertEqual(size, 7)
        self.assertEqual(wchar, 'abc\0def\0')

        nonbmp = chr(0x10ffff)
        if sizeof(c_wchar) == 2:
            nchar = 2
        else: # sizeof(c_wchar) == 4
            nchar = 1
        wchar, size = unicode_aswidecharstring(nonbmp)
        self.assertEqual(size, nchar)
        self.assertEqual(wchar, nonbmp + '\0') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:23,代码来源:test_unicode.py

示例4: _get_image_base_by_name

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _get_image_base_by_name(self, name):
        peb_ldr_data = self.get_proc_attribute('peb_ldr_data')

        firstFLink = 0
        fLink = peb_ldr_data.InLoadOrderModuleList.Flink
        while fLink != firstFLink:
            firstFLink = peb_ldr_data.InLoadOrderModuleList.Flink
            module = wintypes.LDR_MODULE()

            self.k32.ReadProcessMemory(self.handle, fLink, ctypes.byref(module), ctypes.sizeof(module), 0)

            _base_dll_name = (ctypes.c_wchar * module.BaseDllName.MaximumLength)
            base_dll_name = _base_dll_name()

            self.k32.ReadProcessMemory(self.handle, module.BaseDllName.Buffer, base_dll_name,
                                       module.BaseDllName.Length + 2, 0)
            base_dll_name = base_dll_name[:(module.BaseDllName.Length / 2)]
            if name == base_dll_name:
                return module
            fLink = module.InLoadOrderModuleList.Flink
        return None 
开发者ID:Josue87,项目名称:BoomER,代码行数:23,代码来源:windows.py

示例5: shmem_as_ndarray

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def shmem_as_ndarray(raw_array):
    _ctypes_to_numpy = {
        ctypes.c_char: np.int8,
        ctypes.c_wchar: np.int16,
        ctypes.c_byte: np.int8,
        ctypes.c_ubyte: np.uint8,
        ctypes.c_short: np.int16,
        ctypes.c_ushort: np.uint16,
        ctypes.c_int: np.int32,
        ctypes.c_uint: np.int32,
        ctypes.c_long: np.int32,
        ctypes.c_ulong: np.int32,
        ctypes.c_float: np.float32,
        ctypes.c_double: np.float64
    }
    dtype = _ctypes_to_numpy[raw_array._type_]

    # The following works too, but occasionally raises
    # RuntimeWarning: Item size computed from the PEP 3118 buffer format string does not match the actual item size.
    # and appears to be slower.
    # return np.ctypeslib.as_array(raw_array)

    return np.frombuffer(raw_array, dtype=dtype) 
开发者ID:pytroll,项目名称:pyresample,代码行数:25,代码来源:_multi_proc.py

示例6: test_aswidecharstring

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def test_aswidecharstring(self):
        from _testcapi import unicode_aswidecharstring
        support.import_module('ctypes')
        from ctypes import c_wchar, sizeof

        wchar, size = unicode_aswidecharstring('abc')
        self.assertEqual(size, 3)
        self.assertEqual(wchar, 'abc\0')

        wchar, size = unicode_aswidecharstring('abc\0def')
        self.assertEqual(size, 7)
        self.assertEqual(wchar, 'abc\0def\0')

        nonbmp = chr(0x10ffff)
        if sizeof(c_wchar) == 2:
            nchar = 2
        else: # sizeof(c_wchar) == 4
            nchar = 1
        wchar, size = unicode_aswidecharstring(nonbmp)
        self.assertEqual(size, nchar)
        self.assertEqual(wchar, nonbmp + '\0')

    # Test PyUnicode_AsUCS4() 
开发者ID:ShikyoKira,项目名称:Project-New-Reign---Nemesis-Main,代码行数:25,代码来源:test_unicode.py

示例7: __init__

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def __init__(self):

		self.__dll__ = ctypes.windll.LoadLibrary('tests/demo_dll.dll')

		self.__replace_letter_in_null_terminated_string_unicode__ = self.__dll__.replace_letter_in_null_terminated_string_unicode_a
		self.__replace_letter_in_null_terminated_string_unicode__.argtypes = (
			ctypes.POINTER(ctypes.c_wchar), # Generate pointer to wchar manually
			ctypes.c_wchar,
			ctypes.c_wchar
			)
		self.__replace_letter_in_null_terminated_string_unicode__.memsync = [
			{
				'p': [0],
				'n': True,
				'w': True
				}
			] 
开发者ID:pleiszenburg,项目名称:zugbruecke,代码行数:19,代码来源:test_null_terminated_string.py

示例8: _get_window_module

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _get_window_module(self):
        # Get this window's process ID.
        pid = self._get_window_pid()

        # Get the process handle of this window's process ID.
        #  Access permission flags:
        #  0x0410 = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ
        handle = windll.kernel32.OpenProcess(0x0410, 0, pid)

        # Retrieve and return the process's executable path.
        try:
            # Try to use the QueryForProcessImageNameW function
            #  available since Windows Vista.
            buffer_len = c_ulong(256)
            buffer = (c_wchar * buffer_len.value)()
            windll.kernel32.QueryFullProcessImageNameW(handle, 0,
                                                       pointer(buffer),
                                                       pointer(buffer_len))
            buffer = buffer[:]
            buffer = buffer[:buffer.index("\0")]
        except Exception:
            # If the function above failed, fall back to the older
            #  GetModuleFileNameEx function, available since windows XP.
            #  Note that this fallback function seems to fail when
            #  this process is 32 bit Python and handle refers to a
            #  64-bit process.
            buffer_len = 256
            buffer = (c_wchar * buffer_len)()
            windll.psapi.GetModuleFileNameExW(handle, 0, pointer(buffer),
                                              buffer_len)
            buffer = buffer[:]
            buffer = buffer[:buffer.index("\0")]
        finally:
            windll.kernel32.CloseHandle(handle)

        return str(buffer)

    #-----------------------------------------------------------------------
    # Methods related to window geometry. 
开发者ID:dictation-toolbox,项目名称:dragonfly,代码行数:41,代码来源:win32_window.py

示例9: clear_line

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def clear_line(self,param):
			mode=param and int(param)or 0
			sbinfo=self.screen_buffer_info()
			if mode==1:
				line_start=COORD(0,sbinfo.CursorPosition.Y)
				line_length=sbinfo.Size.X
			elif mode==2:
				line_start=COORD(sbinfo.CursorPosition.X,sbinfo.CursorPosition.Y)
				line_length=sbinfo.Size.X-sbinfo.CursorPosition.X
			else:
				line_start=sbinfo.CursorPosition
				line_length=sbinfo.Size.X-sbinfo.CursorPosition.X
			chars_written=c_ulong()
			windll.kernel32.FillConsoleOutputCharacterW(self.hconsole,c_wchar(' '),line_length,line_start,byref(chars_written))
			windll.kernel32.FillConsoleOutputAttribute(self.hconsole,sbinfo.Attributes,line_length,line_start,byref(chars_written)) 
开发者ID:MOSAIC-UA,项目名称:802.11ah-ns3,代码行数:17,代码来源:ansiterm.py

示例10: test_aswidechar

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def test_aswidechar(self):
        from _testcapi import unicode_aswidechar
        support.import_module('ctypes')
        from ctypes import c_wchar, sizeof

        wchar, size = unicode_aswidechar('abcdef', 2)
        self.assertEqual(size, 2)
        self.assertEqual(wchar, 'ab')

        wchar, size = unicode_aswidechar('abc', 3)
        self.assertEqual(size, 3)
        self.assertEqual(wchar, 'abc')

        wchar, size = unicode_aswidechar('abc', 4)
        self.assertEqual(size, 3)
        self.assertEqual(wchar, 'abc\0')

        wchar, size = unicode_aswidechar('abc', 10)
        self.assertEqual(size, 3)
        self.assertEqual(wchar, 'abc\0')

        wchar, size = unicode_aswidechar('abc\0def', 20)
        self.assertEqual(size, 7)
        self.assertEqual(wchar, 'abc\0def\0')

        nonbmp = chr(0x10ffff)
        if sizeof(c_wchar) == 2:
            buflen = 3
            nchar = 2
        else: # sizeof(c_wchar) == 4
            buflen = 2
            nchar = 1
        wchar, size = unicode_aswidechar(nonbmp, buflen)
        self.assertEqual(size, nchar)
        self.assertEqual(wchar, nonbmp + '\0')

    # Test PyUnicode_AsWideCharString() 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:39,代码来源:test_unicode.py

示例11: xget_virtual_keycode

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def xget_virtual_keycode(cls, char):
        if isinstance(char, str):
            code = windll.user32.VkKeyScanA(c_char(char))
        else:
            code = windll.user32.VkKeyScanW(c_wchar(char))
        if code == -1:
            raise ValueError("Unknown char: %r" % char)

        # Construct a list of the virtual key code and modifiers.
        codes = [code & 0x00ff]
        if   code & 0x0100: codes.append(cls.shift_code)
        elif code & 0x0200: codes.append(cls.ctrl_code)
        elif code & 0x0400: codes.append(cls.alt_code)
        return codes 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:16,代码来源:keyboard.py

示例12: get_keycode_and_modifiers

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def get_keycode_and_modifiers(cls, char):
        if isinstance(char, str):
            code = windll.user32.VkKeyScanA(c_char(char))
        else:
            code = windll.user32.VkKeyScanW(c_wchar(char))
        if code == -1:
            raise ValueError("Unknown char: %r" % char)

        # Construct a list of the virtual key code and modifiers.
        modifiers = []
        if   code & 0x0100: modifiers.append(cls.shift_code)
        elif code & 0x0200: modifiers.append(cls.ctrl_code)
        elif code & 0x0400: modifiers.append(cls.alt_code)
        code &= 0x00ff
        return code, modifiers 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:17,代码来源:keyboard.py

示例13: _get_window_module

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _get_window_module(self):
        # Get this window's process ID.
        pid = c_ulong()
        windll.user32.GetWindowThreadProcessId(self._handle, pointer(pid))

        # Get the process handle of this window's process ID.
        #  Access permission flags:
        #  0x0410 = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ
        handle = windll.kernel32.OpenProcess(0x0410, 0, pid)

        # Retrieve and return the process's executable path.
        try:
            # Try to use the QueryForProcessImageNameW function
            #  available since Windows Vista.
            buffer_len = c_ulong(256)
            buffer = (c_wchar * buffer_len.value)()
            windll.kernel32.QueryFullProcessImageNameW(handle, 0,
                                                       pointer(buffer),
                                                       pointer(buffer_len))
            buffer = buffer[:]
            buffer = buffer[:buffer.index("\0")]
        except Exception:
            # If the function above failed, fall back to the older
            #  GetModuleFileNameEx function, available since windows XP.
            #  Note that this fallback function seems to fail when
            #  this process is 32 bit Python and handle refers to a
            #  64-bit process.
            buffer_len = 256
            buffer = (c_wchar * buffer_len)()
            windll.psapi.GetModuleFileNameExW(handle, 0, pointer(buffer),
                                              buffer_len)
            buffer = buffer[:]
            buffer = buffer[:buffer.index("\0")]
        finally:
            windll.kernel32.CloseHandle(handle)

        return str(buffer) 
开发者ID:t4ngo,项目名称:dragonfly,代码行数:39,代码来源:window.py

示例14: _parse_file_notification_information

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _parse_file_notification_information(buff, offset):
  """Parse FileNotificationInformation from a c_char buffer.

  Args:
    buff: a ctypes string buffer that contains
         a FileNotificationInformation structure.
    offset: the offset you want to parse the struct from.

  Returns:
    a class matching the structure.
  """
  notify_information_short = ctypes.cast(
      ctypes.addressof(buff) + offset,
      ctypes.POINTER(FileNotifyInformationShort)).contents
  # This is a variable length structure so we need to do a 2 steps parse to
  # create a perfectly matching result.
  chr_len = notify_information_short.FileNameLength / _WCHAR_BYTESIZE

  class FileNotifyInformation(ctypes.Structure):
    _fields_ = (
        _COMMON_FILE_NOTIFY_FIELDS +
        [('FileName', ctypes.c_wchar * chr_len)])
  return ctypes.cast(ctypes.addressof(buff) + offset,
                     ctypes.POINTER(FileNotifyInformation)).contents


# we want to be sure that at least one notification fits even if it is a big
# one. 
开发者ID:GoogleCloudPlatform,项目名称:python-compat-runtime,代码行数:30,代码来源:win32_file_watcher.py

示例15: _handle_field_getattr

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_wchar [as 别名]
def _handle_field_getattr(self, ftype, fosset, fsize):
        s = self._target.read_memory(self._base_addr + fosset, fsize)
        if ftype in self._field_type_to_remote_type:
            return self._field_type_to_remote_type[ftype].from_buffer_with_target(bytearray(s), target=self._target).value
        if issubclass(ftype, _ctypes._Pointer):  # Pointer
            return RemoteStructurePointer.from_buffer_with_target_and_ptr_type(bytearray(s), target=self._target, ptr_type=ftype)
        if issubclass(ftype, RemotePtr64):  # Pointer to remote64 bits process
            return RemoteStructurePointer64.from_buffer_with_target_and_ptr_type(bytearray(s), target=self._target, ptr_type=ftype)
        if issubclass(ftype, RemotePtr32):  # Pointer to remote32 bits process
            return RemoteStructurePointer32.from_buffer_with_target_and_ptr_type(bytearray(s), target=self._target, ptr_type=ftype)
        if issubclass(ftype, RemoteStructureUnion):  # Structure|Union already transfomed in remote
            return ftype(self._base_addr + fosset, self._target)
        if issubclass(ftype, ctypes.Structure):  # Structure that must be transfomed
            return RemoteStructure.from_structure(ftype)(self._base_addr + fosset, self._target)
        if issubclass(ftype, ctypes.Union):  # Union that must be transfomed
            return RemoteUnion.from_structure(ftype)(self._base_addr + fosset, self._target)
        if issubclass(ftype, _ctypes.Array):  # Arrays
            # if this is a string: just cast the read value to string
            if ftype._type_ == ctypes.c_char: # Use issubclass instead ?
                return s.split("\x00", 1)[0]
            elif ftype._type_ == ctypes.c_wchar: # Use issubclass instead ?
                # Decode from utf16 -> size /=2 | put it in a wchar array | split at the first "\x00"
                return (ftype._type_ * (fsize / 2)).from_buffer_copy(s.decode('utf16'))[:].split("\x00", 1)[0] # Sorry..
            # I am pretty sur something smarter is possible..
            return create_remote_array(ftype._type_, ftype._length_)(self._base_addr + fosset, self._target)
        # Normal types
        # Follow the ctypes usage: if it's not directly inherited from _SimpleCData
        # We do not apply the .value
        # Seems weird but it's mandatory AND useful :D (in pe_parse)
        if _SimpleCData not in ftype.__bases__:
            return ftype.from_buffer(bytearray(s))
        return ftype.from_buffer(bytearray(s)).value 
开发者ID:hakril,项目名称:PythonForWindows,代码行数:34,代码来源:remotectypes.py


注:本文中的ctypes.c_wchar方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。