BBE(1)
π BBE(1) β bestie edition π
okay so. sit down. hydrate. because I am about to put you on to bbe, aka the binary block editor, and it is genuinely one of my favorite little gremlins in the whole toolbox. no cap.
β¨ NAME β¨
bbe β it's a binary block editor, and it's about to be your new hyperfixation π¦
πΈ SYNOPSIS πΈ
bbe [options]...
that's it. that's the whole vibe. options go in, magic comes out π
π DESCRIPTION π
so like. imagine sed, right? but for binary files. that's bbe. she does binary transformations on the blocks of an input stream, and she does it flawlessly. it's giving "I'm not like other editors." π₯
π OPTIONS π
bbe accepts the following options, and yes, we're going through all of them, bestie, no skipping:
-b,--block=BLOCKβ the block definition. we'll get into whatBLOCKcan be in a sec, hold on π«Ά-e,--expression=COMMANDβ addsCOMMANDto the pile of commands that are gonna get executed β¨-f,--file=script-fileβ takes the contents ofscript-fileand adds them to your commands π-o,--output=nameβ write the output tonameinstead of just yeeting it to standard output π-s,--suppressβ suppress the normal output, and only print the block contents. quiet queen behavior π€«-?,--helpβ lists literally every available option and what it means. your cheat sheet fr π-V,--versionβ shows the version of the program β
π BLOCK, explained π
BLOCK can be defined as any of these, and this is the part where it gets so good:
N:Mβ theN'th byte starts a block that'sMbytes long. and yes, the first byte is0, we count from zero here π:Mβ block length in the input stream isM/start/:Mβ the stringstartstarts the block, and the block isMbytes long/start/:/stop/β the stringstartstarts the block, and the block ends at the stringstop/start/:β the stringstartstarts the block, and the block ends at the next occurrence ofstart. and important: only the firststartis included in the block π«£:/stop/β the block starts at the beginning of the input stream (or at the end of the previous block) and ends at the next occurrence ofstop. the stringstopwill be included in the block
special value $ for M means the end of stream π
default value for block is 0:$, meaning the whole input stream. yes, everything. the whole thing. main character energy π
π§ escaping, because binary is messy π§
both start and stop strings are included in the block. nonprintable characters can be escaped like this:
\nnnβ decimal\xnnβ hexadecimal\0nnnβ octal
the character \ can be escaped as \\. and these escape codes also work: \a, \b, \t, \n, \v, \f, \r and \; β¨
length (N and M) can be defined as a decimal (n), a hexadecimal (xn) or an octal (0n) value. iykyk π
π COMMAND SYNOPSIS π
bbe has two types of commands: block commands and byte commands, and both are always related to the current block. which means β and this is the important bit β the input stream outside of the blocks stays untouched. we don't touch what isn't ours, periodt π
π Block commands π
D [n]β deletes then'th block. withoutn, all found blocks are deleted from the output stream πI stringβ inserts the stringstringbefore the blockA stringβ appends the stringstringat the end of the blockJ nβ skipsnblocks before executing the commands after this commandL nβ leaves all blocks unmodified starting from block numbern. only affects the commands that come after this command β οΈNβ before printing a block, the file name in which the block starts is printedF fβ before printing a block, the input stream offset at the beginning of the block is printed.fcan beH,DorOfor Hexadecimal, Decimal or Octal format of the offsetB fβ before printing a block, the block number is printed (first block ==1).fcan beH,DorOfor Hexadecimal, Decimal or Octal format of the block number> fileβ before printing a block, the contents of the filefileare printed< fileβ after printing a block, the contents of the filefileare printed
π¦ Byte commands π¦
quick note bestie: n in byte commands is the offset from the beginning of the current block, and it starts from zero. always zero. we love zero π«Ά
r n stringβ replaces bytes starting at positionnwith the stringstringi n stringβ insertsstringstarting at positionnp formatβ the contents of the block are printed in the format defined byformat.formatcan be any ofH,D,O,AandBfor Hexadecimal, Decimal, Octal, Ascii and Binary πs/search/replace/β replaces all occurrences ofsearchwithreplacey/source/dest/β translates bytes insourceto the corresponding bytes indest.sourceanddestmust be the same length β οΈd n m|*β deletesmbytes starting from the offsetn. if*is defined instead ofm, then all bytes starting fromnare deletedc from toβ converts bytes from formatfromtoto. currently supported formats are:BCDβ Binary coded decimalASCβ Ascii
j nβ commands after thej-command are ignored for the firstnbytes of the blockl nβ commands after thel-command are ignored from then'th byte of the blockw fileβ writes bytes from the current block to the filefile. the commands before thew-command decide what will be written.%Bor%nBinfilewill be replaced by the current block number.nin%nBis the field length, and a leading zero inncauses the block number to be left padded with zeroes π& cβ performs binary and withc| cβ performs binary or withc^ cβ performs binary xor withc~β performs binary negationu n cβ all bytes from the start of the block to offsetnare replaced bycf n cβ all bytes starting from offsetnto the end of the block are replaced bycxβ exchanges the contents of the nibbles (half an octet) of the bytes
nonvisible characters in strings can be escaped the same way as in block definition strings. and fun fact: the character / in the s and y commands can be any visible character β¨
β οΈ heads up bestie, this one matters: note that theD,A,I,F,B,c,s,i,y,p,<,>anddcommands cause the length of the input and output streams to be different. so like. plan accordingly π
π EXAMPLES π
because seeing it is believing, here's the girlies in action:
bbe -e "s/c:\\temp\\data1.txt/c:\\temp\\data2.txt/" file1
all occurrences of c:\temp\data1.txt in the file file1 are changed to c:\temp\data2.txt π«
bbe -b 0420:16 -e "r 4 \x12\x4a" file1
two bytes starting at the fifth byte of a 16 byte long block starting at offset 0420 (octal) in file1 are changed to hexadecimal values 12 and 4a π₯
bbe -b :16 -e "A \x0a" file1
a newline is added after every block, and the block length is 16 πΈ
π SEE ALSO π
sed(1). yeah, that sed. the one you already know and love. go say hi π«Ά
π AUTHOR π
Timo Savinen <tjsa@iki.fi > β iconic behavior, honestly. thank you for our lives π
and that's the whole page bestie!! π this one's dated 2006-11-02 and it's page BBE(1) of the manual β go forth, edit some binary, and slay πβ¨π¦
π¦ where this page comes from
- debian bookworm: bbe 0.2.2-5 Β· GPL-2.0-or-later
- debian trixie: bbe 0.2.2-6 Β· GPL-2.0-or-later
- ubuntu jammy: bbe 0.2.2-4 Β· GPL-2.0-or-later
- ubuntu noble: bbe 0.2.2-5 Β· GPL-2.0-or-later
- ubuntu questing: bbe 0.2.2-6
- ubuntu resolute: bbe 0.2.2-6build1 Β· GPL-2.0-or-later
- ubuntu stonking: bbe 0.2.2-6build1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms