temp restore

This commit is contained in:
Burgess Leo
2025-05-19 13:25:07 +08:00
parent b2e14fdbe0
commit 07a4ae7a74
5 changed files with 83 additions and 8 deletions

View File

@@ -2,6 +2,8 @@ import hashlib
import random
import sqlite3
from mft_analyze import GetFile80hPattern
# 工具函数:获取文件扩展名
def GetFileExtension(name: str) -> str:
@@ -64,7 +66,23 @@ def GetFileHash(full_path: str) -> str:
# 获取分片数1~4
def GetExtentCount(full_path: str) -> int:
return random.randint(1, 4)
try:
pattern = GetFile80hPattern(full_path)
if not pattern:
return 1 # 默认值
# 取第一个80h属性(通常文件只有一个80h属性)
attr = pattern[0]
if attr['is_resident']:
return 1 # 常驻属性只有一个分片
else:
# 非常驻属性需要解析实际分片数
# 这里简化为从sequence中解析实际可能需要更复杂的解析
return 1 # 简化处理,实际应根据数据结构解析
except Exception as e:
print(f"❌ 获取ExtentCount出错: {e}, 使用默认值1")
return 1 # 出错时返回默认值
# 获取随机位置
@@ -77,6 +95,53 @@ def GetRandomLength() -> int:
return random.randint(1000, 9999)
def GetFileLocation(full_path: str) -> int:
try:
pattern = GetFile80hPattern(full_path)
if not pattern:
return GetRandomLocation() # 回退到随机值
attr = pattern[0]
if attr['is_resident']:
# 常驻属性: start_byte + offset + content_offset
# 解析content_offset (sequence第三个元素的后4字节)
content_offset_bytes = attr['sequence'][2].split()[4:8]
content_offset = int.from_bytes(
bytes.fromhex(''.join(content_offset_bytes)),
byteorder='little'
)
return attr['start_byte'] + attr['offset'] + content_offset
else:
# 非常驻属性需要解析runlist
# 这里简化为返回start_byte
return attr['start_byte']
except Exception as e:
print(f"❌ 获取Location出错: {e}, 使用随机值")
return GetRandomLocation() # 出错时返回随机值
def GetFileLength(full_path: str) -> int:
try:
pattern = GetFile80hPattern(full_path)
if not pattern:
return GetRandomLength() # 回退到随机值
attr = pattern[0]
if attr['is_resident']:
# 常驻属性: 解析sequence第三个元素的前4字节
content_length_bytes = attr['sequence'][2].split()[0:4]
return int.from_bytes(
bytes.fromhex(''.join(content_length_bytes)),
byteorder='little'
)
else:
# 非常驻属性: 从属性头中解析实际大小
return attr['attribute_length'] # 简化处理
except Exception as e:
print(f"❌ 获取Length出错: {e}, 使用随机值")
return GetRandomLength() # 出错时返回随机值
# 主函数:将 db_path 数据导入 db_node
def InsertNodeDataToDB(db_path='../src/db_ntfs_info.db', table_name='db_node'):
conn = sqlite3.connect(db_path)
@@ -166,4 +231,4 @@ def InsertNodeDataToDB(db_path='../src/db_ntfs_info.db', table_name='db_node'):
if __name__ == '__main__':
InsertNodeDataToDB()
InsertNodeDataToDB()