Repository navigation
Expand file tree
/
Copy pathbgrep.1
More file actions
97 lines (97 loc) · 2.43 KB
/
Copy pathbgrep.1
File metadata and controls
97 lines (97 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
.TH BGREP 1 "2026-06-09" "bgrep 0.3" "User Commands"
.SH NAME
bgrep \- a binary grep
.SH SYNOPSIS
.B bgrep
[\fB\-r\fR] [\fB\-B\fR bytes] [\fB\-A\fR bytes] [\fB\-C\fR bytes] <hex> [<path> [...]]
.br
.B bgrep
[\fB\-r\fR] \fB\-f\fR <pattern path> [\fB\-m\fR <mask path>] [<path> [...]]
.SH DESCRIPTION
A grep(1), but for binary files; searches for hex patterns.
.PP
When no path is given,
.B bgrep
reads from standard input.
.PP
The pattern is given as
.I <hex>
with two digits per byte (no
.B 0x
prefix); spaces between bytes are ignored and the digits are case-insensitive.
.PP
A pattern containing
.B ??
is a wildcard that matches any value. Text may be embedded by quoting it
(for example
.BR \(dqABC\(dq ),
with backslash as the escape character.
.PP
Alternatively, a file pattern and mask can be supplied;
if present, the mask will be ANDed before the comparison.
.SH OPTIONS
.TP
.BR \-B " <bytes>"
print <bytes> immediately before the match offset
.TP
.BR \-A " <bytes>"
print <bytes> starting at the match offset. The window begins at the match, so
it covers the matched bytes first; to see N bytes following an M-byte pattern,
use
.BR \-A " (M+N)."
.TP
.BR \-C " <bytes>"
print <bytes> before the match and <bytes> after it, with the matched bytes
shown in between
.TP
.B \-r
recurse into directories
.TP
.BR \-f " <file>"
read the search pattern (in binary) from a file instead of <hex>
.TP
.BR \-m " <file>"
read a mask file
.SH OUTPUT
Each match is printed as the file name, a colon, and the zero-padded
hexadecimal offset of the match, one per line. When context is requested with
.BR \-A ", " \-B ", or " \-C ,
the surrounding bytes are dumped on the following line; printable bytes are
shown as-is and others as
.BR \(rsxNN .
See
.B OPTIONS
for exactly which bytes each flag includes.
.SH EXIT STATUS
.B bgrep
exits 0 when it runs successfully, whether or not a match was found. It exits
nonzero on error: 2 for an invalid or empty
.I <hex>
pattern, and other nonzero codes when a pattern, mask, or input file is missing
or cannot be read.
.SH EXAMPLES
Search a file for the byte sequence 0x42 0x42 0x42:
.PP
.RS
bgrep 424242 firmware.bin
.RE
.PP
Recurse through a directory:
.PP
.RS
bgrep -r 424242 ./images
.RE
.SH FILES
The pattern file read with
.B \-f
and the mask file read with
.B \-m
are both plain binary files.
.SH LICENSE
BSD 2-Clause.
.SH AUTHOR
Felix Domke <tmbinc@elitedvb.net>
.SH COPYRIGHT
Copyright 2009 Felix Domke. All rights reserved.
.SH SEE ALSO
.BR grep (1)