本文整理汇总了Python中ctypes.c_buffer方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.c_buffer方法的具体用法?Python ctypes.c_buffer怎么用?Python ctypes.c_buffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ctypes
的用法示例。
在下文中一共展示了ctypes.c_buffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: hardware_info
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def hardware_info(serial_number):
"""
Retrieves hardware information about the devices identified by its
serial number.
Parameters
----------
serial_number : int
Serial number identifying the device
Returns
-------
out : tuple
hardware information: (model, software version, hardware notes)
"""
model = ctypes.c_buffer(255)
swver = ctypes.c_buffer(255)
hwnotes = ctypes.c_buffer(255)
err_code = _lib.GetHWInfo(serial_number, model, len(model),
swver, len(swver), hwnotes, len(hwnotes))
if (err_code != 0):
raise Exception("Getting hardware info failed: %s" %
_get_error_text(err_code))
return (model.value, swver.value, hwnotes.value)
示例2: readSmart
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def readSmart(self):
buf = ctypes.c_buffer(512)
buf = self.readSmartValues()
self.selftestStatus = int.from_bytes(buf[363], byteorder='little')
self.smart = {}
for i in range(30):
if buf[2 + i * 12] == b'\x00':
continue
aid = int.from_bytes(buf[2 + i * 12], byteorder='little')
pre_fail = int.from_bytes(buf[2 + i * 12 + 1], byteorder='little') & 1
online = (int.from_bytes(buf[2 + i * 12 + 1], byteorder='little') & 2) >> 1
current = int.from_bytes(buf[2 + i * 12 + 3], byteorder='little')
if current == 0 or current == 0xfe or current == 0xff:
continue
worst = int.from_bytes(buf[2 + i * 12 + 4], byteorder='little')
raw = int.from_bytes(buf[2 + i * 12 + 5] + buf[2 + i * 12 + 6] + buf[2 + i * 12 + 7] +
buf[2 + i * 12 + 8] + buf[2 + i * 12 + 9] + buf[2 + i * 12 + 10], byteorder='little')
self.smart[aid] = [pre_fail, online, current, worst, raw]
buf = self.readSmartThresholds()
for i in range(30):
if buf[2 + i * 12] == b'\x00':
continue
aid = int.from_bytes(buf[2 + i * 12], byteorder='little')
if aid in self.smart:
self.smart[aid].append(int.from_bytes(buf[2 + i * 12 + 1], byteorder='little'))
示例3: securityDisable
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def securityDisable(self, master, password):
buf = ctypes.c_buffer(512)
if master:
buf[0] = 1
else:
buf[0] = 0
pwd = str.encode(password)
i = 2
for b in pwd:
buf[i] = b
i = i + 1
self.prepareSgio(SECURITY_DISABLE_PASSWORD, 0, 0, 0, SG_DXFER_TO_DEV, buf)
self.clearSense()
self.doSgio()
try:
self.checkSense()
except senseError:
raise securityError()
示例4: securityUnlock
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def securityUnlock(self, master, password):
buf = ctypes.c_buffer(512)
if master:
buf[0] = 1
else:
buf[0] = 0
pwd = str.encode(password)
i = 2
for b in pwd:
buf[i] = b
i = i + 1
self.prepareSgio(SECURITY_UNLOCK, 0, 0, 0, SG_DXFER_TO_DEV, buf)
self.clearSense()
self.doSgio()
try:
self.checkSense()
except senseError:
raise securityError()
示例5: securitySetPassword
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def securitySetPassword(self, master, capability, password):
buf = ctypes.c_buffer(512)
if master:
buf[0] = 1
else:
buf[0] = 0
if capability:
buf[1] = 1
pwd = str.encode(password)
i = 2
for b in pwd:
buf[i] = b
i = i + 1
self.prepareSgio(SECURITY_SET_PASSWORD, 0, 0, 0, SG_DXFER_TO_DEV, buf)
self.clearSense()
self.doSgio()
try:
self.checkSense()
except senseError:
raise securityError()
示例6: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def __init__(self, vertex_source, fragment_source=None):
vertex_shader = self._create_shader(GL_VERTEX_SHADER, vertex_source)
if fragment_source:
fragment_shader = self._create_shader(GL_FRAGMENT_SHADER,
fragment_source)
program = glCreateProgram()
glAttachShader(program, vertex_shader)
if fragment_source:
glAttachShader(program, fragment_shader)
glLinkProgram(program)
status = ctypes.c_int()
glGetProgramiv(program, GL_LINK_STATUS, status)
if not status.value:
length = ctypes.c_int()
glGetProgramiv(program, GL_INFO_LOG_LENGTH, length)
log = ctypes.c_buffer(length.value)
glGetProgramInfoLog(program, len(log), None, log)
print(log.value, file=sys.stderr)
raise RuntimeError('Program link error')
self.program = program
self._uniforms = {}
示例7: _create_shader
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def _create_shader(self, type, source):
shader = glCreateShader(type)
c_source = ctypes.create_string_buffer(source)
c_source_ptr = ctypes.cast(ctypes.pointer(c_source),
ctypes.POINTER(c_char))
glShaderSource(shader, 1, ctypes.byref(c_source_ptr), None)
glCompileShader(shader)
status = ctypes.c_int()
glGetShaderiv(shader, GL_COMPILE_STATUS, status)
if not status.value:
length = ctypes.c_int()
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, length)
log = ctypes.c_buffer(length.value)
glGetShaderInfoLog(shader, len(log), None, log)
print(log.value, file=sys.stderr)
raise RuntimeError('Shader compile error')
return shader
示例8: render
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def render(self, ctx, rtype):
size = 0x10000
buffer = ctypes.c_buffer(size)
rsize = gdef.DWORD()
elementnb = gdef.DWORD()
try:
windows.winproxy.EvtRender(ctx, self, rtype, size, buffer, rsize, elementnb)
except WindowsError as e:
if e.winerror != gdef.ERROR_INSUFFICIENT_BUFFER:
raise
size = rsize.value
buffer = ctypes.c_buffer(size)
windows.winproxy.EvtRender(ctx, self, rtype, size, buffer, rsize, elementnb)
# Adapting return value type
if rtype != gdef.EvtRenderEventValues:
# import pdb;pdb.set_trace()
# assert elementnb.value == 1
return buffer[:rsize.value]
# print("Got <{0}> elt".format(elementnb.value))
return list((ImprovedEVT_VARIANT * elementnb.value).from_buffer(buffer))
示例9: get_param
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def get_param(self, param_type, index=0, raw=False):
data_size = gdef.DWORD()
# https://msdn.microsoft.com/en-us/library/windows/desktop/aa380227(v=vs.85).aspx
winproxy.CryptMsgGetParam(self, param_type, index, None, data_size)
buffer = ctypes.c_buffer(data_size.value)
winproxy.CryptMsgGetParam(self, param_type, index, buffer, data_size)
if raw:
return (buffer, data_size)
if param_type in self.MSG_PARAM_KNOW_TYPES:
buffer = self.MSG_PARAM_KNOW_TYPES[param_type].from_buffer(buffer)
if isinstance(buffer, gdef.DWORD): # DWORD -> return the Python int
return buffer.value
return buffer
# Certificate accessors
示例10: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def __init__(self, msg_or_size=0x1000, attributes=None):
# Init the PORT_MESSAGE
if isinstance(msg_or_size, windows.pycompat.int_types):
self.port_message_buffer_size = msg_or_size
self.port_message_raw_buffer = ctypes.c_buffer(msg_or_size)
self.port_message = AlpcMessagePort.from_buffer(self.port_message_raw_buffer)
self.port_message.set_datalen(0)
elif isinstance(msg_or_size, AlpcMessagePort):
self.port_message = msg_or_size
self.port_message_raw_buffer = self.port_message.raw_buffer
self.port_message_buffer_size = len(self.port_message_raw_buffer)
else:
raise NotImplementedError("Uneexpected type for <msg_or_size>: {0}".format(msg_or_size))
# Init the MessageAttributes
if attributes is None:
# self.attributes = MessageAttribute.with_all_attributes()
self.attributes = MessageAttribute.with_all_attributes() ## Testing
else:
self.attributes = attributes
# PORT_MESSAGE wrappers
示例11: dpapi_encrypt_data
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def dpapi_encrypt_data(self, input_bytes, entropy = extra_entropy):
'''
Encrypts data and returns byte string
:param input_bytes: The data to be encrypted
:type input_bytes: String or Bytes
:param entropy: Extra entropy to add to the encryption process (optional)
:type entropy: String or Bytes
'''
if not isinstance(input_bytes, bytes) or not isinstance(entropy, bytes):
self.fatal('The inputs to dpapi must be bytes')
buffer_in = c_buffer(input_bytes, len(input_bytes))
buffer_entropy = c_buffer(entropy, len(entropy))
blob_in = DATA_BLOB(len(input_bytes), buffer_in)
blob_entropy = DATA_BLOB(len(entropy), buffer_entropy)
blob_out = DATA_BLOB()
if CryptProtectData(byref(blob_in), 'python_data', byref(blob_entropy),
None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blob_out)):
return get_data(blob_out)
else:
self.fatal('Failed to decrypt data')
示例12: dpapi_decrypt_data
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def dpapi_decrypt_data(self, encrypted_bytes, entropy = extra_entropy):
'''
Decrypts data and returns byte string
:param encrypted_bytes: The encrypted data
:type encrypted_bytes: Bytes
:param entropy: Extra entropy to add to the encryption process (optional)
:type entropy: String or Bytes
'''
if not isinstance(encrypted_bytes, bytes) or not isinstance(entropy, bytes):
self.fatal('The inputs to dpapi must be bytes')
buffer_in = c_buffer(encrypted_bytes, len(encrypted_bytes))
buffer_entropy = c_buffer(entropy, len(entropy))
blob_in = DATA_BLOB(len(encrypted_bytes), buffer_in)
blob_entropy = DATA_BLOB(len(entropy), buffer_entropy)
blob_out = DATA_BLOB()
if CryptUnprotectData(byref(blob_in), None, byref(blob_entropy), None,
None, CRYPTPROTECT_UI_FORBIDDEN, byref(blob_out)):
return get_data(blob_out)
else:
self.fatal('Failed to decrypt data')
示例13: _windows_ctypes_host
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def _windows_ctypes_host(host):
# type: (str) -> Optional[str]
if not PY2: # Convert to bytes on Python 3+ (Fixes GitHub issue #7)
host = host.encode() # type: ignore
try:
inetaddr = ctypes.windll.wsock32.inet_addr(host) # type: ignore
if inetaddr in (0, -1):
raise Exception
except Exception:
hostip = socket.gethostbyname(host)
inetaddr = ctypes.windll.wsock32.inet_addr(hostip) # type: ignore
buffer = ctypes.c_buffer(6)
addlen = ctypes.c_ulong(ctypes.sizeof(buffer))
send_arp = ctypes.windll.Iphlpapi.SendARP # type: ignore
if send_arp(inetaddr, 0, ctypes.byref(buffer), ctypes.byref(addlen)) != 0:
return None
# Convert binary data into a string.
macaddr = ''
for intval in struct.unpack('BBBBBB', buffer): # type: ignore
if intval > 15:
replacestr = '0x'
else:
replacestr = 'x'
macaddr = ''.join([macaddr, hex(intval).replace(replacestr, '')])
return macaddr
示例14: __init__
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def __init__(self, dev):
self.smart = {}
self.ssd = 0
self.duration = 0
self.timeout = 1000 # in milliseconds
self.readCommand = ATA_READ_SECTORS
self.verifyCommand = ATA_READ_VERIFY_SECTORS
self.writeCommand = ATA_WRITE_SECTORS
self.sense = ctypes.c_buffer(64)
self.checkExists(dev)
self.devIdentify()
示例15: readSectors
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import c_buffer [as 别名]
def readSectors(self, count, start):
buf = ctypes.c_buffer(count * self.logicalSectorSize)
self.prepareSgio(self.readCommand, 0, count, start, SG_DXFER_FROM_DEV, buf)
self.clearSense()
self.doSgio()
self.checkSense()
return buf