Bonjour,
Ceci concerne seulement le système de fichiers NTFS de Windows.
Voici une procédure qui liste les Alternate Data Streams (ADStreams) d'un fichier ou d'un dossier dont le chemin est passé en paramètre.
(la procédure est conçue pour être exécutée sur OS Windows 32 bits, XP et suivants, ou 64 bits mais je ne l'ai testée que sur OS 32 bits)
Le résultat est une chaîne de caractères UNICODE composée d'autant de lignes qu'il y a de ADStreams (y compris ::$DATA).
Chaque ligne comprend 3 informations séparées par une tabulation:
» le nom complet de l'ADStreams,
» sa taille réelle,
» la taille allouée par NTFS.
Si il n'y a pas de ADStreams, le résultat est une chaîne UNICODE vide
Dans le code, les quelques commentaires mélangent anglais et français. En général, l'anglais est copier-coller à partir des pages de MSDN.
Voici les déclarations à insérer dans le traitement [Déclaration] d'une collection de procédures.
Code WLangage : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 IO_STATUS_BLOCK_32 est une structure // plateforme 32 bits : 4 + 4 octets IoStatus est un entier sur 4 octets // NTSTATUS Status Information est un entier système // ULONG_PTR Information; FILE_INFORMATION_CLASS FIN IO_STATUS_BLOCK_64 est une structure // plateforme 64 bits : 8 + 8 octets // union { NTSTATUS Status; PVOID Pointer; } ==> 8 octets IoStatus est un entier sur 4 octets // NTSTATUS Status Padding32 est un entier sur 4 octets // union PVOID Pointer (pour câler sur 8 octets) Information est un entier système // ULONG_PTR Information; FILE_INFORMATION_CLASS FIN CONSTANTE FileStreamInformation = 22 MAX_PATH = 260 // 260 caractères INVALID_HANDLE_VALUE = -1 //(HANDLE)-1 STATUS_BUFFER_OVERFLOW = 234 STATUS_SUCCESS = 0 // File Creation Disposition CREATE_NEW = 1 CREATE_ALWAYS = 2 OPEN_EXISTING = 3 OPEN_ALWAYS = 4 TRUNCATE_EXISTING = 5 // File Flags and Attributes FILE_FLAG_BACKUP_SEMANTICS = 0x02000000 FILE_SHARE_DELETE = 0x00000004 FILE_SHARE_READ = 0x00000001 FILE_SHARE_WRITE = 0x00000002 FIN FILE_STREAM_INFORMATION est une structure NextEntryOffset est un entier sans signe sur 4 octets StreamNameLength est un entier sans signe sur 4 octets // Length, in bytes, of the StreamName string. StreamSize est un entier sur 8 octets StreamAllocationSize est un entier sur 8 octets StreamName est une chaîne UNICODE sur MAX_PATH // caractères UNICODE codés sur 2 octets FIN // Creates or opens a file or I/O device (file, file stream, directory, physical disk, volume, console buffer, tape drive, communications resource, mailslot, pipe). // The function returns a handle that can be used to access the file or device for various types of I/O depending on the file or device and the flags and attributes specified. CreateFileW est une Description d'API CreateFileW..NomDLL = "kernel32" CreateFileW..NomFonction = "CreateFileW" CreateFileW..TypeRetour = apiEntierSystème // HANDLE open handle to the specified file, device, named pipe, or mail slot. // (if the function fails, the return value is INVALID_HANDLE_VALUE) CreateFileW..Paramètre[1]..Type = apiEntierSystème // LPCTSTR lpFileName CreateFileW..Paramètre[2]..Type = apiEntier_4 // DWORD dwDesiredAccess CreateFileW..Paramètre[3]..Type = apiEntier_4 // DWORD dwShareMode CreateFileW..Paramètre[4]..Type = apiEntierSystème // LPSECURITY_ATTRIBUTES lpSecurityAttributes CreateFileW..Paramètre[5]..Type = apiEntier_4 // DWORD dwCreationDisposition CreateFileW..Paramètre[6]..Type = apiEntier_4 // DWORD dwFlagsAndAttributes CreateFileW..Paramètre[7]..Type = apiEntierSystème // HANDLE hTemplateFile // Returns various kinds of information about a file object NtQueryInformationFile est une Description d'API NtQueryInformationFile..NomDLL = "ntdll" NtQueryInformationFile..NomFonction = "NtQueryInformationFile" NtQueryInformationFile..TypeRetour = apiEntier_4 // NTSTATUS is a standard 32-bit datatype for system-supplied status code values NtQueryInformationFile..Paramètre[1]..Type = apiEntierSystème // HANDLE FileHandle NtQueryInformationFile..Paramètre[2]..Type = apiEntierSystème // PIO_STATUS_BLOCK IoStatusBlock (pointeur sur IO_STATUS_BLOCK_32 ou IO_STATUS_BLOCK_64) NtQueryInformationFile..Paramètre[3]..Type = apiEntierSystème // PVOID FileInformation (pointeur sur buffer) NtQueryInformationFile..Paramètre[4]..Type = apiEntier_4 // ULONG Length NtQueryInformationFile..Paramètre[5]..Type = apiEntier_4 // FILE_INFORMATION_CLASS FileInformationClass (valeurs d'énumération codée sur 4 octets) // Closes an open object handle CloseHandle est une Description d'API CloseHandle..NomDLL = "kernel32" CloseHandle..NomFonction = "CloseHandle" CloseHandle..TypeRetour = apiEntier_4 // BOOL If the function succeeds, the return value is nonzero. CloseHandle..Paramètre[1]..Type = apiEntierSystème // HANDLE hObject
Voici la procédure à ajouter dans la collection de procédures.
Code WLangage : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 PROCEDURE EnumerateStreams(sFilepath est une chaîne UNICODE) // chaîne UNICODE xsIOStatusBlock_32 est un IO_STATUS_BLOCK_32 <utile> // variante pour OS 32 bits xsIOStatusBlock_64 est un IO_STATUS_BLOCK_64 <utile> // variante pour OS 64 bits sVarNameIOStatusBlock est une chaîne pIOStatusBlock est un entier système xbData est un Buffer xsStreamInfo est un FILE_STREAM_INFORMATION pStreamInfo, pData, hFile est un entier système nBufferSize, nErrorCode, nNameLength est un entier sStreamList est une chaîne UNICODE // le flag FILE_FLAG_BACKUP_SEMANTICS est nécessaire pour accéder aussi aux ADStreams d'un dossier hFile = CreateFileW(&sFilepath,0,0,0,OPEN_EXISTING,FILE_FLAG_BACKUP_SEMANTICS,0) SI hFile = INVALID_HANDLE_VALUE ALORS RENVOYER sStreamList // cibler les OS 32 bits ou 64 bits en fonction de la taille d'un entier système // (sans utiliser un code-cible conditionnel) sVarNameIOStatusBlock = "xsIOStatusBlock_" + (Dimension(hFile)=4 ? "32" SINON "64") pIOStatusBlock = &{sVarNameIOStatusBlock,indVariable} BOUCLE nBufferSize += 4096 // augmenter la taille du buffer de 4 Ko xbData = Répète(0c00,nBufferSize) // allouer la mémoire pData = & xbData nErrorCode = NtQueryInformationFile(hFile,pIOStatusBlock,pData,nBufferSize,FileStreamInformation) A FAIRE TANTQUE nErrorCode = STATUS_BUFFER_OVERFLOW SI nErrorCode <> STATUS_SUCCESS _OU_ {sVarNameIOStatusBlock,indVariable}:Information = 0 ALORS RENVOYER sStreamList pStreamInfo = &xsStreamInfo BOUCLE Transfert(pStreamInfo,pData,24) SI xsStreamInfo.StreamNameLength=0 ALORS SORTIR nNameLength = Min(xsStreamInfo.StreamNameLength,MAX_PATH) Transfert(pStreamInfo+24,pData+24,nNameLength) sStreamList += [RC] + Gauche(xsStreamInfo:StreamName,nNameLength/2) + TAB + xsStreamInfo:StreamSize + TAB + xsStreamInfo:StreamAllocationSize SI xsStreamInfo.NextEntryOffset = 0 ALORS SORTIR pData += xsStreamInfo:NextEntryOffset // Jump to next stream FIN SI sStreamList <> "" ALORS Info(sStreamList) RENVOYER sStreamList FIN: SI hFile <> INVALID_HANDLE_VALUE ALORS CloseHandle(hFile)
Ce code est une adaptation dont voici les sources.
NTFS Data Streams: the true way to hide information and extend your file system
http://www.planetsourcecode.com/vb/d...47299&lngWId=1
cf. procédure NTQIF
Project Jedi
http://www.delphi-jedi.org/
cf. UADStreams.pas
Partager