nt net lib roteiro da apresentação: diagrama de fluxo de chamadas da api win32 explicação das...
TRANSCRIPT
NT Net Lib
Roteiro da apresentação:
• diagrama de fluxo de chamadas da API Win32
• explicação das chamadas
• apresentação da classe
Uma mini-biblioteca com as seguintes classes:
• Segurança de arquivos
• Percorrer diretório de arquivos
• Mudar entradas do Registry
File
ACL
SD
SID
Account Name Access Mask
LookupAccountName
InitializeAcl
AddAccessAllowedAce
SetSecurityDescriptorDacl
SetSecurityDescriptorOwner
InitializeSecurityDescriptor
SID
Account Name
SetFileSecurity
File Name
LookupAccountName
FileSecurity
LookupAccountName
PSID_NAME_USE peUse // address of SID-type indicatorLPDWORD cbReferencedDomainName // address of size of domain stringLPTSTR ReferencedDomainName // address of string for referenced domain LPDWORD cbSid // address of size of security identifierPSID Sid // address of security identifierLPCTSTR lpAccountName // address of string for account nameLPCTSTR lpSystemName // address of string for system name
pType \ aponta para um inteiro1000 & \ aponta para um inteiro cujo valor é 1000pDomain \ aponta para um buffer de 1000 bytes1000 &pSID \ aponta para um buffer de 1000 bytes" Administrator"" Susy"Call LookupAccountName .
InitializeAcl
DWORD dwAclRevision // revision level of access-control listDWORD nAclLength // size of access-control listPACL pAcl // address of access-control list
ACL_REVISION \ constante da API1000pACL \ aponta para um buffer de 1000 bytesCall InitializeAcl .
AddAccessAllowedAce
PSID pSid // address of security identifierDWORD AccessMask // access maskDWORD dwAceRevision // ACL revision levelPACL pAcl // address of access-control list
pSID FILE_GENERIC_READ \ constante da APIACL_REVISION \ constante da APIpACLCall AddAccessAllowedAce .
InitializeSecurityDescriptor
DWORD dwRevision // revision levelPSECURITY_DESCRIPTOR pSecurityDescriptor // address of security descriptor
SECURITY_DESCRIPTOR_REVISION \ constante da APIpSD \ aponta para um bufferCall InitializeSecurityDescriptor .
SetSecurityDescriptorOwner
BOOL fOwnerDefaulted // flag for defaultPSID psidOwner, // address of SID for ownerPSECURITY_DESCRIPTOR psd, // address of security descriptor
0 \ defaultpSID \ new ownerpSDCall SetSecurityDescriptorOwner .
SetSecurityDescriptorDacl
BOOL fDaclDefaulted // flag for default discretionary ACLPACL pAcl, // address of discretionary ACLBOOL fDaclPresent, // flag for presence of discretionary ACLPSECURITY_DESCRIPTOR psd, // address of security descriptor
0 \ defaultpACL1 \ presentpSDCall SetSecurityDescriptorDacl .
SetFileSecurity
PSECURITY_DESCRIPTOR psd // address of security descriptorSECURITY_INFORMATION si // type of information to setLPCTSTR lpszFile // address of string for filename
pSDDACL_SECURITY_INFORMATION OWNER_SECURITY_INFORMATION or" arquivo.txt" Call SetFileSecurity .
específico para arquivos:FILE_READ_DATAFILE_WRITE_DATAFILE_APPEND_DATAFILE_EXECUTE
específico para diretórios:FILE_LIST_DIRECTORYFILE_ADD_FILEFILE_ADD_SUBDIRECTORYFILE_TRAVERSEFILE_DELETE_CHILD
Access Mask
específico para ambos:FILE_READ_EAFILE_WRITE_EAFILE_READ_ATTRIBUTESFILE_WRITE_ATTRIBUTES
genérico:GENERIC_ALLGENERIC_EXECUTEGENERIC_READGENERIC_WRITE
geral:DELETE READ_CONTROL WRITE_DAC WRITE_OWNER SYNCHRONIZEACCESS_SYSTEM_SECURITY
Class FileSecurityAccountName Owner
AccountName Read
AccountName Change
FileName Set
1.
2.
3.
FileSecurity sysFile" Administrator" Owner: sysFile" Users" Read: sysFile" gaga.txt" Set: sysFile
Handle
Key Name
Value Name
RegOpenKeyEx
ValueHandle
Computer Name
RegConnectRegistry
RegSetValueEx
Registry EntryRegCloseKey
Registry
RegConnectRegistry
PHKEY phkResult // address of buffer for remote registry handle HKEY hKey, // predefined registry handle LPTSTR lpszComputerName, // address of name of remote computer
pConnectHandle \ aponta para um inteiroHKEY_LOCAL_MACHINE \ constante da API" SUSY"Call RegConnectRegistry .
RegOpenKeyEx
PHKEY phkResult // address of handle of open key REGSAM samDesired, // security access mask DWORD dwReserved, // reserved LPCTSTR lpszSubKey, // address of name of subkey to open HKEY hKey, // handle of open key
pKeyHandle \ aponta para um inteiroKEY_WRITE \ constante da API0 \ reservado" System\CurrentControlSet\Services\Browser"ConnectHandle \ o valor mesmoCall RegOpenKeyEx .
RegSetValueEx
DWORD cbData // size of value data CONST BYTE * lpData, // address of value data DWORD dwType, // flag for value type DWORD Reserved, // reserved LPCTSTR lpValueName, // address of value to set HKEY hKey, // handle of key to set value for
4 \ 4 bytes de dados2 & \ aponta para um inteiro cujo valor é 2REG_DWORD \ tipo é dword - constante da API0 \ reservado" Start"KeyHandle \ o valor mesmoCall RegSetValueEx .
Class RegistryClientNumber Connect
KeyName ValueName IntegerValue SetDWORD
KeyName ValueName StringValue SetSZ
KeyName ValueName StringValue SetESZ
1.
2.
3.
Registry remoto23 Connect: remoto" System\CurrentControlSet\Services\Browser” " Start" 2 SetDWORD: remotoDisconnect: remoto
Disconnect
FindNextFile
Handle
*.*
FindFirstFile
WIN32_FIND_DATA GetLastError
FindClose
SetCurrentDirectoryFILE_ATTRIBUTE_DIRECTORY
ERROR_NO_MORE_FILES
FALSETRUE
Browse
FindFirstFile
LPWIN32_FIND_DATA lpFindFileData // address of returned information LPCTSTR lpFileName, // address of name of file to search for
pFIND_DATA \ aponta para um buffer" *.*"Call FindFirstFile to hFindFile
FindNextFile
LPWIN32_FIND_DATA lpFindFileData // address of structure for data on found file HANDLE hFindFile, // handle of search
pFIND_DATA \ aponta para um bufferhFindFileCall FindNextFile .
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;
WIN32_FIND_DATA
dwFileAttributes
FILE_ATTRIBUTE_ARCHIVEFILE_ATTRIBUTE_COMPRESSEDFILE_ATTRIBUTE_DIRECTORYFILE_ATTRIBUTE_HIDDENFILE_ATTRIBUTE_NORMALFILE_ATTRIBUTE_READONLYFILE_ATTRIBUTE_SYSTEMFILE_ATTRIBUTE_TEMPORARY
SetCurrentDirectory
LPCTSTR lpszCurDir // address of name of new current directory
" Tese"Call SetCurrentDirectory .