Updated the code so it wouldn't crash with the PB 6.01 LTS I was testing on. Minor corrections for English translation.
Code: Select all
; ---------------------------------------------------------------
; PureBasic 6.01 LTS (x64 & x86)
; -------------------------------------------------- --------------
; Version 1.01
; Window Works from 2000 (File System NTFS)
; -------------------------------------------------- --------------
; This code allows only list the streams "Alternate Data"
; contained in the files or folders
; -------------------------------------------------- --------------
; {- Enumerations / DataSections
; {Windows
Enumeration
#Window_Main
EndEnumeration
;}
;{ Gadgets
Enumeration
#String_Dossier_Fichier
#Button_Dossier
#Button_Fichier
#ListIcon_Stream
#Button_Scan
#Button_StopperScan
#Button_SupprimerleStream
#Button_EditeravecNotepad
#Button_Extrairevers
#Button_Quitter
#Text_Info
#Button_OuvrirExplorateur
#BarreEtat
EndEnumeration
; }
; }
Global Chemin$
Global NomStream.s, Dim NomStream.s(100), Dim StreamSize.q(100), StreamCount.l
Global FinRecherche.l
Procedure ReadStream(CheminDossier_CheminFichier.s)
Protected file_h.i, totRead.i,*stream.WIN32_STREAM_ID, *buffer
Protected context.i=0, bytes_read.i=0, bytes_read1.l=0, seek_l.i = 0, seek_h.i = 0, Result.i=0
Protected namesize.l, streamHight.q, streamLow.q, count.l
file_h = CreateFile_(@CheminDossier_CheminFichier, #READ_CONTROL, 0, 0, #OPEN_EXISTING, #FILE_FLAG_BACKUP_SEMANTICS, 0)
If file_h <> 0
*stream.WIN32_STREAM_ID = AllocateMemory(20)
totRead = BackupRead_(file_h, *stream, 20, @bytes_read, 0, 1, @context)
While (bytes_read <> 0 ) ;And Result=0
If *stream\dwStreamID=#BACKUP_ALTERNATE_DATA
namesize = *stream\dwStreamNameSize
If namesize > 0
*buffer = AllocateMemory(namesize)
BackupRead_(file_h,*buffer,namesize,@bytes_read1,0,1,@context)
NomStream(count)= PeekS(*buffer,namesize/2,#PB_Unicode)
FreeMemory(*buffer)
streamHight.q=*stream\Size\LongPart\highpart & $FFFFFFFF
streamLow.q=*stream\Size\LongPart\lowpart & $FFFFFFFF
StreamSize(count) = streamHight<<32 | streamLow
StreamCount = count
count = count + 1
Result=1
EndIf
EndIf
BackupSeek_(file_h, *stream\Size\LongPart\lowpart, *stream\Size\LongPart\highpart, @seek_l, @seek_h, @context)
FreeMemory(*stream)
*stream.WIN32_STREAM_ID = AllocateMemory(20)
bytes_read = 0
totRead = BackupRead_(file_h, *stream, 20, @bytes_read, 0, 1, @context)
Wend
FreeMemory(*stream)
BackupRead_(file_h,0,0,@bytes_read,1,0,@context)
CloseHandle_(file_h)
EndIf
ProcedureReturn Result
EndProcedure
Procedure.s ParseDirectory(folder.s, id.l = 0)
Protected Type.s
If Right(folder, 1) <> "\"
folder + "\"
EndIf
If ExamineDirectory(id, folder, "*.*")
If FinRecherche<2
While NextDirectoryEntry(id)
If DirectoryEntryName(id) <> "." And DirectoryEntryName(id) <> ".."
; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
StatusBarText(#BarreEtat, 0, folder + DirectoryEntryName(id))
If ReadStream(folder + DirectoryEntryName(id))
If DirectoryEntryType(id)= #PB_DirectoryEntry_Directory
Type.s="Back"
Else
Type.s="File"
EndIf
For count = 0 To StreamCount
AddGadgetItem(#ListIcon_Stream, -1, NomStream(count)+Chr(10)+Str(StreamSize(count))+Chr(10)+Type+Chr(10)+folder + DirectoryEntryName(id))
Next
StreamCount = 0
EndIf
; # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
If DirectoryEntryType(id) = #PB_DirectoryEntry_Directory
ParseDirectory(folder + DirectoryEntryName(id), id + 1)
EndIf
EndIf
Wend
EndIf
FinishDirectory(id)
EndIf
EndProcedure
Procedure ParseCheminFichierouDossier(folder.s)
Protected Type.s
If FileSize(folder)=-2
Type.s="Back"
Else
Type.s="File"
EndIf
If ReadStream(folder)
For count = 0 To StreamCount
AddGadgetItem(#ListIcon_Stream, -1, NomStream(count)+Chr(10)+Str(StreamSize(count))+Chr(10)+Type+Chr(10)+folder)
Next
StreamCount = 0
EndIf
If Type="Back"
ParseDirectory(folder)
EndIf
EndProcedure
Procedure DisableGadgetGroup1(Etat.l)
DisableGadget(#Button_Dossier,Etat)
DisableGadget(#Button_Fichier,Etat)
DisableGadget(#Button_Scan,Etat)
DisableGadget(#Button_Quitter,Etat)
EndProcedure
Procedure DisableGadgetGroup2(Etat.l)
DisableGadget(#Button_SupprimerleStream,Etat)
DisableGadget(#Button_EditeravecNotepad,Etat)
DisableGadget(#Button_Extrairevers,Etat)
DisableGadget(#Button_OuvrirExplorateur,Etat)
EndProcedure
Procedure Thread(lParam.i)
ParseCheminFichierouDossier(Chemin$)
StatusBarText(#BarreEtat, 0, "")
FinRecherche=0
DisableGadget(#Button_StopperScan,1)
DisableGadgetGroup1(0)
EndProcedure
Procedure OpenWindow_Window_Main()
If OpenWindow(#Window_Main, 200, 200, 610, 460, "Alternate Data Stream SPY", #PB_Window_SystemMenu|#PB_Window_TitleBar)
StringGadget(#String_Dossier_Fichier, 10, 25, 520, 25, "", #PB_String_ReadOnly)
ButtonGadget(#Button_Dossier, 540, 10, 60, 25, "Back")
ButtonGadget(#Button_Fichier, 540, 40, 60, 25, "File")
ListIconGadget(#ListIcon_Stream, 10, 110, 590, 250, "Name of Stream", 100, #PB_ListIcon_AlwaysShowSelection|#PB_ListIcon_FullRowSelect|#PB_ListIcon_GridLines)
AddGadgetColumn(#ListIcon_Stream, 1, "Size", 60)
AddGadgetColumn(#ListIcon_Stream, 2, "Type", 60)
AddGadgetColumn(#ListIcon_Stream, 3, "Path", 360)
ButtonGadget(#Button_Scan, 110, 70, 170, 25, "Scan Alternate Data Stream")
ButtonGadget(#Button_StopperScan, 340, 70, 155, 25, "Stop the Scan")
ButtonGadget(#Button_SupprimerleStream, 300, 370, 150, 25, "Remove Stream")
ButtonGadget(#Button_EditeravecNotepad, 10, 370, 140, 25, "Edit with Notepad")
ButtonGadget(#Button_Extrairevers, 150, 370, 150, 25, "Stream to extract the ...")
ButtonGadget(#Button_Quitter, 240, 405, 130, 25, "Leave")
TextGadget(#Text_Info, 10, 5, 520, 20, "You can drag and drop a File or Folder into the text box below")
ButtonGadget(#Button_OuvrirExplorateur, 450, 370, 150, 25, "Open in Browser")
CreateStatusBar(#BarreEtat, WindowID(#Window_Main))
AddStatusBarField(#PB_Ignore)
EnableGadgetDrop(#String_Dossier_Fichier, #PB_Drop_Files, #PB_Drag_Copy)
DisableGadget(#Button_StopperScan,1)
DisableGadgetGroup2(1)
EndIf
EndProcedure
OpenWindow_Window_Main()
; {- Event loop
Repeat
Select WaitWindowEvent()
; / / / / / / / / / / / / / / / / / / /
Case #PB_Event_GadgetDrop
Select EventGadget()
Case #String_Dossier_Fichier
Files$ = EventDropFiles()
Count = CountString(Files$, Chr(10)) + 1
SetGadgetText(#String_Dossier_Fichier,StringField(Files$, 1, Chr(10)))
EndSelect
Case #PB_Event_Gadget
Select EventGadget()
Case #Button_Dossier
Chemin$ = PathRequester("Select a directory:", "C: \")
SetGadgetText(#String_Dossier_Fichier,Chemin$)
Case #Button_Fichier
Chemin$ = OpenFileRequester("Choose a file:", "C: \", "*. *",0)
SetGadgetText(#String_Dossier_Fichier,Chemin$)
Case #ListIcon_Stream
Index.l=GetGadgetState(#ListIcon_Stream)
If Index>-1
DisableGadgetGroup2(0)
Else
DisableGadgetGroup2(1)
EndIf
Case #Button_Scan
ClearGadgetItems(#ListIcon_Stream)
Chemin$=GetGadgetText(#String_Dossier_Fichier)
If FileSize(Chemin$) <>-1
DisableGadgetGroup1(1)
DisableGadgetGroup2(1)
DisableGadget(#Button_StopperScan,0)
FinRecherche=1
CreateThread(@Thread(),0)
Else
MessageRequester("Info","Choose a folder path or file valid!")
EndIf
Case #Button_StopperScan
FinRecherche=2
DisableGadget(#Button_StopperScan,1)
DisableGadgetGroup1(0)
Case #Button_EditeravecNotepad
Index.l=GetGadgetState(#ListIcon_Stream)
If Index>-1
NameStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 0)
NameStream=StringField(NameStream,2,":")
CheminStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 3)
MessageRequester("Info","In some cases, Notepad will not be able to open the Stream!"+Chr(13)+"but you can always make an Extraction File and then edit the resulting File")
RunProgram("Notepad.exe",CheminStream+":"+NameStream,"")
EndIf
Case #Button_Extrairevers
Index.l=GetGadgetState(#ListIcon_Stream)
If Index>-1
NameStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 0)
NameStream=StringField(NameStream,2,":")
Taille.s=GetGadgetItemText(#ListIcon_Stream, Index , 1)
If Taille<>"0"
NomFichier$ = SaveFileRequester("Choose a location:", NameStream, "*. *", 0)
If NomFichier$<>""
CheminStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 3)
If ReadFile(0,CheminStream+":"+NameStream)
Longueur.q=Lof(0)
*Buffer=AllocateMemory(Longueur)
ReadData(0,*Buffer,Longueur)
CloseFile(0)
If CreateFile(0,NomFichier$)
WriteData(0,*Buffer,Longueur)
CloseFile(0)
EndIf
FreeMemory(*Buffer)
Else
MessageRequester("Error","Stream could not be Save at!")
EndIf
EndIf
Else
MessageRequester("Info","Size of this Stream is 0 bytes, it is useless to save it!")
EndIf
EndIf
Case #Button_SupprimerleStream
Index.l=GetGadgetState(#ListIcon_Stream)
If Index>-1
NameStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 0)
NameStream=StringField(NameStream,2,":")
CheminStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 3)
Type.s=GetGadgetItemText(#ListIcon_Stream, Index , 2)
Message$="your you sure you want to delete the Stream"+NameStream+"?"+Chr(13)+"of"+Type+" "+CheminStream
Resultat =MessageRequester("Attention",Message$, #PB_MessageRequester_YesNo)
If Resultat = #PB_MessageRequester_Yes
If DeleteFile(CheminStream+":"+NameStream)<>0
RemoveGadgetItem(#ListIcon_Stream, Index)
Else
MessageRequester("Error","Stream could not be erased!")
EndIf
EndIf
EndIf
Case #Button_OuvrirExplorateur
Index.l=GetGadgetState(#ListIcon_Stream)
If Index>-1
CheminStream.s=GetGadgetItemText(#ListIcon_Stream, Index , 3)
RunProgram("Explorer.exe","/ E, / select,"+CheminStream,"")
EndIf
Case #Button_Quitter
CloseWindow(#Window_Main)
Break
EndSelect
; / / / / / / / / / / / / / / / / / / / / / / / /
Case #PB_Event_CloseWindow
Select EventWindow()
Case #Window_Main
If FinRecherche=0
CloseWindow(#Window_Main)
Break
Else
MessageRequester("Info","Click the button Stop Scan before leaving!")
EndIf
EndSelect
EndSelect
ForEver
;
; }