Jump to content

FileRead Bug or limitation?


Recommended Posts

Autoit Version 3.2.4.9

I used to be able to read the Windows pidgen.dll file into a variable but now it only seems to read the first 2 characters and that's it. :rolleyes: I guess it has something to do with the blank spaces after the first 2 characters.

I have attached a zip file with a pidgen.dll and a sample filereadbug.au3

filereadbug.au3:

$file = (@ScriptDir&'\PIDGEN.DLL')
$size = FileGetSize($file)
$string = FileRead($file, $size)
msgbox(0, 'File String is', $string)

When you run the filereadbug.au3 all it returns is:

CODE
MZ

But it should return a lot more:

CODE
MZ ÿÿ ¸ @ è º ´ Í!¸LÍ!This program cannot be run in DOS mode.

$ B1ôÜ#_§Ü#_§Ü#_§m, §Ø#_§,P§ß#_§Ü#^§ñ#_§,§Õ#_§,§Ý#_§,§Ý#_§, §Ö#_§,?§Õ#_§,§Ý#_§RichÜ#_§ PE L âA à -

N m) ` ;t j2 p\ Î (X d p P T À ¼ .text >M N `.data | ` R @ À.rsrc P p T @ @.reloc ø \ @ B F\ 2\ "\ \ \ ¼[ °[ Y ¨Y ´Y ÊY äY üY Z Z ,Z <Z LZ \Z lZ Z Z °Z ¾Z ÐZ ÞZ êZ üZ [ ([ B[

and so on... I'm not gonna post the entire file contents... but I am sure you get the picture. ;)

Edit:

What I am trying to accomplish is I want to detect if the string

'#;tHARDWARE'
exists or not. I don't need it to be in the msgbox but I do need to be able to read it from the $string variable. Edited by Proph
Link to comment
Share on other sites

hmmm... well it seems there is still an issue.

even if I use FileOpen($file, 16) it still doesn't work correctly. Once I use the BinaryToString($string) it still only shows "MZ". I was able to do a FileWrite which showed the entire file string... but then when I tried to use a StringInStr to find a string within it... it fails.

CODE
$file = ("PIDGEN.DLL")

$open = FileOpen($file, 16)

$size = FileGetSize ( $file )

$string = FileRead ($open, $size)

FileWrite('Testit.txt', $string)

$string = StringReplace($string, chr(0), "?")

FileWrite('Testitagain.txt', $string)

FileClose($open)

If StringInStr ($string, '#;tHARDWARE') Then msgbox(0, 'Failed', 'Did not find it')

And is there a reason that Testit.txt and Testitagain.txt are so different in this example?

Link to comment
Share on other sites

hmmm... well it seems there is still an issue.

even if I use FileOpen($file, 16) it still doesn't work correctly. Once I use the BinaryToString($string) it still only shows "MZ". I was able to do a FileWrite which showed the entire file string... but then when I tried to use a StringInStr to find a string within it... it fails.

CODE
$file = ("PIDGEN.DLL")

$open = FileOpen($file, 16)

$size = FileGetSize ( $file )

$string = FileRead ($open, $size)

FileWrite('Testit.txt', $string)

$string = StringReplace($string, chr(0), "?")

FileWrite('Testitagain.txt', $string)

FileClose($open)

If StringInStr ($string, '#;tHARDWARE') Then msgbox(0, 'Failed', 'Did not find it')

And is there a reason that Testit.txt and Testitagain.txt are so different in this example?

That's right, when you use version higher than 3.2.2.0 you get this problem. Only the AutoIt team might be able to help you with this.
Link to comment
Share on other sites

And is there a reason that Testit.txt and Testitagain.txt are so different in this example?

If you perform string operation such as StringReplace on a binary string, it becomes string of chars.

Before writing to file, convert it back with Binary().

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

To summarize.

now you need to FileOpen a file you want to read in binary mode FileRead will return a Binary data that can be used with BinaryMid if you want to extract a part of it.

There is no StringReplace/StringInstr equivalent on Binary data.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...