Jump to content

Check "true file type"


 Share

Recommended Posts

Does anyone know how I can check the real file type regardless of extension.

For example I could rename an XLS file to TXT. Is their a way to verify that's it's not really a plain text file?

I thought there was an IsAlpha() function but I don't see it in the help file.

In this case all I care about is making sure it's plain text, but it would be useful to be able to check content types in general.

Thanks,

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

ahh I found it in another post it was StringIsAlpha()

:)

I ran a search in the help file for IsAlpha but no luck.

Thanks anyway,

Kenny

Edited by ken82m

 "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains."

Link to comment
Share on other sites

I also would like to know a way to extract file-type from the file itself...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

All those programs is good, but we need something on AutoIt :) ... That C# example, could be translated to AutoIt? via WinAPI perhaps? or what it uses...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Get the signature of the different file types and store them to compare.

Open the file you want to check in binary mode and read some of the starting bytes to get the signature and compare against the stored signatures..

That's what I was doing for exe, pdf, ico, mp3, rar.. etc.

But I notice that not all file types have a signature..

Link to comment
Share on other sites

TrID offers a dll library. Look at the first language mentioned in the example list (hint - its AutoIt):

http://mark0.net/code-tridlib-e.html

Nice, but it's too mch (1+ mb) to use it for such litle task :)

But thanks anyway, it's a start...

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Nice, but it's too mch (1+ mb) to use it for such litle task :)

But thanks anyway, it's a start...

Are you crazy? Its not a trivial task at all. The definition file can identify 3,640 different file types, I think 1.4 Mb is small for how many signatures it contains.

Link to comment
Share on other sites

I think 1.4 Mb is small for how many signatures it contains.

Eh? Did i miss something? I just see a 19 KB dll file? Which download are you talking about? Anyway, thinks this will be a nice addition to SMF :)....

Regards

Link to comment
Share on other sites

Eh? Did i miss something? I just see a 19 KB dll file? Which download are you talking about? Anyway, thinks this will be a nice addition to SMF :) ....

Regards

You need the definition file which is a database of file type signatures.

Look at the script example:

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

#include "TrIDLib-const.au3"

$MyFile = "triddefs.trd" ; 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
Edited by weaponx
Link to comment
Share on other sites

You need the definition file which is a database of file type signatures.

Ah, i see, got the demo working... nice find m8 :o, and compressed 440 kb is worth the bandwidth :), will integrate it in SMF :D

Best Regards

Link to comment
Share on other sites

Strangely it always returns "Unknown filetype!" for a simple text or zip file in AutoIt 3.3.0.0

Works for me, identifies zip... had an error in the first try though... zip file was 0 Bytes large, that returned an unkown :)... but you're right bout the txt file. I guess the reason is, that a plain txt file has no unique signature...

Edited by KaFu
Link to comment
Share on other sites

Works for me, identifies zip... had an error in the first try though... zip file was 0 Bytes large, that returned an unkown :) ... but you're right bout the txt file. I guess the reason is, that a plain txt file has no unique signature...

I think you're right. I tried an empty zip file first, it works when not empty. Also if you save the text file as UTF-8 it is recognized.

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...