A simple note on port access under windows NT

I intend to write a short on port access under windows now.

1. Using Microsoft VB, you can not do port access stuff, whatever, NO. If you really need, use c/c++ to write the function, and port to dll, call it from your vb project.

2. under DOS, win98, winMe, port is open accessible; however, for NT kernel system, like winNT, win2000, winXP, direct port access is blocked; to access the port, there are two methods commonly adopted:

a) get/write a driver, like giveio.sys, and load it to grant access inside your project, prior to any port accessing;

b) if you code is already there, or you only have the executable, use portTalk/allowIo to invoke your application and grant access to some port by command line arguments;

------------------------------------------------------------------------------------------
how is the blocking mechanism under NT kernel system working?

basically, under NT kernel, programs run in two mode, user mode and kernel mode. User mode are considered unstable, and thus restricted by OS. it works in this way:
a> user mode program runs in privilege level ring 3, and kernel mode program runs in privilege leve ring 0.
b> if a program request to access a port, the OS checks for two things:
1) if the program runs in ring 0, ok, go; otherwise
2) check the IOPM mapping in TSS, if the corresponding bit for the port is cleared, ok, go, otherwise
3) blocked!!!

--------------------------------------------------------------------------------------------
how does driver like giveio.sys or port talk walk around the limitation?

it changes the IOPM to grant access for certain process; how? the answer is , there is some un-documented api under windows to manipulate the bit in IOPM.

------------------------------------------------------------------------------------
what is IOPM?

forget about the details if you are not interested. it is some system managed memory, each bit inside represents the access right for one port. Bit 1(default value) means blocking, and bit 0 means green light.

How is the details? how does it really really works?

do not ask; u need something like SoftICE or winDBG to dig into TSS to see it yourself. did i? NOT yet. It is not straight forward to me.

anything wrong or inaccurate above, leave a comment. thanks