Python ctypes 模块,Union() 实例源码

我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用ctypes.Union()

项目:noc-orchestrator    作者:DirceuSilvaLabs    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:PythonForWindows    作者:hakril    | 项目源码 | 文件源码
def is_union_type(x):
    return issubclass(x, ctypes.Union)

# ### My types ### #

# # 64bits pointer types # #

# I know direct inheritance from _SimpleCData seems bad
# But it seems to be the only way to have the normal
# ctypes.Structure way of working (need to investigate)
项目:PythonForWindows    作者:hakril    | 项目源码 | 文件源码
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
项目:SwiftKitten    作者:johncsnyder    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:aws-cfn-plex    作者:lordmuffin    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:git_intgrtn_aws_s3    作者:droidlabour    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:Intranet-Penetration    作者:yuxiaokui    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:MKFQ    作者:maojingios    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:bawk    作者:jttwnsnd    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:aws-lambda-python-codecommit-s3-deliver    作者:0xlen    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:OneClickDTU    作者:satwikkansal    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:xxNet    作者:drzorm    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:gardenbot    作者:GoestaO    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:slack_scholar    作者:xLeitix    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:vkstruct    作者:cheery    | 项目源码 | 文件源码
def create_ctype(self):
        self.ctype = type(self.name.encode('utf-8'), (ctypes.Union,), dict(
            _fields_ = [
                (name, get_ctype(value))
                for name, value in self.fields]))
项目:vkstruct    作者:cheery    | 项目源码 | 文件源码
def must_fill(field):
    return isinstance(field, (Union, Structure, Array))
项目:ropi    作者:ThumbGen    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:RemoteTree    作者:deNULL    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:python-ioctl    作者:olavmrk    | 项目源码 | 文件源码
def check_ctypes_datatype(datatype):
    valid_datatypes = (
        ctypes._SimpleCData,
        ctypes.Union,
        ctypes.BigEndianStructure,
        ctypes.LittleEndianStructure,
        ctypes.Structure,
        )
    for t in valid_datatypes:
        if issubclass(datatype, t):
            return
    raise TypeError('datatype must be a ctypes data type, but was {}'.format(datatype.__name__))
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:quickstart-git2s3    作者:aws-quickstart    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:Docker-XX-Net    作者:kuanghy    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:python-vulkan-wrapper    作者:gabdube    | 项目源码 | 文件源码
def define_union(name, *args):
    return type(name, (Union,), {'_fields_': args, '__repr__': repr_fn})
项目:PyQYT    作者:collinsctk    | 项目源码 | 文件源码
def new_union_type(self, name):
        return self._new_struct_or_union('union', name, ctypes.Union)
项目:devito    作者:opesci    | 项目源码 | 文件源码
def ctypes_to_C(ctype):
    """Map ctypes types to C types."""
    if issubclass(ctype, ctypes.Structure):
        return 'struct %s' % ctype.__name__
    elif issubclass(ctype, ctypes.Union):
        return 'union %s' % ctype.__name__
    elif ctype.__name__.startswith('c_'):
        # FIXME: Is there a better way of extracting the C typename ?
        # Here, we're following the ctypes convention that each basic type has
        # the format c_X_p, where X is the C typename, for instance `int` or `float`.
        return ctype.__name__[2:-2]
    else:
        raise TypeError('Unrecognised %s during converstion to C type' % str(ctype))