Jump to content
rudi

Analyze binary file content

Recommended Posts

rudi

Hello.

I'm too stupid to see my mistake:

To investigate the internal "dictionary" of TIFF files I'd like to read in the files in binary mode and to check, if there are more than one pages "in" this TIFF.

Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting

The "TIFF Header Format" is easy:

Offset 00h, 2 Byte = Byte Order, "II"=intel, "MM"=motorola. (I = 0x49)

--> II

Offset 02h, 2 Byte = Version Nr.

Offset 04h, 4 Byte = pointer to first IFD entry

Description of TIFF header: https://www.awaresystems.be/imaging/tiff/faq.html#q3

 


Howto read and analyse the binary content correctly? This is my messy, not operational code:

 

$sampleTiff="H:\daten\tif\11\11\111111.TIF"
$h=FileOpen($sampleTiff,16)
$content=FileRead($h)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
FileClose($h)

$type=VarGetType($content)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $type = ' & $type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console


$ToString=BinaryToString($content)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $ToString = ' & $ToString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite(@CRLF  & @CRLF)

$content=StringTrimLeft($content,2) ; cut off the leading "0x"
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $content = ' & $content & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console


for $i = 1 to 8 step 8
    $next=StringMid($content,$i,2)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :     $next = ' &     $next & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    $Chr=BinaryToString($next)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') :     $Chr = ' &  $Chr & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
    ConsoleWrite(@CRLF & "---" & @CRLF)
Next

Regards, Rudi.

111111.TIF

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
InnI
1 hour ago, rudi said:

Notepad++, "View as Hex" is presenting the first bytes as "49 49 2a 20 08 20 20 20 12" for the TIF attached to this posting

It's strange. I see "49 49 2A 00 08 00 00 00" in attached "111111.TIF"

$hFile = FileOpen("111111.tif", 16)
$ByteOrder = FileRead($hFile, 2)
$Version = FileRead($hFile, 2)
$FirstIFD = FileRead($hFile, 4)
FileClose($hFile)

ConsoleWrite($ByteOrder & @CRLF)
ConsoleWrite($Version & @CRLF)
ConsoleWrite($FirstIFD & @CRLF)

 

Share this post


Link to post
Share on other sites
rudi

Hello,

 

thanks for your reply.

 

You are right. I copy-pasted the displayed values from Notepad++ (Hex View) and didn't notice, that they changed after beeing pasted here.

Amazing behaviour: Notepad++ can copy values to the clipboard, and when using this feature, "00" is modified to "20", no clue, why, all other values are correct. This is reproducable...

49 49 2a 00 08 00 00 00 11 00 fe 00 04 00 01 00 

 

Your code is quite exactly what I was looking for. I wasn't aware, that after opening a file in binary mode I am able to "read <offset> <ount-of-bytes>".

That should do, thanks a lot!

 

Regards, Rudi.

 


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
Danyfirex

Because If you use that notepad change 00 to 20 is to avoid end of string character (null bytes) dont care about. I suggest you to use a real hex editor. HxD is ok.

 

Saludos

 

 

Share this post


Link to post
Share on other sites
rudi

Hello,

 

thanks for your reply. Notepad++ does *NOT* take the real values to the clipboard, but the "string representation". Except for "00", that's  replaced with "20", as far as I can see it right now...

 

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
rudi

Hello.

 

somewhat modified code:

 

; $sampleTiff="H:\DATEN\tif\73\23\M000017323.tif"
; $sampleTiff="H:\daten\tif\11\11\111111.TIF"
$sampleTiff="111111.TIF"

$hFile=FileOpen($sampleTiff,16)



$Bo1=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Bo1 = ' & $Bo1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Bo2=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Bo2 = ' & $Bo2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; is there a way to read the "0x4949" as "II" in one run? (I = indigo = 0x49)


$TVer1=FileRead($hFile,2) ; zwei bytes für TIFF Version. Immer 0x2A00
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $TVer1 = ' & $TVer1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; the first read value seems to be the HighByte (big/little endian???)
; 2A = 42 = Version Number for all TIFFs I can touch right now. But it's 0x2A00, not 0x002A --> again little / big endian???


$IDF1Start=FileRead($hFile,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IDF1Start = ' & $IDF1Start & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; offset 0x08 is correct.

$IDF1Count=FileRead($hFile,2)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IDF1Count = ' & $IDF1Count & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; 0x11 = 17 entries a 12 bytes --> again it's 0x1100, not 0x0011


FileClose($hFile)


$Hex17=Hex(17,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Hex17 = ' & $Hex17 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

This is giving these consolewrite outputs. So I assume, I need to "swap" little-endian/big-endian

Is there a funktion doing so, that I've missed?

 

Regards, Rudi.

 

@@ Debug(11) : $Bo1 = I
>Error code: 0
@@ Debug(13) : $Bo2 = I
>Error code: 0
@@ Debug(18) : $TVer1 = 0x2A00
>Error code: 0
@@ Debug(24) : $IDF1Start = 0x08000000
>Error code: 0
@@ Debug(28) : $IDF1Count = 0x1100
>Error code: 0
@@ Debug(32) : $Hex17 = 0011
>Error code: 0

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
RTFC

May I suggest you read the header into a struct first (see DllStructCreate), then read individual elements with DllStructGetData? See my Xbase.au3 for an example (link in my sig).

Share this post


Link to post
Share on other sites
rudi

Hello.

Thanks for your reply.

I never used DllStructCreate so far ... :sweating:

 

All I need is a look at the Pointer "Next IDF". If that value is 0x0000, then this is a single page tiff. That's all I need:

 

$sampleTiff="111111.TIF"

$hFile=FileOpen($sampleTiff,16)



$Bo1=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Bo1 = ' & $Bo1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Bo2=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Bo2 = ' & $Bo2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; is there a way to read the "0x4949" as "II" in one run? (I = indigo = 0x49)


$TVer1=FileRead($hFile,2) ; zwei bytes für TIFF Version. Immer 0x2A00
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $TVer1 = ' & $TVer1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; the first read value seems to be the HighByte (big/little endian???)
; 2A = 42 = Version Number for all TIFFs I can touch right now. But it's 0x2A00, not 0x002A --> again little / big endian???


$IDF1Start=FileRead($hFile,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IDF1Start = ' & $IDF1Start & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; offset 0x08 is correct.

$IDF1Count=FileRead($hFile,2)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $IDF1Count = ' & $IDF1Count & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; 0x11 = 17 entries a 12 bytes --> again it's 0x1100, not 0x0011


$Hex17=Hex(17,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Hex17 = ' & $Hex17 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console


for $Skip = 1 to 17 ; due to this little / big endian issue manually set "End-Value"
    $foo=FileRead($hFile,12)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $foo = ' & $foo & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
Next

ConsoleWrite("Skipping done" & @CRLF)

$NextIDF=FileRead($hFile,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $NextIDF = ' & $NextIDF & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

if $NextIDF=0 Then
    MsgBox(0,"Multipage TIFF check","This TIFF has just one page.")
Else
    MsgBox(64,"Multipage TIFF check","This TIFF has *MORE* than one page.")
EndIf

FileClose($hFile)

 

That's giving this output:

@@ Debug(11) : $Bo1 = I
>Error code: 0
@@ Debug(13) : $Bo2 = I
>Error code: 0
@@ Debug(18) : $TVer1 = 0x2A00
>Error code: 0
@@ Debug(24) : $IDF1Start = 0x08000000
>Error code: 0
@@ Debug(28) : $IDF1Count = 0x1100
>Error code: 0
@@ Debug(33) : $Hex17 = 0011
>Error code: 0
@@ Debug(38) : $foo = 0xFE0004000100000000000000
>Error code: 0
@@ Debug(38) : $foo = 0x0001040001000000480D0000
>Error code: 0
@@ Debug(38) : $foo = 0x010104000100000030110000
>Error code: 0
@@ Debug(38) : $foo = 0x020103000100000001000000
>Error code: 0
@@ Debug(38) : $foo = 0x030103000100000004000000
>Error code: 0
@@ Debug(38) : $foo = 0x060103000100000000000000
>Error code: 0
@@ Debug(38) : $foo = 0x0A0103000100000001000000
>Error code: 0
@@ Debug(38) : $foo = 0x1101040001000000F6000000
>Error code: 0
@@ Debug(38) : $foo = 0x120103000100000001000000
>Error code: 0
@@ Debug(38) : $foo = 0x150103000100000001000000
>Error code: 0
@@ Debug(38) : $foo = 0x160104000100000030110000
>Error code: 0
@@ Debug(38) : $foo = 0x17010400010000005D2D0000
>Error code: 0
@@ Debug(38) : $foo = 0x1A01050001000000DA000000
>Error code: 0
@@ Debug(38) : $foo = 0x1B01050001000000E2000000
>Error code: 0
@@ Debug(38) : $foo = 0x250104000100000000000000
>Error code: 0
@@ Debug(38) : $foo = 0x280103000100000002000000
>Error code: 0
@@ Debug(38) : $foo = 0x310102000C000000EA000000
>Error code: 0
Skipping done
@@ Debug(44) : $NextIDF = 0x00000000

Important to me is just the value $NextIDF. That's it.

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
rudi

Hello InnI.

Thanks for your suggestions for ....

#include <WinAPIMisc.au3>
_WinAPI_SwapWord()
_WinAPI_SwapDWord()
_WinAPI_SwapQWord()

I fail using it correctly, as the result of reading binary from the file is binary, not hex. And so far I couldn't figure out, how to convert the "binary string" to a "hex string".

 

$sampleTiff="111111.TIF"

$hFile=FileOpen($sampleTiff,16)



$Bo1=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
$Bo2=chr(FileRead($hFile,1)) ; Byte Order Info, Byte 1
; is there a way to read the "0x4949" as "II" in one run? (I = indigo = 0x49)


$TVer=FileRead($hFile,2) ; zwei bytes für TIFF Version. Immer 0x2A00
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $TVer = ' & $TVer & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Type=VarGetType($TVer)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Type = ' & $Type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Swapped=_WinAPI_SwapWord($TVer)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Swapped = ' & $Swapped & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$AsString=$TVer & ""
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $AsString = ' & $AsString & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
VarGetType($AsString)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : VarGetType($AsString) = ' & VarGetType($AsString) & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console

$Swapped2=_WinAPI_SwapWord($AsString)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Swapped2 = ' & $Swapped2 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite("42 is the correct Dec value" & @CRLF)
$Type=VarGetType($Swapped2)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Type = ' & $Type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
ConsoleWrite("Propably here I'm done, as I just need the DEC value to get the correct numbers?"& @CRLF)

ConsoleWrite("------------------" & @CRLF)

$Back2Hex=Hex($Swapped2,4)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Back2Hex = ' & $Back2Hex & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$Type=VarGetType($Back2Hex)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Type = ' & $Type & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
; how would I get a HEX value? What do I miss?

output is this:

@@ Debug(16) : $TVer = 0x2A00
>Error code: 0
@@ Debug(18) : $Type = Binary
>Error code: 0
@@ Debug(21) : $Swapped = 10752
>Error code: 0
@@ Debug(24) : $AsString = 0x2A00
>Error code: 0
@@ Debug(26) : VarGetType($AsString) = String
>Error code: 0
@@ Debug(29) : $Swapped2 = 42
>Error code: 0
42 is the correct Dec value
@@ Debug(32) : $Type = Int32
>Error code: 0
Propably here I'm done, as I just need the DEC value to get the correct numbers?
------------------
@@ Debug(38) : $Back2Hex = 002A
>Error code: 0
@@ Debug(40) : $Type = String
>Error code: 0

 

Thanks again!

 

Regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
rudi

@RTFC

Hello,

 

thanks for your reply.

I downloaded your xbase.au3 and tried this code. It's reporting "invalid header", all files are placed in the same folder (this script, xbase.au3, 111111.tif)

 

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.2
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include "xbase.au3"
#include <array.au3>


dim $myArr[1]

$TIFF="111111.tif"
_Xbase_ReadToArray($TIFF,$myArr)
_ArrayDisplay($myArr)

regards, Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
RTFC
39 minutes ago, rudi said:

I downloaded your xbase.au3 and tried this code. It's reporting "invalid header",

Yes, of course it would,^_^ a tiff file not being an Xbase file.:blink: I suggested this as an example how to produce a struct to read in a file header, in this case an Xbase (.dbf) database file. You define all elements using the appropriate variable type, read in the entire header (or as many bytes as you need to extract the info you need), and then use dllstructGetData to access individual elements as required. Obviously, a tiff file header will have a completely different structure than an Xbase file. But if you're only interested in a single Word, then a straight binary read would suffice.

Edited by RTFC

Share this post


Link to post
Share on other sites
UEZ

You can use GDI+ to get the amount of pages within a TIFF file:

#include <GDIPlus.au3>

Global $sFile_TIFF = FileOpenDialog("Select a TIF image", "", "TIFF (*.tif;*.tiff)")
If @error Then Exit

_GDIPlus_Startup()
Global $hImage = _GDIPlus_ImageLoadFromFile($sFile_TIFF)
Global $tGUID = _GDIPlus_GIFAnimGetFrameDimensionsList($hImage, _GDIPlus_GIFAnimGetFrameDimensionsCount($hImage))
Global $iCount = _GDIPlus_GIFAnimGetFrameCount($hImage, $tGUID)
_GDIPlus_ImageDispose($hImage)
_GDIPlus_Shutdown()
MsgBox(0, "TIF Page Count", "Pages: " & $iCount)


; #FUNCTION# ====================================================================================================================
; Name ..........: _GDIPlus_GIFAnimGetFrameDimensionsCount
; Description ...: Gets the number of frame dimensions in this Image object.
; Syntax ........: _GDIPlus_GIFAnimGetFrameDimensionsCount($hImage)
; Parameters ....: $hImage              - A handle to an image / bitmap object
; Return values .: The number of frame dimensions in this Image object.
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _GDIPlus_GIFAnimGetFrameDimensionsCount($hImage)
    Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsCount", "handle", $hImage, "ulong*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $aResult[2]
EndFunc   ;==>_GDIPlus_GIFAnimGetFrameDimensionsCount

; #FUNCTION# ====================================================================================================================
; Name ..........: _GDIPlus_GIFAnimGetFrameCount
; Description ...: Gets the frame count of the loaded gif by passing the GUID struct
; Syntax ........: _GDIPlus_GIFAnimGetFrameCount($hImage, $tGUID)
; Parameters ....: $hImage              - A handle to an image / bitmap object
;                  $tGUID               - A struct to a GUID that specifies the frame dimension.
; Return values .: The amount of frames from a GIF animated image handle
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......: _GDIPlus_ImageLoadFromFile _GDIPlus_BitmapCreateFromFile
; Link ..........:
; ===============================================================================================================================
Func _GDIPlus_GIFAnimGetFrameCount($hImage, $tGUID)
    Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameCount", "handle", $hImage, "struct*", $tGUID, "ptr*", 0)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return Int($aResult[3])
EndFunc   ;==>_GDIPlus_GIFAnimGetFrameCount

; #FUNCTION# ====================================================================================================================
; Name ..........: _GDIPlus_GIFAnimGetFrameDimensionsList
; Description ...: Gets the identifiers for the frame dimensions of this Image object which fills the GUID struct.
; Syntax ........: _GDIPlus_GIFAnimGetFrameDimensionsList($hImage, $iFramesCount)
; Parameters ....: $hImage              - A handle to an image / bitmap object
;                  $iFramesCount        - An integer value.
; Return values .: tagGUID struct
; Author ........: UEZ
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; ===============================================================================================================================
Func _GDIPlus_GIFAnimGetFrameDimensionsList($hImage, $iFramesCount)
    Local Const $tGUID = DllStructCreate($tagGUID)
    Local Const $aResult = DllCall($__g_hGDIPDll, "int", "GdipImageGetFrameDimensionsList", "handle", $hImage, "struct*", $tGUID, "uint", $iFramesCount)
    If @error Then Return SetError(@error, @extended, 0)
    If $aResult[0] Then Return SetError(10, $aResult[0], 0)
    Return $tGUID
EndFunc   ;==>_GDIPlus_GIFAnimGetFrameDimensionsList

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
InnI

@rudi Try this code for TIFF frame count

#include <WinAPIMisc.au3>

$hFile = FileOpen("111111.tif", 16)
If $hFile = -1 Then Exit ConsoleWrite("File not found" & @CRLF)

$ByteOrder = FileRead($hFile, 2)
$Version = FileRead($hFile, 2)
If ($ByteOrder <> 0x4949 And $Version <> 0x2A00) _
Or ($ByteOrder <> 0x4D4D And $Version <> 0x002A) Then Exit ConsoleWrite("No TIFF" & @CRLF)

$FirstIFD = FileRead($hFile, 4)
If $ByteOrder = 0x4949 Then $FirstIFD = _WinAPI_SwapDWord(String($FirstIFD))
FileSetPos($hFile, $FirstIFD, 0)

$Count = 0
Do
  $Count += 1
  $NumTags = FileRead($hFile, 2)
  If $ByteOrder = 0x4949 Then $NumTags = _WinAPI_SwapWord(String($NumTags))
  FileSetPos($hFile, $NumTags * 12, 1)
  $NextIFD = FileRead($hFile, 4)
  If $ByteOrder = 0x4949 Then $NextIFD = _WinAPI_SwapDWord(String($NextIFD))
  FileSetPos($hFile, $NextIFD, 0)
Until Not $NextIFD

FileClose($hFile)
ConsoleWrite($Count & @CRLF)

 

Share this post


Link to post
Share on other sites
rudi

@InnI

Hello.

 

That's exactly, what I was looking for! :thumbsup:

 

I have to admit, that I didn't really get the _WinApi_SwapDword() function so far ... :mad2:

I'll do further tries later on to get it :)

 

Thanks a lot !!!

 

Regards, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Share this post


Link to post
Share on other sites
UEZ

Here another version:

;Coded by UEZ build 2017-10-20 beta
#include <WinAPI.au3>

Global $sFile_TIFF = FileOpenDialog("Select a TIF image", "", "TIFF (*.tif;*.tiff)")
If @error Then Exit
ConsoleWrite("Pages found: " & TIFFPageCount($sFile_TIFF) & @CRLF)

Func TIFFPageCount($sFile_TIFF)
    Local $hFile = _WinAPI_CreateFile($sFile_TIFF, 2, 2), $Bytes
    Local $iFilesize = FileGetSize($sFile_TIFF)
    Local $tData = DllStructCreate("ushort Order;ushort Type;dword IFD")
    _WinAPI_ReadFile($hFile, DllStructGetPtr($tData), 8, $Bytes)
    If Not BitOR($tData.Order = 0x4949, $tData.Order = 0x4D4D) Then
        _WinAPI_CloseHandle($hFile)
        Return SetError(1, 0, 0)
    EndIf
    Local $IFD = $tData.IFD
    Local $tData2 = DllStructCreate("ushort NumDirEntries")
    Local $iTags, $iPages = 0
    Do
        _WinAPI_SetFilePointer($hFile, $IFD)
        _WinAPI_ReadFile($hFile, DllStructGetPtr($tData2), 2, $Bytes)
        If $tData2.NumDirEntries > 256 Then ExitLoop
        $iTags = $tData2.NumDirEntries * 12 + 2
        _WinAPI_SetFilePointer($hFile, $IFD + $iTags)
        _WinAPI_ReadFile($hFile, DllStructGetPtr($tData, "IFD"), 4, $Bytes)
        $IFD = $tData.IFD
        $iPages += 1
    Until $IFD = 0 or $IFD > $iFilesize - 4
    _WinAPI_CloseHandle($hFile)
    Return $iPages
EndFunc

 

I don't know if it is working also for TIFs multi page MM encoded.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
rudi

@UEZ

Great code sample!

 

Thanks.

 

Rudi.


Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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

  • Similar Content

    • smud
      By smud
      Currently, I'm working on a program that will display Dialog boxes with either Yes or No.
      For each dialog, I reward the user with X amount of Credits.
      I'm hoping to output the amount of credits to a cell in a column (there will be 20 different columns).
      It will only post to a row that is equal to today's date (first column). If no row exists yet with the current date, it will start a new row.
      Any suggestions?
      Thank you
    • nacerbaaziz
      By nacerbaaziz
      hi dears
      am using an ini files as a History
      Sometimes the file size is be larger to 5 MB
      AutoIt does not recognize the full content of the file
      When I did a search to find out why, I discovered that INI files could not be read if they size larger than 64 KB.
      for that I preferred to ask here if is there any way to bypass this obstacle.
      The contents of the file are  as follows
      [filesList]
      c:\...\...\f1.mp3=00:15:20
      c:\...\...\f2.mp3=00:10:20
      c:\...\...\f3.wav=00:59:20
      ....... Etc
      This is the section for reading the file (adapted from my main script)

      case $continue     Local $aArray = IniReadSection($WaitingListFile, StringEncrypt(true, "filesList", $MyPassword))     If Not @error Then Opt("GUICloseOnESC", 1) _GUICtrlListView_DeleteAllItems($scList)         For $i = 1 To $aArray[0][0] $path = path_list(StringEncrypt(false, $aArray[$i][0], $MyPassWord), 1) if FileExists(StringEncrypt(false, $aArray[$i][0], $MyPassWord)) then GUICtrlCreateListViewItem(_GetFileName(FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord))) & Opt("GUIDataSeparatorChar") & " : " & Opt("GUIDataSeparatorChar") & FileGetLongName(StringEncrypt(false, $aArray[$i][0], $MyPassWord)), $scList) else $path = $path endIf         Next GUISetState(@sw_disable, $hGUI) GUISetState(@sw_show, $hGUI2) GUICtrlSetState($SClist, $GUI_FOCUS) else if $accessibilitymode = 1 then speak(str("listEmpty")) endIf endIf
      Is there any way to solve this problem, please?
      am waiting your answers...
      Greetings to All
    • caramen
      By caramen
      Hey.  
       
      I requested help about how to get a value from a text in a variable. 
      Now i know how to do that. But i learned with the command FileRead. Now i whould like to know how to replace the command :
      FileRead('Dossier.txt') The purpose is to read a webpage text. To find some value inside. 
       
      Btw i tryed to play with WindowsInfo.au3 but i dont got much thing.  
    • dadalt95
      By dadalt95
      Hi!
      I want to get the signal in this website:
      https://binary-signal.com/pt/chart/eurusd
      I have tried using _IEBodyReadText  and some _StringBetween. What happens is that the text are being update every tick and _IEBodyReadText doesn't.
      To perform the update I used  _IEAction($oIE, "refresh") but it's not good because the website block me after some time due too many requests..
      Is there any other way to get this text every tick?
      PS: The text I want to get is WAIT, CALL or PUT.
       
      Here is the code:
      global $oIE = _IECreate ('https://binary-signal.com/pt/chart/eurusd', 0, 1 , 1 , 0) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') ;MsgBox ( 0, "asf", $result[0]) $espera=StringInStr($result[0], "WAIT") $compra=StringInStr($result[0], "CALL") $venda=StringInStr($result[0], "PUT") ;MsgBox($MB_SYSTEMMODAL, "", $espera) $n=0 $c=0 Captar() Func Captar() ;_IENavigate($oIE, "https://binary-signal.com/pt/chart/eurusd") ;MsgBox($MB_SYSTEMMODAL, "", $n) Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') If (Not $compra=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "COMPRE") $n=1 $c=$c+1 ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=0 Then MsgBox($MB_SYSTEMMODAL, "", "VENDA") $c=$c+1 $n=1 ;_IEAction($oIE, "refresh") ;MsgBox($MB_SYSTEMMODAL, "", $n) Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() ElseIf (Not $venda=0) And $n=1 Then ;MsgBox($MB_SYSTEMMODAL, "", "Esperando próxima rodada") $n=1 ;MsgBox($MB_SYSTEMMODAL, "", $n) ;_IEAction($oIE, "refresh") Sleep(60000) Captar() Else ;MsgBox("", "", "ESPERE") $n=0 Sleep(1000) ;_IEAction($oIE, "refresh") Local $sText = _IEBodyReadText($oIE) $result = _StringBetween ( $sText , 'PUTEUR/USD on Binary-signal.com', 'sinal está PRONTA') Captar() EndIf EndFunc  
    • Trisha
      By Trisha
      Hello,
      I Have clicked on save as option to save a file, while doing that I need to rename a file appending with sysdate. I have searched in google find the below one line of code:
      FileMove("C:\somefile.txt", "C:\somefile1.txt"), When I am trying to append with sysdate. It is not happening. Please help me out  with the small issue.
×