我正在 python 中创建一个 Windows 工具来读取磁盘映像(即 .001 等)并显示文件树和大小等基本信息。为此,我有这个链接,它正在读取.dd
扩展磁盘映像。当我尝试使用.001
磁盘映像时,它会在读取文件时引发此错误。
# this mathod allows for file upload and it also glues all info received together
def upload_file():
filename = askopenfilename() # takes file and puts it into variable
txt = ""
type_txt = ""
ntfs_exists = False
for partition_no in range(1,5): # only 4 iterations because there is max of 4 partitions
txt += "Partition " + str(partition_no) + ": " # create initial string and as it goes, keep adding info
txt += "Start Sector is "
start_txt = partition_start(filename, partition_no) # info where partiton starts
txt += start_txt
txt += partition_size(filename, partition_no) # info what is the size
type_txt = 'NTFS' #partition_type(filename, partition_no) # infor what is the type
txt += "Type is " + type_txt
txt += "\n" # new space is for another iteration - each iteration is next partition
if type_txt == 'NTFS':
ntfs_exists = True
ntfs_txt = ntfs_info(filename, int(start_txt))
display_info(txt) # in ealier versions this method was called at the very end (after for loop
ends), but I discovered txt looks nicer that way
display_info("--------------------------------------------") # this makes a nice line under
partition info so its easier to read other info
if ntfs_exists:
display_info(ntfs_txt) # ntfs info gets displayed
# this method discovers where partiton starts
def partition_start(filename, partition_no): # the file and partition no. we investigate gets
passed
with open(filename, "rb") as f: # read as binary
size = 446 + (16*partition_no) # each partiton is 16 bytes. First 466 bytes is the initial
MBR info
disk_image = f.read(size) # take the bytes I want to read and put them into variable
txt = disk_image[-8:-4] # put into variable bytes where info on partition start is stored
#txt = txt[::-1] # in ealier versions of this program I was using this line to convert to little endian
txt = int.from_bytes(txt, byteorder='little') # in current version of this program, I use this to convert to little endian
# if partition_no == 1:
# fat_info(filename, txt)
return str(txt)
# this method extracts info about partition size
def partition_size(filename, partition_no): # accept disk image and partition no. we investigate
with open(filename, "rb") as f: # read as binary
size = 446 + (16*partition_no) # 446 inital bytes + partition we are interested in
disk_image = f.read(size)
txt = disk_image[-4:] # bytes where information is stored
#txt = txt[::-1] # used before to convert to little endian
txt = int.from_bytes(txt, byteorder='little') # using this now to convert to little endian
txt = ", Size is " + str(txt) + " sectors, " # put in nice string format
return txt
# this method checks for partition type
def partition_type(filename, partition_no):
with open(filename, "rb") as f:
size = 446 + (16*partition_no)
disk_image = f.read(size)
txt = disk_image[-12:-11] # bytes where information is stored
txt = int.from_bytes(txt, byteorder='little') # its a single byte so there is probably no need for this, but left it in case I need it in future
return check(txt) # check() method takes byte and returns string which is the name of the type
我收到的错误是:
PS C:\Users\hp\Downloads\Basic-Disk-Image-Reader-main\Basic-Disk-Image-Reader-main> &
'C:\Users\hp\AppData\Local\Programs\Python\Python310\python.exe'
'c:\Users\hp\.vscode\extensions\ms-python.python-2021.11.1422169775\pythonFiles\lib\python\debugpy\launcher' '53110' '--'
'c:\Users\hp\Downloads\Basic-Disk-Image-Reader-main\Basic-Disk-Image-Reader-main\disk_image_reader.py'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\hp\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
return self.func(*args)
File "c:\Users\hp\Downloads\Basic-Disk-Image-Reader-main\Basic-Disk-Image-Reader-main\disk_image_reader.py", line 132, in upload_file
ntfs_txt = ntfs_info(filename, int(start_txt))
File "c:\Users\hp\Downloads\Basic-Disk-Image-Reader-main\Basic-Disk-Image-Reader-main\disk_image_reader.py", line 62, in ntfs_info
disk_image = f.read(size)
MemoryError
PS C:\Users\hp\Downloads\Basic-Disk-Image-Reader-main\Basic-Disk-Image-Reader-main>
MBR 大小、分区大小或分区数是否有任何问题,因为这些都是硬编码的,因为这些都是一般值?