Scripts for reading and writing binary files
Alejandro Tejada
capellan2000 at gmail.com
Fri Dec 16 08:03:25 EST 2011
Hi all,
Recently, I had to test and modify some binary files,
so digging in my own stacks, I found these scripts:
[WARNING: The script on step 3, OVERWRITE the
original file. If you do not want this, simply
change the path and/or name of the file]
1) create a field to hold the converted
binary to hexadecimal data.
Set the name of this field to: "tHex"
2) Create a button named "Import" to hold
the following script:
----------------------------------------------------
global tFile
on mouseUp
answer file "select"
if it is not empty then
put "binfile:"&it into tFile
put url tFile into tData
-- convert binary data to Hexadecimal
repeat for each char n in tData
put chartonum(n) into nft
put baseconvert(nft,10,16) into kjh
if the number of chars of kjh < 2 then put "0" before kjh
put kjh & space after cdf
end repeat
put cdf into fld "tHex"
end mouseUp
-----------------------------------------------------
Now, you have the field "tHex" with Hexadecimal numbers,
like these:
46 57 53 03 4F 00 00 00 78 00 05 5F 00 00 0F A0
00 00 0C 01 00 43 02 FF FF FF BF 00 23 00 00 00
01 00 70 FB 49 97 0D 0C 7D 50 00 01 14 00 00 00
00 01 25 C9 92 0D 21 ED 48 87 65 30 3B 6D E1 D8
B4 00 00 86 06 06 01 00 01 00 00 40 00 00 00
After you make all the modifications to
the file (using hexadecimal), save it
back as a binary file:
3) Create a button named "Export"
and paste this script:
------------------------------------------------------
global tFile
on mouseUp
put fld "tHex" into tData
repeat for each word n in tData
put numtochar(baseconvert(n,16,10)) after tBinary
end repeat
put tBinary into url tFile
end mouseUp
------------------------------------------------------
Thanks in advance for your
opinions and comments!
Al
--
View this message in context: http://runtime-revolution.278305.n4.nabble.com/Scripts-for-reading-and-writing-binary-files-tp4204548p4204548.html
Sent from the Revolution - User mailing list archive at Nabble.com.
More information about the use-livecode
mailing list