Manual Reference Pages  - binreplace (1)

NAME

binreplace - search or search/replace a binary data stream

CONTENTS

Synopsis
Description
Options
Examples
License
Copyright
Authors

SYNOPSIS

binreplace [options...]

DESCRIPTION

binreplace is used to search a binary data stream for a binary sequence. Once found the position and/or sequence may be reported, and a replacement binary sequence inserted into the data stream. Reads from stdin, writes to stdout.

binreplace may be obtained as part of the drm_tools package from: http://sourceforge.net/projects/drmtools/

OPTIONS

-find <FIND>
  Locate binary sequence FIND in the data stream. The positions and matching patterns will be written to stderr, depending upon the value of the -verbose parameter. If -replace is not also specified nothing is written to stdout.

-replace <REPLACE>
  Replace each FIND match with binary sequence REPLACE and send the resulting stream to stdout.

-mask <MASK>
  Optional processing for each position in FIND. The number of bytes in the binary sequences FIND and MASK must be the same. [Default - no MASK ]
0 Is the corresponding character in FIND
2 Is alphanumeric
4 Is alphabetic
6 Is blank
8 Is control
10 Is digit
12 Is printable, but not space
14 Is printable, includes space
16 Is lower case
18 Is upper case
20 Is either case
22 Is punctuation
24 Is white space
26 Is hexadecimal digit
28 Is any value (wildcard)
1 NOT, modifies all of the above, example: 7 = NOT blank

-verbose <VALUE>
  Control messages sent to stderr during processing. VALUE is a bit mask, if no bits are set only fatal error messages are emitted.
1 Emit FIND positions [Default]
2 Warn if file size might change [Default]
4 Emit FIND matches (as hex)
8 Emit FIND matches (as text)

-first <FIRST>
  First byte in the data stream that FIND may match. Numbered from 0. [Default 0].

-length <LENGTH>
  Last byte in the data stream, counting from FIRST , that FIND may match. [Default: maximum value of data type unsigned long long (usually at least 9223372036854775807)]

-fformat <FFORMAT>
  Format of the FIND string on the command line. This determines how it is converted to a binary sequence. In the Decimal modes either commas or spaces may be used to delimit the values. In all modes a repeat count like \\123\\value will cause the immediately following value to be repeated 123 times. In text input backslashes must be escaped by an immediately preceding backslash.
0 8 bit text: ’09Af’ -> bytes’30 39 41 66’ [Default]
1 8 bit text, case INSENSITIVE
2 16 bit text: ’09Af’ -> bytes’30 00 39 00 41 00 66 00’
3 16 bit text, case INSENSITIVE
4 Hexadecimal: ’09Af’ -> bytes’09 AF’
5 Hexadecimal, case INSENSITIVE
6 Decimal: ’9,175’ -> bytes’09 AF’
7 Decimal, case INSENSITIVE

-rformat <RFORMAT>
  Format of the REPLACE string. The same options apply as for FFORMAT except the case insensitivity bit is ignored. [Default: same as FFORMAT ]

-mformat <MFORMAT>
  Format of the MASK string. The same options apply as for RFORMAT. [Default: 6 (Decimal list)].

-maxpattern <N>
  Size in bytes to allocate for each binary sequence buffer. [Default 1024]

-h -help --help -? --??
  Print the help message. (Default - do not print help message.)

-hexamples
  Print examples. (Default - do not print examples.)

-i Emit version, copyright, license and contact information.( Default - do not emit information.)

EXAMPLES

% binreplace -h
  List the the command line options.

% echo ’F123 abc’ | binreplace -find ’23 ’ -verbose 15
  Find an exactly matching string, show position, and binary sequence in hexadecimal and ascii. Emits:
2 [ 32 33 20] [23 ]

% echo ’F123 abc’ | binreplace -find ’23 ’ -verbose 0 -replace ’09’
  Find and replace a string in the data stream. Since the replace string is one byte shorter than the find pattern, the data stream is reduced in length by one. The associated warning is suppressed by settig verbose to 0. Emits:
F109abc

% echo ’F123 abc’ | binreplace -find ’xxx’ -verbose 15 -mask ’10 24 16’
  Find a property pattern: number, white space, lower case. Emits:
3 [ 33 20 61] [3 a]

% echo ’F123 abc’ | binreplace -find ’xx’ -verbose 15 -mask ’10 10’
  Only the first of two overlapping matches are emitted or replaced. Here the pattern matches both ’12’ and ’23’, but since they overlap, only the former is found. Emits:
1 [ 31 32] [12]

% echo ’F123 abc’ | binreplace -find ’x’ -verbose 15 -mask ’11’
  Find by NOT digits. Emits:
0 [ 46] [F]
4 [ 20] [ ]
5 [ 61] [a]
6 [ 62] [b]
7 [ 63] [c]
8 [ 0A] [~]

% echo ’F123 abc’ | binreplace -find ’xxxAB’ -verbose 15 -mask ’28 28 28 0 0’ -fformat 1
  Retrieve data next to a known case insensitive tag. Emits:
2 [ 32 33 20 61 62] [23 ab]

% echo ’F123 abc’ | binreplace -find ’Fxxxxxxx’ -verbose 0 -mask ’0 10 10 10 24 16 16 16’ -replace ’G789 new’
  Replace a complex pattern. Emits:
G789 new

% (echo ’F123 abc’; echo ’second’) | ./binreplace -find ’0000000A’ -fformat 4 -verbose 15 -replace ’7071720A’ -mask ’28 28 28 0’
  Use hexadecimal find and replace strings combined with mask pattern. Emits:
5 [ 61 62 63 0A] [abc~]
F123 pqr
12 [ 6F 6E 64 0A] [ond~]
secpqr

% echo ’F123 abc’ | binreplace -find ’xx’ -mask ’28,28’ -verbose 15 -replace ’XY’ -first 2 -length 4
  Replace in a restricted area, here positions 2 through 5. Emits:
2 [ 32 33] [23]
4 [ 20 61] [ a]
F1XYXYbc

%echo ’F123 abc’ | binreplace -find ’\6\xc’ -mask ’\6\28 0’ -verbose 31
  Use repeat counts to shorten binary sequence specifications. Emits:
FIND PATTERN: 78 78 78 78 78 78 33
MASK PATTERN: 1C 1C 1C 1C 1C 1C 00
1 [ 31 32 33 20 61 62 63] [123 abc]

LICENSE

GNU General Public License 2

COPYRIGHT

Copyright (C) 2010 David Mathog and Caltech.

AUTHORS

David Mathog, Biology Division, Caltech <mathog@caltech.edu>


drm_tools binreplace (1) 1.0.0 Aug 31 2010
Generated by manServer 1.07 from /usr/common/man/man1/binreplace.1 using man macros.