sharkdp/hexyl

is there a way to open disk devices in windows?

whitequill opened this issue · 5 comments

I was trying to open a device in hexyl with hexyl.exe \\?\Volume{0893efeb-32d9-46d8-bc15-34d18c0e669a}\
does it not have this functionality yet?
this is the error that I get in cmd:
Error: The system cannot find the path specified. (os error 3)

I am using Administrator.

I was trying to open a device in hexyl with hexyl.exe \\?\Volume{0893efeb-32d9-46d8-bc15-34d18c0e669a}\
does it not have this functionality yet?

I'm not a Windows expert, so I don't really know what you expect this to do. Can other tools open this exact path?

I want to open a device like I would open hexyl /dev/hde1 on Linux.

Can other tools open this exact path?

Checking Windows's own more utility, it returns the same error: The system cannot find the path specified.

This Stack Exchange thread gives more detail on why, but suffice it to say that unlike in Unix-like operating systems, Windows does not just let you access volumes/drives just like you can a file. I did some digging into the Windows file access methods and found that CreateFileW should allow you to access a drive as a file. The winsafe library provides a safe wrapper for this method through its own File::open method. Note that this File uses its own read which wraps ReadFile and does not implement std::io::Read, so in order for this to be implemented into hexyl one would have to create a wrapper struct for it and implement Read on it, in addition to writing logic that would recognize the file path as a drive and handle it as a special case.

EDIT: After some more research, I found the FileMapped struct which will open the drive as a [u8], which does implement Read. The only implementation details left would be handling the path and adding it as an additional variant of Input.

My access to Windows is limited and I would not be able to test this implementation, so I would not be able to contribute to it. However, @whitequill, if you're interested in getting this to work, I've provided all the necessary details here to implement this yourself.

I will give this some thought. As I need to look at the current hexyl code base and the Microsoft documentation.