- Some ideas are:
- Loop through each byte using NumGet, use NumPut on any null bytes.
- Binary data to hex string, edit hex string (use RegEx to put a separator character between every pair of hex digits, replace any 00s, remove the separator character), hex string to binary data.
- Write a machine code function to search for null characters and replace them using NumPut.
InBuf function currently 32-bit only (machine code binary buffer searching) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28393
- Write a machine code function to replace null characters with a specified character.
- (Then, for all of the approaches, to finish, use StrGet to retrieve an ANSI string.)
- Here's an example to loop through each byte using NumGet, and use NumPut on any null bytes.
Code: Select all
q:: ;read binary file, replace null bytes with a character
vChar := "@"
vPath := A_AhkPath
;AHK v1
;FileGetSize, vSize, % vPath
;FileRead, vData, % "*c " vPath
;AHK v1/v2 two-way compatible
oFile := FileOpen(vPath, "r")
oFile.Pos := 0
oFile.RawRead(vData, vSize := oFile.Length)
oFile.Close()
vOrd := Ord(vChar)
Loop, % vSize
if !NumGet(&vData, A_Index-1, "UChar")
NumPut(vOrd, &vData, A_Index-1, "UChar")
Clipboard := StrGet(&vData, vSize, "CP0")
MsgBox, % "done"
return