@BMODVAL — Modifies a value in
a binary buffer.
Syntax:
%@BMODVAL[handle,offset,wordsize,operation,value,fmt,flags]
| handle | a handle returned by @BALLOC |
| offset | the starting offset, in bytes, from the start of the buffer |
| wordssize | the size of the value to return: 1 a byte, 2 a word, 4 a doubleword, 8 a 64-bit integer |
| operation | one of: |
AND or &: logical-ANDs the value in the buffer with value | |
OR or |: logical-ORs the value in the buffer with value | |
XOR: logical-XORs the value in the buffer with value | |
ADD or +: adds value to the value in the buffer | |
SUBTRACT or -: subtracts value from the value in the buffer | |
SHL or <<: shifts the value in the buffer left value bits | |
SHR or >>: shifts the value in the buffer right value bits | |
| fmt | the format in which to return the value |
| flags | bitmapped: |
1: big-endian |
@BMODVAL reads a value from a binary buffer, performs the requested
operation on it, writes the new value back to the binary buffer, and returns the
new value in the specified format.
If the value begins with either a +
or - sign, the value is treated as a
signed value; otherwise it’s unsigned. Either way, the value
must fall within the range specified by the
wordsize parameter.
The optional fmt parameter specifies the format for the returned value. If you
are ignoring @BMODVAL’s return value, then its format doesn’t matter.
0 | unsigned decimal (the default) |
1 | signed decimal |
2 | hexadecimal with a leading 0x |
3 | hexadecimal without any prefix |
4 | octal |
Operation-specific notes:
ADD and SUBTRACT do not check for overflow/underflow. If the
resulting value does not fit in the specified wordsize,
@BMODVAL’s behavior is undefined. SHL and SHR, value is the
number of bits to shift. It must not be greater than 8 * wordsize,
or you’ll get an error message.