开发者

How to write to I/O ports in Windows XP? (Delphi7)

开发者 https://www.devze.com 2022-12-18 08:42 出处:网络
I am trying to write to ports 0x60 and 0x64, with no luck. Delphi code: procedure PortOut(IOport: WORD; Value: BYTE); assembler; register;

I am trying to write to ports 0x60 and 0x64, with no luck.

Delphi code:

procedure PortOut(IOport: WORD; Value: BYTE); assembler; register;
asm
  XCHG DX,AX
  OUT DX,AL
end;

Upon calling PortOut, I get an EPrivilege Privileged instruction exception, because IN and OUT may only execute as Ring0.

I开发者_C百科 would like to know how I can get Ring0 privileges my an application or how I could write to ports 0x60 and 0x64 using some existing external library.


Have a look at the IO.DLL from Geek Hideout.

IO.DLL allows seamless port I/O operations for Windows 95/98/NT/2000/XP using the same library.

Here is an example: Parallel Port I/O Using Delphi V 6.0


The correct way to handle this situations is to write a Windows driver, but it can't be done in Delphi for lack of support. It requires the DDK and a C compiler. The other solutions presented here works, but be aware that usually the give access to any I/O port, not only those your application requires. And that could be a security issue - if the x86 architecture lets the system programmer to define the IOPL (I/O privilege level) and most systems set it a ring 0, there's a reason. General access I/O ports drivers are useful for tests and maybe prototyping or as stopgap measures, but I will be very careful to deploy them, especially if the system in not under strict control. If you need that kind of access, you definitely need to understand how the Windows kernel and its drivers works, and why - and implement your own driver. Most of the time Windows in not unsecure per se - it is running to many unsecure software with the wrong privileges that make it so.


  • Inpout32.dll for Windows 98/2000/NT/XP (binaries and source code)
  • Inpoutx64.dll for WIN XP 64 bit (binaries and source code)
  • Delphi: Accessing Port Hardware and how to use InpOut32.dll


Of course that might cause trouble for devices that are controlled by a driver. Stuff like IO.DLL is mostly meant to interface cards for which no Windows drivers exist, or where the windows driver is dormant until activated.

And since port 60h is the keyboard controller, and the keyboardi is usually in use, it might cause problems.

If you are not interfacing ancient hardware, but just trying to port dos (TP) code, I urgently advise you to rewrite the said code based on normal Windows APIs.


Jeez,

It has been a long time for me. I just launched my DPro 2006 to look at the VCL on this and it bombed. (Guess that is what I get for not doing any Delphi code in the the last couple of years on this machine... and keeping patching up to date, plus installing/uninstalling a jillion other paid and FOSS packages on the box....)

But it would seem to me that if you grabbed the header files for the Windows Driver Framework, or check out Project JEDI's site, you might find something to put together a Miniport driver or such.

Just my $0.02 worth

/s/ BezantSoft

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号