Extracts a string from a binary buffer.
BinaryPeekStr( handle, offset, maxsize )
(i) handle: handle of buffer.
(i) offset: zero-based offset in the buffer the string starts at.
(i) maxsize: maximum number of bytes in string.
(s) string: starting at offset location in binary buffer. String consists of all non-zero bytes up to the first zero byte or maxsize number of bytes.
This function is used to extract string data from a binary buffer. The desired starting offset and a maxsize are passed to the function. The function returns a string of bytes, starting at the specified offset, and continuing until either a zero byte is found (which terminates the string) or the maxsize number of bytes have been copied into the return string.
; This example searches the Config.sys for the first ; occurrence of the string HIMEM. It then extracts ; the line containing the string and prints it out. ; fs = FileSize( "C:\CONFIG.SYS" ) binbuf = BinaryAlloc( fs ) BinaryRead( binbuf, "C:\CONFIG.SYS" ) ; ; Search for first occurrence of HIMEM. himem = BinaryIndex( binbuf, 0, "HIMEM", @FWDSCAN) ; Single out beginning of line which contains HIMEM string, ; skipping over the @crlf. linebegin = BinaryIndex( binbuf, himem, @CRLF, @BACKSCAN) + 2 ; ; Search for the end of the line which contains the HIMEM string. lineend = BinaryIndex( binbuf, himem, @CRLF, @FWDSCAN) linelen = lineend-linebegin+1 ; ; Extract the line with HIMEM string. linedata=BinaryPeekStr(binbuf, linebegin, linelen) binbuf=BinaryFree(binbuf) Message("Himem.sys line in config.sys reads", linedata)
Binary Operations, BinaryCopy, BinaryPeek, BinaryPeekStrW, BinaryPoke, BinaryPokeStr