NT Net Lib Uma mini-biblioteca com as seguintes classes: • Segurança de arquivos • Percorrer diretório de arquivos • Mudar entradas do Registry Roteiro da apresentação: • diagrama de fluxo de chamadas da API Win32 • explicação das chamadas • apresentação da classe FileSecurity Account Name Access Mask LookupAccountName Account Name SID LookupAccountName InitializeAcl SID AddAccessAllowedAce ACL File Name SetSecurityDescriptorOwner SetSecurityDescriptorDacl SetFileSecurity InitializeSecurityDescriptor SD File LookupAccountName PSID_NAME_USE peUse LPDWORD cbReferencedDomainName LPTSTR ReferencedDomainName LPDWORD cbSid PSID Sid LPCTSTR lpAccountName LPCTSTR lpSystemName pType \ aponta para 1000 & \ aponta para pDomain \ aponta para 1000 & pSID \ aponta para " Administrator" " Susy" Call LookupAccountName . // address of SID-type indicator // address of size of domain string // address of string for referenced domain // address of size of security identifier // address of security identifier // address of string for account name // address of string for system name um inteiro um inteiro cujo valor é 1000 um buffer de 1000 bytes um buffer de 1000 bytes InitializeAcl DWORD dwAclRevision DWORD nAclLength PACL pAcl ACL_REVISION 1000 pACL Call InitializeAcl . // revision level of access-control list // size of access-control list // address of access-control list \ constante da API \ aponta para um buffer de 1000 bytes AddAccessAllowedAce PSID pSid DWORD AccessMask DWORD dwAceRevision PACL pAcl // address of security identifier // access mask // ACL revision level // address of access-control list pSID FILE_GENERIC_READ \ constante da API ACL_REVISION \ constante da API pACL Call AddAccessAllowedAce . InitializeSecurityDescriptor DWORD dwRevision PSECURITY_DESCRIPTOR pSecurityDescriptor SECURITY_DESCRIPTOR_REVISION pSD Call InitializeSecurityDescriptor . // revision level // address of security descriptor \ constante da API \ aponta para um buffer SetSecurityDescriptorOwner BOOL fOwnerDefaulted PSID psidOwner, PSECURITY_DESCRIPTOR psd, 0 \ default pSID \ new owner pSD Call SetSecurityDescriptorOwner . // flag for default // address of SID for owner // address of security descriptor SetSecurityDescriptorDacl BOOL fDaclDefaulted PACL pAcl, BOOL fDaclPresent, PSECURITY_DESCRIPTOR psd, 0 \ default pACL 1 \ present pSD Call SetSecurityDescriptorDacl . // flag for default discretionary ACL // address of discretionary ACL // flag for presence of discretionary ACL // address of security descriptor SetFileSecurity PSECURITY_DESCRIPTOR psd SECURITY_INFORMATION si LPCTSTR lpszFile // address of security descriptor // type of information to set // address of string for filename pSD DACL_SECURITY_INFORMATION OWNER_SECURITY_INFORMATION or " arquivo.txt" Call SetFileSecurity . Access Mask genérico: GENERIC_ALL GENERIC_EXECUTE GENERIC_READ GENERIC_WRITE específico para arquivos: FILE_READ_DATA FILE_WRITE_DATA FILE_APPEND_DATA FILE_EXECUTE específico para ambos: FILE_READ_EA FILE_WRITE_EA FILE_READ_ATTRIBUTES FILE_WRITE_ATTRIBUTES específico para diretórios: FILE_LIST_DIRECTORY FILE_ADD_FILE FILE_ADD_SUBDIRECTORY FILE_TRAVERSE FILE_DELETE_CHILD geral: DELETE READ_CONTROL WRITE_DAC WRITE_OWNER SYNCHRONIZE ACCESS_SYSTEM_SECURITY Class FileSecurity 1. 2. 3. AccountName Owner AccountName Read AccountName Change FileName Set FileSecurity sysFile " Administrator" Owner: sysFile " Users" Read: sysFile " gaga.txt" Set: sysFile Registry Computer Name Key Name RegConnectRegistry Value Name Handle Value RegOpenKeyEx Handle RegSetValueEx RegCloseKey Registry Entry RegConnectRegistry PHKEY phkResult HKEY hKey, LPTSTR lpszComputerName, pConnectHandle HKEY_LOCAL_MACHINE " SUSY" Call RegConnectRegistry . // address of buffer for remote registry handle // predefined registry handle // address of name of remote computer \ aponta para um inteiro \ constante da API RegOpenKeyEx PHKEY phkResult REGSAM samDesired, DWORD dwReserved, LPCTSTR lpszSubKey, HKEY hKey, // address of handle of open key // security access mask // reserved // address of name of subkey to open // handle of open key pKeyHandle \ aponta para um inteiro KEY_WRITE \ constante da API 0 \ reservado " System\CurrentControlSet\Services\Browser" ConnectHandle \ o valor mesmo Call RegOpenKeyEx . RegSetValueEx DWORD cbData CONST BYTE * lpData, DWORD dwType, DWORD Reserved, LPCTSTR lpValueName, HKEY hKey, 4 2& REG_DWORD 0 " Start" KeyHandle Call RegSetValueEx . // size of value data // address of value data // flag for value type // reserved // address of value to set // handle of key to set value for \ \ \ \ 4 bytes de dados aponta para um inteiro cujo valor é 2 tipo é dword - constante da API reservado \ o valor mesmo RegCloseKey HKEY hKey KeyHandle Call RegCloseKey . // handle of key to close \ o valor mesmo Class Registry 1. ClientNumber Connect KeyName ValueName IntegerValue SetDWORD 2. KeyName ValueName StringValue SetSZ KeyName ValueName StringValue SetESZ 3. Disconnect Registry remoto 23 Connect: remoto " System\CurrentControlSet\Services\Browser” " Start" 2 SetDWORD: remoto Disconnect: remoto Browse *.* FindFirstFile Handle FindClose FindNextFile TRUE ERROR_NO_ MORE_FILES FALSE WIN32_FIND_DATA GetLastError FILE_ATTRIBUTE_DIRECTORY SetCurrentDirectory FindFirstFile LPWIN32_FIND_DATA lpFindFileData LPCTSTR lpFileName, pFIND_DATA " *.*" Call FindFirstFile to hFindFile // address of returned information // address of name of file to search for \ aponta para um buffer FindNextFile LPWIN32_FIND_DATA lpFindFileData HANDLE hFindFile, pFIND_DATA hFindFile Call FindNextFile . // address of structure for data on found file // handle of search \ aponta para um buffer WIN32_FIND_DATA typedef struct _WIN32_FIND_DATA { DWORD dwFileAttributes; FILETIME ftCreationTime; FILETIME ftLastAccessTime; FILETIME ftLastWriteTime; DWORD nFileSizeHigh; DWORD nFileSizeLow; DWORD dwReserved0; DWORD dwReserved1; TCHAR cFileName[ MAX_PATH ]; TCHAR cAlternateFileName[ 14 ]; } WIN32_FIND_DATA; dwFileAttributes FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_COMPRESSED FILE_ATTRIBUTE_DIRECTORY FILE_ATTRIBUTE_HIDDEN FILE_ATTRIBUTE_NORMAL FILE_ATTRIBUTE_READONLY FILE_ATTRIBUTE_SYSTEM FILE_ATTRIBUTE_TEMPORARY FindClose HANDLE hFindFile, hFindFile Call FindClose . // handle of search SetCurrentDirectory LPCTSTR lpszCurDir " Tese" Call SetCurrentDirectory . // address of name of new current directory GetLastError Call GetLastError . Class DirBrowse 1. 2. pAvoidList Avoid Show pFunction ProcessFiles DirBrowse List : PrintFileName CR Show: List ; \ definir função ' PrintFileName ProcessFiles: List \ executar função para cada arquivo