from PIL import Image import os # ========================= device_path = '/dev/sda' sector_start = 0 rows_to_download = 16 sectors_per_row = 32 # ========================= sectors_to_download = (rows_to_download*sectors_per_row) sector_size = 512 width = 16 height = 32 image_width = (1 + (width * sectors_per_row) + (sectors_per_row)) image_height = (1 + (height * rows_to_download) + (rows_to_download)) image = Image.new('RGB', (image_width, image_height), color=(0, 0, 255)) pixels = image.load() def draw_sector(sector_data, x_offset, y_offset, width, height): for y in range(height): for x in range(width): i = y * width + x if i < len(sector_data): byte_value = sector_data[i] red = byte_value green = byte_value pixels[x + x_offset, y + y_offset] = (red, green, 0) def load_sectors(device_path, start_sector, num_sectors, sector_size): sectors_data = [] with open(device_path, 'rb') as f: for sector_num in range(start_sector, start_sector + num_sectors): f.seek(sector_num * sector_size) sector_data = f.read(sector_size) sectors_data.append(list(sector_data)) return sectors_data sektors = load_sectors(device_path, sector_start, sectors_to_download, sector_size) draw_sector(sektors[0],1,1,width,height) for i in range(rows_to_download): for j in range(sectors_per_row): k = (height*i)+j draw_sector(sektors[k],(1+((width + 1)*j)),(1+((height + 1)*i)),width,height) for x in range(image_width): pixels[x, 0] = (0, 0, 255) for y in range(image_height): pixels[0, y] = (0, 0, 255) image.save('sectors.png')