public abstract class Advapi32Util extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Advapi32Util.AccessCheckPermission |
static class |
Advapi32Util.Account
An account.
|
static class |
Advapi32Util.EnumKey |
static class |
Advapi32Util.EventLogIterator
An iterator for Event Log entries.
|
static class |
Advapi32Util.EventLogRecord
An event log record.
|
static class |
Advapi32Util.EventLogType
Event log types.
|
static class |
Advapi32Util.InfoKey |
Constructor and Description |
---|
Advapi32Util() |
Modifier and Type | Method and Description |
---|---|
static boolean |
accessCheck(File file,
Advapi32Util.AccessCheckPermission permissionToCheck)
Checks if the current process has the given permission for the file.
|
static void |
backupEncryptedFile(File src,
File destDir)
Backup an encrypted file or folder without decrypting it.
|
static String |
convertSidToStringSid(WinNT.PSID sid)
Convert a security identifier (SID) to a string format suitable for
display, storage, or transmission.
|
static byte[] |
convertStringSidToSid(String sidString)
Convert a string representation of a security identifier (SID) to a
binary format.
|
static void |
decryptFile(File file)
Decrypts an encrypted file or directory.
|
static void |
disableEncryption(File directory,
boolean disable)
Disables or enables encryption of the specified directory and the files in
it.
|
static void |
encryptFile(File file)
Encrypts a file or directory.
|
static int |
fileEncryptionStatus(File file)
Checks the encryption status of a file.
|
static Advapi32Util.Account |
getAccountByName(String accountName)
Retrieves a security identifier (SID) for the account on the current
system.
|
static Advapi32Util.Account |
getAccountByName(String systemName,
String accountName)
Retrieves a security identifier (SID) for a given account.
|
static Advapi32Util.Account |
getAccountBySid(String sidString)
Get an account name from a string SID on the local machine.
|
static Advapi32Util.Account |
getAccountBySid(String systemName,
String sidString)
Get an account name from a string SID.
|
static Advapi32Util.Account |
getAccountBySid(String systemName,
WinNT.PSID sid)
Get the account by SID.
|
static Advapi32Util.Account |
getAccountBySid(WinNT.PSID sid)
Get the account by SID on the local system.
|
static Advapi32Util.Account[] |
getCurrentUserGroups()
Return the group memberships of the currently logged on user.
|
static String |
getEnvironmentBlock(Map<String,String> environment)
Converts a map of environment variables to an environment block suitable
for
Advapi32.CreateProcessAsUser(com.sun.jna.platform.win32.WinNT.HANDLE, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, boolean, int, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.STARTUPINFO, com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION) . |
static WinNT.ACCESS_ACEStructure[] |
getFileSecurity(String fileName,
boolean compact) |
static WinNT.SECURITY_DESCRIPTOR_RELATIVE |
getFileSecurityDescriptor(File file,
boolean getSACL)
Gets a file's Security Descriptor.
|
static Memory |
getSecurityDescriptorForObject(String absoluteObjectPath,
int objectType,
boolean getSACL)
Get a self relative security descriptor for the given object type.
|
static Advapi32Util.Account |
getTokenAccount(WinNT.HANDLE hToken)
This function returns the information about the user who owns a security
token,
|
static Advapi32Util.Account[] |
getTokenGroups(WinNT.HANDLE hToken)
This function returns the groups associated with a security token, such
as a user token.
|
static String |
getUserName()
Retrieves the name of the user associated with the current thread.
|
static boolean |
isWellKnownSid(byte[] sidBytes,
int wellKnownSidType)
Compares a SID to a well known SID and returns TRUE if they match.
|
static boolean |
isWellKnownSid(String sidString,
int wellKnownSidType)
Compares a SID to a well known SID and returns TRUE if they match.
|
static void |
registryCloseKey(WinReg.HKEY hKey)
Close the registry key
|
static boolean |
registryCreateKey(WinReg.HKEY hKey,
String keyName)
Create a registry key.
|
static boolean |
registryCreateKey(WinReg.HKEY root,
String parentPath,
String keyName)
Create a registry key.
|
static void |
registryDeleteKey(WinReg.HKEY hKey,
String keyName)
Delete a registry key.
|
static void |
registryDeleteKey(WinReg.HKEY root,
String keyPath,
String keyName)
Delete a registry key.
|
static void |
registryDeleteValue(WinReg.HKEY hKey,
String valueName)
Delete a registry value.
|
static void |
registryDeleteValue(WinReg.HKEY root,
String keyPath,
String valueName)
Delete a registry value.
|
static byte[] |
registryGetBinaryValue(WinReg.HKEY hKey,
String value)
Get a registry REG_BINARY value.
|
static byte[] |
registryGetBinaryValue(WinReg.HKEY root,
String key,
String value)
Get a registry REG_BINARY value.
|
static String |
registryGetExpandableStringValue(WinReg.HKEY hKey,
String value)
Get a registry REG_EXPAND_SZ value.
|
static String |
registryGetExpandableStringValue(WinReg.HKEY root,
String key,
String value)
Get a registry REG_EXPAND_SZ value.
|
static int |
registryGetIntValue(WinReg.HKEY hKey,
String value)
Get a registry DWORD value.
|
static int |
registryGetIntValue(WinReg.HKEY root,
String key,
String value)
Get a registry DWORD value.
|
static WinReg.HKEYByReference |
registryGetKey(WinReg.HKEY root,
String keyPath,
int samDesired)
Get a registry key, the caller is responsible to close the key after use.
|
static String[] |
registryGetKeys(WinReg.HKEY hKey)
Get names of the registry key's sub-keys.
|
static String[] |
registryGetKeys(WinReg.HKEY root,
String keyPath)
Get names of the registry key's sub-keys.
|
static long |
registryGetLongValue(WinReg.HKEY hKey,
String value)
Get a registry QWORD value.
|
static long |
registryGetLongValue(WinReg.HKEY root,
String key,
String value)
Get a registry QWORD value.
|
static String[] |
registryGetStringArray(WinReg.HKEY hKey,
String value)
Get a registry REG_MULTI_SZ value.
|
static String[] |
registryGetStringArray(WinReg.HKEY root,
String key,
String value)
Get a registry REG_MULTI_SZ value.
|
static String |
registryGetStringValue(WinReg.HKEY hKey,
String value)
Get a registry REG_SZ value.
|
static String |
registryGetStringValue(WinReg.HKEY root,
String key,
String value)
Get a registry REG_SZ value.
|
static Object |
registryGetValue(WinReg.HKEY hkKey,
String subKey,
String lpValueName)
Get a registry value and returns a java object depending on the value
type.
|
static TreeMap<String,Object> |
registryGetValues(WinReg.HKEY hKey)
Get a table of registry values.
|
static TreeMap<String,Object> |
registryGetValues(WinReg.HKEY root,
String keyPath)
Get a table of registry values.
|
static boolean |
registryKeyExists(WinReg.HKEY root,
String key)
Checks whether a registry key exists.
|
static Advapi32Util.InfoKey |
registryQueryInfoKey(WinReg.HKEY hKey,
int lpcbSecurityDescriptor)
Queries the information about a specified key.
|
static Advapi32Util.EnumKey |
registryRegEnumKey(WinReg.HKEY hKey,
int dwIndex)
Queries the information about a specified key.
|
static void |
registrySetBinaryValue(WinReg.HKEY hKey,
String name,
byte[] data)
Set a binary value in registry.
|
static void |
registrySetBinaryValue(WinReg.HKEY root,
String keyPath,
String name,
byte[] data)
Set a binary value in registry.
|
static void |
registrySetExpandableStringValue(WinReg.HKEY hKey,
String name,
String value)
Set an expandable string value in registry.
|
static void |
registrySetExpandableStringValue(WinReg.HKEY root,
String keyPath,
String name,
String value)
Set a string value in registry.
|
static void |
registrySetIntValue(WinReg.HKEY hKey,
String name,
int value)
Set an integer value in registry.
|
static void |
registrySetIntValue(WinReg.HKEY root,
String keyPath,
String name,
int value)
Set an integer value in registry.
|
static void |
registrySetLongValue(WinReg.HKEY hKey,
String name,
long value)
Set a long value in registry.
|
static void |
registrySetLongValue(WinReg.HKEY root,
String keyPath,
String name,
long value)
Set a long value in registry.
|
static void |
registrySetStringArray(WinReg.HKEY hKey,
String name,
String[] arr)
Set a string array value in registry.
|
static void |
registrySetStringArray(WinReg.HKEY root,
String keyPath,
String name,
String[] arr)
Set a string array value in registry.
|
static void |
registrySetStringValue(WinReg.HKEY hKey,
String name,
String value)
Set a string value in registry.
|
static void |
registrySetStringValue(WinReg.HKEY root,
String keyPath,
String name,
String value)
Set a string value in registry.
|
static boolean |
registryValueExists(WinReg.HKEY root,
String key,
String value)
Checks whether a registry value exists.
|
static void |
setFileSecurityDescriptor(File file,
WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor,
boolean setOwner,
boolean setGroup,
boolean setDACL,
boolean setSACL,
boolean setDACLProtectedStatus,
boolean setSACLProtectedStatus)
Sets a file's Security Descriptor.
|
static void |
setSecurityDescriptorForObject(String absoluteObjectPath,
int objectType,
WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor,
boolean setOwner,
boolean setGroup,
boolean setDACL,
boolean setSACL,
boolean setDACLProtectedStatus,
boolean setSACLProtectedStatus)
Set a self relative security descriptor for the given object type.
|
public static String getUserName()
public static Advapi32Util.Account getAccountByName(String accountName)
accountName
- Specifies the account name.public static Advapi32Util.Account getAccountByName(String systemName, String accountName)
systemName
- Name of the system.accountName
- Account name.public static Advapi32Util.Account getAccountBySid(WinNT.PSID sid)
sid
- SID.public static Advapi32Util.Account getAccountBySid(String systemName, WinNT.PSID sid)
systemName
- Name of the system.sid
- SID.public static String convertSidToStringSid(WinNT.PSID sid)
sid
- SID bytes.public static byte[] convertStringSidToSid(String sidString)
sidString
- String SID.public static boolean isWellKnownSid(String sidString, int wellKnownSidType)
sidString
- String representation of a SID.wellKnownSidType
- Member of the WELL_KNOWN_SID_TYPE enumeration to compare with
the SID at pSid.public static boolean isWellKnownSid(byte[] sidBytes, int wellKnownSidType)
sidBytes
- Byte representation of a SID.wellKnownSidType
- Member of the WELL_KNOWN_SID_TYPE enumeration to compare with
the SID at pSid.public static Advapi32Util.Account getAccountBySid(String sidString)
sidString
- SID.public static Advapi32Util.Account getAccountBySid(String systemName, String sidString)
systemName
- System name.sidString
- SID.public static Advapi32Util.Account[] getTokenGroups(WinNT.HANDLE hToken)
hToken
- Token.public static Advapi32Util.Account getTokenAccount(WinNT.HANDLE hToken)
hToken
- Token.public static Advapi32Util.Account[] getCurrentUserGroups()
public static boolean registryKeyExists(WinReg.HKEY root, String key)
root
- HKEY_LOCAL_MACHINE, etc.key
- Path to the registry key.public static boolean registryValueExists(WinReg.HKEY root, String key, String value)
root
- HKEY_LOCAL_MACHINE, etc.key
- Registry key path.value
- Value name.public static String registryGetStringValue(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry path.value
- Name of the value to retrieve.public static String registryGetStringValue(WinReg.HKEY hKey, String value)
hKey
- Parent Key.value
- Name of the value to retrieve.public static String registryGetExpandableStringValue(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry path.value
- Name of the value to retrieve.public static String registryGetExpandableStringValue(WinReg.HKEY hKey, String value)
hKey
- Parent Key.value
- Name of the value to retrieve.public static String[] registryGetStringArray(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry path.value
- Name of the value to retrieve.public static String[] registryGetStringArray(WinReg.HKEY hKey, String value)
hKey
- Parent Key.value
- Name of the value to retrieve.public static byte[] registryGetBinaryValue(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry path.value
- Name of the value to retrieve.public static byte[] registryGetBinaryValue(WinReg.HKEY hKey, String value)
hKey
- Parent Key.value
- Name of the value to retrieve.public static int registryGetIntValue(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry key path.value
- Name of the value to retrieve.public static int registryGetIntValue(WinReg.HKEY hKey, String value)
hKey
- Parent key.value
- Name of the value to retrieve.public static long registryGetLongValue(WinReg.HKEY root, String key, String value)
root
- Root key.key
- Registry key path.value
- Name of the value to retrieve.public static long registryGetLongValue(WinReg.HKEY hKey, String value)
hKey
- Parent key.value
- Name of the value to retrieve.public static Object registryGetValue(WinReg.HKEY hkKey, String subKey, String lpValueName)
hkKey
- Root key.subKey
- Registry key path.lpValueName
- Name of the value to retrieve or null for the default value.public static boolean registryCreateKey(WinReg.HKEY hKey, String keyName)
hKey
- Parent key.keyName
- Key name.public static boolean registryCreateKey(WinReg.HKEY root, String parentPath, String keyName)
root
- Root key.parentPath
- Path to an existing registry key.keyName
- Key name.public static void registrySetIntValue(WinReg.HKEY hKey, String name, int value)
hKey
- Parent key.name
- Value name.value
- Value to write to registry.public static void registrySetIntValue(WinReg.HKEY root, String keyPath, String name, int value)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.value
- Value to write to registry.public static void registrySetLongValue(WinReg.HKEY hKey, String name, long value)
hKey
- Parent key.name
- Value name.value
- Value to write to registry.public static void registrySetLongValue(WinReg.HKEY root, String keyPath, String name, long value)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.value
- Value to write to registry.public static void registrySetStringValue(WinReg.HKEY hKey, String name, String value)
hKey
- Parent key.name
- Value name.value
- Value to write to registry.public static void registrySetStringValue(WinReg.HKEY root, String keyPath, String name, String value)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.value
- Value to write to registry.public static void registrySetExpandableStringValue(WinReg.HKEY hKey, String name, String value)
hKey
- Parent key.name
- Value name.value
- Value to write to registry.public static void registrySetExpandableStringValue(WinReg.HKEY root, String keyPath, String name, String value)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.value
- Value to write to registry.public static void registrySetStringArray(WinReg.HKEY hKey, String name, String[] arr)
hKey
- Parent key.name
- Name.arr
- Array of strings to write to registry.public static void registrySetStringArray(WinReg.HKEY root, String keyPath, String name, String[] arr)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.arr
- Array of strings to write to registry.public static void registrySetBinaryValue(WinReg.HKEY hKey, String name, byte[] data)
hKey
- Parent key.name
- Value name.data
- Data to write to registry.public static void registrySetBinaryValue(WinReg.HKEY root, String keyPath, String name, byte[] data)
root
- Root key.keyPath
- Path to an existing registry key.name
- Value name.data
- Data to write to registry.public static void registryDeleteKey(WinReg.HKEY hKey, String keyName)
hKey
- Parent key.keyName
- Name of the key to delete.public static void registryDeleteKey(WinReg.HKEY root, String keyPath, String keyName)
root
- Root key.keyPath
- Path to an existing registry key.keyName
- Name of the key to delete.public static void registryDeleteValue(WinReg.HKEY hKey, String valueName)
hKey
- Parent key.valueName
- Name of the value to delete.public static void registryDeleteValue(WinReg.HKEY root, String keyPath, String valueName)
root
- Root key.keyPath
- Path to an existing registry key.valueName
- Name of the value to delete.public static String[] registryGetKeys(WinReg.HKEY hKey)
hKey
- Registry key.public static String[] registryGetKeys(WinReg.HKEY root, String keyPath)
root
- Root key.keyPath
- Path to a registry key.public static WinReg.HKEYByReference registryGetKey(WinReg.HKEY root, String keyPath, int samDesired)
root
- Root key.keyPath
- Path to a registry key.samDesired
- Access level (e.g. WinNT.KEY_READ)public static void registryCloseKey(WinReg.HKEY hKey)
hKey
- Registry key.public static TreeMap<String,Object> registryGetValues(WinReg.HKEY hKey)
hKey
- Registry key.public static TreeMap<String,Object> registryGetValues(WinReg.HKEY root, String keyPath)
root
- Registry root.keyPath
- Regitry key path.public static Advapi32Util.InfoKey registryQueryInfoKey(WinReg.HKEY hKey, int lpcbSecurityDescriptor)
hKey
- Current registry key.lpcbSecurityDescriptor
- security descriptorpublic static Advapi32Util.EnumKey registryRegEnumKey(WinReg.HKEY hKey, int dwIndex)
hKey
- Current registry key.dwIndex
- public static String getEnvironmentBlock(Map<String,String> environment)
Advapi32.CreateProcessAsUser(com.sun.jna.platform.win32.WinNT.HANDLE, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES, boolean, int, java.lang.String, java.lang.String, com.sun.jna.platform.win32.WinBase.STARTUPINFO, com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION)
. This environment block consists
of null-terminated blocks of null-terminated strings. Each string is in
the following form: name=value\0environment
- Environment variablespublic static WinNT.ACCESS_ACEStructure[] getFileSecurity(String fileName, boolean compact)
public static Memory getSecurityDescriptorForObject(String absoluteObjectPath, int objectType, boolean getSACL)
absoluteObjectPath
- A pointer to a null-terminated string that specifies the name of the object
from which to retrieve security information. For descriptions of the string
formats for the different object types, see SE_OBJECT_TYPE in
AccCtrl.SE_OBJECT_TYPE
objectType
- Object type referred to by the path. See AccCtrl.SE_OBJECT_TYPE
for valid definitions.getSACL
- Get SACL of the object. See Advapi32.GetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference)
for process privilege requirements in getting the SACL.public static void setSecurityDescriptorForObject(String absoluteObjectPath, int objectType, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)
absoluteObjectPath
- A pointer to a null-terminated string that specifies the name of the object
from which to retrieve security information. For descriptions of the string
formats for the different object types, see AccCtrl.SE_OBJECT_TYPE
.objectType
- Object type referred to by the path. See AccCtrl.SE_OBJECT_TYPE
for valid definitions.securityDescriptor
- A security descriptor to set.setOwner
- Set the owner. The owner is extracted from securityDescriptor and must be valid,
otherwise IllegalArgumentException is throw.
See Advapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)
for process privilege requirements in getting the OWNER.setGroup
- Set the group. The group is extracted from securityDescriptor and must be valid,
otherwise IllegalArgumentException is throw.setDACL
- Set the DACL. The DACL is extracted from securityDescriptor and must be valid,
otherwise IllegalArgumentException is throw.setSACL
- Set the SACL. The SACL is extracted from securityDescriptor and must be valid,
otherwise IllegalArgumentException is throw.
See Advapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)
for process privilege requirements in getting the SACL.setDACLProtectedStatus
- Set DACL protected status as contained within securityDescriptor.control.setSACLProtectedStatus
- Set SACL protected status as contained within securityDescriptor.control.public static boolean accessCheck(File file, Advapi32Util.AccessCheckPermission permissionToCheck)
file
- the file to checkpermissionToCheck
- the permission to check for the filepublic static WinNT.SECURITY_DESCRIPTOR_RELATIVE getFileSecurityDescriptor(File file, boolean getSACL)
file
- File object containing a path to a file system object.getSACL
- Get the SACL. See Advapi32.GetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference, com.sun.jna.ptr.PointerByReference)
for process privilege requirements in getting the SACL.public static void setFileSecurityDescriptor(File file, WinNT.SECURITY_DESCRIPTOR_RELATIVE securityDescriptor, boolean setOwner, boolean setGroup, boolean setDACL, boolean setSACL, boolean setDACLProtectedStatus, boolean setSACLProtectedStatus)
file
- File object containing a path to a file system object.securityDescriptor
- The security descriptor to set.setOwner
- Set the owner. See Advapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)
for process privilege requirements in setting the owner.setGroup
- Set the group.setDACL
- Set the DACL.setSACL
- Set the SACL. See Advapi32.SetNamedSecurityInfo(java.lang.String, int, int, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer, com.sun.jna.Pointer)
for process privilege requirements in setting the SACL.setDACLProtectedStatus
- Set DACL protected status as contained within securityDescriptor.control.setSACLProtectedStatus
- Set SACL protected status as contained within securityDescriptor.control. *public static void encryptFile(File file)
file
- The file or directory to encrypt.public static void decryptFile(File file)
file
- The file or directory to decrypt.public static int fileEncryptionStatus(File file)
file
- The file to check the status for.public static void disableEncryption(File directory, boolean disable)
directory
- The directory for which to enable or disable encryption.disable
- TRUE to disable encryption. FALSE to enable it.public static void backupEncryptedFile(File src, File destDir)
src
- The encrypted file or directory to backup.destDir
- The directory where the backup will be saved.