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

问题描述 投票:0回答:4

我知道在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:'

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

python windows disk low-level
4个回答
12
投票

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

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

\\.\PhysicalDriveN

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

打开逻辑驱动器,直接访问 是这样的形式

\\.\X: 

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


2
投票

请记住,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)

0
投票

两者都对我有用。要访问 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))

0
投票

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

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

© www.soinside.com 2019 - 2024. All rights reserved.