Ok Mark, I've had a go at your UDF's ... here's my very crude version of strings ... $filename points a binary file (i used an old version of kix32.exe)
$stringsize is the minimum size requirement for a displayed string (all other strings ignored).
here's the code:
break on
$filename = "c:\kix32\kix32.exe" ; <--- set this to a binary file
$stringsize = 5 ; <--- display strings at least this size
$file = oFileOpen($filename)
$s=""
$c = asc(oFileRead($file,1)) ; read first byte
while not @ERROR
; asc 0-9 A-Z a-z
if ($c > 47 and $c < 58) or ($c > 64 and $c < 91) or ($c > 96 and $c < 123)
$s=$s+chr($c)
else
if len($s) >= $stringsize
?$s
endif
$s=""
endif
$c = asc(oFileRead($file,1))
loop
$=oFileClose($file)
exit 1
I also slightly modified your oFileRead() function to return 0 (zero) and set the value of @ERROR to -1 (on EOF), just like the builtin file functions (just a thought), here's that:
FUNCTION oFileRead($oFile, OPTIONAL $intBytes)
; $oFile is a file object opened for reading as a text stream.
; $intBytes is how many bytes to read from the file.
; Returns the specified number of bytes from a file (1 byte default)
; or "** EOF **" for end-of-file or "** ERROR **" for other error.
$oFileRead = "** ERR **"
$intBytes = 0 + $intBytes
IF VarType($oFile) <> 9 RETURN ENDIF
IF $intBytes < 1 $intBytes = 1 ENDIF
IF NOT $oFile.AtEndOfStream
$oFileRead = $oFile.Read($intBytes)
IF @ERROR
$oFileRead = 0
EXIT @ERROR
ENDIF
ELSE
EXIT -1
ENDIF
ENDFUNCTION
One observation I have so far is that using UDF's to stream over a binary file introduces a lot of overhead and slows down the script considerably, as an example, replace this line in the script:
$c = asc(oFileRead($file,1))
with this:
$c = asc($file.read(1))
you should see a noticable difference. not too sure if it's the UDF overhead, or the UDF parm checking that's done ... your call in terms of optimizing ...
Thoughts ?
-Shawn