| 1 |
<html lang="en"> |
| 2 |
<head> |
| 3 |
<title>bbe - binary block editor</title> |
| 4 |
<meta http-equiv="Content-Type" content="text/html"> |
| 5 |
<meta name="description" content="bbe - binary block editor"> |
| 6 |
<meta name="generator" content="makeinfo 4.8"> |
| 7 |
<link title="Top" rel="top" href="#Top"> |
| 8 |
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> |
| 9 |
<!-- |
| 10 |
This file documents version 0.2.2 of `bbe', a binary block editor. |
| 11 |
|
| 12 |
Copyright (C) 2005 Timo Savinen |
| 13 |
|
| 14 |
Permission is granted to make and distribute verbatim copies of |
| 15 |
this manual provided the copyright notice and this permission |
| 16 |
notice are preserved on all copies. |
| 17 |
|
| 18 |
Permission is granted to copy and distribute modified versions of |
| 19 |
this manual under the conditions for verbatim copying, provided |
| 20 |
that the entire resulting derived work is distributed under the |
| 21 |
terms of a permission notice identical to this one. |
| 22 |
|
| 23 |
Permission is granted to copy and distribute translations of this |
| 24 |
manual into another language, under the above conditions for |
| 25 |
modified versions. |
| 26 |
--> |
| 27 |
<meta http-equiv="Content-Style-Type" content="text/css"> |
| 28 |
<style type="text/css"><!-- |
| 29 |
pre.display { font-family:inherit } |
| 30 |
pre.format { font-family:inherit } |
| 31 |
pre.smalldisplay { font-family:inherit; font-size:smaller } |
| 32 |
pre.smallformat { font-family:inherit; font-size:smaller } |
| 33 |
pre.smallexample { font-size:smaller } |
| 34 |
pre.smalllisp { font-size:smaller } |
| 35 |
span.sc { font-variant:small-caps } |
| 36 |
span.roman { font-family:serif; font-weight:normal; } |
| 37 |
span.sansserif { font-family:sans-serif; font-weight:normal; } |
| 38 |
--></style> |
| 39 |
</head> |
| 40 |
<body> |
| 41 |
<h1 class="settitle">bbe - binary block editor</h1> |
| 42 |
<div class="node"> |
| 43 |
<p><hr> |
| 44 |
<a name="Top"></a> |
| 45 |
Next: <a rel="next" accesskey="n" href="#Overview">Overview</a>, |
| 46 |
Previous: <a rel="previous" accesskey="p" href="#dir">(dir)</a>, |
| 47 |
Up: <a rel="up" accesskey="u" href="#dir">(dir)</a> |
| 48 |
|
| 49 |
</div> |
| 50 |
|
| 51 |
<h2 class="unnumbered">bbe</h2> |
| 52 |
|
| 53 |
<p>This file documents version 0.2.2 of <samp><span class="command">bbe</span></samp>, a binary block editor. |
| 54 |
|
| 55 |
<p>Copyright © 2005 Timo Savinen |
| 56 |
|
| 57 |
<blockquote> |
| 58 |
Permission is granted to make and distribute verbatim copies of |
| 59 |
this manual provided the copyright notice and this permission notice |
| 60 |
are preserved on all copies. |
| 61 |
|
| 62 |
<p>Permission is granted to copy and distribute modified versions of this |
| 63 |
manual under the conditions for verbatim copying, provided that the entire |
| 64 |
resulting derived work is distributed under the terms of a permission |
| 65 |
notice identical to this one. |
| 66 |
|
| 67 |
<p>Permission is granted to copy and distribute translations of this manual |
| 68 |
into another language, under the above conditions for modified versions. |
| 69 |
</blockquote> |
| 70 |
|
| 71 |
<!-- All the menus can be updated with the EMACS command --> |
| 72 |
<!-- texinfo-all-menus-update, which is normally bound to C-c C-u C-a. --> |
| 73 |
<ul class="menu"> |
| 74 |
<li><a accesskey="1" href="#Overview">Overview</a>: Preliminary information. |
| 75 |
<li><a accesskey="2" href="#Samples">Samples</a>: Samples using <samp><span class="command">bbe</span></samp>. |
| 76 |
<li><a accesskey="3" href="#Invoking-bbe">Invoking bbe</a>: How to run <samp><span class="command">bbe</span></samp>. |
| 77 |
<li><a accesskey="4" href="#bbe-programs">bbe programs</a>: How <samp><span class="command">bbe</span></samp> works. |
| 78 |
<li><a accesskey="5" href="#Problems">Problems</a>: Reporting bugs. |
| 79 |
</ul> |
| 80 |
|
| 81 |
<div class="node"> |
| 82 |
<p><hr> |
| 83 |
<a name="Overview"></a> |
| 84 |
Next: <a rel="next" accesskey="n" href="#Samples">Samples</a>, |
| 85 |
Previous: <a rel="previous" accesskey="p" href="#Top">Top</a>, |
| 86 |
Up: <a rel="up" accesskey="u" href="#Top">Top</a> |
| 87 |
|
| 88 |
</div> |
| 89 |
|
| 90 |
<h2 class="chapter">1 Preliminary information</h2> |
| 91 |
|
| 92 |
<p><a name="index-greetings-1"></a><a name="index-overview-2"></a> |
| 93 |
The <samp><span class="command">bbe</span></samp> program is a sed-like editor for binary files. <samp><span class="command">bbe</span></samp> |
| 94 |
performs basic byte related transformations on blocks of input stream. <samp><span class="command">bbe</span></samp> is non-interactive command line tool and |
| 95 |
can be used as a part of a pipeline. <samp><span class="command">bbe</span></samp> makes only one pass over input stream. |
| 96 |
|
| 97 |
<p><samp><span class="command">bbe</span></samp> contains also grep-like features, like printing the filename, offset and block number. |
| 98 |
|
| 99 |
<div class="node"> |
| 100 |
<p><hr> |
| 101 |
<a name="Samples"></a> |
| 102 |
Next: <a rel="next" accesskey="n" href="#Invoking-bbe">Invoking bbe</a>, |
| 103 |
Previous: <a rel="previous" accesskey="p" href="#Overview">Overview</a>, |
| 104 |
Up: <a rel="up" accesskey="u" href="#Top">Top</a> |
| 105 |
|
| 106 |
</div> |
| 107 |
|
| 108 |
<h2 class="chapter">2 Samples using <samp><span class="command">bbe</span></samp></h2> |
| 109 |
|
| 110 |
<p><a name="index-sample-3"></a> |
| 111 |
Few examples of running <samp><span class="command">bbe</span></samp>: |
| 112 |
|
| 113 |
<dl> |
| 114 |
<dt>`<samp><span class="samp">bbe -b "/\x80\x50\x0e/:12" -e "d 0 3" -e "c BCD ASC" -e "A \x0a" -e "w /tmp/numbers" -o /dev/null /tmp/bdata</span></samp>'<dd>Task here is to extract BCD coded numbers from the file <samp><span class="file">/tmp/bdata</span></samp> and write them |
| 115 |
in ascii format with newline to file <samp><span class="file">/tmp/numbers</span></samp>. |
| 116 |
12 bytes long blocks containing the BCD-numbers start with three byte sequence of |
| 117 |
values `<samp><span class="samp">0x80</span></samp>', `<samp><span class="samp">0x50</span></samp>' and `<samp><span class="samp">0x0e</span></samp>'. First three bytes (the block start sequence) |
| 118 |
are removed (`<samp><span class="samp">d 0 3</span></samp>') rest of the block is transformed from BCD to Ascii (`<samp><span class="samp">c BCD ASC</span></samp>') and a newline character is |
| 119 |
appended at the end of the block (`<samp><span class="samp">A \x0a</span></samp>'). |
| 120 |
All transformed blocks are written to <samp><span class="file">/tmp/numbers</span></samp> (`<samp><span class="samp">w /tmp/numbers</span></samp>'). Nothing is written to |
| 121 |
the output (`<samp><span class="samp">-o /dev/null</span></samp>'). |
| 122 |
<br> |
| 123 |
|
| 124 |
<br><dt>`<samp><span class="samp">bbe -b ":525" -e "i 524 \x0a" -o /tmp/data_with_nl /tmp/data</span></samp>'<dd>A newline is added after every 525'th byte of the file <samp><span class="file">/tmp/data</span></samp>. Data with newlines is written to <samp><span class="file">/tmp/data_with_nl</span></samp>. |
| 125 |
<br> |
| 126 |
|
| 127 |
<br><dt>`<samp><span class="samp">bbe -b ":526" -e "d 525 1" -o /tmp/data /tmp/data_with_nl</span></samp>'<dd>Every 526'th byte (inserted newline in previous example) is removed from the file <samp><span class="file">/tmp/data_with_nl</span></samp>. Data without newlines is written to <samp><span class="file">/tmp/data</span></samp>. |
| 128 |
<br> |
| 129 |
|
| 130 |
<br><dt>`<samp><span class="samp">bbe -e "s/\x0d\x0a/\x0a/"</span></samp>'<dd>Same effect as has command <samp><span class="command">dos2unix</span></samp>. |
| 131 |
</dl> |
| 132 |
|
| 133 |
<div class="node"> |
| 134 |
<p><hr> |
| 135 |
<a name="Invoking-bbe"></a> |
| 136 |
Next: <a rel="next" accesskey="n" href="#bbe-programs">bbe programs</a>, |
| 137 |
Previous: <a rel="previous" accesskey="p" href="#Samples">Samples</a>, |
| 138 |
Up: <a rel="up" accesskey="u" href="#Top">Top</a> |
| 139 |
|
| 140 |
</div> |
| 141 |
|
| 142 |
<h2 class="chapter">3 How to run <samp><span class="command">bbe</span></samp></h2> |
| 143 |
|
| 144 |
<p><a name="index-running-bbe-4"></a><a name="index-using-5"></a> |
| 145 |
<samp><span class="command">bbe</span></samp> accepts several commands to operate on blocks. Commands are |
| 146 |
executed in the same order as they appear in command line or in a script file. |
| 147 |
Order is significant, because the changes made to current byte by previous commands are |
| 148 |
seen by next commands. |
| 149 |
|
| 150 |
<ul class="menu"> |
| 151 |
<li><a accesskey="1" href="#Invocation">Invocation</a>: Program invocation |
| 152 |
<li><a accesskey="2" href="#Block">Block</a>: Block definition |
| 153 |
<li><a accesskey="3" href="#Commands">Commands</a>: bbe commands |
| 154 |
<li><a accesskey="4" href="#Limits">Limits</a>: Limitations |
| 155 |
</ul> |
| 156 |
|
| 157 |
<div class="node"> |
| 158 |
<p><hr> |
| 159 |
<a name="Invocation"></a> |
| 160 |
Next: <a rel="next" accesskey="n" href="#Block">Block</a>, |
| 161 |
Up: <a rel="up" accesskey="u" href="#Invoking-bbe">Invoking bbe</a> |
| 162 |
|
| 163 |
</div> |
| 164 |
|
| 165 |
<h3 class="section">3.1 Program invocation</h3> |
| 166 |
|
| 167 |
<p><a name="index-options-6"></a> |
| 168 |
The format for running the <samp><span class="command">bbe</span></samp> program is: |
| 169 |
|
| 170 |
<pre class="example"> bbe <var>option</var> ... |
| 171 |
</pre> |
| 172 |
<p><code>bbe</code> supports the following options: |
| 173 |
|
| 174 |
<!-- Formatting copied from the Texinfo 4.0 manual. --> |
| 175 |
<dl> |
| 176 |
<dt><code>-b </code><var>BLOCK</var><dt><code>--block=</code><var>BLOCK</var><dd>Block definition. |
| 177 |
|
| 178 |
<br><dt><code>-e </code><var>COMMAND</var><dt><code>--expression=</code><var>COMMAND</var><dd>Add command(s) to the commands to be executed. Commands must be separated by semicolon. |
| 179 |
|
| 180 |
<br><dt><code>-f </code><var>script-file</var><dt><code>--file=</code><var>script-file</var><dd>Add commands from <var>script-file</var> to the commands to be executed. |
| 181 |
|
| 182 |
<br><dt><code>-o </code><var>file</var><dt><code>--output=</code><var>file</var><dd>Write output to <var>file</var> instead of standard output. |
| 183 |
|
| 184 |
<br><dt><code>-s</code><dt><code>--suppress</code><dd>Suppress printing of normal output, print only block contents. |
| 185 |
|
| 186 |
<br><dt><code>-?</code><dt><code>--help</code><dd>Print an informative help message describing the options and then exit |
| 187 |
successfully. |
| 188 |
|
| 189 |
<br><dt><code>-V</code><dt><code>--version</code><dd>Print the version number of <samp><span class="command">bbe</span></samp> and then exit successfully. |
| 190 |
</dl> |
| 191 |
|
| 192 |
<p>All remaining options are names of input files, if no input files are specified or <code>-</code> is given, then the standard input is read. |
| 193 |
|
| 194 |
<div class="node"> |
| 195 |
<p><hr> |
| 196 |
<a name="Block"></a> |
| 197 |
Next: <a rel="next" accesskey="n" href="#Commands">Commands</a>, |
| 198 |
Previous: <a rel="previous" accesskey="p" href="#Invocation">Invocation</a>, |
| 199 |
Up: <a rel="up" accesskey="u" href="#Invoking-bbe">Invoking bbe</a> |
| 200 |
|
| 201 |
</div> |
| 202 |
|
| 203 |
<h3 class="section">3.2 Block definition</h3> |
| 204 |
|
| 205 |
<p><a name="index-block-7"></a> |
| 206 |
<samp><span class="command">bbe</span></samp> devides the input stream to blocks defined by the <code>-b</code> option. If block is |
| 207 |
not defined, the whole input stream is considered as one block. Commands have effect only inside a block, rest of the input stream |
| 208 |
remains untouched. Currently <samp><span class="command">bbe</span></samp> supports only one block definition per invocation. If input stream consists of different blocks, |
| 209 |
several <samp><span class="command">bbe</span></samp>s can be combined in a pipeline. |
| 210 |
|
| 211 |
<p>A block can be defined several ways: |
| 212 |
|
| 213 |
<dl> |
| 214 |
<dt><var>N</var><code>:</code><var>M</var><dd>Block starts at offset <var>N</var> of input stream (first byte is 0). Block is <var>M</var> bytes long. This definition allows |
| 215 |
only one block to be defined. |
| 216 |
|
| 217 |
<br><dt><code>:</code><var>M</var><dd>The whole input stream is divided to <var>M</var>-size blocks. |
| 218 |
|
| 219 |
<br><dt><code>/</code><var>start</var><code>/:/</code><var>stop</var><code>/</code><dd>Blocks start with sequence <var>start</var> and end with sequence <var>stop</var>. Both <var>start</var> and <var>stop</var> are included to blocks. |
| 220 |
|
| 221 |
<br><dt><code>/</code><var>start</var><code>/:</code><dd>Blocks start with sequence <var>start</var> and ends at next occurrence of <var>start</var>. Only the first <var>start</var> is included to block. |
| 222 |
|
| 223 |
<br><dt><code>:/</code><var>stop</var><code>/</code><dd>Blocks start at the beginning of input stream or after the end of previous block. Block ends at first occurrence of <var>stop</var>. |
| 224 |
Only the last <var>stop</var> is included to blocks. |
| 225 |
</dl> |
| 226 |
|
| 227 |
<p>It is possible to use c-like byte values in <var>N</var>, <var>M</var>, <var>start</var> and <var>stop</var>. |
| 228 |
Values in <var>start</var> and <var>stop</var> must be escaped with <code>\</code>, <code>\</code> can be escaped as <code>\\</code>. |
| 229 |
|
| 230 |
<p>Byte values can be expressed in decimal, octal or hexadecimal e.g. in <var>start</var> and <var>stop</var>: |
| 231 |
|
| 232 |
<dl> |
| 233 |
<dt><code>\123, \32 or \0</code><dd>Decimal values |
| 234 |
|
| 235 |
<br><dt><code>\012, \08 or \0278</code><dd>Octal values |
| 236 |
|
| 237 |
<br><dt><code>\x0a, \x67 or \xff</code><dd>Hexadecimal values |
| 238 |
</dl> |
| 239 |
|
| 240 |
<p>Also escape code <code>\y</code> can be used. Decimal values of <code>\y</code>'s: |
| 241 |
|
| 242 |
<dl> |
| 243 |
<dt><code>\a</code><dd>7 |
| 244 |
|
| 245 |
<br><dt><code>\b</code><dd>8 |
| 246 |
|
| 247 |
<br><dt><code>\t</code><dd>9 |
| 248 |
|
| 249 |
<br><dt><code>\n</code><dd>10 |
| 250 |
|
| 251 |
<br><dt><code>\v</code><dd>11 |
| 252 |
|
| 253 |
<br><dt><code>\f</code><dd>12 |
| 254 |
|
| 255 |
<br><dt><code>\r</code><dd>13 |
| 256 |
|
| 257 |
<br><dt><code>\;</code><dd>59<br>Semicolon must be escaped, because it is a command delimitter. |
| 258 |
</dl> |
| 259 |
|
| 260 |
<p>Values of <var>N</var> and <var>M</var> can be given in decimal, octal and hexadecimal: |
| 261 |
|
| 262 |
<dl> |
| 263 |
<dt><code>123, 32 or 112232</code><dd>Decimal values |
| 264 |
|
| 265 |
<br><dt><code>0128, 08123 or 0</code><dd>Octal values |
| 266 |
|
| 267 |
<br><dt><code>x456a, x167 or xffde</code><dd>Hexadecimal values |
| 268 |
</dl> |
| 269 |
|
| 270 |
<div class="node"> |
| 271 |
<p><hr> |
| 272 |
<a name="Commands"></a> |
| 273 |
Next: <a rel="next" accesskey="n" href="#Limits">Limits</a>, |
| 274 |
Previous: <a rel="previous" accesskey="p" href="#Block">Block</a>, |
| 275 |
Up: <a rel="up" accesskey="u" href="#Invoking-bbe">Invoking bbe</a> |
| 276 |
|
| 277 |
</div> |
| 278 |
|
| 279 |
<h3 class="section">3.3 <samp><span class="command">bbe</span></samp> commands</h3> |
| 280 |
|
| 281 |
<p><a name="index-commands-8"></a> |
| 282 |
Commands in <samp><span class="command">bbe</span></samp> can be divided in two groups: Block related commands |
| 283 |
and byte related commands. Block related commands operate at block level e.g. remove a block. |
| 284 |
Byte related commands work allways inside a block and they don't have effect beyond the block boundaries. |
| 285 |
|
| 286 |
<p>Same escape codes for byte values in <var>string</var>s can be used as in <var>start</var> and <var>stop</var> of block definition. |
| 287 |
|
| 288 |
<h4 class="subheading">Block commands are:</h4> |
| 289 |
|
| 290 |
<dl> |
| 291 |
<dt><code>I </code><var>string</var><dd>Write the <var>string</var> to output stream before the block. |
| 292 |
|
| 293 |
<br><dt><code>D [</code><var>N</var><code>]</code><dd>Delete the <var>N</var>'th block. If <var>N</var> is not defined all blocks are deleted from output stream. |
| 294 |
<strong>Note</strong>: First block is number one. |
| 295 |
|
| 296 |
<br><dt><code>A </code><var>string</var><dd>Write the <var>string</var> to output stream after the block. |
| 297 |
|
| 298 |
<br><dt><code>J </code><var>N</var><dd>Commands appearing after this command have no effect until <var>N</var> blocks are found. Means "Jump first <var>N</var> blocks". |
| 299 |
<strong>Note</strong>: Commands that are defined before this command have effect on every block. |
| 300 |
|
| 301 |
<br><dt><code>L </code><var>N</var><dd>Commands appearing after this command have no effect after <var>N</var> blocks are found. Means "Leave blocks after <var>N</var>'th block". |
| 302 |
<strong>Note</strong>: Commands that are defined before this command have effect on every block. |
| 303 |
|
| 304 |
<br><dt><code>N</code><dd>Before block contents the file name where the current block starts is printed with colon. |
| 305 |
|
| 306 |
<br><dt><code>F </code><var>f</var><dd>Before block contents the current stream offset and colon is printed in format specified by <var>f</var>. |
| 307 |
Stream offset starts at zero. <var>f</var> can have one of following values: |
| 308 |
<dl> |
| 309 |
<dt><var>H</var><dd>Hexadecimal. |
| 310 |
|
| 311 |
<br><dt><var>D</var><dd>Decimal. |
| 312 |
|
| 313 |
<br><dt><var>O</var><dd>Octal. |
| 314 |
</dl> |
| 315 |
|
| 316 |
<br><dt><code>B </code><var>f</var><dd>Before block contents the current block number and colon is printed in format specified by <var>f</var>. |
| 317 |
Block numbering starts at one. <var>f</var> can have one of the sames codes as <code>F</code>-command. |
| 318 |
|
| 319 |
<br><dt><code>> <samp></code><span class="file">file</span><code></samp></code><dd>Before printing a block, the contents of file <samp><span class="file">file</span></samp> is printed. |
| 320 |
|
| 321 |
<br><dt><code>< <samp></code><span class="file">file</span><code></samp></code><dd>After printing a block, the contents of file <samp><span class="file">file</span></samp> is printed. |
| 322 |
</dl> |
| 323 |
|
| 324 |
<h4 class="subheading">Byte commands are:</h4> |
| 325 |
|
| 326 |
<p><strong>Note</strong>: The <var>n</var> in byte commands is offset from the beginning of current block, first byte is number zero. |
| 327 |
|
| 328 |
<dl> |
| 329 |
<dt><code>c </code><var>from</var> <var>to</var><dd>Converts bytes from <var>from</var> to <var>to</var>. Currently supported formats are: |
| 330 |
<dl> |
| 331 |
<dt><code>ASC</code><dd>Ascii |
| 332 |
|
| 333 |
<br><dt><code>BCD</code><dd>Binary Coded Decimal |
| 334 |
</dl> |
| 335 |
<strong>Note</strong>: Bytes, that cannot be converted are passed through as they are. e.g. in ASC -> BCD conversion, ASCII characters not |
| 336 |
in range <code>'0'</code> – <code>'9'</code> are not converted. |
| 337 |
|
| 338 |
<br><dt><code>d </code><var>n</var> <var>m</var><code>|*</code><dd>Delete <var>m</var> bytes starting from the offset <var>n</var>. If * is defined instead of <var>m</var>, then |
| 339 |
all bytes of the block starting from <var>n</var> are deleted. |
| 340 |
|
| 341 |
<br><dt><code>i </code><var>n</var> <var>string</var><dd>Insert <var>string</var> after byte number <var>n</var>. |
| 342 |
|
| 343 |
<br><dt><code>j </code><var>n</var><dd>Commands appearing after <code>j</code>-command have no effect concerning bytes 0-<var>n</var> of the block. |
| 344 |
|
| 345 |
<br><dt><code>l </code><var>n</var><dd>Commands appearing after <code>l</code>-command have no effect concerning bytes starting from the byte number <var>n</var> of the block. |
| 346 |
|
| 347 |
<br><dt><code>u </code><var>n</var> <var>c</var><dd>All bytes from start of the block to offset <var>n</var> are replaced by <var>c</var>. |
| 348 |
|
| 349 |
<br><dt><code>f </code><var>n</var> <var>c</var><dd>All bytes starting from offset <var>n</var> to the end of the block are replaced by <var>c</var>. |
| 350 |
|
| 351 |
<br><dt><code>p </code><var>format</var><dd>Contents of block is printed in formats specified by <var>format</var>. <var>format</var> can contain following format codes: |
| 352 |
<dl> |
| 353 |
<dt><var>H</var><dd>Hexadecimal. |
| 354 |
|
| 355 |
<br><dt><var>D</var><dd>Decimal. |
| 356 |
|
| 357 |
<br><dt><var>O</var><dd>Octal. |
| 358 |
|
| 359 |
<br><dt><var>A</var><dd>Ascii, nonprintable characters are printed as space. |
| 360 |
|
| 361 |
<br><dt><var>B</var><dd>Binary. |
| 362 |
</dl> |
| 363 |
|
| 364 |
<p><var>format</var> can contain several codes, values are then separated by hyphen. |
| 365 |
|
| 366 |
<br><dt><code>r </code><var>n</var> <var>string</var><dd>Replace bytes with <var>string</var> starting at the byte number <var>n</var> of the block. |
| 367 |
|
| 368 |
<br><dt><code>s/</code><var>search</var><code>/</code><var>replace</var><code>/</code><dd>All occurences of <var>search</var> are replaced by <var>replace</var>. <var>replace</var> can be empty. Separator <code>/</code> can be replaced by any |
| 369 |
character not present in <var>search</var> or <var>replace</var>. |
| 370 |
|
| 371 |
<br><dt><code>w <samp></code><span class="file">file</span><code></samp></code><dd>Contents of blocks are written to file <samp><span class="file">file</span></samp>. <strong>Note</strong>: Data inserted by commands <code>A</code>, <code>I</code>, |
| 372 |
<code>></code> and <code><</code> |
| 373 |
are written to file <samp><span class="file">file</span></samp> and <code>j</code> and <code>l</code> commands have no effect on <code>w</code>-commands. Zero size files are not preserved.<br> |
| 374 |
Filename can contain format string <code>%B</code> or <code>%nB</code>, these format strings are replace by current block number (starting from one), causing every block to have it's own file. |
| 375 |
In <code>%nB</code>, the <code>n</code> is field width in range 0-99. If <code>n</code> has a leading zero, then the block numbers will be left padded with zeroes. |
| 376 |
|
| 377 |
<br><dt><code>y/</code><var>source</var><code>/</code><var>dest</var><code>/</code><dd>Translate bytes in <var>source</var> to the corresponding bytes in <var>dest</var>. <var>source</var> and <var>dest</var> must have equal length. |
| 378 |
Separator <code>/</code> can be replaced by any character not present in <var>source</var> or <var>dest</var>. |
| 379 |
|
| 380 |
<br><dt><code>& </code><var>c</var><dd>Performs binary and with <var>c</var> on block contents. |
| 381 |
|
| 382 |
<br><dt><code>| </code><var>c</var><dd>Performs binary or with <var>c</var> on block contents. |
| 383 |
|
| 384 |
<br><dt><code>^ </code><var>c</var><dd>Performs exclusive or with <var>c</var> on block contents. |
| 385 |
|
| 386 |
<br><dt><code>~</code><dd>Performs binary negation on block contents. |
| 387 |
|
| 388 |
<br><dt><code>x</code><dd>Exchange the contents of nibbles (half an octet) of bytes. |
| 389 |
</dl> |
| 390 |
|
| 391 |
<div class="node"> |
| 392 |
<p><hr> |
| 393 |
<a name="Limits"></a> |
| 394 |
Previous: <a rel="previous" accesskey="p" href="#Commands">Commands</a>, |
| 395 |
Up: <a rel="up" accesskey="u" href="#Invoking-bbe">Invoking bbe</a> |
| 396 |
|
| 397 |
</div> |
| 398 |
|
| 399 |
<h3 class="section">3.4 Limitations</h3> |
| 400 |
|
| 401 |
<p><a name="index-big-files-9"></a><a name="index-limits-10"></a> |
| 402 |
At least in GNU/Linux <samp><span class="command">bbe</span></samp> should be able to handle big files (> 4 GB), other |
| 403 |
systems are not tested. |
| 404 |
|
| 405 |
<p>There are however, some limitations in block and command definitions: |
| 406 |
|
| 407 |
<dl> |
| 408 |
<dt><em>Strings in block definition</em><dt><em>Search string in </em><code>s</code><em> command</em><dd>are limited to <em>16384</em> bytes. |
| 409 |
</dl> |
| 410 |
|
| 411 |
<div class="node"> |
| 412 |
<p><hr> |
| 413 |
<a name="bbe-programs"></a> |
| 414 |
Next: <a rel="next" accesskey="n" href="#Problems">Problems</a>, |
| 415 |
Previous: <a rel="previous" accesskey="p" href="#Invoking-bbe">Invoking bbe</a>, |
| 416 |
Up: <a rel="up" accesskey="u" href="#Top">Top</a> |
| 417 |
|
| 418 |
</div> |
| 419 |
|
| 420 |
<h2 class="chapter">4 How <samp><span class="command">bbe</span></samp> works</h2> |
| 421 |
|
| 422 |
<p><samp><span class="command">bbe</span></samp> scans the input stream just once, so the last block may differ from the block definition, because <samp><span class="command">bbe</span></samp> doesn't |
| 423 |
'peek' the end of the input stream. Last block may be shorter than defined, e.g. if block is defined as `<samp><span class="samp">/string/:128</span></samp>' |
| 424 |
and if the end of input stream is found before 128'th byte of the last block is reached, the last block remains shorter. |
| 425 |
|
| 426 |
<h4 class="subheading">Basic execution cycle:</h4> |
| 427 |
|
| 428 |
<ol type=1 start=1> |
| 429 |
<li>Start of the block is searched. If found, data before block is written to output stream (unless <samp><span class="option">-s</span></samp> is defined) and |
| 430 |
step 2 is executed. |
| 431 |
|
| 432 |
<li>Block commands affecting the start of the block (<code>I</code>, <code>D</code>, <code>J</code>, <code>N</code>, <code>F</code>, <code>></code> and <code>B</code>) are executed. |
| 433 |
|
| 434 |
<li>The block is scanned byte by byte and all byte commands (lower case letters) are executed. |
| 435 |
<strong>Note</strong>: Commands are executed on results of previous commands, if e.g. the first byte of the block is deleted, |
| 436 |
the following commands don't 'see' the removed byte. |
| 437 |
|
| 438 |
<li>When end of the block is reached the end of the block commands (<code>A</code> and <code><</code>) are executed. |
| 439 |
|
| 440 |
<li>Next block is searched, data between the blocks, if not suppressed with <samp><span class="option">-s</span></samp>, is written to output stream. |
| 441 |
</ol> |
| 442 |
|
| 443 |
<h4 class="subheading">Few examples:</h4> |
| 444 |
|
| 445 |
<dl> |
| 446 |
<dt>`<samp><span class="samp">echo "The quick brown fox jumps over a lazy dog" | bbe -b "/The/:21" -e "j 4" -e "s/ /X/"</span></samp>'<dd>Output is |
| 447 |
<pre class="example"> The quickXbrownXfoxXjumps over a lazy dog |
| 448 |
</pre> |
| 449 |
<p>The only block in this is |
| 450 |
<pre class="example"> The quick brown fox j |
| 451 |
</pre> |
| 452 |
<p>All spaces in the block are converted to X's, before conversion first 4 bytes are skipped.<br> |
| 453 |
|
| 454 |
<br><dt>`<samp><span class="samp">echo "The quick brown fox jumps over a lazy dog" | bbe -b ":/ /" -e "J 1" -e "A \x0a"</span></samp>'<dd>Output is: |
| 455 |
<pre class="example"> The quick |
| 456 |
brown |
| 457 |
fox |
| 458 |
jumps |
| 459 |
over |
| 460 |
a |
| 461 |
lazy |
| 462 |
dog |
| 463 |
|
| 464 |
</pre> |
| 465 |
<p>All blocks end at space, a newline character is inserted after every block except the first block.<br> |
| 466 |
|
| 467 |
<br><dt>`<samp><span class="samp">echo "The quick brown fox jumps over a lazy dog" | bbe -e "r 4 fast\x20" -e "s/f/c/"</span></samp>'<dd>Output is: |
| 468 |
<pre class="example"> The cast brown cox jumps over a lazy dog |
| 469 |
</pre> |
| 470 |
<p>Also the <code>f</code> in <code>fast</code> is converted to <code>c</code>.<br> |
| 471 |
|
| 472 |
<br><dt>`<samp><span class="samp">echo "1234567890" | bbe -b ":1" -e "L 9" -e "A -"</span></samp>'<dd>Output is |
| 473 |
<pre class="example"> 1-2-3-4-5-6-7-8-9-0 |
| 474 |
</pre> |
| 475 |
<p>Hyphen is inserted after every 1 byte long block,but not after 9'th block.<br> |
| 476 |
|
| 477 |
<br><dt>`<samp><span class="samp">bbe -s -b "/First line/:/Last line/" /tmp/text</span></samp>'<dd>Print lines between sentences `<samp><span class="samp">First line</span></samp>' and `<samp><span class="samp">Last line</span></samp>'.<br> |
| 478 |
|
| 479 |
<br><dt>`<samp><span class="samp">bbe -s -b "%<a %:%</a>%" -e "s/\x0a/ /" -e "A \n" ./index.html</span></samp>'<dd>Extract all links from <samp><span class="file">./index.html</span></samp>. To get one link per line, |
| 480 |
all newlines are converted to spaces and newline is added after every link.<br> |
| 481 |
|
| 482 |
<br><dt>`<samp><span class="samp">bbe -b "/\x5f\x28\x02/:10" -s -e "F d" -e "p h" -e "A \n" ./bindata</span></samp>'<dd>10 bytes long sequences starting with values <code>x5f</code> <code>x28</code> and <code>x02</code> are printed as hex values. |
| 483 |
Also the file offset is printed before each sequence and new line is added after every sequence. |
| 484 |
Example output: |
| 485 |
<pre class="example"> 52688:x5f x28 x02 x32 x36 x5f x81 x64 x01 x93 |
| 486 |
68898:x5f x28 x02 x39 x46 x5f x81 x64 x41 x05 |
| 487 |
69194:x5f x28 x02 x42 x36 x5f x81 x64 x41 x05 |
| 488 |
</pre> |
| 489 |
<p><br> |
| 490 |
|
| 491 |
<br><dt>`<samp><span class="samp">bbe -b "/Linux/:5" -s -e "N;D;A \x0a" /bin/* | uniq</span></samp>'<dd>Print the file names of those programs in /bin directory which contains word `<samp><span class="samp">Linux</span></samp>'. |
| 492 |
Example output: |
| 493 |
<pre class="example"> /bin/loadkeys: |
| 494 |
/bin/mkbimage: |
| 495 |
/bin/ps: |
| 496 |
/bin/uname: |
| 497 |
</pre> |
| 498 |
<p><br> |
| 499 |
|
| 500 |
<br><dt>`<samp><span class="samp">bbe -b "/\x5f\x81\x18\x06/:10" -s -e "B d;d 0 4;c BCD ASC;A \n" ./bindata</span></samp>'<dd>Print BCD numbers and their block numbers in ascii format. Numbers start with sequence <code>x5f</code> <code>x81</code> <code>x18</code> <code>x06</code>. |
| 501 |
The start sequence is not printed.<br> |
| 502 |
|
| 503 |
<br><dt>`<samp><span class="samp">bbe -b "/\x5f/:2" -e "j 1;& \xf0" -o newdata bindata</span></samp>'<dd>The least significant nybble of bytes after <code>x5f</code> is cleared.<br> |
| 504 |
|
| 505 |
<br><dt>`<samp><span class="samp">bbe -b "/\xff\xd8\xff/:/\xff\xd9/" -s -e "w pic%02B.jpg" -o /dev/null manual.pdf</span></samp>'<dd>Extract jpg-images from pdf-file to separate jpg-files (assuming that the jpg start/stop sequences |
| 506 |
does not appear in other context than jpg-images). |
| 507 |
Files will be named as <samp><span class="file">pic01.jpg</span></samp>, <samp><span class="file">pic02.jpg</span></samp>, <samp><span class="file">pic03.jpg</span></samp>,<small class="dots">...</small> <br> |
| 508 |
|
| 509 |
<br><dt>`<samp><span class="samp">bbe -b "_<body>_:_</body>_" -s -o temp nicebody.html</span></samp>'<dt>`<samp><span class="samp">bbe -b "_<body>_:_</body>_" -e "D;< temp" -o tmpindex.html index.html</span></samp>'<dt>`<samp><span class="samp">mv tmpindex.html index.html</span></samp>'<dd>The body part of the html-document <samp><span class="file">index.html</span></samp> is replaced by the body of the document <samp><span class="file">nicebody.html</span></samp>. |
| 510 |
</dl> |
| 511 |
|
| 512 |
<div class="node"> |
| 513 |
<p><hr> |
| 514 |
<a name="Problems"></a> |
| 515 |
Previous: <a rel="previous" accesskey="p" href="#bbe-programs">bbe programs</a>, |
| 516 |
Up: <a rel="up" accesskey="u" href="#Top">Top</a> |
| 517 |
|
| 518 |
</div> |
| 519 |
|
| 520 |
<h2 class="chapter">5 Reporting Bugs</h2> |
| 521 |
|
| 522 |
<p><a name="index-bugs-11"></a><a name="index-problems-12"></a> |
| 523 |
If you find a bug in <samp><span class="command">bbe</span></samp>, please send electronic mail to |
| 524 |
<a href="mailto:[email protected]">[email protected]</a>. Include the version number, which you can find by |
| 525 |
running `<samp><span class="samp">bbe --version</span></samp>'<!-- /@w -->. Also include in your message the |
| 526 |
output that the program produced and the output you expected. |
| 527 |
|
| 528 |
<p>If you have other questions, comments or suggestions about |
| 529 |
<samp><span class="command">bbe</span></samp>, contact the author via electronic mail to |
| 530 |
<a href="mailto:[email protected]">[email protected]</a>. The author will try to help you out, although he |
| 531 |
may not have time to fix your problems. |
| 532 |
|
| 533 |
<div class="contents"> |
| 534 |
<h2>Table of Contents</h2> |
| 535 |
<ul> |
| 536 |
<li><a name="toc_Top" href="#Top">bbe</a> |
| 537 |
<li><a name="toc_Overview" href="#Overview">1 Preliminary information</a> |
| 538 |
<li><a name="toc_Samples" href="#Samples">2 Samples using <samp><span class="command">bbe</span></samp></a> |
| 539 |
<li><a name="toc_Invoking-bbe" href="#Invoking-bbe">3 How to run <samp><span class="command">bbe</span></samp></a> |
| 540 |
<ul> |
| 541 |
<li><a href="#Invocation">3.1 Program invocation</a> |
| 542 |
<li><a href="#Block">3.2 Block definition</a> |
| 543 |
<li><a href="#Commands">3.3 <samp><span class="command">bbe</span></samp> commands</a> |
| 544 |
<li><a href="#Limits">3.4 Limitations</a> |
| 545 |
</li></ul> |
| 546 |
<li><a name="toc_bbe-programs" href="#bbe-programs">4 How <samp><span class="command">bbe</span></samp> works</a> |
| 547 |
<li><a name="toc_Problems" href="#Problems">5 Reporting Bugs</a> |
| 548 |
</li></ul> |
| 549 |
</div> |
| 550 |
|
| 551 |
</body></html> |
| 552 |
|