Hard to explain what this does :)
I use it in my console filemanager. The output is a string like in bash for each file
and directory:
means the file has attributes archiv, system, readonly.
means the directory has attribute system
I use it in my console filemanager. The output is a string like in bash for each file
and directory:
-as-r
means the file has attributes archiv, system, readonly.
d-s--
means the directory has attribute system
GetAttribString proc
; szDirBuffer == directory with terminating "\"
; ex: "C:\"
invoke lstrlen, addr szDirBuffer
lea edi, szDirBuffer
add edi, eax
mov byte ptr [edi], 42 ; *
; wfd == WIN32_FIND_DATA structure
invoke FindFirstFile, addr szDirBuffer, addr wfd
mov hFind, eax
; sz ListBuffer == buffer for storing the string
@@:
lea edi, szListBuffer
mov eax, wfd.dwFileAttributes
.if (eax & FILE_ATTRIBUTE_DIRECTORY)
mov byte ptr [edi], 100 ; d
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_ARCHIVE)
mov byte ptr [edi], 97 ; a
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_SYSTEM)
mov byte ptr [edi], 115 ; s
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_HIDDEN)
mov byte ptr [edi], 104 ; h
.else
mov byte ptr [edi], 45 ; -
.endif
inc edi
.if (eax & FILE_ATTRIBUTE_READONLY)
mov byte ptr [edi], 114 ; r
.else
mov byte ptr [edi], 45 ; -
.endif
invoke MessageBox, 0, addr szListBuffer, 0, 0 ; or do whatever you want
invoke RtlZeroMemory, addr szListBuffer, 512
invoke FindNextFile, hFind, addr wfd
invoke GetLastError
cmp eax, ERROR_NO_MORE_FILES
jne @B
invoke CloseHandle, hFind
ret
GetAttribString endp
Another method to avoid jumps and minimize memory writes :
mov edx, 'hsad'-'----'
bt eax, 4 ; FILE_ATTRIBUTE_DIRECTORY = 10h
sbb ecx, ecx ; if directory cl = FF else cf = 0
and dl, cl ; if directory dl = 'd'-'-' else dl = 0
; we will add '-' to have the correct result
; same thing
bt eax, 5 ; FILE_ATTRIBUTE_ARCHIVE = 20h
sbb ecx, ecx
and dh, cl
bswap edx
bt eax, 1 ; FILE_ATTRIBUTE_HIDDEN = 2
sbb ecx, ecx
and dl, cl
bt eax, 2 ; FILE_ATTRIBUTE_SYSTEM = 4
sbb ecx, ecx
and dh, cl
bswap edx
add edx, '----'
mov ecx, '-'
mov ebx, 'r'
bt eax, 0 ; FILE_ATTRIBUTE_READONLY = 1
cmovc ecx, ebx
mov [esi], edx
mov WORD PTR [esi+4], cx