Jump to content
Sign in to follow this  
kevinlaikf

[SOLVED] Different StringinStr with BinarytoSring results on Win2K and WinXP

Recommended Posts

kevinlaikf

My script will read a subdirectory for files 200*.DAT, and store into array.

Useful data start after 691280 bytes of every files.

For each array data, it will extract a series JPEG data streams and 8-bytes of every 34 bytes header before every JPEG header.

This first 8 bytes contain numeric value of epoch-seconds (seconds since 01-01-1970 00:00:00) in GMT +0 timezone.

This script was developed on a Windows 2000 workstation, and work perfectly fine.

But when run on a WinXP, it produced different results (incorrect data extracted, due to wrong value obtained in $jpegstart and $jpegend, $jpegstart keep returning null value).

I believe it has to be some unicode issue. But I can't proof it as the system setting was alright.

I had checked my Region settings on both PC, they are using 0409, same region settings.

Same AutoIt3 compiler version (AutoIt v3.2.12.1), same AutoIt Script Editor (14-8-2008).

Anyone know the cause of the erratic results?

Thank you.

; ====================

; My script start here

; ====================

#include <File.au3>

#include <string.au3>

#include <Date.au3>

$gmt = 8 ;GMT Timezone for Singapore +8

$sourcedir = "C:\SCREEN\"

$targetdir = "C:\JPEG\"

$filelist = _FileListToArray($sourcedir, "200*.DAT", 0)

$listcount = 0

For $fc = 1 To $filelist[0]

$errfound=0

$listcount += 1

$binfile = $sourcedir & $filelist[$fc]

$count=1

$file = FileOpen($binfile, 4)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

EndIf

$size = FileGetSize($binfile)

$usefuldata=FileRead($file, $size)

FileClose ($file)

$jpegend=0

While $size <> $jpegend + 1

; Search for JPEG Stream Header (0xFFD8FF)

$jpegstart = StringInStr(BinaryToString($usefuldata),BinaryToString("0xFFD8FF"),1,$count,691280)

if @Error = 1 Then

MsgBox (0,"Status","EOF Reached",2)

ExitLoop

endif

; Search for JPEG Stream End of File (0xFFD9)

$jpegend = StringInStr(BinaryToString($usefuldata),BinaryToString("0xFFD9"),1,$count,691280)

;MsgBox(0,"Debug", "$count: "& $count &" [ $jpegstart : " & $jpegstart & "] [ $jpegend : " & $jpegend & " ] " & $size,3)

if $jpegend = 0 Then

MsgBox (0,"Status","EOF Reached",2)

ExitLoop

endif

;Every file creation date in epoch second data stored first 8 of the 34 bytes offset before the JPEG header 0xFFD8FF

$epochraw = BinaryMid ( BinaryToString($usefuldata),$jpegstart-34,8)

$hex1 = StringMid($epochraw, 3, 2)

$hex2 = StringMid($epochraw, 5, 2)

$hex3 = StringMid($epochraw, 7, 2)

$hex4 = StringMid($epochraw, 9, 2)

$epochhex = "0x" & $hex4 & $hex3 & $hex2 & $hex1

$epochsec = Number($epochhex)

$creationdate = _DateAdd("s", $epochsec, "1970/01/01 00:00:00")

$creationdate2 = _DateAdd("h", $gmt, $creationdate)

;MsgBox(0,"Debug", "[ $jpegstart : " & $jpegstart & "] [ $jpegend : " & $jpegend & " ]" & @CRLF & "$epochraw : " & $epochraw & @CRLF & "[ $epochhex = " & $epochhex & " ] " & " [ $epochsec = "& $epochsec & " ]",3)

$fyear = StringMid($creationdate2, 1, 4)

$fmonth = StringMid($creationdate2, 6, 2)

$fday = StringMid($creationdate2, 9, 2)

$fhour = StringMid($creationdate2, 12, 2)

$fmin = StringMid($creationdate2, 15, 2)

$fsec = StringMid($creationdate2, 18, 2)

$newdir = $targetdir & $fyear & $fmonth & $fday

If Not FileExists($newdir) Then

DirCreate($newdir)

EndIf

$filename = $newdir & "\" & $fyear & $fmonth & $fday & "_" & $fhour & $fmin & $fsec & ".jpg"

;TrayTip("Status",$listcount & " [Raw Files: " & $binfile & "]" & @CRLF & "Bytes Processed: " & $jpegend + 1 & "/" & $size & @CRLF & "[" & $count & "] " & $filename & @CRLF,1,16)

$data=BinaryMid($usefuldata,$jpegstart,$jpegend-$jpegstart+2)

FileDelete($filename)

filewrite($filename,Binary($data))

$count+=1

WEnd

MsgBox(0,"File Deletion","Deleting " & $binfile,2)

FileDelete($binfile)

Next

; ===================

; My script ends here

; ===================

Edited by kevinlaikf

Share this post


Link to post
Share on other sites
kevinlaikf

My script will read a subdirectory for files 200*.DAT, and store into array.

Useful data start after 691280 bytes of every files.

For each array data, it will extract a series JPEG data streams and 8-bytes of every 34 bytes header before every JPEG header.

This first 8 bytes contain numeric value of epoch-seconds (seconds since 01-01-1970 00:00:00) in GMT +0 timezone.

This script was developed on a Windows 2000 workstation, and work perfectly fine.

But when run on a WinXP, it produced different results (incorrect data extracted, due to wrong value obtained in $jpegstart and $jpegend, $jpegstart keep returning null value).

I believe it has to be some unicode issue. But I can't proof it as the system setting was alright.

I had checked my Region settings on both PC, they are using 0409, same region settings.

Same AutoIt3 compiler version (AutoIt v3.2.12.1), same AutoIt Script Editor (14-8-2008).

Anyone know the cause of the erratic results?

RESOLVED.

I did not noticed that there is option to compile my script as ANSI version.

I believe my Win2K script was defaulted as ANSI using standard compile, whereas WinXP was default to unicode version.

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  

×