void vmware_set_clipboard(char *buf) { struct vm_backdoor frame; uint32_t total, left; if (debug) { char visbuf[strlen(buf) * 4]; strnvis(visbuf, buf, sizeof(visbuf), VIS_TAB | VIS_NL | VIS_CSTYLE); printf("vmware_set_clipboard: \"%s\"\n", visbuf); } if (!strlen(buf)) return; bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_SET_CLIPBOARD_LEN; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; frame.ebx.word = (uint32_t)strlen(buf); vm_cmd(&frame); total = left = strlen(buf); for (;;) { bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_SET_CLIPBOARD; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; memcpy(&frame.ebx.word, buf + (total - left), left > 4 ? 4 : left); vm_cmd(&frame); if (left <= 4) break; else left -= 4; } return; }
static bool vmt_probe(uint32_t *type) { struct vm_backdoor frame; memset(&frame, 0, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ebx.word = ~VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_VERSION; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; vm_cmd(&frame); if (frame.eax.word == 0xffffffff || frame.ebx.word != VM_MAGIC) return false; if (type) *type = frame.ecx.word; return true; }
void vmware_get_mouse_position(void) { struct vm_backdoor frame; int last_x = host_mouse_x; int last_y = host_mouse_y; int was_grabbed = mouse_grabbed; bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_MOUSEPOS; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; vm_cmd(&frame); host_mouse_x = frame.eax.word >> 16; host_mouse_y = frame.eax.word & 0xffff; if (host_mouse_x == VM_MOUSE_UNGRABBED_POS) mouse_grabbed = 0; else mouse_grabbed = 1; if (debug && ((last_x != host_mouse_x) || (last_y != host_mouse_y) || (was_grabbed != mouse_grabbed))) printf("vmware_get_mouse_position: host cursor is at %d, %d (%s)\n", host_mouse_x, host_mouse_y, (mouse_grabbed ? "grabbed" : "ungrabbed")); }
static void vmt_sync_guest_clock(struct vmt_softc *sc) { struct vm_backdoor frame; struct timespec ts; memset(&frame, 0, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_TIME_FULL; frame.edx.part.low = VM_PORT_CMD; vm_cmd(&frame); if (frame.eax.word != 0xffffffff) { ts.tv_sec = ((uint64_t)frame.esi.word << 32) | frame.edx.word; ts.tv_nsec = frame.ebx.word * 1000; tc_setclock(&ts); } }
void vmware_set_mouse_position(int x, int y) { struct vm_backdoor frame; if (debug) printf("vmware_set_mouse_position: setting to %d, %d\n", x, y); bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_SET_MOUSEPOS; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; frame.ebx.word = ((uint32_t)x << 16) | y; vm_cmd(&frame); }
void vmware_check_version(void) { struct vm_backdoor frame; bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ebx.word = ~VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_VERSION; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; vm_cmd(&frame); if (debug) printf("vmware_check_version: received version 0x%x\n", frame.eax.word); if (frame.eax.word == 0xffffffff || frame.ebx.word != VM_MAGIC) errx(1, "not running under vmware\n"); }
int vmware_get_clipboard(char **buf) { struct vm_backdoor frame; uint32_t total, left; bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_CLIPBOARD_LEN; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; vm_cmd(&frame); total = left = frame.eax.word; if (total == 0 || total > 0xffff) { if (debug) printf("vmware_get_clipboard: nothing there\n"); return (0); } if (debug) printf("vmware_get_clipboard: have %d byte%s to read\n", total, (total == 1 ? "" : "s")); if ((*buf = malloc(total + 1)) == NULL) err(1, "malloc"); for (;;) { bzero(&frame, sizeof(frame)); frame.eax.word = VM_MAGIC; frame.ecx.part.low = VM_CMD_GET_CLIPBOARD; frame.ecx.part.high = 0xffff; frame.edx.part.low = VM_PORT_CMD; frame.edx.part.high = 0; vm_cmd(&frame); memcpy(*buf + (total - left), &frame.eax.word, left > 4 ? 4 : left); if (left <= 4) { buf[0][total] = '\0'; break; } else left -= 4; } if (debug) { char visbuf[strlen(*buf) * 4]; strnvis(visbuf, *buf, sizeof(visbuf), VIS_TAB | VIS_NL | VIS_CSTYLE); printf("vmware_get_clipboard: \"%s\"\n", visbuf); } return (1); }