Difference between revisions of "Bset"
m |
m |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | The bset command is used to set a [[Binary Files|binary file]]. | + | The bset command is used to set a [[:Category:Binary Files|binary file]]. |
<nowiki>bset [-t] <&binvar> <N> <asciivalue> [asciivalue ... asciivalue]</nowiki> | <nowiki>bset [-t] <&binvar> <N> <asciivalue> [asciivalue ... asciivalue]</nowiki> | ||
− | This sets the | + | This sets the ''N''th byte of the binary file ''&binvar'' to the [[$asc|asciivalues]]. All asciivalues after are set to positions after the ''N''th byte. |
− | If you set a binary file that doesn't exist yet, the file will be created and zero filled to the | + | If you set a binary file that doesn't exist yet, the file will be created and zero filled to the ''N''th byte. If you set a binary file that already exists and is smaller then ''N'' bytes, it will be extended with zeros to the ''N''th byte. |
− | The -t switch indicates that bset should treat the values as plain text and copy them directly into the binary file. | + | The ''-t'' switch indicates that bset should treat the values as plain text and copy them directly into the binary file. |
== Examples == | == Examples == | ||
Line 10: | Line 10: | ||
Now &test is filled with 1 byte, and it containes asciivalue 65 wich is "A". | Now &test is filled with 1 byte, and it containes asciivalue 65 wich is "A". | ||
bset &test 5 65 | 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. | 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 1 65 | ||
bset &test 5 66 | bset &test 5 66 | ||
− | echo -a | + | 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. | + | 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 | bset -t &test 1 just a test | ||
− | echo -a $bvar(&test,1,$bvar(&test,0)) | + | 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 | + | 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" |
[[Category:Binary Files]] | [[Category:Binary Files]] | ||
[[Category:Commands]] | [[Category:Commands]] |
Latest revision as of 19:41, 13 October 2006
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"