rudi

Analyze binary file content

18 posts in this topic

#1 ·  Posted (edited)

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



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

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

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

#5 ·  Posted (edited)

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

#6 ·  Posted (edited)

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

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

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

#10 ·  Posted

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

#11 ·  Posted

@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

#13 ·  Posted (edited)

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

#14 ·  Posted

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

#15 ·  Posted

@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

#16 ·  Posted (edited)

@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

#17 ·  Posted

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

#18 ·  Posted

@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

    • Dragonfighter
      By Dragonfighter
      I'm searching a way to do xor and shift and if possible also other operations. Thanks in advance for the replies.
    • ur
      By ur
      When I am trying to compile the autoit files with aut2exe.
      I am getting below error.
      There is no issue in code as the same code is getting compiled on different machine.
      I tried reinstalling the AUtoIT, but the issue replicates.

      Any suggestions?
    • robcull
      By robcull
      Hello all! I have had some issues reading text from different types of windows, occasionally, specifically with controlgettext. 
      **Before I begin, I know there are better ways to do what I attempt in the example below. That's not the point of this post. The point is my issues with controlgettext. 
      I am about to cite an example with an application you may be familiar with called SpeedFan (v4.52). My problem is not specific to speedfan, it is simply the most recent and easily reproducible example I can think of. 
      So, the goal of the script below is to get a string of text containing the current fan RPMs from the highlighted control in the screenshot below (see "speedfan_control_details.png").

      Now, here's a simple script for grabbing the window handle and reading the text from that control: 
      $wintitle = "SpeedFan 4.52" $controlID = "197934" ;will be reformatted as "[ID:######]" $hwnd = wingethandle($wintitle) if @error<>0 then msgbox(0, "WinGetHandle", "FAILURE. @error="&@error) Exit EndIf $text = ControlGetText($hwnd, "", "[ID:"&$controlID&"]") if @error=1 then msgbox(0, "ControlGetText", "FAILURE. @error="&@error) ;failure returns "" and @error=1 Exit EndIf msgbox (0, "ControlGetText", "SUCCESS. @error="&@error &@CRLF& "$text="&$text) ;success returns string and @error=0 You'll see that the ControlGetText operation runs without error, however it does not capture any text from the control. If you explore the other controls in this one window, you'll find mixed results across the board. Neither the temps nor voltages can be read, while the log field and some other elements can be read. Even when you read the text from the whole window, those elements are not included in the visible nor hidden texts. 
       
      I have run into this issue many times in the past- inconsistencies in the ability of autoit to interact with certain controls. What is it which makes this text different than any other readable texts? Is there an alternate method of reading the text in the window/control which could work? Any and all info to help me solve this mystery and satisfy my curiosity would be greatly appreciated. 
      Thanks  -Rob C
      PS: Running Autoit v3.3.14.2 on Win7 Ultimate x64
    • usmiv4o
      By usmiv4o
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.2.4.3 Author: usmiv4o Script Function: AutoIt script to check if files in directory are changed. It is usefull for security contra-inteligense measures. Function Name: LoadTripwireDB() Description: Loads database (text file tripwire.txt) and compare files in /test folder for changes. compares Hash (MD5) checksums. If they are not the same starts Initial() Function Name: Initial() Description: Checks directory and makes index of files and their MD5 checksums in text file (tripwire.txt) Function Name: Hush() Description: Checks file and returns its MD5 checksum. Requirement(s): Windows XP Return Value(s): On Success - Returns true. Files are the same as before. On Failure - return false. Example: LoadTripwireDB() #ce ---------------------------------------------------------------------------- #include <Crypt.au3> #include <File.au3> #include <Array.au3> $sDir = @ScriptDir & "\Test" $sFilePath = @ScriptDir & "\tripwire.txt" Func Hush(ByRef $sFile) $sRead = FileOpen( $sFile) $dHash = _Crypt_HashData($sRead, $CALG_MD5) ; Create a hash of the text entered. ConsoleWrite("Hash of file " & $sFile & " is " & $dHash & @CRLF) EndFunc ;ConsoleWrite("Files in Dir are " & $aScriptDir[0] & @CRLF) ;$sFilePath = @ScriptDir & "\Examples.txt" ;_FileWriteFromArray($sFilePath, $aScriptDir, 1) ;_ArrayDisplay($aScriptDir, "1D display") Func Initial() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 $dHash = _Crypt_HashData($i, $CALG_MD5) ;ConsoleWrite("File " & $aScriptDir[$i] & " is " & $dHash & @CRLF) ConsoleWrite($aScriptDir[$i] & ":" & $dHash & @CRLF) ;Hush($aScriptDir[$i]) ;FileWrite $hFileOpen = FileOpen($sFilePath, $FO_APPEND) If $hFileOpen = -1 Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the file.") EndIf FileWrite($hFileOpen, $aScriptDir[$i] & ":" & $dHash & @CRLF) Next EndFunc Func Monitor() $aScriptDir = _FileListToArray($sDir) for $i = 1 To UBound($aScriptDir) - 1 Next EndFunc Func LoadTripwireDB() $comparison_ok = false $dArray = _FileListToArray($sDir) ;directory $dArray0 = UBound($dArray) - 1 $fArray = FileReadToArray($sFilePath) ;file $fArray0 = UBound($fArray) ;_ArrayDisplay($dArray, "files array") if $dArray0 = $fArray0 Then ; are file same as recorded in txt file? ;ConsoleWrite("files in monitoring dir: " & $dArray[0] & " = file recorded: " & $fArray0 & @CRLF & $fArray[0]& @CRLF) for $i = 1 To UBound($dArray) - 1 ;ConsoleWrite("i = " & $i & @CRLF) $dHash = _Crypt_HashData($i, $CALG_MD5) ;binary ;$dHash = BinaryToString($dHash) $ffhash = StringSplit( $fArray[$i-1],":") $fhash = $ffhash[2] ;ConsoleWrite("IsBinary $dHash " & IsBinary($dHash) & @CRLF) if $dHash = $fhash Then ;if compared hashes are equal ;ConsoleWrite($fhash & ":" & $dHash & " equal" & @CRLF) ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: yes " & @CRLF) Else ;if compared hashes are not equal ;ConsoleWrite("File: " & $fhash & @CRLF & "Directory: " & $dHash & @CRLF & "equal: not " & @CRLF) ;MsgBox(0,"hash md5",$fhash & ":" & $dHash & " not equal") EndIf Next ;ConsoleWrite("hashes are equal" & @CRLF) $comparison_ok = true Else ConsoleWrite("number of files in monitoring dir are not same as recorded" & @CRLF) ConsoleWrite("directory: " & $dArray[0] &":"& "files: " & UBound($fArray) - 1 & @CRLF) EndIf Return $comparison_ok EndFunc #main if LoadTripwireDB() = true Then ConsoleWrite(" hashes are equal " & @CRLF) ElseIf LoadTripwireDB() <> true Then ConsoleWrite(" hashes are not equal " & @CRLF) ConsoleWrite(" hashes are not equal " & @CRLF) Initial() EndIf  
      tripwire.au3
      tripwire.txt
    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      Today I'll give you three functions to manage the list View items
      These functions will help you to do some works in your list view items
      1. list view Read
      To get the selected item text  
      2. listView_checke
      To checke an item
      3. isListViewChecked
      To see if the item is checked
      All of these functions will be illustrated by the following example
      You can download the include file from the link below
      Now with the example
      #include <easy_listView_functions.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example()  Local $idListview  GUICreate("ListView Get Item Checked State", 1000, 700)  $idListview = GUICtrlCreateListView("", 50, 30, 250, 120, 50)  _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) ; Add items $item1 = GUICtrlCreateListViewItem("item1", $idListview) $item2 = GUICtrlCreateListViewItem("item2", $idListview) _listview_Checke($idListview, "item1") $btn = GUICtrlCreateButton("&read", 100, 150, 50, 50) $btn2 = GUICtrlCreateButton("&if checked", 100, 200, 100, 50)  GUISetState(@SW_SHOW) while 1 switch GUIGetMSG() case $GUI_EVENT_CLOSE  GUIDelete() exit case $btn $read = _ListView_read($idListView) if $read then msgBox(0, "read listview", $read) else msgBox(0, "read listview", "no text ditected") endIf case $btn2 if _isListviewChecked($idListView, "item1") then msgBox(0, "get", "the item is checked") else msgBox(0, "get", "the item isn't checked") endIf endSwitch wend EndFunc   ;==>Example
       
      easy_listView_functions.au3