Skip to content

Instantly share code, notes, and snippets.

@csrutil
Created February 23, 2025 04:32
Show Gist options
  • Save csrutil/d275c60cb787e3e62e7f69e19a62138d to your computer and use it in GitHub Desktop.
Save csrutil/d275c60cb787e3e62e7f69e19a62138d to your computer and use it in GitHub Desktop.
# 文件路径和目标参数
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