flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ACP 03 Feb 2015, 15:48
|
|||
![]() |
|
smiddy 03 Feb 2015, 19:24
ACP wrote: Here you are https://github.com/fone32/extenders/tree/master/fone32/examples Whoa, thanks! I was going to try a search like that. No reinventing the wheel. Much appreciated! Smiddy |
|||
![]() |
|
ACP 03 Feb 2015, 22:34
You're welcome. The other possible technique for detecting the emulator is to actually use INT 1 to tunnel into BIOS and check how things are looking there. Actually DosBOX BIOS is pretty simple. You can even use Sourcer package to dump it and disassemble from DosBox prompt.
|
|||
![]() |
|
smiddy 03 Feb 2015, 22:54
Thanks! I was going to look at the source next and see what I could delve from it. I hadn't known about INT 1 either, I'll take a close look there as well.
I don't know if these are helpful to you (or others), I think I post these way back when I wrote them: Code: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; VM - Detects if we're in a virtual machine. Current virtual machines ;; detected: Virtual PC, VMWare, and Bochs. I am developing ways to ;; detect DOSBox and QEMU. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data Area for DetectVPC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;align 4 VPCDetectedMessage db 'Virtual PC Detected',13,10,0 VPCNotDetectedMessage db 'Virtual PC NOT Detected',13,10,0 ;align 4 VPCOn dd 0 DetectVPC: pusha cli ; Turn off interrupts mov esi,VPCInvalidOpcodeException ; Store new Invalid Opcode Exception mov eax,6 ; Invalid Opcode is 6 call AddExceptionToIDT ; Call routine to replace it sti ; Turn on interrupts mov ebx,0 ; This will stay 0 if VPC running mov eax,1 ; VPC function number .CallVPC: db 0Fh,3Fh,07h,0Bh ; Call VPC test ebx,ebx jz .InVPC mov eax,0 mov esi,VPCNotDetectedMessage jmp .Done .InVPC: mov eax,1 mov esi,VPCDetectedMessage .Done: mov [VPCOn],eax call PrintString32 cli mov esi,IllegalInstruction ; Restore original unhandled interrupt mov eax,6 ; Invalid Opcode is 6 call AddExceptionToIDT sti popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; VPCInvalidOpcodeException - replaced invalid opcode exception handler with ;; this one to go past the VPC call in the above ;; procedure. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VPCInvalidOpcodeException: mov ebx,-1 ; Not running VPC add DWORD [ss:esp],4 ; Fix the EIP in stack to skip past call VPC iret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data area for SetectBochs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;align 4 BochsDetectedMessage db 'Bochs detected',13,10,0 BochsNotDetectedMessage db 'Bochs NOT detected',13,10,0 ;align 4 BochsOn dd 0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DetectBochs - Detects if Bochs is running your code. This has been tested ;; to work with standard release build for Windows environment. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DetectBochs: mov dx,0E9h in al,dx cmp al,0E9h je .InBochs mov eax,0 mov esi,BochsNotDetectedMessage jmp .Done .InBochs: mov eax,1 mov esi,BochsDetectedMessage .Done: mov [BochsOn],eax call PrintString32 ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data area for DetectVMWare ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;align 4 VMWareDetectedMessage db 'VM Ware Detected',13,10,0 VMWareNotDetectedMessage db 'VM Ware NOT Detected',13,10,0 ;ALIGN 4 VMWareOn dd 0 ; Default = 0 = OFF, 1 = ON ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DetectVMWare - Detects if your code is running under VMWare ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DetectVMWare: mov eax,564D5868h ; 'VMXh' mov ebx,12345678h ; This can be any number, but not 'VMXh' mov ecx,0Ah ; Get VMWare version mov edx,5658h ; Port number IN eax,dx ; Read port 5658h ; call ShowRegisters ; Shows EAX, EBX, ECX, and EDX (more later) cmp ebx,564D5868h ; Is this from the EAX? je .InVMWare ; Yes, goto flag it mov eax,0 mov esi,VMWareNotDetectedMessage jmp .Done .InVMWare: mov eax,1 mov esi,VMWareDetectedMessage .Done: mov [VMWareOn],eax call PrintString32 ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data Area for DetectVPC ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;align 4 QEMUDetectedMessage db 'QEMU Detected',13,10,0 QEMUNotDetectedMessage db 'QEMU NOT Detected',13,10,0 ;align 4 QEMUOn dd 0 DetectQEMU: pusha cli ; Turn off interrupts mov esi,QEMUInvalidOpcodeException ; Store new Invalid Opcode Exception mov eax,6 ; Invalid Opcode handler is 6 call AddExceptionToIDT ; Call routine to replace it sti ; Turn on interrupts mov ebx,0 ; This will stay 0 if VPC running mov eax,1 ; VPC function number .CallQEMU: db 0Fh,3Fh,07h,0Bh ; Call VPC test ebx,ebx jz .InQEMU mov eax,0 mov esi,QEMUNotDetectedMessage jmp .Done .InQEMU: mov eax,1 mov esi,QEMUDetectedMessage .Done: mov [QEMUOn],eax call PrintString32 cli mov esi,IllegalInstruction ; Restore original unhandled interrupt mov eax,6 ; Invalid Opcode is 6 call AddExceptionToIDT sti popa ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; QEMUInvalidOpcodeException - replaced invalid opcode exception handler with ;; this one to go past the VPC call in the above ;; procedure. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; QEMUInvalidOpcodeException: mov ebx,-1 ; Not running VPC add DWORD [ss:esp],4 ; Fix the EIP in stack to skip past call VPC iret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DetectDOSBox - Detects if we are running under DOSBox (stub) ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; DOSBoxMessage db 'DOSBox detection is not implemented, yet.',13,10,0 DetectDOSBox: mov esi,DOSBoxMessage call PrintString32 My coding is ugly, but effective. LOL! I haven't tested these lately, so they may not work with current versions. I will be testing them again very soon, once I get my boot drive working, which is why I needed to know DOSBox is loading the my OS, so I can load another file, VENDORS.TXT to check the PCI bus pool against that data. |
|||
![]() |
|
ACP 05 Feb 2015, 10:55
The code you see on the github has been developed for a DOS Extender in order to know which INTs should be extended (for example there is no point in installing extended int handler if the BIOS is not handling it anyway under emulator) and to be able to use internal DPMI host if emulator provides one. You are also detecting CPU emulators and hypervisor. From extender point of view hypervisor is transparent but for other uses your code is definitively useful. The rpix86 detection method has been discussed with it's author. Code has been tested and is known to be working.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.