Code: Select all
uint64_t region64 = (uint64_t)((size_t)(memory_location) & 0xFFFFFFFF);
asm("vmxon (%0);" ::"m"((uint32_t)region64));
printf("VMXON instruction..."); did_vm_operation_fail();
Code: Select all
void did_vm_operation_fail(){
uint32_t flags = 0;
asm("pushf; pop %%eax; mov %%eax, %0" :"=r"(flags));
if(flags & (1<<0)) printf("VMFailInvalid.\n");
else if(flags & (1<<6)) printf("VMFailValid.\n");
else printf("VMSuccess");
}
Code: Select all
*(uint32_t*)memory_location = msr.bits.rev_ident;
asm("vmptrld %0" ::"m"(region64));
did_vm_operation_fail();
However, this ends up giving me a #UD, which according to the SDM, this
should only happen either when:
- The operand is a register
- If I'm not in a VMX operation
The exception happens at 0x200b79, so...
Code: Select all
(qemu) x/1i 0x200b79
0x00200b79: 0f c7 75 f0 vmptrld -0x10(%ebp)
Code: Select all
(qemu) x/1i 0x200b4e
0x00200b4e: f3 0f c7 75 f0 vmxon -0x10(%ebp)
Yes, CR0.NE, CR0.PG, CR0.PE, and CR4.VMXE are all set before all this stuff was done.

