Bset

From Scriptwiki
Revision as of 20:41, 13 October 2006 by Vliedel (talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The bset command is used to set a binary file.

bset [-t] <&binvar> <N> <asciivalue> [asciivalue ... asciivalue]

This sets the Nth byte of the binary file &binvar to the asciivalues. All asciivalues after are set to positions after the Nth byte. If you set a binary file that doesn't exist yet, the file will be created and zero filled to the Nth byte. If you set a binary file that already exists and is smaller then N bytes, it will be extended with zeros to the Nth byte.

The -t switch indicates that bset should treat the values as plain text and copy them directly into the binary file.

Examples

bset &test 1 65

Now &test is filled with 1 byte, and it containes asciivalue 65 wich is "A".

bset &test 5 65
echo -a $bvar(&test,1,$bvar(&test,0)) returns 0 0 0 0 65  

In this case we only set one asciivalue at the 5th place, but the first 4 bytes are filled with zeros.

bset &test 1 65
bset &test 5 66
echo -a $bvar(&test,1,5) returns 65 0 0 0 66

Now we first set 65 at byte one, then set 66 at byte 5. With this second set, bytes 2 to 4 were filled with zeros.

bset -t &test 1 just a test
echo -a $bvar(&test,1,$bvar(&test,0)) returns 106 117 115 116 32 97 32 116 101 115 116

Using the -t switch the text will be converted to asciivalues and set to the binary file. The echo returns the asciivalues of the text "just a test"