zerozha Posted February 28, 2009 Share Posted February 28, 2009 C/C++ code like thisexpandcollapse popup/* try to open filename for reading */ FILE *fp; if(!(fp=fopen(filename,"rb"))) { printf("Cannot open '%s' for reading. Exit.\n",filename); exit(1); } /* get file size */ fseek (fp, 0, SEEK_END); filesize = ftell(fp); fseek (fp, 0, SEEK_SET); /* read file in buf */ buf = (unsigned char *) malloc(filesize+1); if(!buf) { printf("Cannot allocate %lu bytes. Exit.\n",filesize); exit(1); } unsigned long int readed=fread(buf,1,filesize,fp); if(readed!=filesize) { printf("By some reason i cant read '%s'. I want to read %lu bytes, but can read only %lu bytes.Exit.\n", filename, filesize, readed); exit(1); } fclose(fp); if(debug)printf("File read complete\n"); /* Ready? All seems to be in order? Go! */ int messageflag=0; unsigned long int messagestart=0; unsigned long int messageend=0; for(unsigned long int i=0;i<(filesize-6);i++) { if(buf[i]==0x1B) if(buf[i+1]==0x54) /* TrSM signarure. */ if(buf[i+2]==0x72) if(buf[i+3]==0x53) if(buf[i+4]==0x4D) { if(debug)printf("'TrSM' signarure found at %lX\n",i); if(messageflag) /* message begin */ { messageflag=1; messagestart=i; } else { /* we just skip the message. now we know address of last byte of message. */ messageflag=0; messageend=i; if(messagestart) /* in additional we need to skip 'garbage' at begin of the file */ { processmessage(messagestart,messageend); } messagestart=i; } } } processmessage(messageend,filesize); /* and dont forget the last one */ free(buf); return 0; }I convert to Autoit like thisexpandcollapse popup#AutoIt3Wrapper_Run_Tidy=y $debug = 0 $smsfile = "MessagesDatabase.pdb" $file = FileOpen($smsfile, 16) $tmpbuf = FileRead($file) $filesize = BinaryLen($tmpbuf) If $debug Then ConsoleWrite($filesize & @CRLF) Dim $buf[$filesize] For $j = 0 To $filesize - 1 $buf[$j] = BinaryMid($tmpbuf, $j, 1) If $debug Then ConsoleWrite($buf[$j] & @CRLF) Next If $debug Then ConsoleWrite("Done" & @CRLF) $messageflag = 0 $messagestart = 0 $messageend = 0 $i = 0 Do If ($buf[$i] = 0x1B) And ($buf[$i + 1] = 0x54) And ($buf[$i + 2] = 0x72) And ($buf[$i + 3] = 0x53) And ($buf[$i + 4] = 0x4D) Then If $debug Then ConsoleWrite($i & @CRLF) If $messageflag Then;/* message begin */ $messageflag = 1 $messagestart = $i EndIf Else ;/* we just skip the message. now we know address of last byte of message. */ $messageflag = 0 $messageend = $i If $messagestart Then _processmessage($messagestart, $messageend);;/* in additional we need to skip 'garbage' at begin of the file */ $messagestart = $i EndIf _processmessage($messageend, $filesize); /* and dont forget the last one */ $i += 1 Until $i < ($filesize - 6) FileClose($file)Now , this step Dim $buf[$filesize]For $j = 0 To $filesize - 1 $buf[$j] = BinaryMid($tmpbuf, $j, 1) If $debug Then ConsoleWrite($buf[$j] & @CRLF)Nexttake me hours to run this scripts.what's wrong with this script? Link to comment Share on other sites More sharing options...
MerkurAlex Posted February 28, 2009 Share Posted February 28, 2009 Unless im missing something (i could be im tired) you could use the function _FileReadToArray or fileread and then use stringsplit($read,@crlf,1). [quote name='PsaltyDS' post='635433' date='Jan 27 2009, 07:04 AM']Larry is a mass murderer?! It's always the quiet, clean cut, bald guys... [/quote] Link to comment Share on other sites More sharing options...
zerozha Posted February 28, 2009 Author Share Posted February 28, 2009 (edited) $smsfile = "MessagesDatabase.pdb" $filesize = FileGetSize($smsfile) $file = FileOpen($smsfile, 16) Dim $aArray, $bArray _FileReadToArray($smsfile, $aArray) ConsoleWrite($aArray[0] & @CRLF) $buf = FileRead($file) $bArray = StringSplit($buf, @CRLF, 1) ConsoleWrite($bArray[0] & @CRLF) It do not work wright. the results is: $aArray[0]=1 and $bArray[0]=1 Edited February 28, 2009 by zerozha 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