惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

云风的 BLOG
云风的 BLOG
P
Privacy International News Feed
Vercel News
Vercel News
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 叶小钗
F
Fortinet All Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LINUX DO - 最新话题
AWS News Blog
AWS News Blog
Engineering at Meta
Engineering at Meta
Attack and Defense Labs
Attack and Defense Labs
Recent Announcements
Recent Announcements
Recent Commits to openclaw:main
Recent Commits to openclaw:main
PCI Perspectives
PCI Perspectives
Cloudbric
Cloudbric
AI
AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
IT之家
IT之家
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
J
Java Code Geeks
M
MIT News - Artificial intelligence
Cisco Talos Blog
Cisco Talos Blog
V2EX - 技术
V2EX - 技术
Webroot Blog
Webroot Blog
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
博客园 - 聂微东
G
Google Developers Blog
W
WeLiveSecurity
罗磊的独立博客
P
Privacy & Cybersecurity Law Blog
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
T
Tailwind CSS Blog
V
Visual Studio Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research
Hugging Face - Blog
Hugging Face - Blog
Google DeepMind News
Google DeepMind News
Google DeepMind News
Google DeepMind News
雷峰网
雷峰网
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Full Disclosure
Blog — PlanetScale
Blog — PlanetScale
The Last Watchdog
The Last Watchdog
P
Proofpoint News Feed

博客园 - Mojies

Prompt 相关 T-Lite 简介 CRC 计算 C 语言例子 一个 python 拆解文本文件的工具 UNIX 环境编程 Note ( UPDATING ) 航模.fs.ia6b 接收机记录 线程同步 STM32 Note Linux FrameBuffer note VIM Note Android 开发笔记(更新中....) Effective C++ (暂停更新) Linux Note (Updateing) 关于 HID 你可能需要知道的几件事 (更新中...) 自制树莓派 3D 模型,附 STL 文件 《重构改善既有代码的设计》Tips 翻译: buildroot 用户手册 (更新中...) Some view of engineers 地球地址
Linux 命令行对比二进制文件脚本
Mojies · 2022-03-28 · via 博客园 - Mojies

以下脚本可以完成如下工作:

  1. 使用 ./comp A B 或者 ./comp A B force 来对比文件
  2. 该脚本会用 hexdump 导出二进制文件的十六进制字符表达
  3. 之后使用 vimdiff 打开对比,第一视窗为 A 的 HEX 文件,第二视窗为 B 的 HEX 文件
  4. 可以直接修改 HEX 文件,退出后会用 xxd 保存为二进制文件b
  5. 不使用 force 的时候改动文件会分别保存到 /tmp/${A_NAME}.a.chg /tmp/${A_NAME}.b.chg 路径下
  6. 使用 force 的时候会直接修改原文件

注意: 文件名不能包含空格,否则会出错

A=$1
B=$2

if [ ! -f ${A} ]; then
echo "${A} not exist"
exit
fi
if [ ! -f ${B} ]; then
echo "${B} not exist"
exit
fi

A_NAME=$(basename ${A})
B_NAME=$(basename ${B})

A_HEX=/tmp/${A_NAME}.a.$$$$
B_HEX=/tmp/${B_NAME}.b.$$$$

A_EDITED=/tmp/${A_NAME}.a.chg
B_EDITED=/tmp/${B_NAME}.b.chg

hexdump -v -e '16/1 "%02X ""|\t"' -e '16/1 "%_c""\n"' ${A} > ${A_HEX}
hexdump -v -e '16/1 "%02X ""|\t"' -e '16/1 "%_c""\n"' ${B} > ${B_HEX}

vimdiff -O ${A_HEX} ${B_HEX}

case $3 in
f|force)
cat ${A_HEX} | cut -d'|' -f1 | xxd -r -p > ${A}
cat ${B_HEX} | cut -d'|' -f1 | xxd -r -p > ${B}
;;
*)
cat ${A_HEX} | cut -d'|' -f1 | xxd -r -p > ${A_EDITED}
cat ${B_HEX} | cut -d'|' -f1 | xxd -r -p > ${B_EDITED}
;;
esac

rm -rf ${A_HEX}
rm -rf ${B_HEX}