Les Snippets

Connexion

Savoir si un fichier est un executable Windows

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 25/03/2006 23:48:26 et initié par EBArtSoft [Liste]
Date de mise à jour : 14/08/2006 01:36:13
Vue : 7213
Catégorie(s) : Fichier / Disque, Système
Langages dispo pour ce code :
- VB6, VBA
- VB 2005
- C# 2.x
- C
- Javascript



Langage : VB6 , VBA
Date ajout : 25/03/2006
Posté par EBArtSoft [Liste]

Const PESIGNATURE = &H4550&
Const MZSIGNATURE = &H5A4D&

Public Function IsPE(ByVal StrFileName As String) As Boolean
    On Error GoTo Xe
    Dim rMZ   As Integer
    Dim rOfs  As Long
    Dim rFree As Long
    Dim rPE   As Long
    rFree = FreeFile
    Open StrFileName For Input As #rFree: Close #rFree
    Open StrFileName For Binary Access Read As #rFree
    Get #rFree, , rMZ
    If (rMZ = MZSIGNATURE) Then
        Get #rFree, 61, rOfs
        If (rOfs > 61) And (rOfs < LOF(rFree)) Then
            Get #rFree, 1 + rOfs, rPE
            IsPE = (rPE = PESIGNATURE)
        End If
    End If
    Close #rFree
Xi: Exit Function
Xe: 'MsgBox Err.Description, vbCritical
    Resume Xi
End Function


Langage : VB 2005
Date ajout : 15/04/2006
Posté par FREMYCOMPANY [Liste]
Imports Microsoft.VisualBasic
Public Module X
    Const PESIGNATURE As Integer = &H4550
    Const MZSIGNATURE As Integer = &H5A4D
    Public Function IsWinExe(ByVal StrFileName As String) As Boolean
        On Error GoTo Xe
        Dim rMZ As Short
        Dim rOfs As Integer
        Dim rFree As Integer
        Dim rPE As Integer
        rFree = FreeFile
        FileOpen(rFree, StrFileName, OpenMode.Input) : FileClose(rFree)
        FileOpen(rFree, StrFileName, OpenMode.Binary, OpenAccess.Read)
        'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
        FileGet(rFree, rMZ)
        If (rMZ = MZSIGNATURE) Then
            'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
            FileGet(rFree, rOfs, 61)
            If (rOfs > 61) And (rOfs < LOF(rFree)) Then
                'UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
                FileGet(rFree, rPE, 1 + rOfs)
                IsPE = (rPE = PESIGNATURE)
            End If
        End If
        FileClose(rFree)
Xi:    Exit Function
Xe:   Resume Xi
    End Function
End Module

Langage : C# 2.x
Date ajout : 15/04/2006
Posté par FREMYCOMPANY [Liste]

using Microsoft.VisualBasic;
public class X
{
 const int PESIGNATURE = 17744;
 const int MZSIGNATURE = 23117;
 public bool IsWinExe(string StrFileName)
 {
  
  short rMZ;
  int rOfs;
  int rFree;
  int rPE;
  rFree = FreeFile;
  FileSystem.FileOpen(rFree, StrFileName, OpenMode.Input);
  FileSystem.FileClose(rFree);
  FileSystem.FileOpen(rFree, StrFileName, OpenMode.Binary, OpenAccess.Read);
  //UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
  FileSystem.FileGet(rFree, rMZ);
  if ((rMZ == MZSIGNATURE))
  {
   //UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
   FileSystem.FileGet(rFree, rOfs, 61);
   if ((rOfs > 61) & (rOfs < FileSystem.LOF(rFree)))
   {
    //UPGRADE_WARNING: Get was upgraded to FileGet and has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"'
    FileSystem.FileGet(rFree, rPE, 1 + rOfs);
    IsPE = (rPE == PESIGNATURE);
   }
  }
  FileSystem.FileClose(rFree);
  Xi:
  return;// might not be correct. Was : Exit Function
  Xe:
  
 }
}


Remarque :
A besoin de l'espace de nom Microsoft.VisualBasic pour fonctionner - et tant pis pour les réticents ;-) -
Langage : C
Date ajout : 13/08/2006
Posté par SAKingdom [Liste]
DateMAJ : 14/08/2006
BOOL isWin32Exe (char *FileName)
{
  BYTE *buffer;
  HANDLE hFile;
  DWORD peLocation, d, FileSize;
  BOOL retval = 0; // PRESUME ERREUR
  hFile = CreateFile(FileName, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
  if(hFile == INVALID_HANDLE_VALUE) goto exeEXIT;
  FileSize = GetFileSize(hFile, 0);
  if(GetLastError()) goto closeEXE;
  if(FileSize <= 0x3F) goto closeEXE;
  buffer = (BYTE*) VirtualAlloc(0, FileSize, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  if(!buffer) goto closeEXE;
  d = 0; ReadFile(hFile, buffer, FileSize, &d, 0);
  if(d != FileSize) goto relMEM; // ERREUR LECTURE
  if(*((WORD*) buffer) != 0x5A4D) goto relMEM; // MZ au début
  peLocation = *((DWORD*) (buffer + 60));  // pointeur vers l'offset PE
  if(peLocation >= FileSize) goto relMEM; // pointeur pointerait hors buffer alors on quitte
  if(*((WORD*) (buffer + peLocation)) == 0x4550) retval = TRUE; // signature PE, module Win32
relMEM: VirtualFree(buffer, 0, MEM_RELEASE);
closeEXE: CloseHandle(hFile);
exeEXIT: return retval;
}
Langage : Javascript
Date ajout : 06/04/2007
Posté par stfou [Liste]
var ext=new ActiveXObject("Scripting.FileSystemObject").GetExtensionName("chemin du fichier");
var executable=if(ext=="exe" | "com"){true} else {false};

Snippets en rapport avec : Fichier, Executable



Codes sources en rapport avec : Fichier, Executable

{Visual Basic, VB6, VB.NET, VB 2005} MANIPULATION FICHIER EXECUTABLE
Comment ajouter des données de plus dans un fichier exécutable ? c'est comme winzip, il le fait ave...

{Flash} ENREGISTRER DANS UN FICHIER TEXTE AVEC L'AIDE D'UN EXE
Voici une classe permettant d'enregistrer dans un fichier texte, ca fonctionne grace à un éxécutable...

{Visual Basic, VB6, VB.NET, VB 2005} GENERATEUR D AUTO EXTRACTIBLE EN VB6
Cette source permet de générer un programme auto extracteur de fichiers en vb6. Elle comprend le pro...

{C / C++ / C++.NET} ICONVIEWER
Voici commment afficher tous les icones contenues dans n'importe quel fichier....

{Visual Basic, VB6, VB.NET, VB 2005} ENREGISTRER LIRE ET MODIFIER/ÉCRIRE DANS UN FICHIER TEXTE AU FORMAT UNICODE
Ayant ramé pour trouver comment faire je vous offre cette petite source pour vous éviter de fastidie...

{PHP} PHP EXTRAIRE DES MAILS D'UN GROS FICHIER LOCAL OU DISTANT
On peut extraire tout les mails d'un fichier sans se prendre la tête pendant dans jours... Qu'en pe...

{Visual Basic, VB6, VB.NET, VB 2005} LECTURE ET MODIFICATION DES PROPRIÉTÉS DES FICHIERS OFFICE ET NTFS5
Lorsque vous cliquez sur Propriété d'un fichier, vous avez surement remarqué les onglets Résumé (pou...

{Delphi} MODIFIER LES DATES DE CRÉATION, DE MODIFICATION ET DE DERNIER ACCÈS D'UN FICHIER
La Source de grandvizir actuellement présente sur le site (http://www.delphifr.com/codes/CORRUPTEUR-...

{PHP} UTILISATION DU COMPOSANT MULTIPOWUPLOAD
Exemple d'utilisation du composant MultiPowUpload.... Le dossier UploadedFiles doit avoir les dro...

{C / C++ / C++.NET} BASE DE DONNÉES FICHIER
LOGICIEL COMPILE AVEC BC++ 5 STANDARD Ce logiciel genere une base de données des fichiers...