Skip to content

Commit 73ed69d

Browse files
committed
add binary-grep.sh
1 parent 952ea77 commit 73ed69d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

bash/binary-grep.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /bin/sh
2+
# binary-grep.sh
3+
# find offset of one small binary file
4+
# inside another large binary file
5+
# license: public domain
6+
# https://unix.stackexchange.com/questions/39728
7+
8+
if [ $# != 2 ]; then
9+
echo "usage: $0 needle.bin haystack.bin" >&2
10+
exit 1
11+
fi
12+
13+
needle="$1"
14+
haystack="$2"
15+
16+
# the order of the files $haystack and $needle
17+
# matters for performance
18+
19+
xdelta3 -e -s "$haystack" "$needle" /dev/stdout |
20+
xdelta3 printhdrs /dev/stdin |
21+
grep "VCDIFF copy window offset" | cut -c 31-

0 commit comments

Comments
 (0)