문제

I have a USB mass storage device that I encrypt with TrueCrypt. When I connect it to Windows, it asks to format. Using TrueCrypt reveals its contents, as expected.

enter image description here

How can I read the first 100 bytes of that device?

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. It works.

다른 팁

What solutions have you considered so far? Does your application figure out when the USB device is plugged in or unplugged?

As far as I know, there's no native support in .Net for directly accessing USB devices. 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.

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.

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). 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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top