Content-type: text/html Manpage of bed

bed

Section: User Commands (1)
Updated: 24 Feb 2000
Index Return to Main Contents
 

NAME

bed - Variable dataformat binary editor  

SYNOPSIS

bed [Options] [Files]
xbed [Options] [Files]
 

DESCRIPTION

Menu driven binary editor. Dataformats are ascii, unsigned and signed integers, float, bitflags, bitfields, labels, ebcdic and time_t. Different sizes and byte ordenings are possible. Datatypes can be used in structures. Other dataformats, filters and procedures can be defined in plugins. Contains copy, past, undo, redo, search, replace, marks and record/play. Linux & FreeBSD: edit block devices (linux limit 1023 gigabyte).  

Interface

Some general remarks about working bed. In bed you can do everything with the menu. You open a menu by pressing Alt in combination with the highlighted key a menuitem is selected by pressing only the highlighted key or using movement keys followed by Enter. You can get help about a menuitem by pressing F1. You escape from menu by pressing Esc. In dialog boxes you can jump to the highlighted character by pressing Alt-char or by using Tab and Alt-tab or shift-tab. Options are switched on by pressing space or *. Buttons like Ok and Cancel are operated by moving to the button and pressing Enter.

While editing the usual movement keys should work, if they don't run bed -k.

Select works wp5.1 (and vi) like: You specify a starting point (Alt-e,s) and with whatever moving function exist you go to an other point and you then press copy (Alt-e,c) or save selection (Alt-e,a).

bed has only a typeover mode, so your data doesn't move to another offset without explicitly saying so. To extend a file you should explicitly call prockey extend. If you like to left something out you should copy everything after it past it over what you like to remove and truncate the file with Alt-e,t.

To be able to handle large files (e.g. whole harddrives) bed only holds in memory what is changed and reads the other parts from disk at the moments they are needed.  

Data types


Bed has build in supports for ASCII and unsigned integers of base 2-36 (including binary, octal, decimal and hexidecimal) and size only limited to screen size. For other data types plugins can be written. Currently there exist plugins for floating point numbers, signed integers, bcd and char2. Except for plugins you handle data types in the Data type menu (Alt-d).


|--------------|
|Prev        F7|
|Next        F8|
|Remove     M-t|
|Full       C-f|
|--------------|
|Save selection|
|--------------|
|Skip bytes    |
|Reverse       |
|Bytes         |
|Base          |
|--------------|
|Identical     |
|Ascii         |
|Integer       |
|--------------|


Switching datatype
Moving between parts of the screen with different datatypes you can do with Prev (Alt-d,p) and Next (Alt-d,n).
Zooming a datatype you do with Full (Alt-d,f), removing a datatype with Remove (Alt-d,r).
Save selection saves the selected part of the file in the format of the active datatype.
Adding datatypes
You can add a datatype with Ascii, Integer, Identical. You can also define datatypes in plugins and then you can add the datatype in the plugin.
Identical gives an identical copy of the currently active datatype.
Integer (alt-d,i) gives the following window:


|----------------------------------------|
|                                        |
|  [ ] Skip Len:    0   After:    0      |
|                                        |
|  [ ] Last low with unit:    0          |
|                                        |
|  ( ) Hex   (*) Dec   ( ) Custom:       |
|  ( ) Oct   ( ) Bin   Base nr:          |
|                                        |
|  Nr bytes:    1                        |
|                                        |
|    Ok        Cancel                    |
|                                        |
|----------------------------------------|



You can specify the base of the integer in the field Base nr or you can use one of the options Hex,Oct,Dec or Bin. Hex stands for hexidecimal, Oct for octal, Dec for decimal and bin for binary.
You can specify the number of bytes and the order in which the bytes are interpreted. Last low when
the last unit is interpreted as the lowest unit of the integer. The unit determines with what unit (in bytes) the bytes are reordered. When for example specifying 4 in a 8 byte integer the upper and lower four bytes are exchanged leaving the order within this four bytes intact.


Modifying datatypes:
This are operation you can apply on some datatypes which changes certain aspects while leaving other aspects the same.
Bytes: Change the number of bytes of each item.
Base: Change the base
Reverse: reverse the order in which the bytes are interpretated by a multibyte datatype
Unit: The number of bytes which reorder together
Skip bytes: periodically skip a certain number of bytes.


Reorder and skip
Here is an example to illustrate the use reorder and skip.
Put the following code in file longlongs.c


#include <stdio.h>
int main(void) {

        long long threes=3333333333333333333;

        printf("%lld\n",threes);

        return 0;
}


When compiling with gcc -O6 -S longlong.c -o longlong.s you will get the following assemble code in longlongs.s:




        .string "%}lld\n"

main:

        pushl %}ebp

        movl %}esp,%}ebp

        pushl $776102145

        pushl $-2092083883

        pushl $.LC0

        call printf

        xorl %}eax,%}eax

        leave

        ret


When you take in bed 8 bytes decimal integers and 4 bytes signed integers (plugin signed.plug) beside
each other and type in the number you get:



         hex1  dec8signed4


55 55 4D 83 01 61 42 2E 03333333333333333333 -2092083883 0776102145


You see that

        pushl $776102145

        pushl $-2092083883
contains the same numbers as the two the signed four byte integers making up 03333333333333333333.
The difference is that $776102145 is now before $-2092083883 and that pushl stands between $776102145 and $-2092083883.


Now do gcc longlong.s -o longlong and view longlong in bed.
To locate the number you can search for 01 61 42 2E in hex1 or 0776102145 in dec4.
In hex1 you will find:


01 61 42 2E 68 55 55 4D 83


This consists of "01 61 42 2E" followed with "68" and that followed with "55 55 4D 83"
In the assemble code "01 61 42 2E" corresponds with $776102145, "68" with pushl, and
"55 55 4D 83" with $-2092083883.
When comparing the hex representation of 03333333333333333333 "55 55 4D 83 01 61 42 2E" with what the compiler made of it "01 61 42 2E 68 55 55 4D 83". You will see that the following
has happened: 68 is put between and the the order of "01 61 42 2E" and "55 55 4D 83" is reversed. (What is pushed first on the stack has occupies the lowest address with a upwards growing stack).


In bed you can now conveniently view the number in the machine code by leaving out one byte after 4 bytes and reversing with unit 4:


|----------------------------------------|
|                                        |
|  [x] Skip Len:    1   After:    4      |
|                                        |
|  [x] Last low with unit:    4          |
|                                        |
|  ( ) Hex   (*) Dec   ( ) Custom:       |
|  ( ) Oct   ( ) Bin   Base nr:          |
|                                        |
|  Nr bytes:    8                        |
|                                        |
|    Ok        Cancel                    |
|                                        |
|----------------------------------------|


After appropriately aligning the bytes you will get:


nrhex1


00972 01 61 42 2E 68 55 55 4D 83 68 03333333333333333333


Now you can change the number and save the file without difficulty. If you don't optimize you need different options to view the number.


 

Search


-----------------------------------------------------------
|                                                          |
|  [x] Regular expression                   [x] Forward    |
|  [x] Case sensitive       [ ] Boundaries  [ ] Edge file  |
|                                                          |
|                                                          |
|  Find:    linux                                          |
|                                                          |
|                                                          |
|           [ ] List    ( ) Ascii ( ) Dec   ( ) Oct        |
|    Ok                 ( ) Hex   ( ) Bin   (*) char2      |
|                                                          |
|  Cancel               Nr bytes:    2     [ ] Last low    |
|                                                          |  
------------------------------------------------------------


When you press on search of the Move menu, you come in the search window. Standard you search in the currently active datatype. To select a different data type you press on space when the appropriate data type is selected (like Ascii).
When you instead presses on Return the search string is also converted from the old data type to the new data type.
Beside this there are also the usual features like starting from the top or the bottum of the file instead of the cursor position, searching backwards, searching case insensitive and using regular expressions.


Regular expression: Use the GNU regular expression library to match a pattern against the text (See regex(7) ). When using regular expression you can search forward and backward in ascii text. In any other data type you can only search forward. When "Regular expression" is not checked everything is first converted to a general byte string and then for this byte string is searched in the file. When searching with regular expressions enabled the file is block for block converted to the currently active datatype and this printable representation is searched for regular expressions in exactly the same way as when the file was originally in this form. This means for example that when searching case sensitively the hex datatype ff is different from FF.
When using a floating point plugin different byte strings can give the same superficial appearance. When you convert the search pattern first into bytes and then search for the bytes, you will only find one of this underlying byte strings. When searching in regex mode you will find all of them. The char2 plugin contains a data type which leaves out every other byte. And when converting to bytes you have to fill them in with something and when in the file they are filled different you will not find the byte string. But when searching only in the superficial appearance you can find them.
I haven't tried any attempt to optimize regular expressions so regular expression search in ascii is very slow, and this conversion to other datatypes before searching makes it even slower. So only small distances can be searched this way.
Further shortcoming of regular expressions search:
- Only one hit in a single datatype is returned. When searching for 1 in a hex datatype it stops only once in 11.
- The same byte can generate a hit in different alignments. Only one is shown. To see them all you should change the alignment around every hit.

Case sensitive: When checked upper and lower case are treated distinctively
Boundaries: Multibyte datatypes can be aligned differently a 4 byte digit can start at offset 0,1,2 or 3 and give then different 4 byte digits. Without checking Boundaries all will be returned. With Boundaries checked only bytes aligned in the same way as is now shown on the screen are returned.
Forward: When checked the file is searched in the forward direction going from lower to higher offsets. When not checked the file is searched backward.
Edge file: When checked the file is searched from the edge of the file. From offset 0 when searching forward, from end of file when searching backward.
Find: Here you type the search pattern
List: Generated a list of all hits. When compiled with CONFIG_THREADS=y you can go on editing whilehits are marked so you can view them in marklist (Alt-m,l).
Ascii, Dec etc give when checked the current active datatype. The last datatype is the currently active. In this case that it char2. Which is a plugin datatype.
Nr bytes: give the number of bytes each data item occupies. By some datatype you can change this for example by unsigned integers.
Last low: changes the byte order of multibyte datatypes. With last low checked the last byte of an integer is the lowest.  

Replace




 -----------------------------------------------------------
|                                                          |
|  [x] Regular expression                    [x] Forward   |
|  [x] Case sensitive       [ ] Boundaries   [ ] Edge file |
|                                                          |
|                                                          |
|  Find:                                                   |
|                                                          |
|  Replace with:                                           |
|                                                          |
|                                                          |
|                       ( ) Ascii   ( ) Dec     ( ) Oct    |
|    Ok                 ( ) Hex     ( ) Bin     (*) char2  |
|                                                          |
|  Cancel               Nr bytes:    2     [ ] Last low    |

 -----------------------------------------------------------



Everthing has the same meaning as in search, with a replace string added.
At the place where the search string is found the replacestring is placed. The replace string
overwrites the data. When Regular expression is checked you can insert the whole search string by & or
supexpressions by \1 \2 to \9. In the searchstring subexpressions are demarcated by \(pattern\).




 

Options



 -------------------
|Numbertype         |
|Messageline        |
|Menu               |
|Commandmode(on/off)|
|-------------------|
|Procedures         |
|Dynamic            |
|Load plugin        |
|Key binding        |

 -------------------
A few options not handles by other menus.
Numbertype: changing the number type in which the offset in the file is shown (or removing offset numbers).
Messageline: switching the messageline on and off,
Menu: switching the menu bar on and off
Commandmode: setting commandmode on and off. Inside command mode the normal keys are not automatically put into the document. This makes it possible to bound commands to normal keys, like is done inside vi. By default there are no keysbindings of this kind, but you can put it into the configuration file if you want.
Procedures: View list off all procedures which can be bounded to keys or are part of the menu. Press return on a procedure to execute the procedure.
Dynamic: view procedures defined in plugins
Load plugin: filemanager to select a plugin
Key binding: shows the procedure bounded to a particular key

 

OPTIONS

Press bed -h to get an overview of options.

 

CONFIGURATION


In the configuration file you can change colors, assign keys, change the menulayout, loud plugins. and configure to call procedure's at certain moments. As configuration file is used the first file of the environments found of the argument to -f at the commandline , the environmental variable BEDRC, ~/.bedrc or /usr/share/bed/bedrc.  

Path


plugindir path
Set directory were is looked for plugins to path. Also effects Alt-t,l.

datatypedir path
Set directory were is looked for saved datatypes to path. Effects Alt-y,w and Alt-y,d.  

Keys


When the keys don't work or you want to make different key bindings, you can assign
 new key bindings in the configuration file. 
In bedrc the keys are defined by lines of the following format:

keys key1 key2 ...keyn = procedure


for example:


keys 27 115 = search


In which case Alt-s is bound to 'search' which is the search function.


The numbers are a decimal representation of the escape sequences generated by a key or a key combination. Within bed you can press Alt-t,k to press a key and see the keycodes and keybinding.

Bed version 0.2.7 added the possibility to make keys statements of the following format:

keys capname = procedure

capname is a terminfo name for a key sequence. For example

keys kf1 = selectprocedure

binds selectprocedure to function key F1. See man terminfo for details. There seems to be as much variation in keylabels as keycodes, so don't expect to much.


bed -k
If you only want to assign the right meaning to the keys used by the program (instead of making new keybinding), you can press bed -k. You are asked to press function keys and it will append the corresponding key assignments to ~/.bedrc.
Personal keybindings
If you want to make personal keybindings you should come to know the procedure argument to keys. To come to know the name of a procedure mentioned in the menu or bounded to an other key you press Alt-t,k followed by the key or menukey combination.
If you want for example to know what the name is of the procedure behind Alt-f,o you press Alt-t,k followed by Alt-f,o and on the commandline you see something like "menu item Alt-f,o = addfile". To bind this to insert you press Alt-t,k,INS and get as answer something like: No keybinding for 27 91 50 126 You add now at the bottum of ~/.bedrc
keys 27 91 50 126 = addfile
An other way to learn the names of the procedures is the read the Procedures section later in this manual, but the program itself is always more up to date then the manual.  

Menu


New in bed-0.2.12 is the possibility to change the menu layout. You can add new items to the menu, add new menus and delete menuitems and menu's. A 'menu' corresponds to the list of names you get when you press for example Alt-f, (the menu with menulabel "~File"). A 'menuitem' corresponds on name in this list for example "~Open C-o".
The menu's are numbered. The first menu on the left usually "~File" has number 0, the following menu "~Edit" number 1 etc. This number I will call 'menunum' in this manual.
menu [menunum] menulabel [+]
This command is used to give a menu a certain label and keybinding. One character in label should be prefixed by ~ meaning that is the highlighted letter what should be pressed in combination with Alt to open the menu. The menu label should be surrounded by "'-s. e.g.
     menu 0 "My F~ile"
Changes the label of the "~File" menu to "My ~File". To insert a new empty menu at position 0 shifting the other menu's to the right, you should add a + after the previous command, getting:

     menu 0 "My F~ile" +
To create an empty menu at the very right you can use:

     menu 8 "~Hallo"
In this case you can also leave out 8,

     menu "~Hallo"
In the menu command menunum defaults to the highest used menu number+1.
menuitem [menunum] menuitemlabel [keylabel] [menitemnum] [+]= procedure
This command is used to add menuitems to menu's. For example:
       menuitem 0 "~Quit" 1 = quit

       menuitem menunum menuitemlabel menuitemnum

Replaces the existing menuitem at position 1 in menu 0 with the label "~Quit" and the procedure quit. Menuitem's are numbered from 0 starting from above. If you like to insert the menuitem, while shifting the existing menuitems downwards, you can add a +, which gives:
       menuitem 0 "~Quit" 1 + = quit

If you like to add a keylabel (e.g. M-q) you can change it to
       menuitem 0 "~Quit" "M-q" 1 + = quit

this will be displaced as something like " Quit M-q " to make M-q work you should also add something like:
       keys 27 113 =quit

In menuitem menunum defaults to the last mentioned menu. menuitemnum defaults to the highest menuitem number + 1 (in this menu). You can write:

     menu "S~imple"

     menuitem "~New" = emptyfile

     menuitem "~Open" = addfile

     menuitem "~Save" = dosave

     menuitem "~Quit" = quit
menuitem [menunum] LINE [menitemnum] [+]
This command is used to create a blank like in a menu (leaving a menuitem empty).
To insert a line after "~Open" in the previous menu you can write:

     menuitem LINE 2 +
deletemenu [menunum]
This command is used to delete a menu and all it's menuitems. If you dislikes the first menu ("~File") you simply writes:

     deletemenu 0
In deletemenu menunum defaults to the highest numbered menu.
deletemenuitem [menunum] [menitemnum]
Deletes menuitem menuitemnum from menu menunum. menunum defaults to the last mentioned menu, menuitemnum to the highest numbered menuitem. When only one number is given it is interpret as meaning menuitemnum (for menunum the default is used). To delete the fourth menuitem out of the first menu, you write:
       deletemenuitem 0 3

In all menu commands you can explicitly use the default value by using a negative number.  

Call_on

Instead of calling a procedure after pressing a key or using a menu, you can also specify in the configuration file that procedure will be called at certain moment (on startup,open,switch).
call_on_start procedure
Calls procedure at startup, which means after the program is has started, and a file is opened. Operated is on this file.
call_on_open procedure
Procedure is called every time a file is opened.
call_on_switch procedure
Procedure is called every time you switch to a file.

 

Context


When you use more than one terminal (for example linux console and rxvt), you can set a environmental variable to differentiate between the type of terminal and use the context key word in ~/.bedrc.
Everything started with the context keyword until the following context keyword or end of file is only used when the right environmental variable set.
The format of context is the following.

context [!] variablename [variablevalue]

For example:

context term xterm

You can also say

context variablename

when it should apply for all cases in which the variablename has a definition.
For example

context termcap

applies in all cases in which termcap is defined.
If you like to apply the next configuration only when an enviromental variable is not set or has a different value, you have to write ! before the enviromental variable.
context ! DISPLAY
means to apply the statements following this context statement and before the next context statement only when DISPLAY is not set.
If there is no environmental variable shared by the context you like to give the same configuration you can set a environmental variable and use this at a context argument. It is possible to set enviromental variables within the configuration file with:
setenv name val
To do the same by TERM=cons25 as with TERM=cons50 you can write:
       context TERM cons25

       setenv consoleterm yes

       context TERM cons50

       setenv consoleterm yes

       context TERM cons43

       setenv consoleterm yes

       context consoleterm

       keys 27 91 97 = beginfile #S-F3

       keys 27 91 98 = endfile #S-F4

       keys 27 91 101 = middlepage #S-F7      


In combination with '!' you can this way create every possible boolean logic formula (using the statement that every propositional logical formula can be written with only not and or). With setenv you have an or and '!' adds the not. To apply statementZ only if X and Y you use "X and Y"<=>"not (not X or not Y)" transforming this to bedrc you get
context !X
setenv dont 1
context !Y
setenv dont 1
context !dont 1
statementZ
 

Color



Colors can also be changed in the configuration file. There are around 17 screen elements which you can give a foreground and background color and a list of attributes (standout, underline, etc).
The format is:


color screen-element [foreground background] [attr,attr...]


You can give only attributes or both the foreground and the background color and any number of attributes.


The screen parts are the following:
TEXT: The color the text is showed in. It is better not to give this a color because this makes the screen updating much slower (some feature of ncurses)
COMMAND: the commandline
SELECTION: selection
CURSOR: cursor in active datatype
CURSORPAS: cursor in passive datatype
SELCURSOR: cursor during selection
BAR: the menubar
BARKEY: Key highlighting in the menubar
MENU: Opened menu's
MENUKEY: key highlighting in menu
MENUSEL: color of menu element which is selected
OPENTITLE: title of file manager
OPENKEY: key highlighting of key manager
OPENNORMAL: background key manager
OPENLIST: color of non active items of list
OPENLISTSEL: color of active item
OPENLISTACT: color of active item when this piece is used
SHOWBACK: Search/replace window
SPACEAFTER: color of space before and between datatypes


The colors and attributes are just the colors and attributes of ncurses. When they don't look the way the name suggests you should send your complains to the makers of ncurses.


Colors: BLACK RED GREEN YELLOW BLUE MAGENTA CYAN WHITE


Attributes: NORMAL STANDOUT UNDERLINE REVERSE BLINK DIM BOLD PROTECT INVIS ALTCHARSET CHARTEXT


For me only STANDOUT UNDERLINE REVERSE BLINK BOLD have a useful meaning.


On example:


color BAR WHITE RED blink


Which makes a blinking white on red menu bar (on my computer it blinks only under linux console and not in xterm or rxvt).


To make the cursor bold and underlined you can do


color cursor bold underline


The color lines can be intermixed with the keys lines and can also be specific to a context.


 

Procedures


When you want to make you own key bindings you need to know the names of the procedures you can bind to keys. A selected subset of the procedures can also be assigned by using the name of the key they are normally bound to. There are the following key labels: home , end, f1, up, down, left, right, pgup, pgdn, stab, delete, backspace and esc. When you assign a key sequence to a key label the meaning in the filemanager, search window and menu is also changed. so
       keys 1 = home

gives Contr-A the home functionality in all this application parts.

For the filemanager and search window this is the only way the change keybindings. Inside the menu you can also change keybindings by putting 253 in front of the key numbers. See procedure firstmenuitem.
What follows are all procedures mentioned in the menu with a description and their place in the menu. It is exactly the same information as you get when you press F1 within the menu.

addfile
Open (Alt-f,o)

Opens a new file, adding it to the files already on the screen.

dosave
Save (Alt-f,s)

Save current file.

saveas
Save as (Alt-f,a)

Save currently active file to a file with another name.

rewrite
Refresh (Alt-f,r)

Rewrites screen.

selectprocedure
Procedures (Alt-t,p)

Listing of available procedures to bind to keys or use in plugins. You can press return on the name to run the procedure. Press F1 to get help about the procedure.

selectdynprocedure
Dynamic (Alt-t,d)

Listing of available dynamic procedures (procedures defined in plugins) to bind to keys, place in menu or use in plugins. You can press return on the name to let it work. Press F1 to get help about a procedure.

closethis
Close (Alt-f,c)

Close the current file.

quit
Exit (Alt-f,x)

Quit application. For all changed files you are asked to save it.

undo
Undo (Alt-e,u)

Undo last change.

redo
Redo (Alt-e,r)

After you have undone something with undo, you can redo it with redo.

setselect
Select (Alt-e,s)

Turns selection on or of.

copyselect
Copy (Alt-e,c)

Copies selected part of the file to copy buffer.

pastselect
Past (Alt-e,p)

Past selection.

saveselect
Save selection (Alt-e,a)

Save selection or copy buffer.

replace
Replace (Alt-e,e)

Regular expression:         Use the GNU regular expression library to match a pattern
        against the text (See man regex(7)).
        In normal search the search string is first converted to bytes
        and then matched with the raw file content. With regex search the
        file content is first converted to the datatype before regex search.
        Sometimes different bytes have the same appearance in a datatype.
        In that case you should always search with regex checked,
        examples: Float, char2 and when filters like duplicate or skip
        are applied.
Case sensitive:         When checked upper and lower case are treated distinctively.
Boundaries:         Multibyte datatypes can be aligned differently. For example a 4
        byte digit can start at offset 0,1,2 or 3 and that will give
        different 4 byte digits. Without checking Boundaries all will
        be returned. With Boundaries checked only bytes aligned in the
        same way as is now shown on the screen are returned.
Forward:         When checked the file is searched in the forward
        direction going from lower to higher offsets. When not checked
        the file is searched backward.
Edge file:         When checked the file is searched from the edge of
        the file. From offset 0 when searching forward, from end of
        file when searching backward.
Find:   Here you type the search pattern
Replace:         At the place where the search string is found the
        replacestring is placed. The replace string overwrites the data.
        When Regular expression is checked you can insert the whole search
        string by & or supexpressions by 1 2 to 9. In the searchstring
        subexpressions are demarcated by pattern).
List:         Generates a list of all hits. When compiled with
        CONFIG_THREADS=y you can go on editing while hits are marked
        so you can view them in marklist (Alt-k,l).
Ascii, Digit etc are when checked the current active datatype. Base:         Base of digit. E.g 16 for heximal.
Nr bytes:         Gives the number of bytes each data item occupies. By
        some datatypes you can change this for example by unsigned integers.
Reverse:         Reverse bytes while transforming from datatype to bytes.
Set:         After changing datatype info (base,bytes,type) you press Return
        on Set to make this the search datatype.
Convert:         the same as Set in addition the current search string is converted.
Ok:     search
Cancel: Cancel

extend
Extend file (Alt-e,x)

Make the file larger, adding zeros to the end of file.

truncate
Truncate (Alt-e,t)

Truncates file on the right of cursor.

repeat
Repeat nr (Alt-e,n)

Repeats command a certain number of times.

search
Search (Alt-m,s)

You can move by pressing Alt in combination with a highlighted character, or by pressing Tab,Shift-Tab or Alt-Tab. Press Shift to check options. Standard you search within the currently active datatype, but you can also use Ascii or Digit (unsigned integers) by selecting them, specifying base and bytes and pressing Set. Regular expression:         Use the GNU regular expression library to match a pattern
        against the text (See man regex(7)).
        In normal search the search string is first converted to bytes
        and then matched with the raw file content. With regex search the
        file content is first converted to the datatype before regex search.
        Sometimes different bytes have the same appearance in a datatype.
        In that case you should always search with regex checked,
        examples: Float, char2 and when filters like duplicate or skip are
        applied.
Case sensitive:         When checked upper and lower case are treated distinctively.
Boundaries:         Multibyte datatypes can be aligned differently. For example a 4
        byte digit can start at offset 0,1,2 or 3 and that will give
        different 4 byte digits. Without checking Boundaries all will
        be returned. With Boundaries checked only bytes aligned in the
        same way as is now shown on the screen are returned.
Forward:         When checked the file is searched in the forward
        direction going from lower to higher offsets. When not checked
        the file is searched backward.
Edge file:         When checked the file is searched from the edge of
        the file. From offset 0 when searching forward, from end of
        file when searching backward.
Find:   Here you type the search pattern
List:         Generates a list of all hits. When compiled with
        CONFIG_THREADS=y you can go on editing while hits are marked
        so you can view them in marklist (Alt-k,l).
Ascii, Digit etc are when checked the current active datatype. Base:         Base of digit. E.g 16 for heximal.
Nr bytes:         Gives the number of bytes each data item occupies. By
        some datatypes you can change this for example by unsigned integers.
Reverse:         Reverse bytes while transforming from datatype to bytes.
Set:         After changing datatype info (base,bytes,type) you press Return
        on Set to make this the search datatype.
Convert:         the same as Set in addition the current search string is converted.
Ok:     search
Cancel: Cancel

nextsearch
Nextsearch (Alt-m,n)

Search again for the same word.

gettopos
Position (Alt-m,p)

Ask for a file offset and jumps to this offset. Forward:         count up
Edge File:         If checked: count from begin (forward) or end (backward) file.
        If not checked you count from the cursor position.
Boundaries:         If checked: In multibyte units the screen is aligned at the current
        alignment (boundary) after changing position.
Position:         Offset to jump to.
You can specify in what format to specify the offset. All: specify offset with 0x for hex and 0 for oct. Numbers not starting with 0         are decimal numbers.
Hex,Dec,Oct: type of number without need to use 0x or 0

keymark
Make (Alt-k,m)

Set mark

tomark
Goto (Alt-k,g)

Goto mark. You are asked to type the corresponding key.

nextmark
Next (Alt-k,x)

Goto next mark

prevmark
Previous (Alt-k,p)

Goto previous mark.

showmarks
List (Alt-k,l)

Shows list of all marks. Press Return to jump to the file offset of the selected mark.

deletemark
Delete (Alt-k,t)

Delete mark. You get an overview of current marks. Press return to delete the currently selected mark.

clearmarks
Clear (Alt-k,c)

Delete all marks.

savemarks
Save (Alt-k,s)

Save marks to file.

readmarks
Read (Alt-k,r)

Read saved marks.

postotop
Top (Alt-i,t)

Place the text at the cursor position in the upper left corner of the screen.

beginfile
Begin file (Alt-m,b)

Goto the beginning of file.

endfile
End file (Alt-m,e)

Goto end of file.

beginpage
Begin Pg (Alt-m,i)

To the top of page.

endpage
End Pg (Alt-m,d)

Goto end of page

middlepage
Middle Pg (Alt-m, )

Goto the middle of the page.

nextmode
Next (Alt-d,n)

Goto the data type on the right of this data type.

prevmode
Prev (Alt-d,v)

Goto the data type shown on the left of current active data screen.

removemode
Remove (Alt-d,r)

Closes data type screen part.

zoommode
Full (Alt-d,f)

Zooms current data type (For example ASCII).

addprev
Add Prev (Alt-w,d)

Adds previous file to the screen

addnext
Add Next (Alt-w,a)

Adds the next file to the screen.

prevfile
Prev (Alt-w,p)

Goto previous file. Zooming the file.

nextfile
Next (Alt-w,n)

Goto next file.

firstfile
First (Alt-w,f)

Goto the first opened buffer.

lastfile
Last (Alt-w,t)

Goto last opened file.

zoomwindow
Zoom (Alt-w,z)

Zooms current window

hidewindow
Hide (Alt-w,h)

Get opened file from the screen without closing it

listfiles
List (Alt-w,l)

List opened files. Press Enter to edit selected filename.

askbase
Offset (Alt-t,o)

Changes the number type (base) with which the offset in the file is shown.

switchmessage
Messageline (Alt-t,m)

Hides or shows message line.

switchmenu
Menu (Alt-t,u)

Hides or shows menu bar.

switchcommand
Commandmode(on/off) (Alt-t,c)

Switches command mode on or of. In command mode characters you type are not put in the document. Instead of this procedures are bound to normal characters. If you like to completely emulate 'vi' or 'less' you should assign the keybindings yourselves. A beginning is made in the configuration file.

backchar
Left

Go back one character.

beginline
Go to begin line (Home).
endline
Goto end line (End).
fileinfo
Show the name and size of file in the message line. (No key binding).
firstmenuitem
Goto the first menu element. (Home).

Only applies within an opened menu. You have to put 253 immediately after the keys keyword. So for example:

keys 253 1 = firstmenuitem

makes that within an opened menu contr-a jumps to the first menu item.

lastmenuitem
Goto last menu element. See firstmenuitem for more information. (End).
fromcommand
Turns command mode off.
linedown
Down one line (Down).
lineup
Up one line (Up).
nextchar
Next character. (Right).
nextmenu
Goto next opened menu. (Right). Only applies in the context of the menu. See firstmenuitem for more information,
nextmenuitem
Goto next menu item. (Down). See firstmenuitem for more information.
nop
Does nothing.
pagedown
Page down. (Pgdn).
pageup
Page up. (Pgup).
prevmenu
Goto previous menu. (Left). See firstmenuitem for more information.
prevmenuitem
Goto previous menuitem (Up). See firstmenuitem for more information.
tocommand
Turns command mode on.
tosubscreen
Goto the data screen corresponding to the number you type after this command. 0 is the first from the left, 1 the second etc. (No key binding).
emptyfile
New (Alt-f,n)

Opens new document of size 1. You can enlarge the document with Alt-e,x.

filedata
Fileinfo (Alt-f,f)

Displays information about current file.

checkchanged
Modified? (Alt-f,m)

Checks if current file is modified by comparing changed parts with the original file.

suspend
Shell (Alt-f,h)

Go to shell. Starts a new shell or uses suspend.

If a new shell is evoked, it uses the SHELL environmental variable to decide which shell to use. You can also set environmental variables in beds configuration file (see manual).

input
Input (Alt-e,i)

Modifies current data item. With this procedure you edit the current item and only after pressing Enter the modifications are inserted. Certain datatypes you can't edit without this procedure (e.g. Float and Time_t). If you don't use this procedure, then the data item is converted to and from binary format after every key you press.

editdata
Edit (Alt-e,d)

Evokes text editor to edit selected data in active datatype.

If the environmental variable EDITOR is set to the full path of an editor that editor is used. You can set environmental variables in beds configuration file with the following command:

setenv name [val]

Leaving out val means unsetenv.

See bed's manual page or bed -h for more information.

select
Turn on or off selection. Selections can be copied and pasted, saved, edited etc.
saveshown
Save Shown (Alt-e,v)

Save selection in the active datatype as shown on the screen. So the selected data is first converted to the active datatype and then saved to a file.

readshown
Insert shown (Alt-e,h)

Insert file content within active datatype. The content of the file is interpreted as consisting of data in the active datatype.

gotolastsearchpos
Not searched (Alt-m,o)

Jumps to file offset not yet searched. Useful if you interrupted searching or are searching on the background and want to know where search was left.

nextitem
Next Item (Alt-m,x)

Moves one item forwards. Item is the active datatype unit.

backitem
Back Item (Alt-m,a)

Moves one item backwards. Item is the active datatype unit.

prevpos
Undo move (Alt-m,m)

Go to previous file offset.

nextpos
Redo move (Alt-m,v)

Go again to file offset before undo move.

scrollup
Up (Alt-i,u)

Scrolls file up, so that the first line becomes what was the second line.

edscholldown
Down (Alt-i,w)

Scrolls file down, so that the second line becomes what was the first line.

scrollitem
Left item (Alt-i,l)

Shift left one item. The second item on the screen becomes the first item.

scrollbackitem
Right item (Alt-i,r)

Shift right one item. The first item on the screen becomes the second item.

scrollbyte
Left byte (Alt-i,f)

Shift left one byte. The second byte on the screen becomes the first byte.

scrollbackbyte
Right byte (Alt-i,g)

Shift right one byte. The fist byte on the screen becomes the second byte.

makemode
Integer (Alt-d,i)

Create unsigned integer datatype. You can select bases from 2 to 36. The number of bytes per unit range from 1 to some unknown limit depending on hardware speed. You can start a separate datatype or add a field to an existing datatype. In the last case the position of the new field depends on the cursor position:         - At the end if cursor is at the end of the screen
        - At the beginning of cursor is at the beginning of the screen
        - Otherwise at the place most close the the cursor.
         After the cursor position if there is no difference.

naarASCII
Ascii (Alt-d,a)

Create ascii datatype. No print:         character to show if byte is not printable.
You can also decide which byte values are interpreted as printable characters. Strict is ascii only, +161-255 adds byte value 161-255 etc. It is possible to make units of more then one character. The meaning of separete/add field is explained under Integer help.

emptycontain
Empty (Alt-d,y)

Skip empty parts within a composed datatype. Useful if a file contains records with parts you are not interested in.

copymode
Clone (Alt-d,c)

Create a datatype that is identical to the active (sub) datatype.

addSigned
Signed (Alt-d,s)

Create signed integer datatype. See Integer help for more information.

addFloat
Float (Alt-d,o)

Create float datatype:         4 bytes: float
        8 bytes: double
        12 bytes: long double

addBitFlags
BitFlags (Alt-d,b)

Create bitflags. Give every bit a label which is shown if that bit has value 1. Not char:         If that bit is zero, the value of Not char is shown.
Add:         Bit-label correspondences are assigned by typing a bit number after
        Bit and the corresponding label after Label and pressing return on
        Add. Bits are numbered from 0 to (8*bytenr-1). With the lowest bit
        having number 0.
        This creates a list of bit-label correspondences under Flags.
Flags:         You can edit one such correspondence by pressing Alt-f followed by
        selecting the correspondence and pressing return. You change the
        Bit and label values and again press Return at Add.
Del:         If you press on delete the selected correspondence is deleted.
Between:         What to write between bytes. Default: nothing.
Order:         When editing a file in bitflags every item is shown as some flags.
        If you want to set a certain flag you write the label. If order is
        set this is only possible if you are above the position of this
        label. If order is not set you can set the label at every position.
        Example:
        If the flags are zyx and order is set you can change --- in --x only
        by pressing x at position 0, without order you can press x
        also at position 1 or 2.

bitfielder
Bitfield (Alt-d,e)

This is a record/struct in which you specify the number of bits for every field. After making a bitfield around a datatype it works like a normal composed datatype. You just add the other fields. You change the number of bits of a certain field by setting the cursor on that field and selecting again Alt-d,e but now you press 'Change Bits'. Another way is to make the bitfield the active datatype by pressing Alt-y,t (Parent) and then selecting Config (Alt-y,g).

translate
Translate (Alt-d,l)

Translate assigns labels to values of another datatype. You can use it when numbers have a certain meaning. After selecting 'New' or 'Change': Type:         The To datatype is what is shown on the screen (usually Ascii).
        For certain values of the 'From' datatype you specify what should be
        shown in the To datatype.
Add:         After specifiying the To and From datatypes, you specify the From
        and To values and press Add.
Default:         If there is no assignment Default is shown.
Assignments:         After pressing Alt-g you can select a certain existing assignment.
        Pressing Return makes it editable, pressing Del deletes it.

After selecting 'Use;         Select label and press return to insert this value.

listtypes
List (Alt-d,t)

List of all datatypes. Use movement keys to select one of them and press Return to create it.

reorderunit
Reorder (Alt-y,o)

One of the filters that is transforms the data when read from the file and before interpreted by the datatype. Reorders bytes within item. Unit gives the number of bytes to keep together. If the bytes are 'abcdef', reorder with unit=1 gives 'fedcba', with unit=2 gives 'efcdab', with unit=3 gives 'defabc'.

duplicate
Duplicate (Alt-y,i)

Useful if you like to use the same data more than once in a composed datatype. It acts like an union in c. Filter that duplicates bytes before being interpret by the active (sub-) datatype. You have to specify how many times it is duplicated (dubnr). The active (sub) datatype consists of a certain number of bytes (size). usenr=(size/dubnr) gives the number of bytes used for every item. dubnr times the same usenr bytes are appended and given to the datatype. Example: You use ascii/4 (ascii consisting of 4 bytes). You say duplicate 2 and the file consists of abcdefghijkl. Before applying the filter this was displayed as abcd efgh ijkl. After applying the duplicate filter it becomes abab cdcd efef ghghe ijij klkl.

addskip
Skip (Alt-y,k)

Filter to skips a certain number of bytes. You have to specify after how many bytes and how many bytes are to be skipped. This is then repeatedly applied to every unit of the active (sub-) datatype. Example: The active datatype is ascii/4. The file contains 'abcdefghijkl'. abcd efgh ijkl is displayed. Applying Skip with After=2 and Skip=1 gives: abde ghjk. After ab c is skipped after de f is skipped and after jk l is skipped.

rmlastfilter
Rm filter (Alt-y,m)

Removes last filter (Reorder, Duplicate, Skip or some other filter defined in a plugin).

repeatcontain
Repeat (Alt-y,p)

Repeats active (sub-)datatype a certain number of times. It behaves the same as a composed datatype with multiple version of the current active (sub-) datatype.

datatypeconfig
Config (Alt-y,g)

Modify parameters of active (sub-) datatype. Things like number of bytes and the base of Integers.

dataconfig
Misc (Alt-y,s)

Modify some general display parameters of datatype. Label:         Name for datatype shown on the message line
Apart:         number of spaces between items of this datatype
Spaceafter:         number of spaces between this datatype and an other datatype
        or the offset numbers.
Conf:         Configuration string every datatype has. Usually you don't need
        to change this.

savedatatype
Write Type (Alt-y,w)

Save datatype to file so you don't have to recreate complex datatype everytime you need them.

readcontain
Read Type (Alt-y,d)

Read saved datatype. So that the current file is displayed in that format.

record
Record keys (Alt-t,r)

Start recording. Keystrokes are recorded until you press C-t. You can save recorded keystrokes to replay them at some other moment.

Take notice of the fact that RAW keystrokes are saved. This means that the recorded keystrokes are very unportable. They are not portable between operating systems but also not portable between terminals and configurations. What's is recorded withing xterm does not nessesarily work with rxvt or with linux console. You can use more portable keystrokes by using only Alt-char and Control-char keys. The movement and function keys are very unportable and also combinations of Alt or Control that make use of non alphabetic characters.

saverecord
Save Recorded (Alt-t,s)

Save recorded keystrokes to file.

playkeysfile
Play file (Alt-t,y)

Play saved keystrokes (recorded with Record). The program runs like the keystrokes are pressed by the user, except when other programs are evoked from bed.

playrecord
Play (Alt-t,a)

If you have recorded keystrokes after program startup you can play them off with this procedure.

opendynlib
Load plugin in program. The plugin can contain datatypes or procedures. Procedures you can view under Dynamic (Alt-t,d), datatypes under Alt-d,t.
showprocedure
Key binding (Alt-t,k)

Shows procedure in menu or binded to key sequence. You are asked to press the keys you want to know the procedure off. Within menus you can only use a key and not movement keys to go to the procedure you are interested in.

Beside the procedure it is shown what you need to write in the configuration file to declare this key/menu-procedure binding.

Examples After Alt-t,k, you press F12 and get         keys 27 91 50 52 126 = makeselection

The procedure is makeselection with is bounded to escape sequence: 27 91 50 52 126 If you like to bind makeselection to an other key sequence you press after Alt-t,k, the keys you want to bind it to, for example C-a and replace '27 91 50 52 126' with what you found there for example 1. So add keys 1 = makeselection to the end of ~/.bedrc

After Alt-t,k you press Alt-f,x and get

menuitem 0 "E~xit" "M-x" 12 = quit

Procedure quit is bounded to a menuitem. The menu item is in menu 0 (the first menu) has label 'E~xit' and had keylabel 'M-x' and is the twelves menuitem in the menu (starting with 0 and counting empty places).

If you like to change to name from 'E~xit' to '~Quit' you can add menuitem 0 "~Quit" "M-x" 12 = quit to the end of ~/.bedrc

See the bed manual page for more details about assigning procedures to menu items and keys.

newcontain
Sub (Alt-y,u)

Creates a new composed datatype (record/struct) around current datatype.

stretchcontain
Stretch (Alt-y,r)

Used to handle nested composed datatypes (made with Alt-y,u). If you have made a composed (struct/record) datatype for example: {{a,b,c},d,g} Here the letters are datatypes and {..} is one composed datatype. {a,b,c} is a nested (or sub) composed datatype. If you put the cursor on d and apply this function, you can add d to this sub composed datatype. So you get then {{a,b,c,d},g}.

levelout
Levelout (Alt-y,v)

Applies if active datatype is a composed/record datatype. With this function the composed datatype is removed so that the item(s) endup at a higher level. It can be used in two cases:         1. nested composed;
        2. composed containing only one datatype.

uplevel
Parent (Alt-y,t)

Parent datatype. Make active datatype the datatype in which the current datatype is contained.

downlevel
Child (Alt-y,c)

If applied to a composed datatype, this makes the current active datatype the member of the composed datatype the cursor is on.

goto1
Goto the first open file.
toclipboard
Puts selection in active datatype in MS Windows clipboard.
pastclipboard
Insert MS Windows clipboard in active datatype.
 

PLUGINS



Bed has the possibility to call c functions from within bed and to assess some of the data of bed.


Here is an example:


/*Begin example1.c */


#ifdef GLOBAL
#endif


#ifdef EDITOR


int example1(void) {

        message("Hello world!!!");

        }


#endif


call(example1)


/* End example1 */


Everything in the area in which GLOBAL is defined is code outside of the EDITOR class. Everything inside the area in which EDITOR is defined is inside the Editor class and at the end of the files are the names of the procedures which should be bounded to a key in bed.
In this example the procedure example1 uses an function of bed which writes a message to the messageline and call(example1) says that the function example1 should be assessable by bed.
This function example1 you can bound to a key the same way as bed's own procedures . For example
keys 1 = example1
to bind contr-A to example1.


To compile the example you need just to do
       make example1.plug

in the plugings/examples directory. Which assumes that there is the original Makefile and the make variable PLUGINDIR is assigned to the directory in which plugin.cpp, faked.h and mainprocedures.h reside.


Ones compiled you have to put the line
plugin ABSOLUTEFILENAME
in ~/.bedrc before you bind a key to the corresponding functions.


So in for this example you can add


plugin /usr/share/bed/plugins/example1.plug
keys 1 = example1


in ~/.bedrc to enjoy the pleasure of getting "Hello world!!" when you press Contr-A.


In the procedures you write you can use all the procedures which can bounded to keys (which have the format int name(void)), plus some extra procedures I am going to describe now.
The following functions are inside class Editor:


int topos(long pos)

Go to offset pos in the current file.


int dosearch(char *str, int len)

Search for str with length len in the current document


int getfilepos()

Get the offset of the shown part of the file.


int geteditpos()

Get the offset of the cursor in the current screen.


int getmem(long pos,char *buf,int len)

Get from position pos a piece of the current file with length len.


int putmem(long pos,char *buf,int len)

Put at position pos the array buf of length len.


int getmode(Type type)

Get (goto) a display with data type type. Type has the following definition:


typedef enum {HEX=16,ASCII=256,DEC=10,BIN=2,OCT=8 } Type;


int getselbuf(char **buf)
Put a pointer to the cutbuffer in *buf and returns the length of the cutbuffer.

int putselbuf(char *buf,int len)
Puts buf with length len in the cutbuffer.

int getselect(void)
int putselect(int pos)

getselect returns the starting position of the current selection or -1 if there is no selection. Putselect put's the starting position of the selection or with -1 unselects.
(The end position is the cursor position).


int screensize()

Get the number of bytes currently on the screen.


char *getfilename(char *buf)

The current filename is copied to buf.


int message(char *format ...)

Write to messageline. Same format as printf.


int getkeyinput(char *format ...)

Ask in the same format as printf. And get an key as answer.


int inputget(char *answer,const char *format,...)

Ask in the same format as printf and get an answer in answer (should hold enough memory).


int filesize(void)

Get filesize.


int toscreen(void)

Makes that the effect of previous operations is shown on the screen.


void filesup(void)

When a newwin (of ncurses) is used you can with filesup get the file windows of bed again on top.

Global procedures:


extern Editor *editfile(const char *file)

Open a new file. When you want to do operations on this file you should hold in mind that the previous functions are part of the class Editor. So when you can do for example:
/*start stupid.cpp
#compile with make stupid.plug
#put in ~/.bedrc
plugin /usr/share/bed/plugins/stupid.plug
keys 1 stupid
# and call contr-A in bed
*/


#ifdef EDITOR


int another(void) {
       topos(400);

       toscreen();

       getkeyinput("I am going to delete everyting O.K. ");

       putmem(0,"Hello",5);

       }


int stupid(void) {
       Editor *ed=editfile("/boot/zimage");

       return ed->another();

       }


#endif
call(stupid)
/*end stupid.c */


extern Editor *getactive(void)

Get the currently active Editor.


extern void rewriteall(void)

Rewrites everything on the screen.


Some examples of plugins are put in plugins/examples: one shows the assembler labels of the bytes starting with the cursor (gdb.plug), one shows the file type (when the cursor is on the first byte of a file) (file.plug) and and one filters what's selected through an other program (filter.plug).
A new syntac uses class Editor {} instead of the defines. See plugin sources ending in *.cc. By the way don't define variables in the EDITOR (or class Editor) part, also don't try to assess class Editor variables of the main program directly. It will mess up everything. The setup of plugin using class Editor should be changed in the feature because it relies too much on undocumented features.
You can also define you own datatypes a a subclass. See for example float.cc
The information about plugins is not updated since version 0.0.0.. For additions and modifications you can look at the example plugins or in faked.h or the Options menu inside bed (Key binding and Procedures).  

ENVIRONMENT

BEDRC
Absolute filename of configuration file.
EDITOR
Preferred editor unix: export EDITOR=vi windows: set EDITOR=notepad
SHELL
Preferred shell
TMPDIR (unix) or TMP or TEMP (win95)
Directory for temporary files
It is possible to set environmental variables in the configuration file:
setenv name [val]

Leaving leaving out val means unsetenv.
 

FILES

~/.bedrc
Individual configuration.
/usr/share/bed/bedrc
System wide configuration.
/usr/share/bed/plugins/*
Files needed to compile plugins: plugin.cpp faked.h mainprocedures.h Makefile


 

PORTABILITY


Binaries available for:
Linux RedHat 7.1
FreeBSD 4.3
Windows95+cygwin-1.1.4+pdcurses-2.3b-win32+gnu/regex-0.12  

AUTHOR


Jaap Korthals Altes
<jkaltes@cyberbrain.com>
<jkaltes@itookmyprozac.com>
 

LOCATION



 http://bedlinux.tripod.com

 ftp://sunsite.unc.edu/pub/Linux/apps/editors/terminal/  

SEE ALSO

printf(3), scanf(3), strings(1), grep(1), dd(1) head(1), tail(1), regex(7), ncurses(3), od(1), hexdump(1), hex(1), bpe(1), beav(1), hexed(1), hexedit(1), khexdit(1), khexedit(1), ghex(1), bvi(1) terminfo(5)


 

Index

NAME
SYNOPSIS
DESCRIPTION
Interface
Data types
Search
Replace
Options
OPTIONS
CONFIGURATION
Path
Keys
Menu
Call_on
Context
Color
Procedures
PLUGINS
ENVIRONMENT
FILES
PORTABILITY
AUTHOR
LOCATION
SEE ALSO

This document was created by man2html, using the manual pages.
Time: 21:27:17 GMT, September 23, 2001