Created
February 23, 2025 04:32
-
-
Save csrutil/d275c60cb787e3e62e7f69e19a62138d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 文件路径和目标参数 | |
input_file = "recovery.bin" # 输入文件名 | |
output_file = "output.bin" # 输出文件名 | |
search_marker = b"UBI#" # 要查找的标记 | |
cut_size = 0x04000000 # 切割的大小 | |
try: | |
with open(input_file, "rb") as f: | |
data = f.read() # 读取整个文件内容 | |
# 查找标记的位置 | |
start_pos = data.find(search_marker) | |
if start_pos == -1: | |
print("未找到标记 'UBI#'!") | |
else: | |
print(f"标记 'UBI#' 的起始位置: {start_pos:#x}") | |
# 确定切割范围 | |
end_pos = start_pos + cut_size | |
if end_pos > len(data): | |
print("警告: 切割范围超过文件大小,将截取到文件末尾。") | |
end_pos = len(data) | |
# 提取目标数据 | |
cut_data = data[start_pos:end_pos] | |
# 写入输出文件 | |
with open(output_file, "wb") as f: | |
f.write(cut_data) | |
print(f"切割完成,已保存到 '{output_file}'。") | |
except FileNotFoundError: | |
print(f"文件 '{input_file}' 未找到!") | |
except Exception as e: | |
print(f"发生错误: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment