Jump to content
Sign in to follow this  
zeroZshadow

FILE TO HEX

Recommended Posts

Hi guys, i'm making a function to convert a file to hex so you can use the au3xtra.dll to send it. (sned the hex and convert it to a file again)

Opt("TrayIconDebug",1)
_Transfer()
Global $trans[6000000]
Func _Transfer()
    $file = FileOpenDialog("Send File","","Zip files (*.zip)")
    FileCopy($file,@scriptdir&"\file.txt")
    $getfile = FileOpen(@ScriptDir&"\file.txt",0)
    MsgBox(0,"test",$getfile)
    While Not @error = -1
    $line = 1
    $trans[$line] = FileReadLine($getfile,$line)
    MsgBox(0,"test",$trans[$line])
    $line = $line + 1
    Wend
    $type = "Zip"
EndFunc

but the damn thing won't work

PLEASS help me :lmao:


*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

I can see the error now, you too? :lmao:

Opt ("TrayIconDebug", 1)
_Transfer()
Global $trans[6000000]
Func _Transfer()
    $file = FileOpenDialog("Send File", "", "Zip files (*.zip)")
    FileCopy($file, @ScriptDir & "\file.txt")
    $getfile = FileOpen(@ScriptDir & "\file.txt", 0)
    MsgBox(0, "test", $getfile)
    While Not @error = -1
        $line = 1
        $trans[$line] = FileReadLine($getfile, $line)
        MsgBox(0, "test", $trans[$line])
        $line = $line + 1
    WEnd
    $type = "Zip"
EndFunc ;==>_Transfer

The $line=1 has to be outside the while-loop or else it will read line 1 over and over again.

BTW: I suggest taking FileRead for binary files instead of FileReadLine. Because you don't know how long "lines" will get in binary files.

Edited by ZeDMIN

Share this post


Link to post
Share on other sites

how do you get how many bytes are in a file?


[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Share this post


Link to post
Share on other sites

oke, i really changed the script now, but it still has problems with counting lines.

#include <string.au3>
#include <file.au3>
_filetohex()
Func _filetohex()
    $getfile = FileOpenDialog("Open","","All files (*.*)")
    $string = stringsplit ( $getfile, "." )
    $file = $string[1] & ".txt"
    filecopy ( $getfile, $file )
    Global $countline = _FileCountLines($file)
    if $countline = 0 Then
        MsgBox(0,"Error","File could not be read")
    Else
        MsgBox(0,"Error",$countline)
            Global $lineread[$countline+1]
            Global  $linehex[$countline+1]
            For $line = 1 to $countline
            $lineread[$line] = Filereadline($getfile,$line)
            $linehex[$line] = _StringToHex($lineread[$line])
            ConsoleWrite($linehex[$line]&@lf)
            Next
        EndIf
    FileDelete($file)
EndFunc

YOU NEED SCITE FOR THIS ONE, OR A THING THAT READS CONSOLEWRITE

o ya.......thanks for helping

EDIT:

text based files are going fine, but need to have it work with zip and exe and .......

Edited by zeroZshadow

*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

_FileToHexFile(FileOpenDialog("Open","","All files (*.*)"))
_HexFileToFile(FileOpenDialog("Open","","All files (*.*)"))

Func _FileToHexFile($getfile)
    Local $file = $getfile & " - in hex.txt", _
    $null = FileCopy ( $getfile, $file, 1), _
    $file_content = FileRead ( $file, FileGetSize($file)), _
    $file_handle = FileOpen ( $file , 2)    
    FileWrite( $file_handle, _StringToHex( $file_content))
    FileClose( $file_handle)
EndFunc


Func _HexFileToFile($getfile)
    Local $file = StringReplace($getfile , " - in hex.txt" , ""), _
    $null = FileCopy ( $getfile, $file, 1), _
    $file_content = FileRead ( $file, FileGetSize($file)), _
    $file_handle = FileOpen ( $file , 2)    
    FileWrite( $file_handle, _HexToString( $file_content))
    FileClose( $file_handle)
EndFunc





Func _HexToString($strHex)
    Local $strChar, $iOne, $aryHex = StringSplit($strHex, "")
    For $i = 1 To $aryHex[0]
        $iOne = $aryHex[$i]
        $i = $i + 1
        $strChar = $strChar & Chr(Dec($iOne & $aryHex[$i]))
    Next
    If $strChar = "" Then
        SetError(1)
        Return -1
    Else
        Return $strChar
    EndIf
EndFunc

Func _StringToHex($strChar)
    Local $strHex, $aryChar = StringSplit($strChar, "")
    For $i = 1 To $aryChar[0]
        $strHex = $strHex & Hex(Asc($aryChar[$i]), 2)
    Next
    If $strHex = "" Then
        SetError(1)
        Return -1
    Else
        Return $strHex
    EndIf
EndFunc

EDIT:

Or Should i say

5F46696C65546F48657846696C652846696C654F70656E4469616C6F6728224F70656E222C22222C22416C6C2066696C6573

20282A2E2A292229290D0A5F48657846696C65546F46696C652846696C654F70656E4469616C6F6728224F70656E222C2222

2C22416C6C2066696C657320282A2E2A292229290D0A0D0A46756E63205F46696C65546F48657846696C6528246765746669

6C65290D0A094C6F63616C202466696C65203D202467657466696C6520262022202D20696E206865782E747874222C205F0D

0A09246E756C6C203D2046696C65436F70792028202467657466696C652C202466696C652C2031292C205F0D0A092466696C

655F636F6E74656E74203D2046696C65526561642028202466696C652C2046696C6547657453697A65282466696C6529292C

205F0D0A092466696C655F68616E646C65203D2046696C654F70656E2028202466696C65202C203229090D0A0946696C6557

7269746528202466696C655F68616E646C652C205F537472696E67546F48657828202466696C655F636F6E74656E7429290D

0A0946696C65436C6F736528202466696C655F68616E646C65290D0A456E6446756E630D0A0D0A0D0A46756E63205F486578

46696C65546F46696C65282467657466696C65290D0A094C6F63616C202466696C65203D20537472696E675265706C616365

282467657466696C65202C2022202D20696E206865782E74787422202C202222292C205F0D0A09246E756C6C203D2046696C

65436F70792028202467657466696C652C202466696C652C2031292C205F0D0A092466696C655F636F6E74656E74203D2046

696C65526561642028202466696C652C2046696C6547657453697A65282466696C6529292C205F0D0A092466696C655F6861

6E646C65203D2046696C654F70656E2028202466696C65202C203229090D0A0946696C65577269746528202466696C655F68

616E646C652C205F486578546F537472696E6728202466696C655F636F6E74656E7429290D0A0946696C65436C6F73652820

2466696C655F68616E646C65290D0A456E6446756E630D0A0D0A0D0A0D0A0D0A0D0A46756E63205F486578546F537472696E

672824737472486578290D0A094C6F63616C2024737472436861722C2024694F6E652C2024617279486578203D2053747269

6E6753706C697428247374724865782C202222290D0A09466F72202469203D203120546F20246172794865785B305D0D0A09

0924694F6E65203D20246172794865785B24695D0D0A09092469203D202469202B20310D0A09092473747243686172203D20

2473747243686172202620436872284465632824694F6E65202620246172794865785B24695D29290D0A094E6578740D0A09

4966202473747243686172203D202222205468656E0D0A09095365744572726F722831290D0A090952657475726E202D310D

0A09456C73650D0A090952657475726E2024737472436861720D0A09456E6449660D0A456E6446756E630D0A0D0A46756E63

205F537472696E67546F486578282473747243686172290D0A094C6F63616C20247374724865782C20246172794368617220

3D20537472696E6753706C69742824737472436861722C202222290D0A09466F72202469203D203120546F20246172794368

61725B305D0D0A090924737472486578203D2024737472486578202620486578284173632824617279436861725B24695D29

2C2032290D0A094E6578740D0A0949662024737472486578203D202222205468656E0D0A09095365744572726F722831290D

0A090952657475726E202D310D0A09456C73650D0A090952657475726E20247374724865780D0A09456E6449660D0A456E64

46756E63

:lmao:

Edited by UP NORTH

Share this post


Link to post
Share on other sites

@UP NORTH

doesn't work well. if i try to convert a wma it returns just a little piece of the text. this also happens with other, NOT TEXT BASED, files. and thats what i just need, the hex code is needed to send a file to another pc, that will deconvert it again to use it


*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

common guys, is there ANY way to read a WHOLE file in a array that i can loop to lines of hex??


*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

Have you tried:

_FileReadToArray($sFilePath, ByRef $aArray)

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.

Share this post


Link to post
Share on other sites

nop doesn't work it'll stop ate the ☻ thingy.

but the strange thing is that the wininfo tool can see the WHOLE text.

then why doesn't the damn filetoarray and others do that???

i think where gonna need to ask this to jon or another smart guy :lmao:

(i ment that possitive)


*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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...