blitzkrg Posted January 30, 2006 Posted January 30, 2006 Need some help understanding hex conversions. I have a binary file that i'm trying to read (and eventually write to) i am using _hextostring to convert some of the *text* stuff and it's working fine. i throw in some hex code and it spits out the ascii text string.. which is great but when it comes to the numbers i'm having a problem 76AB4D0000000000 is hex code, it's supposed to be a filesize (audio file) but i'm not sure how to convert it to mb/kb file size AD000000 is hex code, it's supposed to be the "play time" of an audio file thanks
JSThePatriot Posted January 30, 2006 Posted January 30, 2006 That hex doesnt even return numbers. You sure that is the proper hex for what you are looking for? JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
blitzkrg Posted January 30, 2006 Author Posted January 30, 2006 JSThePatriot said: That hex doesnt even return numbers. You sure that is the proper hex for what you are looking for?JSyeah i know, that's why i asked for help umm.. the file is a playlist file, it's a binary file. when i look at it with hex editor, i can see the ascii text.i found a blog that had the "breakdown" of the formatfor examplethe 1st (4 bytes) is an init sequencethe 2nd (2 bytes) is the track numberthe 3rd (8 bytes) is the song namethe 4th (8 bytes) is the file sizenone of that is accurate, just as an example of how it had it broke downand when i followed the file i found when he said the <artist> was here, it wasthe <song title> was here. it wasso like i said the ascii stuff all worked out fine.its the numbers (file size, song legnth) all that jazz was just little boxes in my hex editor.so i'm thinking i have convert from binary some how?i'm just not sure what to do with them.
blitzkrg Posted January 30, 2006 Author Posted January 30, 2006 Header 01 00 00 00 00 00 Init Sequence 00 00 00 00 Nr of Entries For each Entry: 02 00 Init entry 00 00 00 00 Entrynumber /position 00 00 00 00 00 00 00 00 Filesize 00 00 00 00 Playtime 00 00 00 00 Size of title ? ? ? ? ? ? ? ? Title 00 00 00 00 Size of artist ? ? ? ? ? ? ? ? Artist 00 00 00 00 Size of album ? ? ? ? ? ? ? ? Album 00 00 00 00 Size of genre ? ? ? ? ? ? ? ? Genre 00 00 00 00 Size of absolute file path ? ? ? ? ? ? ? ? Absolute file path 00 Track nr 00 Closing byte
blitzkrg Posted January 30, 2006 Author Posted January 30, 2006 (edited) that's how he broke down the file. so from the start of the file if i count allt he way down to "title" it's in the right spot the ?'s just mean variable legnth because the title could be anything so if i punch in the hex codes for "title" from my hex editor and i use _hextostring, it returns the title of the song.. and that's what it should do but when i get to things like file size or playtime or size of artist.. all that jaz. it's just a bunch of boxes. i assume _hextostring isnt going to work since the hex codes are for numbers? i dunno.. numbers are ascii strings to.. soooo i'm confused edit: if it helps i've uploaded a sample playlist file. rename it to <whatever>.spl1.txt Edited January 30, 2006 by blitzkrg
JSThePatriot Posted January 30, 2006 Posted January 30, 2006 Its possible maybe that the HEX is encoded at that point for some weird reason. When I run the code and output the result to a message box, it shows just some odd characters (not numbers). Hrm... I am not sure about your issue... is it possible that this file just doesnt have the time or something along those lines? Does this hold true on all the files you try? I wish I could help more... JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
blitzkrg Posted January 31, 2006 Author Posted January 31, 2006 JSThePatriot said: Its possible maybe that the HEX is encoded at that point for some weird reason. When I run the code and output the result to a message box, it shows just some odd characters (not numbers).Hrm... I am not sure about your issue... is it possible that this file just doesnt have the time or something along those lines? Does this hold true on all the files you try?I wish I could help more...JSI'm told it's little endian format?but i'm not sure what to do with that info
Helge Posted January 31, 2006 Posted January 31, 2006 Maybe you want to make it yourself, but you could anyway check outLazyCat's UDFs http://www.autoitscript.com/fileman/users/Lazycat/udfs.html. Scroll down a bit and you'll see.
w0uter Posted January 31, 2006 Posted January 31, 2006 (edited) endian is the way it is written big endian: 00112233 litle endian: 33221100 both are 0x00112233 pff just saw the attached file. that aint really hard Edited January 31, 2006 by w0uter My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
JSThePatriot Posted January 31, 2006 Posted January 31, 2006 Maybe the following links will help. I didnt have the time to read but the first part of them, and they both looked helpful.Link 1Link 2Hope this helps,JS AutoIt Links File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out. ComputerGetInfo UDF's Updated! 11-23-2006 External Links Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)
w0uter Posted January 31, 2006 Posted January 31, 2006 small example: $s_file = 'index.php' $as_hex = StringRegExp(StringTrimLeft(String(BinaryString(Chr(0) & FileRead($s_file))), 4), '(..)*', 1) $i_title = '0x' & $as_hex[0x1F] & $as_hex[0x1E] & $as_hex[0x1D] & $as_hex[0x1C] $s_title = '' for $i = 0 to $i_title-1 $s_title &= Chr('0x' & $as_hex[0x20+$i]) Next ConsoleWrite($s_title & @LF) $i_artist = '0x' & $as_hex[0x23+$i_title] & $as_hex[0x22+$i_title] & $as_hex[0x21+$i_title] & $as_hex[0x20+$i_title] $s_artist = '' for $i = 0 to $i_artist-1 $s_artist &= Chr('0x' & $as_hex[0x24+$i_title+$i]) Next ConsoleWrite($s_artist & @LF) My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll
jaenster Posted January 31, 2006 Posted January 31, 2006 (edited) why not hextostring , string to bits Edited January 31, 2006 by jaenster -jaenster
blitzkrg Posted January 31, 2006 Author Posted January 31, 2006 (edited) string to bits? is that a funciton? the 1st part of my file looks like this (i broke it down based on the above posted layout 010000000000<INIT SEQUENCE>13000000<NR. OF ENTRIES>0200<INIT ENTRY>01000000<ENTRY NUMBER>76AB4D0000000000<FILESIZE>AD000000<PLAYTIME>08000000<size of title>576F726420557021<title>04000000<size of artist>4B6F726E<artist>14000000<size of album>4772656174657374204869747320566F6C2E2031<album>09000000<size of genre>4861726420526F636B<genre>3C000000<size of absolute file path>5C4469736B5C4D79204D757369635C4B6F726E5C4772656174657374204869747320566F6C2E20315C30312D6B6F726E2 D776F72645F75702E6D7033<ABSOLUTE FILE PATH>01<TRACK NUMBER>00<CLOSING BYTE> Note: the description is to the right of the numbers. IF you use _hextostring and plug in the hex values for the text stuff, it will spit out everything correctly (i.e. artist, title, path) all that stuff works. What doesnt work is Filesize, playtime, size of artist, etc... I understand that it could be written in a little endian format BUT JSthepatriot raised a good point, are those values correct. I didnt have the time to confirm last night. (i will do so tonight) But i want to not only be able to read the information out of here, i want to be able to write back to it. 00 00 00 is going to equal = 0 correct? so no matter what format it's written in, it's still 0 so i dont understand how these numbers are valid in a LE encoding? (filesize) 76AB4D0000000000 (playtime) AD000000 (size of album)14000000 Looking up LE i found(as all of you correctly indicated it would be): "Little Endian" means that the low-order byte of the number is stored in memory at the lowest address, and the high-order byte at the highest address. (The little end comes first.) For example, a 4 byte LongInt Byte3 Byte2 Byte1 Byte0 will be arranged in memory as follows: Base Address+0 Byte0 Base Address+1 Byte1 Base Address+2 Byte2 Base Address+3 Byte3 so the quandry is how do i transform 76AB4D0000000000 into something meaningful? Edited January 31, 2006 by blitzkrg
jaenster Posted January 31, 2006 Posted January 31, 2006 All progaming langauges has a sting to bit :S .. -jaenster
seandisanti Posted January 31, 2006 Posted January 31, 2006 i think everyone and their mom has written number conversion scripts, could just use a hex2dec and a dec2bin. You could just write a script to change from hex to bin, but it was easier to just use both of these than to do that. expandcollapse popup$hex = "FF" msgbox(0,"Hex2Bin",Dec2Bin(Hex2Dec($hex))) Func Dec2Bin($number) $result = "" $power = 7 While $number > 0 If BitAND(2 ^ $power, $number) Then $result = $result & "1" $number = $number - 2 ^ $power Else $result = $result & "0" EndIf $power = $power - 1 WEnd While StringLen($result) < 8 If StringLen($result) < 8 Then $result = $result & "0" WEnd Return String($result) EndFunc ;==>Dec2Bin Func Hex2Dec($number) $result = 0 For $x = 0 To StringLen($number) Switch StringMid($number, StringLen($number) - $x, 1) Case "A" $result = $result + 10 * 16^$x Case "B" $result = $result + 11 * 16^$x Case "C" $result = $result + 12 * 16^$x Case "D" $result = $result + 13 * 16^$x Case "E" $result = $result + 14 * 16^$x Case "F" $result = $result + 15 * 16^$x Case "x" ExitLoop Case Else $result = $result + Int(StringMid($number, StringLen($number) - $x, 1)) * 16^$x EndSwitch Next Return $result EndFunc
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