Writing Drivers in Delphi
Driver development has always been the privilege of C/C++ and Assembler programmers. If someone needs to write a device driver in Delphi, he has to settle for “adapter” drivers that would allow their user-mode program some ability to interface with kernel-mode functions. There are also “wizards” that (supposedly) allow one to create a driver without much driver-development knowledge. Both of these are often commercial software.
For some tasks one could also use a service (which can be written in Delphi). Well, either that or learn to program C/C++. With older Delphi versions you could still use the Microsoft linker included in DDK to link the object files produced by the Delphi compiler to get a valid .sys file, but newer Delphi versions have a different .obj file format. Is there any hope? Well, yes there is!
The main reasons why you can’t usually create drivers in Delphi are such :
- It’s compiler/linker can’t produce .sys files.
- The object file format incompatibility mentioned above.
- DDK isn’t generally available in languages other than C/C++.
- Some essential units (RTL) aren’t intended for use in kernel-mode and might crash a driver (and the whole system along with it).
The solution I recently discovered is the Delphi Driver Development Kit v0.0.4 (local mirror) that addresses most of these issues and lets you create kernel-mode drivers even in Delphi 7! It includes translated DDK headers, an utility to convert Delphi OBJ files to a format compatible with the Microsoft linker and some other things. And the best thing is it’s free! I compiled and run one of the samples on my Windows XP machine using Delphi 7 and it worked OK
DDDK 0.0.4 was created by The Hacker Defender Project team. Take a look at their site, they also have some other interesting programs and articles there.
Update 04.07.2007 : Looks like “The Hacker Defender Project” is down. You can still get the DDK at http://w-shadow.com/files/DDDK004.zip
Related posts :
May 20th, 2008 at 12:30 pm
THX!
HDTeam
July 11th, 2008 at 2:58 pm
The DDDK004.zip contains a virus according to my Norton 2008!!! DO NOT USE.
July 11th, 2008 at 11:45 pm
And it’s clean according to my NOD32. Norton probably just got something caught in its heuristic filters.
August 1st, 2008 at 2:02 pm
Thanks, that seems interesting.
Just wanted to point out that also Avira AntiVir believes that DCC32.exe contains a virus/trojan horse (”TR/Agent.257941″). I guess this file was patched. Would you maybe know what changes were made to the compiler?
Cheers, phs
August 1st, 2008 at 3:00 pm
Nope, I don’t know the specifics. And the original webpage has been down for a long time, so good luck finding an explanation anywhere. Ah well.
September 24th, 2008 at 8:44 pm
I’ve found the same, and also omf2d.exe contains the Virus WORM/Generic 27127 (AVIRA).
But, fortunally, DDDK04 is not necessary to create drivers with Delphi! The only reason, to use omf2d.exe is, because since Delphi4(?) the resulting obj-Files are not compatible with MS-Linker to produce the sys-File. Use Delphi3 dcc32.exe instead!
See this link:
http://forum.sysinternals.com/forum_posts.asp?TID=5324&PN=2
To link the obj-files you can use the linker and the ntoskrnl.lib from the Win-Sever2003-DDK you can get under
http://www.microsoft.com/whdc/devtools/ddk/default.mspx
The only difficulty is to translate the DDK-headers to Delphi…
Have fun
Thomas