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

{C / C++ / C++.NET} EDITER UN FICHIER BIT PAR BIT
Bonjout, J'ai récemment eu besoin d'éditer un fichier bit à bit mais ne trouvant pas de moyen de ...

{PHP} CHARGER DES DONNÉES DEPUIS UN FICHIER TXT DANS UNE BASE DE DONNÉE
le titre dit tout dejàs ce script utilise une base de données Mysql les requêtes pour la création ...

{Visual Basic, VB6, VB.NET, VB 2005} INSERER TOUT TYPE DE FICHIERS DANS ORACLE EN VB.NET
Ce petit code permet d'ajouter tout type de fichiers dans oracle et par la suite de les récupérer, l...

{C / C++ / C++.NET} FICHIER ALBUM MUSICAL
.............................................................................creer un fichier conten...

{PHP} CLASSE SIMPLE DE GESTION DE FICHIERS
Bonjour, Dans le cadre d'un projet lié à mon lycée, j'ai dû développer un certain nombre de class...

{Visual Basic, VB6, VB.NET, VB 2005} CAPTURE ET ENREGISTREMENT D'UNE IMAGE DEPUIS UNE WEBCAM
Ce code permet de capturer une photo à partir d'un flux WebCam avec la technologie ActiveX. Inspiré ...