Jump to content
Sign in to follow this  
ken82m

Check "true file type"

Recommended Posts

ken82m

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

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites
ken82m

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

My Contributions _StringMultiReplace PC Builders Console - Secure PDF Creator - Cisco VPN Installer MS DNS Server Backup Script - MS DHCP Backup Script IT Admin Console - Toggle Admin Mode - MyMovies-Add Discs Script - IT Help Desk and System Information Tool - Set On Lid Close Power Option - Streaming Media Server & Website "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."

Share this post


Link to post
Share on other sites
MrCreatoR

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

Share this post


Link to post
Share on other sites
weaponx

I found this program call TrID as well, not sure if it works.

Share this post


Link to post
Share on other sites
MrCreatoR

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

Share this post


Link to post
Share on other sites
smashly

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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
MrCreatoR

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

Share this post


Link to post
Share on other sites
weaponx

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.

Share this post


Link to post
Share on other sites
KaFu

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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
KaFu

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

Share this post


Link to post
Share on other sites
weaponx

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

Share this post


Link to post
Share on other sites
KaFu

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

Share this post


Link to post
Share on other sites
weaponx

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.

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
Sign in to follow this  

×