Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top