如何在windows下打开磁盘并低级读取数据?

发布于 2024-11-18 05:37:58 字数 337 浏览 3 评论 0原文

我知道在 Linux 中它就像 /dev/sda 一样简单,但是在 Windows 中如何打开磁盘并开始在低级别读取数据?

在 python 中,我尝试过:

f = open("K:", "r")

并且收到此错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: 'K:'

即使作为管理员,我也会收到此错误。

I know in linux it is as simple as /dev/sda but in Windows how do you open a disk and start reading data at the low level?

In python I've tried:

f = open("K:", "r")

and I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 13] Permission denied: 'K:'

I get this error even as administrator.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

懒的傷心 2024-11-25 05:37:58

来自 http://support.microsoft.com /kb/100027

打开物理硬盘
直接磁盘访问(原始 I/O)
基于Win32的应用程序,使用设备
表格名称

\\.\PhysicalDriveN

其中 N 为 0、1、2 等,
代表着每一个物理
系统中的驱动器。

打开逻辑驱动器,直接访问
其形式为

\\.\X: 

其中 X: 是
硬盘分区号、软盘
磁盘驱动器或 CD-ROM 驱动器。

From http://support.microsoft.com/kb/100027

To open a physical hard drive for
direct disk access (raw I/O) in a
Win32-based application, use a device
name of the form

\\.\PhysicalDriveN

where N is 0, 1, 2, and so forth,
representing each of the physical
drives in the system.

To open a logical drive, direct access
is of the form

\\.\X: 

where X: is a
hard-drive partition letter, floppy
disk drive, or CD-ROM drive.

云雾 2024-11-25 05:37:58

请记住,Windows 和其他操作系统中的所有对象都是文件。要从驱动器 E 打开并读取 16 字节数据:使用以下代码:

# Open a Disk in binary format read only 16 bytes
file = "\\\\.\\E:"
with open(file,'rb') as f:
    print("Disk Open")
    data = f.read(16)
    # Convert the binary data to upper case hex ascii code
    hex_data = " ".join("{:02X}".format(c) for c in data)
    print(hex_data)

Remember that all objects in windows and other operating systems are files. To open and read 16 bytes of data from drive E: use the code below:

# Open a Disk in binary format read only 16 bytes
file = "\\\\.\\E:"
with open(file,'rb') as f:
    print("Disk Open")
    data = f.read(16)
    # Convert the binary data to upper case hex ascii code
    hex_data = " ".join("{:02X}".format(c) for c in data)
    print(hex_data)
兮子 2024-11-25 05:37:58

两者都为我工作。要访问 C 分区或整个驱动器,需要管理员权限。这是一个替代 open() 的示例:

def open_physical_drive(
    number,
    mode="rb",
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None,
):
    """
    Opens a physical drive in read binary mode by default
    The numbering starts with 0
    """
    return open(
        fr"\\.\PhysicalDrive{number}",
        mode,
        buffering,
        encoding,
        errors,
        newline,
        closefd,
        opener,
    )


def open_windows_partition(
    letter,
    mode="rb",
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None,
):
    """
    Opens a partition of a windows drive letter in read binary mode by default
    """
    return open(
        fr"\\.\{letter}:", mode, buffering, encoding, errors, newline, closefd, opener
    )


# first 16 bytes from partition C:
# on Linux it's like /dev/sda1
with open_windows_partition("C") as drive_c:
    print(drive_c.read(16))


# first 16 bytes of first drive
# on Linux it's like /dev/sda
with open_physical_drive(0) as drive_0:
    print(drive_0.read(16))

Both worked for me. To gain access to Partition C: or the whole drive, administrator privileges are needed. Here an example as replacement for open():

def open_physical_drive(
    number,
    mode="rb",
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None,
):
    """
    Opens a physical drive in read binary mode by default
    The numbering starts with 0
    """
    return open(
        fr"\\.\PhysicalDrive{number}",
        mode,
        buffering,
        encoding,
        errors,
        newline,
        closefd,
        opener,
    )


def open_windows_partition(
    letter,
    mode="rb",
    buffering=-1,
    encoding=None,
    errors=None,
    newline=None,
    closefd=True,
    opener=None,
):
    """
    Opens a partition of a windows drive letter in read binary mode by default
    """
    return open(
        fr"\\.\{letter}:", mode, buffering, encoding, errors, newline, closefd, opener
    )


# first 16 bytes from partition C:
# on Linux it's like /dev/sda1
with open_windows_partition("C") as drive_c:
    print(drive_c.read(16))


# first 16 bytes of first drive
# on Linux it's like /dev/sda
with open_physical_drive(0) as drive_0:
    print(drive_0.read(16))
昔日梦未散 2024-11-25 05:37:58

这在 Windows 10 上对我不起作用,实际上自 Windows 7 以来就不再对我起作用,而它在 Windows XP 下确实有效。

我正在运行CMD.EXE“以管理员身份”,我的用户帐户似乎是管理员组的成员,并且我不知道我还可以做些什么来让自己能够执行此操作。我不明白怎么会有这么多人声称可以如此随意地做到这一点。

This doesn't work for me on Windows 10, and indeed hasn't worked for me since Windows 7, whereas it DID work under Windows XP.

I am running CMD.EXE "As Administrator," my user account appears to be a member of the Administrators group, and I have no idea what else I could possibly do to give myself the ability to do this. I don't understand how so many people claim to be able to do it so casually.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文