1tweak(1)                         Simon Tatham                         tweak(1)
2
3
4

NAME

6       tweak - efficient hex editor
7

SYNOPSIS

9       tweak [-l | -f] [-e] [-w width] [-o offset] filename
10

DESCRIPTION

12       tweak  is a hex editor. It allows you to edit a file at very low level,
13       letting you see the full and exact binary contents of the file. It  can
14       be  useful for modifying binary files such as executables, editing disk
15       or CD images, debugging programs  that  generate  binary  file  formats
16       incorrectly, and many other things.
17
18       Unlike  simpler  hex editors, tweak possesses a fully functional insert
19       mode. This is not useful  when  editing  many  of  the  types  of  file
20       described above, but can be useful in other situations. Also, an insert
21       mode makes it easy to use tweak to construct new files from scratch.
22
23       When you open a file in tweak, you can expect to see  the  screen  con‐
24       tents looking something like this:
25
26       00000000   7F 45 4C 46 01 01 01 00   .ELF....
27       00000008   00 00 00 00 00 00 00 00   ........
28       00000010   02 00 03 00 01 00 00 00   ........
29       00000018   D0 8E 04 08 34 00 00 00   ....4...
30       00000020   2C EF 01 00 00 00 00 00   ,.......
31
32       The  central column shows you the hexadecimal value of each byte in the
33       file you are editing. The column on the right shows the ASCII interpre‐
34       tation  of  those  bytes,  where  applicable. In the example above, the
35       sequence 45 4C 46 on the first line translates into  the  ASCII  upper-
36       case  letters  `ELF',  but the subsequent sequence 01 01 01 00 does not
37       have any printable ASCII representation and so  the  right-hand  column
38       simply prints dots.
39
40       The  column on the left shows the position within the file of the start
41       of each row.
42
43       In fact, when you start tweak, you will usually see  16  bytes  of  the
44       file  per  row,  not 8 as shown above. However, this is configurable if
45       your screen is narrower - or wider - than the usual 80 columns,  or  if
46       the  file  you are editing consists of fixed-size records of some other
47       size.
48
49       By default, tweak does not load its  entire  input  file  into  memory.
50       Instead,  it  loads  it  lazily, reading from the file on disk when you
51       request a view of a part of the file it doesn't have stored.  When  you
52       modify  the file, it stores your modifications in memory, but continues
53       to refer to the original disk file for the parts you have not  touched.
54       This  means  you can edit extremely large files (for example, entire CD
55       images) without difficulty; opening such a file is instantaneous,  mak‐
56       ing  modifications causes tweak's memory usage to grow with the size of
57       the changes rather than the size of the whole file, and only when  sav‐
58       ing  the  altered  version  will  tweak have to read through the entire
59       input file to write the output.
60
61       However, this mode of operation has a disadvantage, which  is  that  if
62       the  input  file is modified by another program while tweak is running,
63       tweak's internal data structures will not be sufficient to keep  track,
64       and  it  is  likely that the file written out will contain a mixture of
65       the old and new contents of the input file. Therefore, you can  disable
66       this lazy loading if you need to; see the -e option below.
67

OPTIONS

69       This section lists the command-line options supported by tweak.
70
71       -f     Runs tweak in `fix' mode, i.e. with the insert function entirely
72              disabled. This might be useful if you  are  editing  a  file  in
73              which  the  insert  mode is of no use (executables, for example,
74              tend to have strong dependencies on precise file  offsets  which
75              make  it almost impossible to insert data in one without render‐
76              ing it unusable) and you want to avoid turning it on by mistake.
77
78       -l     Runs tweak in `look' mode. In this mode tweak does not allow you
79              to  modify the data at all; it becomes simply a tool for examin‐
80              ing a file in detail.
81
82       -e     Runs tweak in `eager' mode. In this mode  tweak  will  read  its
83              entire  input  file  when starting up. This causes it to take up
84              more memory, but means that it has no dependency  on  the  input
85              file  remaining  unmodified,  and other programs can alter it if
86              they need to without causing trouble.
87
88       -w width
89              Specifies the number of bytes tweak will display per  line.  The
90              default is 16, which fits neatly in an 80-column screen.
91
92       -o offset
93              If  this  option  is specified, tweak will ensure that the given
94              file offset occurs at the start of a line. For example,  if  you
95              loaded  a  file  using the options -w 8 -o 0x13, you might see a
96              display a bit like this:
97
98              00000000                  7F 45 4C        .EL
99              00000003   46 01 01 01 00 00 00 00   F.......
100              0000000B   00 00 00 00 00 02 00 03   ........
101              00000013   00 01 00 00 00 D0 8E 04   ........
102              0000001B   08 34 00 00 00 2C EF 01   .4...,..
103
104              By putting only three bytes of the file on the very first  line,
105              tweak  has  arranged  that  the file offset 0x13 (19 in decimal)
106              appears at the beginning of the fourth line.
107
108              You might use this option if you knew you were editing a file in
109              a  particular  format.  For  example,  if  your file contained a
110              53-byte header followed by a  series  of  22-byte  records,  you
111              might  find  it  useful to specify the options -w 22 -o 53. This
112              would arrange that after the header, each individual  record  of
113              the file would appear on precisely one line of tweak's display.
114
115       -D     If  this option is specified, tweak will not attempt to load and
116              edit a file at all, but will simply produce its default .tweakrc
117              file on standard output. This is a useful way to give yourself a
118              starting point if you want to begin reconfiguring  tweak's  key‐
119              board layout.
120

KEYS

122       This  section  describes  all  the  editing  keys supported by tweak by
123       default. The default key bindings for tweak are basically Emacs-like.
124
125   Movement keys
126       The Emacs cursor movement keys should all work, and their  counterparts
127       in ordinary function keys ought to work too:
128
129       ·      ^P  and ^N go to the previous and next lines; Up and Down should
130              do the same.
131
132       ·      ^B and ^F go back and forward  one  character;  Left  and  Right
133              should do the same.
134
135       ·      M-v  and  ^V go up and down one screenful at a time; Page Up and
136              Page Down should do the same.
137
138       ·      ^A and ^E go to the beginning and end of the line; Home and  End
139              should do the same.
140
141       Press M-< and M-> go to the beginning and end of the file.
142
143       Press ^X g to go to a particular byte position in the file; you will be
144       asked to type in the position you want. You can enter it in decimal, or
145       as a hex number with `0x' before it.
146
147   Editing keys
148       Press  Return  to move the cursor between the hex section of the screen
149       and the ASCII section.
150
151       When in the hex section, you can  enter  hexadecimal  digits  to  alter
152       data; when in the ASCII section, you can directly type ASCII text.
153
154       In  ASCII mode, you can also press ^Q to literally quote the next input
155       character; for example, if you want to  insert  a  Control-V,  you  can
156       press ^Q^V and tweak will automatically insert the byte value 0x16.
157
158       Press  ^X^I, or the Insert key if you have one, to toggle between over‐
159       write mode and insert mode. In insert mode, typing hex or  ASCII  input
160       will  insert new bytes containing the values you provide. Also, you can
161       then press Backspace to delete the byte to the left of the  cursor,  or
162       ^D or Delete to delete the byte under the cursor.
163
164   Cut and paste
165       Press  ^@  (this character may be generated by the key combination Con‐
166       trol-@, or Control-2, or Control-Space) to mark the end of a  selection
167       region.  After  you do this, the bytes between that mark and the cursor
168       will be highlighted. Press ^@ again to abandon the selection.
169
170       Press M-w while a selection is active to copy the selected region  into
171       tweak's cut buffer.
172
173       In  insert  mode,  you  also  have the option of pressing ^W to cut the
174       selected region completely out of the file and place it in the cut buf‐
175       fer.
176
177       Finally,  press  ^Y to paste the cut buffer contents back into the file
178       (this will overwrite or insert depending on the current mode).
179
180   Searching
181       Press ^S to search for a byte sequence. You will be asked to enter some
182       text  to search for on the bottom line of the screen. You can type this
183       text in ASCII, or as a sequence of hex byte values prefixed with  back‐
184       slashes  (\). For example, if you wanted to search for the byte value 5
185       followed by the word `hello', you might enter \05hello. If you want  to
186       specify  a  literal backslash character, you can either enter it in hex
187       (as \5C), or simply double it on input (\\).
188
189       Press ^R to search backwards instead of forwards from the current  cur‐
190       sor position.
191
192       Since  tweak deals in pure binary data, searches are always case-sensi‐
193       tive.
194
195   Controlling the display
196       If you press ^X w, you will be asked to enter a new display width. This
197       has the same effect as passing the -w option on the command line. Simi‐
198       larly, pressing ^X o allows you to enter a new display offset,  equiva‐
199       lent to the -o option.
200
201       By  default,  the  current file position and file size are displayed on
202       tweak's status line in hex. If you prefer  them  in  decimal,  you  can
203       press ^X x or ^X h to toggle them between hex and decimal.
204
205   Miscellaneous
206       Press ^L to redraw the screen and recentre the cursor. Press ^Z to sus‐
207       pend tweak and return temporarily to the shell.
208
209       Press ^X^S to save the file you are editing.
210
211       Press ^X^C to exit tweak. (If you do this  with  changes  unsaved,  you
212       will be asked whether you want to save them.)
213

CONFIGURATION FILE

215       tweak's  keyboard  bindings are configurable. It will attempt to read a
216       file from your home directory called .tweakrc, and if it finds  one  it
217       will  use  the  keyboard  bindings described in it. If it does not find
218       one, it will use its internal default bindings.
219
220       Most of the directives in .tweakrc are of the form  `bind  command-name
221       key'.  For example, `bind exit ^X^C'. Additionally, there are two other
222       directives, width and offset, which give the default display parameters
223       if no -w and -o options are specified.
224
225       The  easiest way to learn about the .tweakrc file is to begin by having
226       tweak output its internal default one:
227
228       tweak -D > $HOME/.tweakrc
229
230       Then you can read the default file, learn the  tweak  internal  command
231       names, and edit the file to do what you want.
232

BUGS

234       This  man  page  probably ought to contain an explicit list of internal
235       command  names,  rather  than  simply  referring  you  to  the  default
236       .tweakrc.
237
238
239
240Simon Tatham                      2004‐11‐05                          tweak(1)
Impressum