C#驱动开发?

发布于 2024-07-04 18:31:35 字数 436 浏览 10 评论 0原文

在我一头扎进 C# 之前……

我一直认为 C,或者 C++,最适合在 Windows 上开发驱动程序。 我不喜欢在 .NET 机器上开发驱动程序的想法。

但 .NET 似乎是微软应用程序开发的方向,所以我现在想知道:

  • 人们正在使用 C# 来开发驱动程序吗?
  • 您是否必须执行大量 API 挂钩,或者 C# 是否具有与内核交互的设施,而无需进行大量黑客操作?
  • 谁能谈谈在比通常情况更接近 Ring 0 的位置运行 C# 程序的可靠性和安全性吗?

我希望我的设备可以在 C# 中使用,如果 C# 中的驱动程序开发成熟,这显然是可行的方法,但如果不推荐的话,我不想在那里花费大量精力。

  • 例如,开发一个简单的虚拟串行端口驱动程序有哪些好的入门资源?

-亚当

Before I jump headlong into C#...

I've always felt that C, or maybe C++, was best for developing drivers on Windows. I'm not keen on the idea of developing a driver on a .NET machine.

But .NET seems to be the way MS is heading for applications development, and so I'm now wondering:

  • Are people are using C# to develop drivers?
  • Do you have to do a lot of API hooks, or does C# have the facilities to interface with the kernel without a lot of hackery?
  • Can anyone speak to the reliability and safety of running a C# program closer to Ring 0 than would normally be the case?

I want my devices to be usable in C#, and if driver dev in C# is mature that's obviously the way to go, but I don't want to spend a lot of effort there if it's not recommended.

  • What are some good resources to get started, say, developing a simple virtual serial port driver?

-Adam

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

_失温 2024-07-11 18:31:35

在 .net 中编写设备驱动程序对于当前版本的 Windows 来说没有任何意义。

<猜测>
有传言称微软正在投入大量资金来将奇点提升到一个新的水平。 只需查找 Midori 即可。 但这是 2015 年以后的事了

Writing device drivers in .net makes no sense for current versions of windows.

<speculation>
Rumors are that MS is investing a lot of money in bringing Singularity to the next level. Just look for Midori. But that's 2015+
</speculation>

生死何惧 2024-07-11 18:31:35

如果我没记错的话, Dokan 项目 是一个用户模式文件系统驱动程序,它还允许由系统驱动程序执行的.NET代码: https://github.com/dokan-dev /dokan-dotnet

因此,您可以开发一个 C#“驱动程序”(实际上是用户模式应用程序),然后由 C++ 内核模式驱动程序调用/调用。 内核驱动程序可以简单地传递所有内容而无需操纵数据并充当简单的包装器。

不用说,这是非常不安全的,你很可能会以 BSOD 结束(我尝试过)。


轻微相关:

Cosmos 项目 是一个开源操作系统,采用 C# 开发并运行
“(内核)驱动程序”和完全用 C#/F#/VB.NET/ 编写的用户级应用程序...

虽然这些在技术上是内核级驱动程序,但操作系统不再是 Windows 而是您自己的,所以我猜这是不是正确答案……

If I remember it correctly, the Dokan Project is a user-mode file system driver, which also allows .NET code to be executed by a system driver: https://github.com/dokan-dev/dokan-dotnet.

So, you could develop a C# "driver" (user-mode application really), which is then called/invoked by a C++ kernel-mode driver. The kernel-driver could simply pass everything along without manipulating the data and act as a simple wrapper.

Needless to mention, that it is very unsafe and you would most likely end with a BSOD (I tried it).


Mildly related:

The Cosmos Project is an open-source Operating system, which is developed in C# and runs
"(kernel) drivers" and user-level applications written completely in C#/F#/VB.NET/...

Though these are technically kernel-level drivers, the OS is no longer Windows but your own, so I guess that this is not a correct answer ......

池予 2024-07-11 18:31:35

您无法在 C# 中制作内核模式设备驱动程序,因为运行时无法安全地加载到ring0 中并按预期运行。

此外,C# 不会创建适合作为设备驱动程序加载的二进制文件,特别是关于驱动程序需要公开的入口点。 加载期间对运行时跳转、分析和 JIT 二进制文件的依赖禁止驱动程序子系统加载二进制文件所需的直接访问。

不过,正在开展工作,将某些设备驱动程序提升到用户模式,您可以参阅采访 此处 与 UDMF(用户模式驱动程序框架)团队的 Peter Wieland 合作。

用户模式驱动程序更适合托管工作,但您必须在 google 上搜索一下以了解是否直接支持 C# 和 .NET。 我所知道的是内核级驱动程序不能仅在 C# 中实现。

但是,如果您绝对必须用 C# 编写大量代码,那么您可以制作一个 C/C++ 驱动程序和一个 C# 服务(或类似服务),并让驱动程序与托管代码进行对话。

You can not make kernel-mode device drivers in C# as the runtime can't be safely loaded into ring0 and operate as expected.

Additionally, C# doesn't create binaries suitable for loading as device drivers, particularly regarding entry points that drivers need to expose. The dependency on the runtime to jump in and analyze and JIT the binary during loading prohibits the direct access the driver subsystem needs to load the binary.

There is work underway, however, to lift some device drivers into user mode, you can see an interview here with Peter Wieland of the UDMF (User Mode Driver Framework) team.

User-mode drivers would be much more suited for managed work, but you'll have to google a bit to find out if C# and .NET will be directly supported. All I know is that kernel level drivers are not doable in only C#.

You can, however, probably make a C/C++ driver, and a C# service (or similar) and have the driver talk to the managed code, if you absolutely have to write a lot of code in C#.

a√萤火虫的光℡ 2024-07-11 18:31:35

这将在某种程度上帮助您:Windows 驱动程序工具包

This shall help you in a way: Windows Driver Kit

浮云落日 2024-07-11 18:31:35

这不是您问题的直接答案,但如果您感兴趣,您可以查看 Singularity 项目

It's not direct answer to your question but if you're interested you might look at Singularity project.

淡笑忘祈一世凡恋 2024-07-11 18:31:35

有人能谈谈运行 C# 程序比通常情况更接近 Ring 0 的可靠性和安全性吗?

C# 在 .NET 虚拟机中运行,您不能将其移至比 VM 更靠近 Ring 0 的位置,并且 VM 在用户空间中运行。

Can anyone speak to the reliability and safety of running a C# program closer to Ring 0 than would normally be the case?

C# runs in the .NET Virtual Machine, you can't move it any closer to Ring 0 than the VM is, and the VM runs in userspace.

若无相欠,怎会相见 2024-07-11 18:31:35

如果您愿意尝试专有框架,Jungo 的 WinDriver 工具包 支持USB、PCI 和 PCI-E 设备的用户模式驱动程序开发(甚至是托管代码)。

If you're willing to have a go at a proprietary framework, Jungo's WinDriver toolkit supports user-mode driver development (even in managed code) for USB, PCI, and PCI-E devices.

小猫一只 2024-07-11 18:31:35

微软在托管代码操作系统领域有许多研究项目,换句话说,用 Win32 API 进行杀戮。

请参阅 Mary Jo Foley 的文章:重建遗产

Microsoft has a number of research projects in the area of having a managed-code OS, in other words kill with Win32 API.

See Mary Jo Foley's article: Rebuilding a Legacy

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文