Jump to content
Sign in to follow this  
Guest tanewha

Write null (00H) to file

Recommended Posts

Guest tanewha

Can anyone tell me how I can use AutoIt 3 to write a null (00H) to file? Any nulls in the "line" string of the WriteFile command seem to be ignored.

Thanks in anticipation.

:ph34r:

Share this post


Link to post
Share on other sites
Valik

You can't read or write NULL characters. If reading, you can read up to the first NULL, but not beyond (At least not without reading character by character). It's not possible to write NULL characters.

Share this post


Link to post
Share on other sites
ezzetabi

About writing there is a workaround using XVI:

Simply write in the file a character you can write and that is unique and after, using this UDF, you can change it in NULLs.

In the example it creates a small file where I want to write NULLs, the nulls value are wrote as pipes and changed.

Here the UDF:

FileWrite("Test.txt", "Some text ||, some other text");It is just a test.
;The pipes must become 00

_ReplaceWith00h("Test.txt", "7c");7c is the HEX value of the pipe


Func _ReplaceWith00h($FILENAME, $ORIG);$Orig must be in the HEX value to change in 00
   If Not FileExists($FILENAME) Then Return -1;Returns -1 if the file do not exists.
   $FILENAME = FileGetLongName($FILENAME)

   
  ;Download http://www.handshake.de/user/chmaas/delphi/download/xvi32.zip and unpack
  ;XVI32.exe in c:\XVI32 before compiling.

   DirCreate(@ScriptDir & "\tmp")   
   FileInstall("C:\XVI32\XVI32.exe", @ScriptDir & "\tmp\")
   
   FileWrite(@ScriptDir & "\tmp\x.xsc", "ADR 0" & @CRLF & "REPLACEALL " & $ORIG & " BY 00")
  ;It creates the istructions file for XVI
   
   RunWait(@ScriptDir & '\tmp\xvi32.exe "' & $FILENAME & '" /s=x.xsc', _
         @ScriptDir & "\tmp", @SW_HIDE)
   DirRemove(@ScriptDir & "\tmp", 1)
   Return 0
EndFunc  ;==>_ReplaceWith00h
Edited by ezzetabi

Share this post


Link to post
Share on other sites
ezzetabi

Otherwise you can just add the 00 chars using XVI if you know the exatly place wher to put them.

Share this post


Link to post
Share on other sites
Guest tanewha

Thanks ezzetabi, that looks like it should do the trick.

Sorry it took so long to acknowlrdge your reply, I was having trouble with my log-on.

I haven't tried your solution yet but I'm just about to .... so fingers crossed.

Thanks again

Share this post


Link to post
Share on other sites
seanhart

I also had a similar issue, needed to write NULL data to a file from within AutoIt, and ended up creating a little external utility to do this. Thought I would share this with the group for anyone who is interested.

The tiny utility (18K) is called "BINWRITE" and is designed to write binary data to a file (provided in either binary, hex, or string format).

E.g.:

binwrite.exe file.bin hex 00

binwrite.exe file.bin hex ff1a3f002c

binwrite.exe file.bin bin 10010110

binwrite.exe file.bin asc "This is some normal text."

Obviously this can be called with a RunWait command in AutoIt.

Hope someone else finds this useful.

Sean

binwrite.zip

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.