-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
40 lines (33 loc) · 1.18 KB
/
Copy pathutils.py
File metadata and controls
40 lines (33 loc) · 1.18 KB
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
31
32
33
34
35
36
37
38
39
40
import constants as C
import time
from datetime import datetime
import hashlib
from structures import SuperBlockStruct
from construct import Container
from rich import print as rprint
def timestamp() -> int:
return int(time.time())
def timestr(timestamp: int) -> str:
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def get_disk_start(block: bytes) -> int:
# 检查mbr的魔数
if block[-2:] == b'\x55\xaa':
return 200
else:
return 0
def get_disk_params(data: bytes) -> tuple[int, int]:
superblock = SuperBlockStruct.parse(data)
inode_block_size = superblock.s_isize
disk_block_size = superblock.s_fsize
return inode_block_size, disk_block_size
def bytes_or(b1: bytes, b2: bytes) -> bytes:
return bytes(b1[i] | b2[i] for i in range(len(b1)))
def get_superblock_hash(superblock: bytes) -> bytes:
data = superblock[:C.SUPERBLOCK_BYTES - 16]
hash = hashlib.sha256(data).digest()
return bytes_or(hash[:8], C.MAGIC)
start_time = time.time()
def debug_print(*args):
if C.OUTPUT_LOG:
text = " ".join(str(arg) for arg in args)
rprint(f"[yellow]{time.time() - start_time:.2f}[/yellow] : {text}")