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

推荐订阅源

Engineering at Meta
Engineering at Meta
Cloudbric
Cloudbric
云风的 BLOG
云风的 BLOG
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
IT之家
IT之家
F
Full Disclosure
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Hugging Face - Blog
Hugging Face - Blog
B
Blog
H
Help Net Security
The Cloudflare Blog
Recorded Future
Recorded Future
P
Proofpoint News Feed
P
Proofpoint News Feed
C
Cisco Blogs
T
Tailwind CSS Blog
P
Palo Alto Networks Blog
D
Docker
爱范儿
爱范儿
Know Your Adversary
Know Your Adversary
博客园 - 聂微东
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Y
Y Combinator Blog
雷峰网
雷峰网
AWS News Blog
AWS News Blog
D
DataBreaches.Net
博客园 - 司徒正美
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - Franky
C
Cybersecurity and Infrastructure Security Agency CISA
Blog — PlanetScale
Blog — PlanetScale
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Latest news
Latest news
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
C
CERT Recently Published Vulnerability Notes
阮一峰的网络日志
阮一峰的网络日志
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CXSECURITY Database RSS Feed - CXSecurity.com
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
腾讯CDC
小众软件
小众软件
G
Google Developers Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Scott Helme
Scott Helme
O
OpenAI News

博客园 - 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}