def list_guest_processes(self): job_handle = vixlib.VixVM_ListProcessesInGuest(self._vm_handle, 0, None, None) err = vixlib.VixJob_Wait(job_handle, vixlib.VIX_PROPERTY_NONE) try: _check_job_err_code(err) process_count = vixlib.VixJob_GetNumProperties( job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_ITEM_NAME) processes = [] for i in range(process_count): process_name = ctypes.c_char_p() owner = ctypes.c_char_p() cmdline = ctypes.c_char_p() pid = ctypes.c_uint64() is_debugged = ctypes.c_bool() start_time = ctypes.c_int() err = vixlib.VixJob_GetNthProperties( job_handle, i, vixlib.VIX_PROPERTY_JOB_RESULT_ITEM_NAME, ctypes.byref(process_name), vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_ID, ctypes.byref(pid), vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_OWNER, ctypes.byref(owner), vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_COMMAND, ctypes.byref(cmdline), vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_BEING_DEBUGGED, ctypes.byref(is_debugged), vixlib.VIX_PROPERTY_JOB_RESULT_PROCESS_START_TIME, ctypes.byref(start_time), vixlib.VIX_PROPERTY_NONE) processes.append( dict(pid=pid.value, name=process_name.value, owner=owner.value, cmdline=cmdline.value, is_debugged=is_debugged.value, start_time=start_time.value)) vixlib.Vix_FreeBuffer(process_name) vixlib.Vix_FreeBuffer(owner) vixlib.Vix_FreeBuffer(cmdline) finally: vixlib.Vix_ReleaseHandle(job_handle) return processes
def capture_guest_screenshot(self, screenshot_path): data_blob = ctypes.c_void_p() data_size = ctypes.c_size_t() job_handle = vixlib.VixVM_CaptureScreenImage( self._vm_handle, vixlib.VIX_CAPTURESCREENFORMAT_PNG, vixlib.VIX_INVALID_HANDLE, None, # callback None) # client data err = vixlib.VixJob_Wait( job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_SCREEN_IMAGE_DATA, ctypes.byref(data_size), ctypes.byref(data_blob), vixlib.VIX_PROPERTY_NONE) vixlib.Vix_ReleaseHandle(job_handle) _check_job_err_code(err) try: buff = (ctypes.c_char * data_size.value).from_address( data_blob.value) with open(screenshot_path, "wb") as fp: fp.write(buff) finally: vixlib.Vix_FreeBuffer(data_blob) return screenshot_path, data_size
def guest_os_str(self): if self._guest_os_str is None: guest_os = ctypes.c_char_p() err = vixlib.Vix_GetProperties(self._vm_handle, vixlib.VIX_PROPERTY_VM_GUESTOS, ctypes.byref(guest_os), vixlib.VIX_PROPERTY_NONE) _check_job_err_code(err) self._guest_os_str = guest_os.value vixlib.Vix_FreeBuffer(guest_os) return self._guest_os_str
def get_vmteam_path(self): vmx_path = ctypes.c_char_p() try: err = vixlib.Vix_GetProperties( self._vm_handle, vixlib.VIX_PROPERTY_VM_VMTEAM_PATHNAME, ctypes.byref(vmx_path), vixlib.VIX_PROPERTY_NONE) _check_job_err_code(err) return vmx_path.value finally: vixlib.Vix_FreeBuffer(vmx_path)
def name(self): if not self._vm_name: vm_name = ctypes.c_char_p() err = vixlib.Vix_GetProperties(self._vm_handle, vixlib.VIX_PROPERTY_VM_NAME, ctypes.byref(vm_name), vixlib.VIX_PROPERTY_NONE) _check_job_err_code(err) self._vm_name = vm_name.value vixlib.Vix_FreeBuffer(vm_name) return self._vm_name
def callback(jobHandle, eventType, moreEventInfo, clientData): if vixlib.VIX_EVENTTYPE_FIND_ITEM != eventType: return url = ctypes.c_char_p() err = vixlib.Vix_GetProperties( moreEventInfo, vixlib.VIX_PROPERTY_FOUND_ITEM_LOCATION, ctypes.byref(url), vixlib.VIX_PROPERTY_NONE) vmx_paths.append(url.value) vixlib.Vix_FreeBuffer(url) _check_job_err_code(err)
def get_vmx_path(self): if not self._vmx_path: vmx_path = ctypes.c_char_p() err = vixlib.Vix_GetProperties(self._vm_handle, vixlib.VIX_PROPERTY_VM_VMX_PATHNAME, ctypes.byref(vmx_path), vixlib.VIX_PROPERTY_NONE) _check_job_err_code(err) self._vmx_path = vmx_path.value vixlib.Vix_FreeBuffer(vmx_path) return self._vmx_path
def get_software_version(self): assert self.connected, "VixConnection not connected" if not self._software_version: version = ctypes.c_char_p() err = vixlib.Vix_GetProperties( self._host_handle, vixlib.VIX_PROPERTY_HOST_SOFTWARE_VERSION, ctypes.byref(version), vixlib.VIX_PROPERTY_NONE) _check_job_err_code(err) self._software_version = version.value vixlib.Vix_FreeBuffer(version) return self._software_version
def read_guest_variable_str(self, variable_name, variable_type=vixlib.VIX_VM_GUEST_VARIABLE, timeout=30): if variable_type in (vixlib.VIX_VM_GUEST_VARIABLE, vixlib.VIX_GUEST_ENVIRONMENT_VARIABLE): self.wait_for_tools_in_guest(timeout) job_handle = vixlib.VixVM_ReadVariable(self._vm_handle, variable_type, variable_name, 0, None, None) read_value = ctypes.c_char_p() err = vixlib.VixJob_Wait( job_handle, vixlib.VIX_PROPERTY_JOB_RESULT_VM_VARIABLE_STRING, ctypes.byref(read_value), vixlib.VIX_PROPERTY_NONE) vixlib.Vix_ReleaseHandle(job_handle) _check_job_err_code(err) value = read_value.value vixlib.Vix_FreeBuffer(read_value) return value