[英]Read bytes of a USB mass storage device
I have a USB mass storage device that I encrypt with TrueCrypt . 我有一个用TrueCrypt加密的USB大容量存储设备。 When I connect it to Windows, it asks to format.
当我将其连接到Windows时,它要求格式化。 Using TrueCrypt reveals its contents, as expected.
如预期的那样,使用TrueCrypt会显示其内容。
How can I read the first 100 bytes of that device? 如何读取该设备的前100个字节?
I know the bytes will not make sense because they're encrypted but I want to read them in order to create a checksum. 我知道字节是没有意义的,因为它们已加密,但是我想读取它们以创建校验和。
Did this on the top of my head. 这是在我头上做的。 But is should work.
但是应该起作用。
public static long getBytes(string letter)
{
ManagementObject disk = new ManagementObject(String.Format("win32_logicaldisk.deviceid=\"{0}:\"", letter));
disk.Get();
return long.Parse(disk["Size"].ToString());
}
EDIT: Tested it and changed int to long. 编辑:对其进行了测试并将int更改为long。 It works.
有用。
What solutions have you considered so far? 到目前为止,您考虑过哪些解决方案? Does your application figure out when the USB device is plugged in or unplugged?
插入或拔出USB设备时,您的应用程序会知道吗?
As far as I know, there's no native support in .Net for directly accessing USB devices. 据我所知,.Net没有直接支持USB设备的本机支持。 I had to use libraries such as LibUsbDotNet ( http://sourceforge.net/projects/libusbdotnet/ ) or SharpUSBLib ( http://www.icsharpcode.net/OpenSource/SharpUSBLib/ ) There were pros and cons to both in terms of samples, documentation etc. I am sure you will be able to find what suits you best.
我不得不使用诸如LibUsbDotNet( http://sourceforge.net/projects/libusbdotnet/ )或SharpUSBLib( http://www.icsharpcode.net/OpenSource/SharpUSBLib/ )之类的库样本,文档等。我相信您将能够找到最适合自己的东西。
In one case I was able to connect to the device using WMDC, once the connection was established I used OpenNETCF RAPI library to read from / write to the device. 在一种情况下,我能够使用WMDC连接到设备,一旦建立了连接,我就使用OpenNETCF RAPI库读取/写入设备。
Here's another excellent resource that I had found useful when I wrote an application that needed to interact with a USB device (a barcode scanner). 这是我编写一个需要与USB设备(条形码扫描仪)进行交互的应用程序时发现的另一个非常有用的资源。 http://www.developerfusion.com/article/84338/making-usb-c-friendly/
http://www.developerfusion.com/article/84338/making-usb-c-friendly/
There was a good resourceful discussion to a similar question here on Stackoverflow : Working with USB devices in .NET 关于Stackoverflow的类似问题,这里进行了很好的讨论,内容丰富: 在.NET中使用USB设备
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.