1\cfg{man-identity}{tweak}{1}{2004-11-05}{Simon Tatham}{Simon Tatham} 2\cfg{man-mindepth}{1} 3 4\C{tweak-manpage} Man page for \cw{tweak} 5 6\H{tweak-manpage-name} NAME 7 8\cw{tweak} - efficient hex editor 9 10\H{tweak-manpage-synopsis} SYNOPSIS 11 12\c tweak [-l | -f] [-e] [-w width] [-o offset] filename 13\e bbbbb bb bb bb bb iiiii bb iiiiii iiiiiiii 14 15\H{tweak-manpage-description} DESCRIPTION 16 17\cw{tweak} is a hex editor. It allows you to edit a file at very low 18level, letting you see the full and exact binary contents of the 19file. It can be useful for modifying binary files such as 20executables, editing disk or CD images, debugging programs that 21generate binary file formats incorrectly, and many other things. 22 23Unlike simpler hex editors, \cw{tweak} possesses a fully functional 24insert mode. This is not useful when editing many of the types of 25file described above, but can be useful in other situations. Also, 26an insert mode makes it easy to use \cw{tweak} to construct new files 27from scratch. 28 29When you open a file in \cw{tweak}, you can expect to see the screen 30contents looking something like this: 31 32\c 00000000 7F 45 4C 46 01 01 01 00 .ELF.... 33\c 00000008 00 00 00 00 00 00 00 00 ........ 34\c 00000010 02 00 03 00 01 00 00 00 ........ 35\c 00000018 D0 8E 04 08 34 00 00 00 ....4... 36\c 00000020 2C EF 01 00 00 00 00 00 ,....... 37 38The central column shows you the hexadecimal value of each byte in 39the file you are editing. The column on the right shows the ASCII 40interpretation of those bytes, where applicable. In the example 41above, the sequence \c{45 4C 46} on the first line translates into 42the ASCII upper-case letters \q{ELF}, but the subsequent sequence 43\c{01 01 01 00} does not have any printable ASCII representation and 44so the right-hand column simply prints dots. 45 46The column on the left shows the position within the file of the 47start of each row. 48 49In fact, when you start \cw{tweak}, you will usually see 16 bytes of 50the file per row, not 8 as shown above. However, this is 51configurable if your screen is narrower - or wider - than the usual 5280 columns, or if the file you are editing consists of fixed-size 53records of some other size. 54 55By default, \cw{tweak} does not load its entire input file into 56memory. Instead, it loads it \e{lazily}, reading from the file on 57disk when you request a view of a part of the file it doesn't have 58stored. When you modify the file, it stores your modifications in 59memory, but continues to refer to the original disk file for the 60parts you have not touched. This means you can edit extremely large 61files (for example, entire CD images) without difficulty; opening 62such a file is instantaneous, making modifications causes \cw{tweak}'s 63memory usage to grow with the size of the changes rather than the 64size of the whole file, and only when saving the altered version 65will \cw{tweak} have to read through the entire input file to write 66the output. 67 68However, this mode of operation has a disadvantage, which is that if 69the input file is modified by another program while \cw{tweak} is 70running, \cw{tweak}'s internal data structures will not be sufficient 71to keep track, and it is likely that the file written out will 72contain a mixture of the old and new contents of the input file. 73Therefore, you can disable this lazy loading if you need to; see the 74\cw{-e} option below. 75 76\H{tweak-manpage-options} OPTIONS 77 78This section lists the command-line options supported by \cw{tweak}. 79 80\dt \cw{-f} 81 82\dd Runs \cw{tweak} in \q{fix} mode, i.e. with the insert function 83entirely disabled. This might be useful if you are editing a file in 84which the insert mode is of no use (executables, for example, tend 85to have strong dependencies on precise file offsets which make it 86almost impossible to insert data in one without rendering it 87unusable) and you want to avoid turning it on by mistake. 88 89\dt \cw{-l} 90 91\dd Runs \cw{tweak} in \q{look} mode. In this mode \cw{tweak} does not 92allow you to modify the data at all; it becomes simply a tool for 93examining a file in detail. 94 95\dt \cw{-e} 96 97\dd Runs \cw{tweak} in \q{eager} mode. In this mode \cw{tweak} will read 98its entire input file when starting up. This causes it to take up 99more memory, but means that it has no dependency on the input file 100remaining unmodified, and other programs can alter it if they need 101to without causing trouble. 102 103\dt \cw{-w} \e{width} 104 105\dd Specifies the number of bytes \cw{tweak} will display per line. 106The default is 16, which fits neatly in an 80-column screen. 107 108\dt \cw{-o} \e{offset} 109 110\dd If this option is specified, \cw{tweak} will ensure that the given 111file offset occurs at the start of a line. For example, if you 112loaded a file using the options \cw{-w 8 -o 0x13}, you might see a 113display a bit like this: 114 115\lcont{ 116 117\c 00000000 7F 45 4C .EL 118\c 00000003 46 01 01 01 00 00 00 00 F....... 119\c 0000000B 00 00 00 00 00 02 00 03 ........ 120\c 00000013 00 01 00 00 00 D0 8E 04 ........ 121\c 0000001B 08 34 00 00 00 2C EF 01 .4...,.. 122 123By putting only three bytes of the file on the very first line, 124\cw{tweak} has arranged that the file offset 0x13 (19 in decimal) 125appears at the beginning of the fourth line. 126 127You might use this option if you knew you were editing a file in a 128particular format. For example, if your file contained a 53-byte 129header followed by a series of 22-byte records, you might find it 130useful to specify the options \cw{-w 22 -o 53}. This would arrange 131that after the header, each individual record of the file would 132appear on precisely one line of \cw{tweak}'s display. 133 134} 135 136\dt \cw{-D} 137 138\dd If this option is specified, \cw{tweak} will not attempt to load 139and edit a file at all, but will simply produce its default 140\cw{.tweakrc} file on standard output. This is a useful way to give 141yourself a starting point if you want to begin reconfiguring 142\cw{tweak}'s keyboard layout. 143 144\H{tweak-manpage-keys} KEYS 145 146This section describes all the editing keys supported by \cw{tweak} by 147default. The default key bindings for \cw{tweak} are basically 148Emacs-like. 149 150\S{tweak-manpage-keys-movement} Movement keys 151 152The Emacs cursor movement keys should all work, and their 153counterparts in ordinary function keys ought to work too: 154 155\b \cw{^P} and \cw{^N} go to the previous and next lines; Up and 156Down should do the same. 157 158\b \cw{^B} and \cw{^F} go back and forward one character; Left and 159Right should do the same. 160 161\b \cw{M-v} and \cw{^V} go up and down one screenful at a time; Page 162Up and Page Down should do the same. 163 164\b \cw{^A} and \cw{^E} go to the beginning and end of the line; Home 165and End should do the same. 166 167Press \cw{M-<} and \cw{M->} go to the beginning and end of the file. 168 169Press \cw{^X g} to go to a particular byte position in the file; you 170will be asked to type in the position you want. You can enter it in 171decimal, or as a hex number with \cq{0x} before it. 172 173\S{tweak-manpage-keys-editing} Editing keys 174 175Press Return to move the cursor between the hex section of the 176screen and the ASCII section. 177 178When in the hex section, you can enter hexadecimal digits to alter 179data; when in the ASCII section, you can directly type ASCII text. 180 181In ASCII mode, you can also press \cw{^Q} to literally quote the 182next input character; for example, if you want to insert a 183Control-V, you can press \cw{^Q^V} and \cw{tweak} will automatically 184insert the byte value 0x16. 185 186Press \cw{^X^I}, or the Insert key if you have one, to toggle 187between overwrite mode and insert mode. In insert mode, typing hex 188or ASCII input will insert new bytes containing the values you 189provide. Also, you can then press Backspace to delete the byte to 190the left of the cursor, or \cw{^D} or Delete to delete the byte 191under the cursor. 192 193\S{tweak-manpage-keys-cnp} Cut and paste 194 195Press \cw{^@} (this character may be generated by the key 196combination Control-@, or Control-2, or Control-Space) to mark the 197end of a selection region. After you do this, the bytes between that 198mark and the cursor will be highlighted. Press \cw{^@} again to 199abandon the selection. 200 201Press \cw{M-w} while a selection is active to copy the selected 202region into \cw{tweak}'s cut buffer. 203 204In insert mode, you also have the option of pressing \cw{^W} to 205\e{cut} the selected region completely out of the file and place it 206in the cut buffer. 207 208Finally, press \cw{^Y} to paste the cut buffer contents back into 209the file (this will overwrite or insert depending on the current 210mode). 211 212\S{tweak-manpage-keys-search} Searching 213 214Press \cw{^S} to search for a byte sequence. You will be asked to 215enter some text to search for on the bottom line of the screen. You 216can type this text in ASCII, or as a sequence of hex byte values 217prefixed with backslashes (\cw{\\}). For example, if you wanted to 218search for the byte value 5 followed by the word \q{hello}, you 219might enter \cw{\\05hello}. If you want to specify a literal 220backslash character, you can either enter it in hex (as \cw{\\5C}), 221or simply double it on input (\cw{\\\\}). 222 223Press \cw{^R} to search backwards instead of forwards from the 224current cursor position. 225 226Since \cw{tweak} deals in pure binary data, searches are always 227case-sensitive. 228 229\S{tweak-manpage-keys-display} Controlling the display 230 231If you press \cw{^X w}, you will be asked to enter a new display 232width. This has the same effect as passing the \cw{-w} option on the 233command line. Similarly, pressing \cw{^X o} allows you to enter a 234new display offset, equivalent to the \cw{-o} option. 235 236By default, the current file position and file size are displayed on 237\cw{tweak}'s status line in hex. If you prefer them in decimal, you 238can press \cw{^X x} or \cw{^X h} to toggle them between hex and 239decimal. 240 241\S{tweak-manpage-keys-misc} Miscellaneous 242 243Press \cw{^L} to redraw the screen and recentre the cursor. Press 244\cw{^Z} to suspend \cw{tweak} and return temporarily to the shell. 245 246Press \cw{^X^S} to save the file you are editing. 247 248Press \cw{^X^C} to exit \cw{tweak}. (If you do this with changes 249unsaved, you will be asked whether you want to save them.) 250 251\H{tweak-manpage-cfg} CONFIGURATION FILE 252 253\cw{tweak}'s keyboard bindings are configurable. It will attempt to 254read a file from your home directory called \cw{.tweakrc}, and if it 255finds one it will use the keyboard bindings described in it. If it 256does not find one, it will use its internal default bindings. 257 258Most of the directives in \cw{.tweakrc} are of the form \cq{bind 259command-name key}. For example, \cq{bind exit ^X^C}. 260Additionally, there are two other directives, \cw{width} and 261\cw{offset}, which give the default display parameters if no \cw{-w} 262and \cw{-o} options are specified. 263 264The easiest way to learn about the \cw{.tweakrc} file is to begin by 265having \cw{tweak} output its internal default one: 266 267\c tweak -D > $HOME/.tweakrc 268 269Then you can read the default file, learn the \cw{tweak} internal 270command names, and edit the file to do what you want. 271 272\H{tweak-manpage-bugs} BUGS 273 274This man page probably ought to contain an explicit list of internal 275command names, rather than simply referring you to the default 276\cw{.tweakrc}. 277 278\versionid tweak version 3.02 279