davornik 4 Posted May 15, 2020 // VMware detection as described by Elias Bachaalany function IsInsideVMware: Boolean; //------------------------------ procedure ChkVMware; asm push edx; push ecx; push ebx; mov eax, 'VMXh'; mov ebx, 0; mov ecx, 10; mov edx, 'VX'; in eax, dx; cmp ebx, 'VMXh'; setz [Result]; pop ebx; pop ecx; pop edx; end; //------------------------------ begin Result := True; try ChkVMware; except Result := False; end; end; function IsRunningUnderHyperV: BOOL; stdcall; var VMBranding: array[0..12] of AnsiChar; //------------------------------ procedure GetVMBrand; asm mov eax, $40000000; cpuid; mov dword ptr [VMBranding+0], ebx; // Get the VM branding string mov dword ptr [VMBranding+4], ecx; mov dword ptr [VMBranding+8], edx; end; //------------------------------ begin GetVMBrand; VMBranding[12] := #0; Result := CompareText(String(VMBranding), 'Microsoft Hv') = 0; end; How can thiese function be done in 64-bit? On compile I get [dcc64 Error] Unit1.pas(33): E2116 Invalid combination of opcode and operands Registers need to be changed. Which to use? Share this post Link to post
Der schöne Günther 316 Posted May 15, 2020 I have no clue about assembler, maybe this is helpful: https://stackoverflow.com/questions/51364707/ Share this post Link to post
davornik 4 Posted May 15, 2020 procedure ChkVMware; asm push rdx; push rcx; push rbx; mov rax, 'VMXh'; mov rbx, 0; mov rcx, 10; mov rdx, 'VX'; in rax, dx; <-- here is error: operand size mismatch cmp rbx, 'VMXh'; setz [Result]; pop rbx; pop rcx; pop rdx; end; Thank you. In that link registers are like eax, edx, ecx and rbx for 32-bit, but if you change them to 64-bit (rax, rdx, rcx, rbx) then I get error: operand size mismatch. I even dont know if this is proper way to change registers? Share this post Link to post
davornik 4 Posted May 18, 2020 I have finally found solution and posted it here: https://stackoverflow.com/a/61874765/3225668 4 Share this post Link to post