How to write the physical sectors of a BitLocker-encrypted volume?

非 Y 不嫁゛ 提交于 2020-05-30 09:48:51

问题


I call CreateFile() and I open \\.\PhysicalDrive0, then I read the sectors of a BitLocker-encrypted volume, and everything works fine. This way I create a backup copy of the physical (encrypted) sectors of a volume that is encrypted with BitLocker.

Then, I call CreateFile() again and I open \\.\PhysicalDrive0 again, then I try to write the sectors of said BitLocker-encrypted volume (I'm trying to restore the backup), and it doesn't work.

If the volume is unlocked, I get an IOException with HResult = 0x80370000 and text "This drive is locked by BitLocker Drive Encryption. You must unlock this drive from Control Panel."

After I unlock the volume from the UI, the exception changes to HResult = 0x80070013 and text "The media is write protected."

Question: What do I have to do to be allowed to write the physical sectors of a BitLocker-encrypted volume? I mention that I do run the code as an admin, and I do lock the volume, to no avail. The same code works fine with non-encrypted volumes.

So far, I only have 2 options, and neither of them is good:

  1. Writing the physical sectors of the BitLocker volume works fine if I take the ENTIRE drive offline (calling DeviceIOControl()), but I cannot do this, since the drive also contains other volumes, that need to be online.

  2. It also works if (before restoring) I format the volume as a non-encrypted volume, thus removing the BitLocker encryption. After doing this, writing the physical sectors works fine, but Windows does not detect the new written sectors as a BitLocker volume. However, after removing and re-inserting the drive (or after a restart if the drive is fixed) it does detect the volume as a BitLocker encrypted volume.

Thanks a lot.

来源:https://stackoverflow.com/questions/61207309/how-to-write-the-physical-sectors-of-a-bitlocker-encrypted-volume

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!