1HEXER(1) General Commands Manual HEXER(1)
2
3
4
6 hexer - binary file editor
7
9 hexer [options] [file [...]]
10
12 hexer is a multi-buffer editor for viewing and manipulating binary
13 files. It can't (shouldn't) be used for editing block devices, because
14 it tries to load the whole file into a buffer (it should work for
15 diskettes). The most important features of hexer are: multi buffers,
16 multi level undo, command line editing with completion, binary regular
17 expressions (see below). The user interface is kept similar to vi, so
18 if you know how to use vi, you'll get started easily.
19
21 -R, --readonly
22
23 -v, --view
24 Edit files in read only mode.
25
26 -r, --recover filename
27 Recover the file filename after a crash. (not implemented)
28
29 -c, --command command
30 Start the editing session by executing the editor command command.
31 If command contains spaces, it must be surrounded by double quotes.
32 It is possible to specify multiple commands on the command line:
33 hexer -c command1 -c command2 ...
34
35 -t, --tite
36 Turn off the usage of the termcap/terminfo ti/te sequence.
37
38 -h, --help
39 Print out a short help message and exit.
40
41 +command
42 This is equivalent to the -c option.
43
44 Note: The long options are not available on all systems.
45
47 The editor reads its startup commands from the file ~/.hexerrc (another
48 startup file may be specified by setting the environment variable HEX‐
49 ERRC). Empty lines and lines starting with a `"'‐character (double
50 quote) are ignored. It is not possible to have a command and a comment
51 in the same line.
52
54 As in vi, there are several editing modes:
55
56 Command Mode
57 Some commands in Command Mode can take a numeric argument. To
58 enter a numeric argument just type the (decimal) number. The num‐
59 ber will be echoed at the bottom line of the screen as you type.
60 To enter an octal number, type a `0' as the first digit. To enter
61 a hexadecimal number, type `0x' (this is not a problem, because the
62 x-command with a zero counter wouldn't make sense anyway). Some of
63 the commands can take a visually selected area as an argument (see
64 subsection Visual Mode).
65
66 b Move backwards to the beginning of a word.
67
68 e Move to the end of a word.
69
70 G If a numeric argument n is given, move the cursor to posi‐
71 tion n. If no argument is specified, set the position to
72 the end of the buffer. The first byte in the buffer is at
73 position `0', so the command to move to the beginning of the
74 buffer is `0G'.
75
76 Control-G
77 Display the buffer name, size, status and the current posi‐
78 tion at the bottom line.
79
80 h j k l
81 Move the cursor. The arrow keys work as well. The numeric
82 argument (if specified) determines the number rows or col‐
83 umns the cursor will move. Different from vi: the cursor
84 can be positioned behind the last byte in the buffer.
85
86 i Enter Insert Mode (see below) at the current position of the
87 point. If a numeric argument n is given, the typed text
88 will be inserted n times. Note: Moving the cursor (using
89 the arrow keys) will discard the numeric argument.
90
91 n Move to the next match using the current RE. This is equiv‐
92 alent to typing `/', <Return>.
93
94 N Move to the previous match using the current RE. This is
95 equivalent to typing `?', <Return>.
96
97 Control-O
98 Paste over. Copy the kill buffer to the current position
99 overwriting the contents of the current buffer. If a
100 numeric argument n is given, the kill buffer is pasted n
101 times.
102
103 p Paste. Insert the kill buffer at the current position. If
104 a numeric argument n is given, the kill buffer is pasted n
105 times.
106
107 r Replace a single byte using the Replace Mode. If an area is
108 selected, all bytes in the selected area are replaced. If a
109 numeric argument is given, the specified number of bytes is
110 replaced.
111
112 R Enter Replace Mode (see below). If a numeric argument n is
113 given, the replace command is repeated n times. Note: Mov‐
114 ing the cursor (using the arrow keys) will discard the
115 numeric argument.
116
117 Control-R
118 Redo the last undo.
119
120 u Undo the last change to the current buffer.
121
122 Whenever possible hexer creates a file name.hexer in the current
123 directory (the swapfile) for each buffer visited (where name is the
124 name of the buffer). All changes made to the buffer name are
125 stored in that file, so it is possible to undo (and redo) all
126 changes made to the buffer. If the swapfile can't be created, the
127 undo list is stored in the memory.
128
129 v Enter Visual Mode (see below). Visual selection of areas.
130
131 w Move forward to the beginning of a word.
132
133 x Delete the byte under the cursor. If a numeric argument n
134 is given, n bytes are deleted. In Visual Mode, the selected
135 area is deleted. Note: The bytes deleted using the x-com‐
136 mand are not copied to the kill buffer.
137
138 Control-X
139 The same as the x-command, but the bytes deleted are copied
140 to the kill buffer.
141
142 y Yank. Yank the byte under the cursor into the kill buffer.
143 If a numeric argument n is given, n bytes are yanked into
144 the kill buffer. In Visual Mode, the selected area is
145 copied to the kill buffer.
146
147 zb Place the cursor in the bottom line of the screen.
148
149 zt Place the cursor in the top line of the screen.
150
151 zz Place the cursor in the middle line of the screen.
152 Note that the commands zb, zt and zz don't change the posi‐
153 tion in the file - only the screen is scrolled (if neces‐
154 sary).
155
156 : Enter Exh Mode (see below). The Exh Mode is similar to the
157 ex-mode in vi, but not compatible. If an area is selected,
158 the bounds of the selection are copied to the command line.
159
160 / Search forward through the buffer using a RE(regular expres‐
161 sion). If no RE is specified, the RE given in the previous
162 /- or ?-command is reused.
163 Note: The REs in hexer are a little bit different from regu‐
164 lar expressions in vi (see section REGULAR EXPRESSIONS).
165
166 ? Search reverse using a regular expression.
167
168 . Repeat the last change to the buffer at the current posi‐
169 tion. This means that if the previous command deleted n
170 bytes and replaced them by m other bytes (n or m may be
171 zero), the .-command will do exactly the same at the current
172 position in the file.
173
174 < Shift the hex column left n bytes, where n is the (optional)
175 numeric argument. Note that the <-command only changes the
176 way the buffer is displayed in the hex column, the buffer
177 itself is kept unchanged.
178
179 > Shift the hex column right n bytes.
180
181 Control-^
182 Switch to the alternate buffer (see below).
183
184 % Enter a calculator command (see section CALCULATOR).
185
186 Visual Mode
187 Select an area on the buffer. You can enter the Visual Mode by
188 using the v-command or by specifying an area in Exh Mode. The
189 selection starts at the cursor position when entering the Visual
190 Mode and ends at the current cursor position. You can leave the
191 Visual Mode without performing a command on the selected area by
192 pressing v or Escape. To perform a command on the selected area
193 simply enter the command as if you where in Command Mode. Commands
194 that can't use the selection will ignore it. As in Command Mode,
195 it is possible to specify a numeric argument. Commands that can
196 take the selection as an argument will ignore the numeric argument.
197
198 Insert Mode
199 In Insert Mode the bytes you type are inserted at the current posi‐
200 tion of the cursor. At any time, you can toggle the active column
201 (hex column or text column) by pressing the TAB key. If the hex
202 column is active the bytes are entered as two digit hex numbers, if
203 the text column is active, the bytes are entered as ASCII text.
204 The Delete or BackSpace key deletes the previously inserted byte.
205 If the hex column is active, the previously inserted nibble (hex
206 digit) is deleted. It is not possible to delete more bytes than
207 have been inserted in the current insert command. While in Insert
208 Mode, you can move the cursor using the arrow keys. Note that mov‐
209 ing the cursor discards the numeric argument given to the insert
210 command. To leave the Insert Mode, type Escape. If a numeric
211 argument n was given to the insert command and is hasn't been dis‐
212 carded by a cursor movement, the typed bytes are inserted n times.
213
214 Replace Mode
215 In Replace Mode you replace the bytes under the cursor as you type.
216 Hitting BackSpace restores the original contents of the buffer.
217 The effect of a numeric argument is similar to the Insert Mode: the
218 typed bytes are replaced n times. As in Insert Mode, moving the
219 cursor using the arrow keys discards the numeric argument.
220
221 Exh Mode
222 The Exh Mode in hexer is kept similar to the ex-mode in vi. Typi‐
223 cally, an exh command looks like:
224
225 :area command arguments
226 Perform the command command on the area area.
227
228
229 :command arguments
230 Perform the command command at the current posi‐
231 tion.
232
233 :area Select the area area.
234
235 :position
236 Move the cursor to position position.
237
238 An area may be defined as:
239
240 position1,position2
241 The area starts at position1 and ends at posi‐
242 tion2 (inclusive).
243
244 position
245 The area selects one byte at position
246
247 % The area selects the entire buffer.
248
249 A position may be defined as:
250
251 offset A decimal, octal (prefixed with `0') or hex (pre‐
252 fixed with `0x') number.
253
254 . The beginning of the buffer.
255
256 $ The end of the buffer.
257
258 /regexp/
259 A regular expression (see section REGULAR EXPRES‐
260 SIONS). The buffer is searched forward starting
261 at the current position. If a match was found,
262 the current position is set to the position of
263 the match.
264
265 ?regexp?
266 The buffer is searched reverse.
267
268 Commands may be abbreviated with a unique prefix of the
269 command, some commands may be abbreviated with a single
270 character, even if that character isn't a unique prefix
271 of the command name. Currently the following commands
272 are supported:
273
274 s, substitute
275 Synopsis: area s /regexp/replace/flags
276 Search for the regular expression regexp and
277 replace it with replace (see section REGULAR
278 EXPRESSIONS). replace may contain `\' references
279 to subexpressions of regexp. flags:
280
281 g: global, this flag is ignored (it doesn't
282 make sense in a binary editor).
283
284 c: confirm, ask the user to confirm each sub‐
285 stitution.
286
287 (Note that the `/' character used as separator
288 could be any character, it's just common practice
289 to use `/'.) Trailing separators may be omitted.
290 If area is omitted, the whole buffer is searched.
291
292 w, write
293 Synopsis: area w filename
294 Write area to the file filename. If area is
295 omitted. the whole buffer is written to the file,
296 if filename is omitted, the filename associated
297 with the buffer is used.
298
299 r, read
300 Synopsis: position r filename
301 Insert the contents of the file filename at posi‐
302 tion. If position is omitted, the current posi‐
303 tion is used.
304
305 e, edit
306 Synopsis: e name or: e #
307 Change to buffer name. If there is no such buf‐
308 fer, hexer tries to open a file named name and
309 load it into a new buffer. If name is a hash
310 sign (#), the alternate buffer is selected. On
311 success the current buffer becomes the alternate
312 buffer.
313
314 b, buffer
315 Synopsis: b name
316 or: b
317 Change to buffer name. On success the current
318 buffer becomes the alternate buffer. If name is
319 omitted, a list of all buffers is displayed.
320
321 n, next
322 Select the next buffer in the buffer list.
323
324 N, previous
325 Select the previous buffer in th buffer list.
326
327 S, skip
328 Select the next unvisited buffer in the buffer
329 list.
330
331 rewind Select the first buffer in the buffer list.
332
333 wall Write all unsaved buffers.
334
335 c, close
336 Synopsis: c name
337 or: c! name
338 or: c
339 or: c!
340 Close the buffer name. If name is omitted, the
341 current buffer is closed. If the buffer has been
342 modified, but not saved, it can't be closed using
343 a :c-command; use :c! to override.
344
345 h, help
346 View an online help text.
347
348 q, quit
349 Synopsis: q name
350 or: q! name
351 or: q
352 or: q!
353 Close all buffers and exit the editor. If an
354 opened buffer has bee modified, but not saved,
355 the :q-command can't be performed; use :q! to
356 override.
357
358 map
359
360 imap
361
362 vmap Synopsis: map from to
363 or: imap from to
364 or: vmap from to
365 The key sequence from is mapped to to. To enter
366 special keys (e.g. function keys), mask them
367 using Control-V. :map affects the Command Mode
368 only, :imap affects the Insert Mode only and
369 :vmap affects the Visual Mode only. It is not
370 possible to re-map key sequences on the command
371 line editor.
372
373 unmap
374
375 iunmap
376
377 vunmap Synopsis: unmap from
378 or: iunmap from
379 or: vunmap from
380 Delete a key mapping created with :map, :imap or
381 :vmap.
382
383 set Synopsis: set variable [...]
384 or: set variable=value [...]
385 or: set novariable [...]
386 or: set
387 There are not too many variables that could be
388 modified, this might change though. The follow‐
389 ing variables can be used: iso (bool): display
390 the whole ISO-8859/1 character set; ascii (bool):
391 display ASCII characters only; TERM (string):
392 the name of the terminal; maxmatch (number), spe‐
393 cialnl (bool): see section REGULAR EXPRESSIONS.
394 :set called without an argument lists all vari‐
395 ables and values.
396
397 d, delete
398 Synopsis: area d
399 Delete all bytes in area. The deleted bytes are
400 copied to the kill buffer.
401
402 y, yank
403 Synopsis: area y
404 Copy the bytes in area to the kill buffer.
405
406 version
407 Display the version number of hexer.
408
409 zz Place the cursor in the middle line of the
410 screen. Note that the screen is scrolled (if
411 necessary); the cursor position is kept
412 unchanged.
413
414 zt Place the cursor in the top line of the screen.
415
416 zb Place the cursor in the bottom line of the
417 screen.
418
419 wq The same as :x.
420
421 x, exit
422 Save all buffers and exit the editor.
423
424 If a command is called and can't use the given posi‐
425 tions, areas or arguments, the additional positions,
426 areas, arguments are ignored.
427 Conditional commands: It is possible to specify a list
428 of terminal names for which the given command should be
429 executed. The syntax is:
430 :terminals:command
431 where terminals is a colon-separated list of terminal
432 names. The command is executed if and only if the value
433 of TERM is in the list. I.e. you could have a command
434 like
435 :xterm:set iso
436 in your .hexerrc-file (use the ISO character set only if
437 working on an xterm).
438
439 Cursor Motion
440 In Command Mode, Insert Mode, Replace Mode and Visual
441 Mode, you can use the following cursor motion commands:
442
443 Arrow Keys
444 Move the cursor.
445
446 Control-F
447 Move forward one page.
448
449 Control-B
450 Move back one page.
451
452 Control-D
453 Move forward half a page.
454
455 Control-U
456 Move back half a page.
457
459 On the command line you can use the following commands:
460
461 UpArrow DownArrow
462 Move up and down through the history of the current
463 context.
464
465 LeftArrow RightArrow
466 Move the cursor.
467
468 Control-A
469 Move the cursor to the beginning of the line.
470
471 Control-E
472 Move the cursor to the end of the line.
473
474 Control-K
475 Delete all characters from the current cursor posi‐
476 tion up to the end of the line.
477
478 Control-U
479 Delete all characters from the beginning of the line
480 up to the current cursor position.
481
482 Delete
483
484 BackSpace
485 Delete the character left of the cursor.
486
487 Control-D
488 Delete the character under the cursor.
489
490 Enter Return
491 Accept the line.
492
493 Escape Discard the line. Note: This is different from vi.
494
495 TAB Try to complete currently typed word. If the comple‐
496 tion is not unique, the word is completed as far as
497 unique. If the TAB key is hit twice on the same
498 position, a list of all possible completions is dis‐
499 played.
500
502 In this section it is assumed that you are familiar with REs
503 (regular expressions). In most applications (egrep, vi,
504 ...) REs work on lines, that means it is not possible to
505 use a RE containing a line break (newline character). In
506 hexer, the buffer is not split up into distinct lines and a
507 newline character is considered to be a `normal' character,
508 now here's the problem: imagine searching for "a.*b" in a 5
509 MB file, this would take very long (might be up to several
510 minutes on a slow machine). That's why there's a maxmatch
511 limit (a repeat operator matches at most maxmatch occur‐
512 rences of its operand). The default value of maxmatch is
513 1024, but it may be customized using the :set-command. For
514 simple expressions (expressions for which the length of the
515 match can be determined from the expression) it is possible
516 to override the maxmatch limit by doubling the `*' or `+'
517 operator, e.g. "a.**b" or "foo\(bar\)\+\+".
518 Note that the context specifiers `^'/`$' (beginning/end of a
519 line) and `\<'/`\>' (beginning/end of a word) are available
520 and actually do what you expect. If you don't want the
521 atoms `.' and `[^...]' to match the newline character you
522 can set the specialnl option using the :set-command.
523 To enter a special character, you can use the standard C
524 `\'‐escape sequences. To enter a character using its octal
525 code, use a `\o'‐prefix followed by up to three octal dig‐
526 its. (C-style octal escapes are not supported, because
527 `\0', ... `\9' are interpreted as back-references to subex‐
528 pressions of the RE.) To enter a character using it's hex
529 code, type a `\x'-prefix followed by up to two hex digits;
530 decimal codes can be entered using a `\d'‐prefix followed by
531 up to three decimal digits. It is possible to enter strings
532 of codes by doubling the base specifier, e.g. "\xxfe ff 5a
533 7e" or "\oo276 277 132 176". Note that such a string is
534 treated as an atom, i.e. the RE "\xxff fe*" matches any
535 number (< maxmatch) of repetitions of ff fe.
536 It is possible to use all kinds of character `\'‐escapes
537 (escapes representing a single character) within
538 `[]'‐ranges. Within a range, the `o' selecting an octal
539 base for the escape may be omitted, since back-references
540 within a range don't make sense. When specifying a minimum
541 and/or maximum number of repetitions using the `\{,}'‐opera‐
542 tor, the numbers may be given in decimal (no prefix), octal
543 (`0'-prefix) or hex (`0x'-prefix). If no maximum number is
544 specified and the operand is not a simple expression, at
545 most maxmatch matches will be found.
546
548 Hexer provides a simple calculator (myc) capable of all
549 operations available in C. To enter a myc command just
550 enter a % (percent) sign and an expression in infix nota‐
551 tion. It is possible to use parentheses. myc understands
552 the following binary infix operators (from highest priority
553 to lowest): ** (power), * (multiply), / (divide), % (mod‐
554 ulo), + (add), - (subtract), << (shift left), >> (shift
555 right), < (less), <= (less or equal), > (greater), >=
556 (greater or equal), == (equal), != (not equal), & (arith‐
557 metical and), | (arithmetical or), ^ (arithmetical exclusive
558 or), && (logical and), || (logical or), = (assign); and the
559 following unary prefix operators: - (negate, unary minus), !
560 (logical not), ~ (bitwise complement). myc knows three data
561 types: boolean, integer (32 bit), float (64 bit, equivalent
562 to C double). On some esoteric platforms the precision of
563 integer and float may be different. As in C the result of a
564 division depends on the data types of the operands. An
565 integer divided by an integer yields an integer. If you
566 want the result to be a float, make sure one of the operands
567 is a float, e.g. type 4/7. instead of 4/7 or a/(b+0.)
568 instead of a/b. The power operation returns a float if the
569 result is too large to fit in an integer. The result of a
570 calculation is stored in the special variables $$ and $n
571 where n is the number of the command.
572
574 Probably. Please report bugs to demetrio@cs.uni-sb.de.
575
577 hexer is not in the public domain, but freely distributable.
578 It may be used for any non-commercial purpose. See file
579 COPYRIGHT for details.
580
582 Sascha Demetrio
583 demetrio@cs.uni-sb.de
584
585
586
587
588Hexer 1.0.3 October 12, 2016 HEXER(1)