Jump to content

FileRead() not stopping at EOF


Recommended Posts

I don't know if this is because of my computer or a bug?

I use the sample from the help file and the script keep reading blank eventhough it set @error to -1.

$file = FileOpen("test.txt", 0)

; Check if file opened for reading OK
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf

; Read in 1 character at a time until the EOF is reached
While 1
    $chars = FileRead($file, 1)
    If @error = -1 Then ExitLoop
    MsgBox(0, "Char read:", $chars)
Wend

FileClose($file)
Link to comment
Share on other sites

It works fine here. What is in your "test.txt" file?

Hurm, strange. I just put a random word file.

I tested it with random short, long or even single words.

Nothing specific in the txt file, just want to know if it's a bug or just my computer.

Recently, _StringEncrypt() also doesn't work fine for me.

I don't know why is this happening to me.

Link to comment
Share on other sites

Hurm, strange. I just put a random word file.

I tested it with random short, long or even single words.

Nothing specific in the txt file, just want to know if it's a bug or just my computer.

You haven't provided a way to duplicate your symptoms.

Recently, _StringEncrypt() also doesn't work fine for me.

The _StringEncrypt() function may have a sensitivity to certain code pages being used. Do you have a foreign language pack loaded?

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

You haven't provided a way to duplicate your symptoms.

The _StringEncrypt() function may have a sensitivity to certain code pages being used. Do you have a foreign language pack loaded?

:D

yup..since i play around autoit with japs windows xp, i think this could be the reason.

Other than that, when I use FileWrite() function, I always got unrecognized character.

Anyway, I don't know. Maybe if I had english ver of windows xp laying around, I could test

on it.

By the way, you guys are awesome! thanks for the help.

Link to comment
Share on other sites

whatever Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • 2 weeks later...

You haven't provided a way to duplicate your symptoms.

The _StringEncrypt() function may have a sensitivity to certain code pages being used. Do you have a foreign language pack loaded?

:D

I thought I've solved my problem. but still not. So, I come back.

How do you unload the language pack?

Well this the code I was playing around.

I thought by using crypt.au3, I would have solved my problem, but still it didn't decrypt properly.

The problem is that when I try with "ConsoleWrite($vall2)" , it did decrypt properly.

But, when i try using with "ConsoleWrite($vall2 & @CRLF & $vall2)" or "msgbox(0, "", $vall2)

it gives me the weird number, although the variable still the same.

#include <Crypt.au3>

Global $myDll = @ScriptDir & "\encryptdata.dll"
Global $IniSection = Encrypt("iniSectionName")
Global $SupEncKey = "aBcDeFg"
Global $Mac = StringUpper (StringReplace (_GetMAC(),":","") & StringRight ( Hex(@YEAR),1))


IniWrite ($myDLL,$IniSection,Encrypt("GeneratedMac"),Encrypt($Mac))

$vall2 = Decrypt(IniRead ($myDll,$IniSection,Encrypt("GeneratedMac"),"Not Found"))
ConsoleWrite($vall2)
ConsoleWrite($vall2 & @CRLF & $vall2)
Msgbox(0,"",$vall2)

Func Encrypt($string)
        _Crypt_Startup()
        Local $hKey=_Crypt_DeriveKey("aBcDeFg", $CALG_RC4)
        Return _Crypt_EncryptData($string, $SupEncKey, $CALG_USERKEY)
        _Crypt_DestroyKey($hKey)
        _Crypt_Shutdown()
EndFunc

Func Decrypt($string)
        _Crypt_Startup()
        Local $hKey=_Crypt_DeriveKey("aBcDeFg", $CALG_RC4)
        Return _Crypt_DecryptData($string, $SupEncKey, $CALG_USERKEY)
        _Crypt_DestroyKey($hKey)
        _Crypt_Shutdown()
    EndFunc

Func _GetMAC($getmacindex = 1);thanks to ChrisL for this function
    $ipHandle = Run(@ComSpec & ' /c ipconfig /all', '', @SW_HIDE, 2)
    $read = ""
    Do
        $read &= StdoutRead($ipHandle)
    Until @error

    $read = StringStripWS($read,7)

    $macdashed = StringRegExp( $read , '([0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2}-[0-9A-F]{2})', 3)
    If Not IsArray($macdashed) Then Return 0
    If $getmacindex <  1 Then Return 0
    If $getmacindex > UBound($macdashed) Or $getmacindex = -1 Then $getmacindex = UBound($macdashed)
    $macnosemicolon = StringReplace($macdashed[$getmacindex - 1], '-', ':', 0)
    Return $macnosemicolon
EndFunc;==>_GetMAC
Edited by mrmacadamia
Link to comment
Share on other sites

Hmm...interesting result I get when I change my system language to "English". but still doesn't decrypt properly which is giving me different result using the code above.

I got different decrypt result which is much shorter(?) i guess.

Opsssss...I'm sorry. I think I've found the solution.

I should use "BinaryToString($vall2)".

But anyway, I'm still wondering why if I use "ConsoleWrite($vall2 & @CRLF & $vall2)" gives me different value than "ConsoleWrite($vall2)"

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...