BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can someone complete this...

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Dennis Passmore
Guest





PostPosted: Sun Mar 20, 2005 7:36 pm    Post subject: Can someone complete this... Reply with quote



I found a example of this on TheCodeProject.com at

http://www.codeproject.com/system/VmDetect.asp

but it was written in C++ so I am trying to convert it to Delphi. I have everything except
the section where it calls VPC and I do not know how to do this in Delphi's ASM blocks.
Will someone complete this

// call VPC
// _asm __emit 0Fh
// _asm __emit 3Fh
// _asm __emit 07h
// _asm __emit 0Bh

and post the correct code?

Delphi example source:
====================================
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function IsInsideVMWare: boolean;
asm
push edx;
push ecx;
push ebx;

mov eax, 'VMXh';
mov ebx, 0; // any value but MAGIC VALUE
mov ecx, 10; // get VMWare version
mov edx, 'VX'; // port number
in eax, dx; // read port
// on return EAX returns the VERSION
cmp ebx, 'VMXh'; // is it a reply from VMWare?
setz [result]; // set return value

pop ebx;
pop ecx;
pop edx;
end;

function IsInsideVPC: boolean;
asm
push ebp;
mov ebp, esp;

mov ecx, offset @exception_handler;

push ebx;
push ecx;

push dword ptr fs:[0];
mov dword ptr fs:[0], esp;

mov ebx, 0; // Flag
mov eax, 1; // VPC function number

// call VPC
// _asm __emit 0Fh
// _asm __emit 3Fh
// _asm __emit 07h
// _asm __emit 0Bh

mov eax, dword ptr ss:[esp];
mov dword ptr fs:[0], eax;

add esp, 8;

test ebx, ebx;

setz al;

lea esp, dword ptr ss:[ebp-4];
mov ebx, dword ptr ss:[esp];
mov ebp, dword ptr ss:[esp+4];

add esp, 8;

jmp @ret1;

@exception_handler:
mov ecx, [esp+0Ch];
mov dword ptr [ecx+0A4h], -1; // EBX = -1 ->; not running, ebx = 0 -> running
add dword ptr [ecx+0B8h], 4; // ->; skip past the call to VPC
xor eax, eax; // exception is handled

@ret1:

end;

procedure TForm1.Button1Click(Sender: TObject);
var
fInsideVPC: boolean;
fInsideVMWare: boolean;
begin
fInsideVPC := false;
fInsideVMWare := false;
try
fInsideVMWare := IsInsideVMWare;
except end;
if not fInsideVMWare then
try
fInsideVPC := IsInsideVPC;
except end;
if fInsideVMWare then
edit1.text := 'in VmWare session'
else
if fInsideVPC then
edit1.text := 'in Virtual PC session'
else
edit1.text := 'not in VmWare or Virtual PC session';
end;



Back to top
Avatar Zondertau
Guest





PostPosted: Sun Mar 20, 2005 7:48 pm    Post subject: Re: Can someone complete this... Reply with quote



Quote:
but it was written in C++ so I am trying to convert it to Delphi. I
have everything except the section where it calls VPC and I do not
know how to do this in Delphi's ASM blocks. Will someone complete
this

// call VPC
// _asm __emit 0Fh
// _asm __emit 3Fh
// _asm __emit 07h
// _asm __emit 0Bh

and post the correct code?

db $0F, $3F, $07, $0B

Back to top
Dennis Passmore
Guest





PostPosted: Sun Mar 20, 2005 7:58 pm    Post subject: Re: Re: Can someone complete this... Reply with quote



Quote:
and post the correct code?

db $0F, $3F, $07, $0B

duhhh, I feal kind of dumb when the answer is in front of me.

It works like a champ and the completed code works fine in a VPC session.

Thank you,


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.