News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Identify a text file

Started by ToutEnMasm, September 11, 2011, 03:19:09 PM

Previous topic - Next topic

ToutEnMasm

#15
Here something giving a good result:
Quote
   ;------------------------ see if ASCII  file ---------------------------      
   ;Release\vc90.idb
   ;test 127 --> 168 sur 1000 caracteres
   mov ecx,ArchiveFile.Tfichier      ;size of file
   .if ecx > 1000
      mov ecx,1000
   .else
      ;don't include the zero end
      dec ecx
      .if ecx == 0      ;NULL size
         mov retour,1
         jmp Findeadd_to_archive      ;Nothing to do
      .endif
   .endif
   @@:
   .if byte ptr [esi] != 0
      .if byte ptr [esi] >= 127 && byte ptr [esi] <= 144 ;No printable char
         jmp Extension_filtrer ; NOT a text file
      .endif
      .if byte ptr [esi] >= 147 && byte ptr [esi] <= 159 ;non imprimable
         jmp Extension_filtrer
      .endif      
                               ;a good tool to see that is  maketbl in the masm32 package
   .else
      jmp Extension_filtrer
   .endif
   dec ecx
   .if ecx != 0
      inc esi
      jmp @B
   .endif

   mov esi,ArchiveFile.Pfichier   
   ;pointeur sur ext
   .if word ptr [esi] == "ZM"
      jmp   Extension_filtrer ;Windows/DOS executable file
   .elseif word ptr [esi] == "iM"  ;microsoft
      invoke lstrcmpi,esi,SADR("Microsoft")   ;text
      .if eax == 0
         jmp   Extension_filtrer      
      .endif
   .elseif word ptr [esi] == 0D8FFh  ;jpeg probable
      jmp   Extension_filtrer
   .elseif word ptr [esi] == 4947h ; IG gif probable
      jmp   Extension_filtrer         
   .elseif word ptr [esi] == 0BBEFh ;UTF_8 (made bad char ù*¤ in notepad)
      jmp   Extension_filtrer   
   .elseif word ptr [esi] == 4D42h ;MB bitmap probable
      ;need more test here   
      jmp   Extension_filtrer      
   .elseif byte ptr [esi] < 32 && byte ptr [esi+1] < 32
      mov eax,0
      .if byte ptr [esi] == 13
         inc eax
      .elseif byte ptr [esi] == 10   
         inc eax      
      .elseif byte ptr [esi] == 9
         inc eax      
      .endif
      .if byte ptr [esi+1] == 13
         inc eax
      .elseif byte ptr [esi+1] == 10   
         inc eax      
      .elseif byte ptr [esi+1] == 9
         inc eax      
      .endif         
      .if eax != 2      ;not  text file                           
         jmp Extension_filtrer
      .endif
   .endif
   rejet_signature:
   mov NbRetourLigne,1