Solved

How to call VxD API from application?

Posted on 2000-04-06
5
272 Views
Last Modified: 2013-12-03
Hi,

   Could anyone please help me with this question:

I am trying to write a simple VxD, which exports a simple API function. For example:

   BeginProc VSIMPLE_API_Proc, PUBLIC
                    mov [ebp.Client_Word_Reg_Struc.Client_DX],1234h
                    mov [ebp.Client_Reg_Struc.Client_EFLAGS],NOT(CF_Mask)
                    clc
                    ret
   EndProc VSIMPLE_API_PROC

The above code simple returns the value 1234h in DX of the calling VM. I added the name of the API in the DDB, in both the V86_API_PROC and PM_API_PROC macro input, so that this API can be called by both V86 and PM VMs.

To test my API, I wrote a simple program in Visual C++ Win32 Console Application, that has this:

    _asm
    {    mov  ax,1684h
          mov  bx, 0    ; 0 for Undefined_Device_ID
          int 2fh
          mov  entry,di    ; get the entry point
          mov  entryseg, es
    }

However, what I get is the blue screen Protection Fault. At first I thought my  VxD is faulty, so I tried int 2fh, with ax=1600h. Still, I got the error.

Could anyone tell me what is the real way of calling an API? Is int 2fh permitted in a win32 console application? Or only specific applications with higher priviledge are permitted of calling a VxD API?

Thank you very much.

Yours sincerely,
Stephen
0
Comment
Question by:chiehlim
  • 3
  • 2
5 Comments
 
LVL 32

Accepted Solution

by:
jhance earned 90 total points
Comment Utility
Under WIN32 you don't use INT 2F to call into a VxD.  Use DeviceIoControl instead.

Basically the process is:

1) Use CreateFile to open the VxD's virtual device and get a handle to it.

2) Use DeviceIoControl to talk to the VxD.

3) Use CloseHandle() to close the handle when you are done.


Based on the code you've posted above, however, it's unlikely that this will work since your VxD must be written to receive the W32_DEVICEIOCONTROL message that the DeviceIoControl API function generates.

What is your source of information for writing this VxD?  If you are trying to do it just using the DDK, good luck, that is a very incomplete resource.  I'd suggest the book, "Writing Windows VxDs and Device Drivers" by Karen Hazzah and published by R&D Books.
0
 

Author Comment

by:chiehlim
Comment Utility
Hi,

   Thanks for the answer. I did look for answers myself and found the same as what you mentioned. Could you give me more details on createfile() and DeviceIOControl()?

   One question about DeviceIOControl() is that, one of the parameters is an address to an input buffer. OK, I am just a beginner to Win32 programming so my question might be a trivial one:

   Do I need to use MAP_FLAT of the VMM service to make the address sent to my VxD into a 32-bit flat model address? In other words, are the addresses sent by my application to my VxD compatible (both 32-bit flat model address?)? I know VxD's use 32-bit flat model, with all selectors using the base address of 0. But what about win32 applications. Are the selectors in win32 applications pointing to the descriptor with base address of 0 as well?

   If you can provide me with this answer, then I will be satisfied. Thanks

Yours sincerely
Stephen
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
Any address passed via DeviceIoControl will be a "virtual" address from the point of view of the calling process, but Windows translates this to a physical address for the VxD during the call to DeviceIoControl().  This keeps you from having to mess with mapping the address.

So you might open a VxD like this:

const char *lpszVxD = "\\\\.\\TEST.VXD"
HANDLE hVxD = CreateFile(
  lpszVxD,
  0,
  0,
  0,
  CREATE_NEW,
  FILE_FLAG_DELETE_ON_CLOSE,
  0
);


Now you have a handle (hVxD) that can be used in a call to DeviceIoControl:

DeviceIoControl(
  hVxD,
  YOUR_DEVICE_CONTROL_CODE,
  (LPVOID)&InBuffer,
  dwInBufferSize,
  (LPVOID)&OutBuffer,
  dwOutBufferSize,
  &dwBytesReturned,
  NULL
);
0
 

Author Comment

by:chiehlim
Comment Utility
Hi,

    Thank you very much. I tried it out and found that it worked. One last question, how do I specify my path in the createfile function? If my vxd is "c:\masm32\test.vxd", how do I specify in the createfile function?

   I tried "c:\\masm32\\test.vxd" but it didn't work. The error was file already existed. Strange, I put my vxd in the current directory of my calling application, with the same syntax but this time using "\\\\.\\test.vxd", and it worked.

   Thanks again.

Yours sincerely
Stephen
0
 
LVL 32

Expert Comment

by:jhance
Comment Utility
The \\\\.\\TEST.VXD is not the filesystem pathname to the VxD, it's the specification for the module name.  So for this to work, the VxD file must be in the standard search path.

See:

http://msdn.microsoft.com/library/psdk/win95/devio_886c.htm
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now