Jump to content

Determine file type: text or binary


Go to solution Solved by KaFu,

Recommended Posts

  • Solution

 

Looks promising, especially this library also used in SMF! thanks!

Unfortunetely, no matter what file I put to analyzed, it always display: "Unknown filetype!"

; TrIDlib AutoIt Demo
; http://mark0.net/code-tridlib-e.html

#include "TrIDLib-const.au3"

$MyFile = "c:\temp\11.jpg" ; a random file to analyze
$Buf = "" ; allocate a string for the results

$Dll = DllOpen("TrIDLib.DLL") ; Open TrIDLib DLL

$Ret = DllCall($Dll, "int", "TrID_LoadDefsPack", "str", "") ; load the definitions
$Ret = DllCall($Dll, "int", "TrID_SubmitFileA", "str", $MyFile) ; submit the file
$Ret = DllCall($Dll, "int", "TrID_Analyze") ; perform the analysis

if @error = 1 then
    MsgBox(48, "TrID_Analyze", "Error(s) occurred!")
Else
    $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_NUM, "int", 0, "str", $Buf)
    $ResNum = $Ret[0] ; get the results number
    $Out = ""
    if $ResNum = 0 Then
        $Out = "Unknown filetype!"
    Else
        For $ResId = 1 to $ResNUm ; cycle trough results
            $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILETYPE, "int", $ResId, "str", $Buf)
            $Out = $Out & $ResId & ":" & Chr(9) &  $Ret[3] ; get the filetype description
            $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILEEXT, "int", $ResId, "str", $Buf)
            $Out = $Out & " (" & $Ret[3] & ")" ; get the filetype extension
            $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_POINTS, "int", $ResId, "str", $Buf)
            $Out = $Out & " - " & $Ret[0] ; get the matching points
            $Out = $Out & Chr(13)
        Next
    EndIf
    MsgBox(0, "TrIDLib demo", $Out)
EndIf

DllClose($Dll) ; cleanup

 

WinXP, AutoIT 3.8.8.1

What did I do wrong?

Link to comment
Share on other sites

In SMF I replaced "unkown" with "Indeterminable (e.g. text-file) / unknown filetype". There is nothing unique about a txt file, except from the extension it could also be an .au3 file, an .html file or a .py file... TrID is looking for file specific patterns / headers (jpg, zip, exe), but txt files just don't have these kind of patterns.

Link to comment
Share on other sites

In SMF I replaced "unkown" with "Indeterminable (e.g. text-file) / unknown filetype". There is nothing unique about a txt file, except from the extension it could also be an .au3 file, an .html file or a .py file... TrID is looking for file specific patterns / headers (jpg, zip, exe), but txt files just don't have these kind of patterns.

 

aha! understand now :)

So could I say if it is detected as "unknown", it's quite a big chance it's a text file? Not 100% for sure, but pretty big chance?

Link to comment
Share on other sites

  • 4 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...