def decompress(self, in_buffer, in_len, out_len): self.prepare_library() assert len(in_buffer) >= in_len in_buffer = ctypes.create_string_buffer(in_buffer) out_buffer = ctypes.create_string_buffer(out_len) # p0 = ctypes.POINTER(ctypes.c_uint64)() # p1 = ctypes.POINTER(ctypes.c_uint64)() # p2 = ctypes.POINTER(ctypes.c_int64)() p0 = 0 # ctypes.POINTER(ctypes.c_uint64)() p1 = 0 # ctypes.POINTER(ctypes.c_uint64)() p2 = 0 # ctypes.POINTER(ctypes.c_int64)() ret = self._decompress(in_buffer, in_len, out_buffer, out_len, 1, 0, 0, p0, 0, p1, 0, p2, 0, 3) out_buffer = out_buffer.raw return out_buffer, ret
def replace_letter_in_null_terminated_string_buff(self, in_string, old_letter, new_letter): string_buffer = ctypes.create_string_buffer(in_string.encode('utf-8')) self.__replace_letter_in_null_terminated_string__( string_buffer, old_letter.encode('utf-8'), new_letter.encode('utf-8')) return string_buffer.value.decode('utf-8')
def tag_string(self, in_string): in_buffer = ctypes.create_string_buffer(in_string.encode('utf-8')) out_buffer = ctypes.pointer(ctypes.c_void_p()) self.__tag_string__(in_buffer, out_buffer) return ctypes.cast( out_buffer.contents, ctypes.POINTER(ctypes.c_char * (len(in_buffer) + 2)) ).contents[:].decode('utf-8').rstrip('\0')
def setIniPath(self, ini_path): """ Set the path of ini (configuration) file. TODO: Check if this function work. :param ini_path: The ini file path to be set. Can be set to NULL(0) to reset to the default path. :type ini_path: str :return: error code :rtype: int """ self.ini_path_ptr_ = create_string_buffer(ini_path.encode('utf-8')) return self.__SetIniPath__(self.ini_path_ptr_)
def replace_letter_in_null_terminated_string(self, in_string, old_letter, new_letter): BUFFER_LENGTH = 128 string_buffer = ctypes.create_string_buffer(BUFFER_LENGTH) string_buffer.value = in_string.encode('utf-8') self.__replace_letter_in_null_terminated_string__( string_buffer, old_letter.encode('utf-8'), new_letter.encode('utf-8')) return string_buffer.value.decode('utf-8')