Sign in to follow this  
Followers 0
kcd-clan

loading a big file ~40mb from chr to hex ? read plz

29 posts in this topic

#1 ·  Posted (edited)

I need to do this fast.

So fair iv not even got to finish it cause it takes to long.

I know il find a way soon enuff.

Heres my code.

O yea its not 40 mb its 4 mb but it still takes while.

$i=0
    $files = FileOpen($location&$file, 0)
; Check if file opened for reading OK
If $files = -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
    $i=$i+1
    ToolTip("Bytes: "&$i)
    $chars = FileRead($files,1)
    If @error = -1 Then ExitLoop
    $hex=Asc ( $chars )
    If $out<>"" Then
    $out=$out&" "&$hex
    EndIf
    If $out="" Then
    $out=$hex
EndIf
Wend
MsgBox(0,0,$out)
FileClose($files)
Edited by kcd-clan

Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

FileRead the whole File

StringSplit with a '' parameter in delimiters parameter

Hex it, and store it as a string with &=

Edit: This will take long, no matter what. Only i think my way is the fastest way of doing this..

Edited by Manadar

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Try opening it in raw mode (4) and then doing FileRead() with no extra paramters. This will load the whole file in one command which is faster than byte by byte

Edit: curses...my post was foiled agian :D

Edited by evilertoaster

Share this post


Link to post
Share on other sites

That is when one is unabled or too lazy too open the helpfile to look up FileOpen.

When using the mode=4 (Raw Read) the filename is defined as "\\.\A:" for reading sector on a floppy disk the count must be a multiple of sector size(512).

I still don't know what it is though.. :D

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

You need the beta verion of autoit i think for raw mode. When you have it, use file open with a 4 as the second parameter.

Edit: also what raw mode does is read direct hex from the file so you won't have to manually convert it later

Edited by evilertoaster

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

And how can i split sring if i dono where im splitting it cep that its ever chr

In beta this is done by:

Dim $result

$File = FileRead("C:\File.ext")
$SplitFile = StringSplit($File,'')

For $x = 0 to $SplitFile[0]
      $result &= Hex($SplitFile[$x])
Next

Edit: Nice thing to know eviltoaster! Thanks.

Edited by Manadar

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

$path=FileOpenDialog("Choose a file",@ScriptDir,"All (*.*)")
$File=FileOpen($path,4)
$read=FileRead($file,FileGetSize($path))
;MsgBox(0,"",String($read))
MsgBox(0,"",StringReplace(String($read),"0x",""))

This will load a whole file and show it's hex string in a message box. Uncomment the first msgbox if you want the "0x" hex identifier to be there also

Edit: BTW there's no error checking on this so dont do anything foolish :D

Edited by evilertoaster

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I dono about you but that dont work for me.

It just returnes the value of 0

I need ALL the hex code.

And it shows the output of hex not the hex codes....

Edited by kcd-clan

Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

are you using the latest beta?

Share this post


Link to post
Share on other sites

does that mean you didn't ahve beta before and now you do and it's showing you the 'garbled' text now?

Share this post


Link to post
Share on other sites

Just for clarification-

Is it showing you garbled ASCI test or a long hex string?

Share this post


Link to post
Share on other sites

.......

I said it show what it would show if you open in notepad.

Cause im trying ith a normal text file.

It wont even work on a program type file with hex of 00-20 or whatever.


Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

I may be misunderstanding what you want.

This will read the raw Hex data from a file (for instance if you opened it in a hex editor) if you use this on a .txt file i dont see what the point is but it should still work (i've now tried this on 3 computers).

Is this not want you want?

Share this post


Link to post
Share on other sites

no

I am geting alot of problems with this il probly ahve to write it all and define all hex values.

When im reading hex in autoit it comes to a number when hex go from 0-f and autoit dose 0-9 because a declerations

If i have to i can get it cause i have the way to read it and know the number on autoit of the hex code.


Visit mEMy programs made.Iul - IulG-V Console - G-V Console_RandomLetter - _RandomLetter()Saftey Kill - Saftey Killcolorzone() = colorzone()

Share this post


Link to post
Share on other sites

When im reading hex in autoit it comes to a number when hex go from 0-f and autoit dose 0-9 because a declerations

If i have to i can get it cause i have the way to read it and know the number on autoit of the hex code.

I can't really tell what you're talking about...anyone want to translate?

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  
Followers 0