4

Is there a Linux command-line tool (like grep) that can take a binary file and a series of bytes and return the first index where these bytes appear in the file?

Eldad Mor
  • 5,405
  • 3
  • 34
  • 46

2 Answers2

2
$ grep --only-matching --byte-offset --max-count=1 --text --perl-regexp "\xefa" pathtofile

22157929:ïa

Outputs offset in bytes (start with 0) along with found text, e.g. \xefa searchs for byte with hex code xe followed by char a, --max-count how many occurrences to find. Works on my Linux Mint.

Martian2020
  • 307
  • 3
  • 12
0

You can use xxd to create a hexdump of the binary files and search that.

Amir Afghani
  • 37,814
  • 16
  • 84
  • 124