python类memmove()的实例源码

protocol.py 文件源码 项目:gps_track_pod 作者: iwanders 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def load_settings(cls, b):
        a = cls()
        ctypes.memmove(ctypes.addressof(a.start_of_settings), bytes(b),
                       min(len(b), ctypes.sizeof(a)))
        return a
protocol.py 文件源码 项目:gps_track_pod 作者: iwanders 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def read(cls, byte_object):
        a = cls()
        a.body_length = len(byte_object) - ctypes.sizeof(Command)
        ctypes.memmove(ctypes.addressof(a), bytes(byte_object),
                       min(len(byte_object), ctypes.sizeof(cls)))
        return a
protocol.py 文件源码 项目:gps_track_pod 作者: iwanders 项目源码 文件源码 阅读 49 收藏 0 点赞 0 评论 0
def __bytes__(self):
        length = self.body_length + ctypes.sizeof(Command)
        a = ctypes.create_string_buffer(length)
        ctypes.memmove(ctypes.addressof(a), ctypes.addressof(self), length)
        return bytes(a)
protocol.py 文件源码 项目:gps_track_pod 作者: iwanders 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def load_payload(self, b):
        self.body_length = len(b) + 8  # II from position, length
        ctypes.memmove(ctypes.addressof(self.data_reply.data), bytes(b),
                       len(b))
        self.command.packet_length = self.body_length
syswow64.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def try_generate_stub_target(shellcode, argument_buffer, target, errcheck=None):
    if not windows.current_process.is_wow_64:
        raise ValueError("Calling execute_64bits_code_from_syswow from non-syswow process")
    native_caller = generate_64bits_execution_stub_from_syswow(shellcode)
    native_caller.errcheck = errcheck if errcheck is not None else target.errcheck
    # Generate the wrapper function that fill the argument_buffer
    expected_arguments_number = len(target.prototype._argtypes_)
    def wrapper(*args):
        if len(args) != expected_arguments_number:
            raise ValueError("{0} syswow accept {1} args ({2} given)".format(target.__name__, expected_arguments_number, len(args)))
        # Transform args (ctypes byref possibly) to int
        writable_args = []
        for i, value in enumerate(args):
            if not isinstance(value, (int, long)):
                try:
                    value = ctypes.cast(value, ctypes.c_void_p).value
                except ctypes.ArgumentError as e:
                    raise ctypes.ArgumentError("Argument {0}: wrong type <{1}>".format(i, type(value).__name__))
            writable_args.append(value)
        # Build buffer
        buffer = struct.pack("<" + "Q" * len(writable_args), *writable_args)
        ctypes.memmove(argument_buffer, buffer, len(buffer))
        # Copy origincal args in function, for errcheck if needed
        native_caller.current_original_args = args # TODO: THIS IS NOT THREAD SAFE
        return native_caller()
    wrapper.__name__ = "{0}<syswow64>".format(target.__name__,)
    wrapper.__doc__ = "This is a wrapper to {0} in 64b mode, it accept <{1}> args".format(target.__name__, expected_arguments_number)
    return wrapper
pythonutils.py 文件源码 项目:PythonForWindows 作者: hakril 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def swallow_ctypes_copy(ctypes_object):
    new_copy = type(ctypes_object)()
    ctypes.memmove(ctypes.byref(new_copy), ctypes.byref(ctypes_object), ctypes.sizeof(new_copy))
    return new_copy


# type replacement based on name
system.py 文件源码 项目:llk 作者: Tycx2ry 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _set_argv(process_name):
  """
  Overwrites our argv in a similar fashion to how it's done in C with:
  strcpy(argv[0], 'new_name');
  """

  if Py_GetArgcArgv is None:
    return

  global _PROCESS_NAME

  # both gets the current process name and initializes _MAX_NAME_LENGTH

  current_name = get_process_name()

  argv, argc = ctypes.c_int(0), argc_t()
  Py_GetArgcArgv(argv, ctypes.pointer(argc))

  if len(process_name) > _MAX_NAME_LENGTH:
    raise IOError("Can't rename process to something longer than our initial name (this would overwrite memory used for the env)")

  # space we need to clear
  zero_size = max(len(current_name), len(process_name))

  ctypes.memset(argc.contents, 0, zero_size + 1)  # null terminate the string's end
  process_name_encoded = process_name.encode('utf8')
  ctypes.memmove(argc.contents, process_name_encoded, len(process_name))
  _PROCESS_NAME = process_name
backend_ctypes.py 文件源码 项目:SwiftKitten 作者: johncsnyder 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
_freeimage.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _finish_wrapped_array(self, array):  # IS_PYPY
        """ Hardcore way to inject numpy array in bitmap.
        """
        # Get bitmap info
        with self._fi as lib:
            pitch = lib.FreeImage_GetPitch(self._bitmap)
            bits = lib.FreeImage_GetBits(self._bitmap)
            bpp = lib.FreeImage_GetBPP(self._bitmap)
        # Get channels and realwidth
        nchannels = bpp // 8 // array.itemsize
        realwidth = pitch // nchannels
        # Apply padding for pitch if necessary
        extra = realwidth - array.shape[-2]
        assert extra >= 0 and extra < 10
        # Make sort of Fortran, also take padding (i.e. pitch) into account
        newshape = array.shape[-1], realwidth, nchannels
        array2 = numpy.zeros(newshape, array.dtype)
        if nchannels == 1:
            array2[:, :array.shape[-2], 0] = array.T
        else:
            for i in range(nchannels):
                array2[:, :array.shape[-2], i] = array[i, :, :].T
        # copy data
        data_ptr = array2.__array_interface__['data'][0]
        ctypes.memmove(bits, data_ptr, array2.nbytes)
        del array2
_ffi.py 文件源码 项目:pyShadowsocks 作者: FTwOoO 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def write_to_buffer(buffer, data, offset=0):
    if isinstance(buffer, ctypes.POINTER(ctypes.c_byte)):
        ctypes.memmove(buffer, data, len(data))
        return

    if offset == 0:
        buffer.value = data
    else:
        buffer.value = buffer.raw[0:offset] + data
_ffi.py 文件源码 项目:pyShadowsocks 作者: FTwOoO 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def struct_from_buffer(library, type_, buffer):
    class_ = getattr(library, type_)
    value = class_()
    ctypes.memmove(ctypes.addressof(value), buffer, ctypes.sizeof(class_))
    return ctypes.pointer(value)
system.py 文件源码 项目:spiderfoot 作者: wi-fi-analyzer 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _set_argv(process_name):
  """
  Overwrites our argv in a similar fashion to how it's done in C with:
  strcpy(argv[0], 'new_name');
  """

  if Py_GetArgcArgv is None:
    return

  global _PROCESS_NAME

  # both gets the current process name and initializes _MAX_NAME_LENGTH

  current_name = get_process_name()

  argv, argc = ctypes.c_int(0), argc_t()
  Py_GetArgcArgv(argv, ctypes.pointer(argc))

  if len(process_name) > _MAX_NAME_LENGTH:
    raise IOError("Can't rename process to something longer than our initial name (this would overwrite memory used for the env)")

  # space we need to clear
  zero_size = max(len(current_name), len(process_name))

  ctypes.memset(argc.contents, 0, zero_size + 1)  # null terminate the string's end
  process_name_encoded = process_name.encode('utf8')
  ctypes.memmove(argc.contents, process_name_encoded, len(process_name))
  _PROCESS_NAME = process_name
backend_ctypes.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
backend_ctypes.py 文件源码 项目:git_intgrtn_aws_s3 作者: droidlabour 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
backend_ctypes.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
backend_ctypes.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
backend_ctypes.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
backend_ctypes.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def write_variable(self, BType, name, value):
        new_ctypes_obj = BType._to_ctypes(value)
        ctypes_obj = BType._ctype.in_dll(self.cdll, name)
        ctypes.memmove(ctypes.addressof(ctypes_obj),
                       ctypes.addressof(new_ctypes_obj),
                       ctypes.sizeof(BType._ctype))
PyKinectInfraRed.py 文件源码 项目:python-kinect 作者: jgerschler 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def draw_infrared_frame(self, frame, target_surface):
        if frame is None:  # some usb hub do not provide the infrared image. it works with Kinect studio though
            return
        target_surface.lock()
        f8=np.uint8(frame.clip(1,4000)/16.)
        frame8bit=np.dstack((f8,f8,f8))
        address = self._kinect.surface_as_array(target_surface.get_buffer())
        ctypes.memmove(address, frame8bit.ctypes.data, frame8bit.size)
        del address
        target_surface.unlock()
PyKinectBodyGame.py 文件源码 项目:python-kinect 作者: jgerschler 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def draw_color_frame(self, frame, target_surface):
        target_surface.lock()
        address = self._kinect.surface_as_array(target_surface.get_buffer())
        ctypes.memmove(address, frame.ctypes.data, frame.size)
        del address
        target_surface.unlock()


问题


面经


文章

微信
公众号

扫码关注公众号