androidusbfat32usb-mass-storage

Can't properly read the boot sector from a FAT32 USB drive on Android device


I'm trying to read the boot sector from a FAT32 drive on Android device, but I'm getting totally different data from what I expect.

This is the output I'm receiving with bulkTransfer on read endpoint on my Android device.

33C08ED0BC007C8EC08ED8BE007CBF00
06B90002FCF3A450681C06CBFBB90400
BDBE07807E00007C0B0F850E0183C510
...
656D000000637B9A5BE2B3D70000800F
30000BFEFFF4E0030000205CF8000000
00000000000000000000000000000000
00000000000000000000000000000000
000000000000000000000000000055AA

This is the boot sector dumped with hex viewer on my PC.

EB58904D53444F53352E300002081004
0200000000F800003F00FF00E0030000
205CF800F83D00000000000002000000
...
0000000000000000000000000D0A5573
75E4206479736B69206C756220696E6E
79206E6F986E696BFF0D0A4288A56420
6479736B75FF0D0A5A72657374617274
756A2C206E616369736B616AA563206B
6C617769737A0D0A00ACC9D6000055AA

The data I received on Android contains following message near the end: "Invalid partition table.Error loading operating system.Missing operating system".

Can anyone tell me what's wrong here? Is there any action I should perform before reading the boot sector?

As of now my code flow is as follows:

  1. Find desired USB device
  2. Get the permission to communicate with USB device
  3. Open connection do the device
  4. Execute "Test Unit Ready" command until successful response
  5. Execute "Read Capacity" command - this returns correct results
  6. Execute "Read 10" command to read first 512 bytes - this returns incorrect data

I will be thankful for any suggestions


Solution

  • Which hex viewer?

    Non-admin user on win cannot access the partition table on the physical device, so you usually get the first sector of the partition only. You can check this, it would contain the FAT32 string at offset 0x52. To read the real partition table, you need to access the pysical device with admin privileges.

    On android, you read the partition table itself because you access the physical "disc" at a low level.