WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Binary Functions

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

BinaryReplace With NULL Characters

 Keywords: BinaryReplace NULL 00 BinaryPeekHex BinaryPokeHex ChrStringToHex

Question:

I've got a binary buffer that contains a lot of NULL characters. Using BinaryReplace, I can make them human-readable, since the search string allows "" to find NULL characters (say I replace them with "[NULL]").

Lots of other stuff happens -- the buffer gets placed in a file, the user edits it, and it gets read back in to a buffer.

How do I get "[NULL]" back to a NULL character? Using "" as the replacement string seems to be deleting the search string.

Answer:

Yes BinaryReplace is not designed to handle NULL charaters. However here is a cute trick using BinaryPeekHex:
;Detlev Dalitz
;DD.20100715.2255.CEST
intBBSize = 100
hdlBB = BinaryAlloc (intBBsize)
intBytesWritten = BinaryPokeStr (hdlBB, 0, StrFill ("[NULL] ABC", intBBSize))
strHex = BinaryPeekHex (hdlBB, 0, BinaryEodGet (hdlBB))
strHex = StrReplace (strHex, ChrStringToHex ("[NULL]"), "00")
BinaryEodSet (hdlBB, BinaryPokeHex (hdlBB, 0, strHex))
hdlBB = BinaryFree (hdlBB)

Or the ever tricky one-liner.....

;Detlev Dalitz
;DD.20100715.2255.CEST
BinaryEodSet (hdlBB, BinaryPokeHex (hdlBB, 0, StrReplace (BinaryPeekHex (hdlBB, 0, BinaryEodGet (hdlBB)), ChrStringToHex ("[NULL]"), "00")))

Article ID:   W17679
Filename:   BinaryReplace With NULL Characters.txt
File Created: 2010:07:16:11:21:08
Last Updated: 2010:07:16:11:21:08