2

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.

p.campbell
  • 98,673
  • 67
  • 256
  • 322
Tono Nam
  • 34,064
  • 78
  • 298
  • 470

2 Answers2

2

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.

AaronDancer
  • 649
  • 1
  • 7
  • 22
  • 1
    +1 for help thanks! .All usbs are the same size though :( . They all have different content that's why I want to create a hash of the bytes. – Tono Nam Jan 23 '14 at 23:36
  • 1
    Oh... my bad. I must have missed your question. If you're going to use a checksum for identifying each drive I'd use a HWID instead. Something like this might work: http://stackoverflow.com/questions/4084402/get-hard-disk-serial-number – AaronDancer Jan 23 '14 at 23:42
  • I did not though about that and did not knew hard disk had a serial. I guess thats the way to go. about to give it a try! – Tono Nam Jan 24 '14 at 00:03
1

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

Community
  • 1
  • 1
skolte
  • 367
  • 2
  • 9