Sign in to follow this  
Followers 0
zeroZshadow

File to hex

9 posts in this topic

is it FINEALY possible to convert a file to hex and revers??

this way i can stream my files over the net.

i started a topic like this before, but then file handeling like this wasn't possible, but is it now??

please reply


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites



doesn't enyone knows the anwser??


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

#include<string.au3>

FileWrite("file2.txt", _StringToHex(FileRead("file.txt", FileGetSize("file.txt"))))
FileWrite("file3.txt", _HexToString(FileRead("file2.txt", FileGetSize("file2.txt"))))

Probably not what you're looking for but...

Edit...Go with Larry's, that works for binary files...

Edited by MSLx Fanboy

Writing AutoIt scripts since
_DateAdd("d", -2, _NowCalcDate())

Share this post


Link to post
Share on other sites

mlx that doesn't work :)

and THANKS LARRY!!!

i'll try to speed it up for ya :evil:


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

Dear Larry, if ur reading this... else ANYBODY OUT THERE~!!

can somebody PLEASE fix the eof bug with files other then text files...

its really anoying.

because i finished my file to ascii and backwards completely, but the problem is that it only takes a little part of the file because it finds a NOT EXISTING EOF in the file...

...i hate that bug...

well here is the code so far, have fun.

#include <file.au3>

Global $asciires = ""
Global $chrres = ""
Global $read = ""

_ascii()
_file()


Func _ascii()
ConsoleWrite("Converting to Ascii"&@LF)
$file = FileOpen("test.jpeg",0)

$l = 1
while 1
    $lineread = FileReadLine ($file,$l)
    if @error = -1 then exitloop
    if @error = 1 then 
        msgbox(0,"Error","File Could not be opened")
        Exit
    EndIf
    $linecharcount = StringLen ($lineread)
    for $ll = 1 to $linecharcount
        $char = StringMid ($lineread,$ll,1)
        $result = Asc($char) 
        $asciires = $asciires& "|" & $result
    Next
    $l = $l + 1
Wend

FileWrite("Test.asc",$asciires)
fileclose($file)
ConsoleWrite("Done converting"&@CRLF)
EndFunc

Func _file()
ConsoleWrite("Converting to File"&@LF)
if NOT _FileReadToArray(@scriptdir&"\Test.asc",$read) then 
    msgbox(0,"ERROR","An error has found while opening the file.  Error: "&@error)
    Exit
EndIf

$asciiread = stringsplit($read[1],"|")

for $l = 1 to $asciiread[0]
    $result = chr($asciiread[$l])
    $chrres = $chrres & $result
Next

filedelete("Test.asc")
FileWrite("result.jpeg",$chrres)
ConsoleWrite("Done converting"&@CRLF)
EndFunc

*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

This is not really a BUG... You are converting a jpeg. Jpegs should be treated as binary files. You need to use AutoIT beta and Larry's Binary UDF. Also, you might want to use Hex instead. Hex representation of characters will always be 2 digits so no delimiters are needed. Your current code would, if it worked on the entire file, create a new file up to 4 times the original size! With hex you would only double the size.

JamesBand

Dear Larry, if ur reading this... else ANYBODY OUT THERE~!!

can somebody PLEASE fix the eof bug with files other then text files...

its really anoying.

because i finished my file to ascii and backwards completely, but the problem is that it only takes a little part of the file because it finds a NOT EXISTING EOF in the file...

...i hate that bug...

well here is the code so far, have fun.

#include <file.au3>

Global $asciires = ""
Global $chrres = ""
Global $read = ""

_ascii()
_file()
Func _ascii()
ConsoleWrite("Converting to Ascii"&@LF)
$file = FileOpen("test.jpeg",0)

$l = 1
while 1
    $lineread = FileReadLine ($file,$l)
    if @error = -1 then exitloop
    if @error = 1 then 
        msgbox(0,"Error","File Could not be opened")
        Exit
    EndIf
    $linecharcount = StringLen ($lineread)
    for $ll = 1 to $linecharcount
        $char = StringMid ($lineread,$ll,1)
        $result = Asc($char) 
        $asciires = $asciires& "|" & $result
    Next
    $l = $l + 1
Wend

FileWrite("Test.asc",$asciires)
fileclose($file)
ConsoleWrite("Done converting"&@CRLF)
EndFunc

Func _file()
ConsoleWrite("Converting to File"&@LF)
if NOT _FileReadToArray(@scriptdir&"\Test.asc",$read) then 
    msgbox(0,"ERROR","An error has found while opening the file.  Error: "&@error)
    Exit
EndIf

$asciiread = stringsplit($read[1],"|")

for $l = 1 to $asciiread[0]
    $result = chr($asciiread[$l])
    $chrres = $chrres & $result
Next

filedelete("Test.asc")
FileWrite("result.jpeg",$chrres)
ConsoleWrite("Done converting"&@CRLF)
EndFunc

<{POST_SNAPBACK}>

Share this post


Link to post
Share on other sites

lol, i think i can better find a way to directly transfer the bineary over the net then :)


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

The best way to use binary files I've found is to convert them to Base64 text and send them as text files, then decode them back to binary on the other side.

AutoIt cannot do the conversion natively. I wrote a Base64 Encoding and Decoding UDF, but the Decoding one doesn't work because it still cannot write char #0 to a file.

So my advice is to use an external decoder.

Here is an easy-to-use open-sourced command-line driven encoder/decoder:

http://www.fourmilab.ch/webtools/base64/

Edited by blindwig

Share this post


Link to post
Share on other sites

THAT WORKS GREAT!!!

man i love you :), wel not really :evil:

it can even be handeled by autoit after encoding :D

man i like you :D:D:D

its ALLOT faster then larry's way


*If u thought life couldn't get worse, u meet me *<guy> What would you give my little sister to unzip ?<friend> 10 bucks<guy> No, i mean like Winzip...

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