Jump to content

Help around TrID...


Recommended Posts

Sometimes, files downloaded in eMule (ed2k) are fakes - porno movies renamed to a wrong extension (for example - zip). When I try to open them with the supposed appropriate program (for example, zip is expected to open with WinZip), of course, I get an error message, since the file is a video file awry renamed to other extension.

This is the reason why I cannot give up from getting a way (script) to automatically scan all files inside my eMule's Download Folder; detect and isolate faked files...

On the other hand, I know some curious facts:

*) "Universal Extractor" [http://www.legroom.net/software/uniextract] is a superb application programmed in AutoIt Language;

*) "Universal Extractor" sometimes uses "TrID" [http://mark0.net/soft-trid-e.html] to help in detection of "file type/identification"...

Thus, I had an idea: see Universal Extractor's source-code (.au3) and try to imitate the methodology around using TrID to get file type/identification...

TrID is a command-line tool, which have the syntax:

trid.exe "file.ext" [+/- optional parameters]

The people that coded Universal Extractor did => scan each file with trid.exe => write a log/text file containing TrID scan's results => compare strings between what is expected and what TrID truly says...

I tried to imitate this, but my script does not work... Here it is:

#include <Array.au3>
#include <File.au3>

$path = "C:\eMule\Incoming" 



$fso = ObjCreate("Scripting.FileSystemObject")


$obj_dict = ObjCreate("Scripting.Dictionary")
$obj_dict.CompareMode = 1 ; "Text Mode"


$array_files = _FileListToArray($path, "*.*")


For $n = 1 To $array_files[0]
    $attribs = FileGetAttrib($path & "\" & $array_files[$n])
    
    If Not StringInStr($attribs, "D") Then
        
        RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\" & $array_files[$n] & """" & " >  " & @TempDir & "\" & """" & $array_files[$n] & """" & ".TrID.log", "", @SW_HIDE)
        
        $open_log_file = FileOpen(@TempDir & "\" & $array_files[$n] & ".TrID.log", 0)
        
        $read_log_file = FileRead($open_log_file)
        
        ConsoleWrite($read_log_file & Chr(13))
        
        
        $fso_get_file = $fso.GetFile ($path & "\" & $array_files[$n])
        $extension = $fso.GetExtensionName ($fso_get_file)
        
        ConsoleWrite($extension & Chr(13))
        
        Switch $extension
            Case "chm" 
                If Not StringInStr($read_log_file, "Windows HELP File") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "djvu"  Or "djv" 
                If Not StringInStr($read_log_file, "DjVu file") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "doc" 
                If Not StringInStr($read_log_file, "Microsoft Word document") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "html"  Or "htm" 
                If Not StringInStr($read_log_file, "HyperText Markup Language") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "mht" 
                If Not StringInStr($read_log_file, "Microsoft Internet Explorer Web Archive") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "mpg" 
                If Not StringInStr($read_log_file, "MPEG Video") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "pdb" 
                If Not StringInStr($read_log_file, "Palm iSilo") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "pdf" 
                If Not StringInStr($read_log_file, "Adobe Portable Document Format") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "ppt"  Or "pps" 
                If Not StringInStr($read_log_file, "Microsoft PowerPoint document") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "rar" 
                If Not StringInStr($read_log_file, "RAR Archive") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case "zip" 
                If Not StringInStr($read_log_file, "RAR Archive") Then
                    FileMove($path & "\" & $array_files[$n], $path & "\TrID\", 8)
                    FileCopy(@TempDir & "\" & $array_files[$n] & ".TrID.log", $path & "\TrID\")
                    RunWait(@ComSpec & " /c " & "trid.exe " & """" & $path & "\TrID\" & $array_files[$n] & """" & "-ae", "", @SW_HIDE)
                EndIf
            Case Else
                If Not $obj_dict.Exists ($extension) Then
                    FileWrite(@DesktopDir & "TrID - MISSING EXTENSIONS.log", $extension)
                    $obj_dict.Add ($extension)
                EndIf
        EndSwitch
        
        
        
        
        $close_log_file = FileClose($open_log_file)
        $delete_log_file = FileDelete(@TempDir & "\" & $array_files[$n] & ".TrID.log")
    EndIf
Next

I am in despair; my brain is boiling; can you please help me?

Thanks in advance.

Regards.

MLMK - my blogging craziness...
Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

one small thing, i have been looking for a freeware to identify the filetypes by its content metadata / header info rather than actual file extension because i could have autoit.au3 just as folder name yet extension info will give wrong notation. similarly jpg could be easily renamed to save as exe et all.

i did stumble upon trid and started building a gui / interface around it to use in my apps but alas, i felt i read a note its designed in detecting binary file info. i did try a few file types which were not entirely correct output!!! anyways, for media files i would recommend using mediainfo.dll which is a wonderful freeware and they do have the dllcall function usage example in autoit posted on their website itself!!!

Link to comment
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
 Share

  • Recently Browsing   0 members

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