cgmark Posted June 6, 2009 Share Posted June 6, 2009 I am trying to read in a file and have autoit write it back out as a hex file. I need the hex file that is written out to exactly match that of how a hex editor like hex workshop would save the file if I loaded it and saved it as hex from that program.I can get autoit to write the file as hex, but it mangles some of the values, so if I had FF 24 times in a row in what hex workshop would output, my text file from autoit has FF 32 times. $FileToOpen = "data.bin"$Filebin = FileOpen ($FileToOpen,4) ; Read file with bin extension into $Filebin$size = FileGetSize($FileToOpen)For $a = 1 to $size $chars = FileRead($Filebin,1) $one = $one & hex( $chars) Next FileClose($Filebin)$Filebin = FileOpen("data.txt", 2)FileWrite($Filebin, $one)FileClose($Filebin)exit Link to comment Share on other sites More sharing options...
oMBRa Posted June 6, 2009 Share Posted June 6, 2009 you need to open the file in binary mode: 16 Link to comment Share on other sites More sharing options...
cgmark Posted June 7, 2009 Author Share Posted June 7, 2009 you need to open the file in binary mode: 16Thanks for the tip !The problem now is that it returns the characters prefixed with 0x, so FF become 0xFFIf I use something like StringTrimLeft to remove the first two characters that gives me the desired result, but it is too slow for large files and I have to read it 1 byte at a time..Any ideas ?Thanks in advance. Link to comment Share on other sites More sharing options...
Inverted Posted June 7, 2009 Share Posted June 7, 2009 $FileToOpen = "data.bin" $Filebin = FileOpen ($FileToOpen,16) ; Read file with bin extension into $Filebin $size = FileGetSize($FileToOpen) $one = "" For $a = 1 to $size $chars = FileRead($Filebin,1) $one = $one & hex( $chars) Next FileClose($Filebin) $Filebin = FileOpen("data.txt", 2) FileWrite($Filebin, $one) FileClose($Filebin) exit This works fine for me For my random example it returns : EBFEEBFE8F98A9A0F0F09098436FFFFF909F0FFF Link to comment Share on other sites More sharing options...
KaFu Posted June 7, 2009 Share Posted June 7, 2009 In my UDF (to be sometimes) MFT-Access I use a function I found somewhere to do the Hex-Notation... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21)HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Zedna Posted June 7, 2009 Share Posted June 7, 2009 Thanks for the tip !The problem now is that it returns the characters prefixed with 0x, so FF become 0xFFIf I use something like StringTrimLeft to remove the first two characters that gives me the desired result, but it is too slow for large files and I have to read it 1 byte at a time..Any ideas ?Thanks in advance.Look at _WinAPI_SetFilePointer() + _WinAPI_ReadFile()http://www.autoitscript.com/forum/index.php?showtopic=76829 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now