-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathext2reader.py
More file actions
30 lines (18 loc) · 784 Bytes
/
ext2reader.py
File metadata and controls
30 lines (18 loc) · 784 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""ext2reader.py: EXT2 File reader."""
__author__ = "Frederik Bußmann"
__license__ = "MIT"
__version__ = "1.0.0"
__maintainer__ = "Frederik Bußmann"
__email__ = "frederik@bussmann.io"
import io
from ext2 import file
from PIL import Image
ext2file = file.File()
ext2file.read("data/", "agwc.txt")
ext2file.print_statistics()
# Extract agwc.jpg from ext2file
first_inode_index = ext2file.super_block.s_first_ino # Get block index of first inode
first_inode = ext2file.inodes[first_inode_index] # Get first inode via their block index
data_blocks = ext2file.get_inode_blocks(first_inode) # Get data blocks from first inode
img = Image.open(io.BytesIO(data_blocks)) # Save bytes from data_blocks into image file
img.save("data/agwc.jpg") # Save image file at path/name