use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class COMTest method testTYPEATTR.
public void testTYPEATTR() {
int pSize = Native.POINTER_SIZE;
TYPEATTR typeAttr = new TYPEATTR();
typeAttr.guid = GUID.fromString("{50A7E9B0-70EF-11D1-B75A-00A0C90564FE}");
typeAttr.lcid = Kernel32.INSTANCE.GetSystemDefaultLCID();
typeAttr.dwReserved = new DWORD(1);
typeAttr.memidConstructor = new MEMBERID(2);
typeAttr.memidDestructor = new MEMBERID(3);
typeAttr.lpstrSchema = new LPOLESTR("Hello World");
typeAttr.cbSizeInstance = new ULONG(4);
typeAttr.typekind = new TYPEKIND(5);
typeAttr.cFuncs = new WORD(6);
typeAttr.cVars = new WORD(7);
typeAttr.cImplTypes = new WORD(8);
typeAttr.cbSizeVft = new WORD(9);
typeAttr.cbAlignment = new WORD(10);
typeAttr.wMajorVerNum = new WORD(11);
typeAttr.wMinorVerNum = new WORD(12);
typeAttr.tdescAlias = new TYPEDESC();
typeAttr.idldescType = new IDLDESC();
typeAttr.write();
typeAttr.read();
//System.out.println(typeAttr.toString());
//System.out.println("TYPEATTR size: " + typeAttr.size());
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Advapi32Test method testMapGenericExecuteMask.
public void testMapGenericExecuteMask() {
final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
mapping.genericRead = new DWORD(FILE_GENERIC_READ);
mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_EXECUTE));
Advapi32.INSTANCE.MapGenericMask(rights, mapping);
assertEquals(FILE_GENERIC_EXECUTE, rights.getValue().intValue());
assertTrue(GENERIC_EXECUTE != (rights.getValue().intValue() & GENERIC_EXECUTE));
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Advapi32Test method testMapGenericReadMask.
public void testMapGenericReadMask() {
final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
mapping.genericRead = new DWORD(FILE_GENERIC_READ);
mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_READ));
Advapi32.INSTANCE.MapGenericMask(rights, mapping);
assertEquals(FILE_GENERIC_READ, rights.getValue().intValue());
assertTrue(GENERIC_READ != (rights.getValue().intValue() & GENERIC_READ));
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Advapi32Test method testMapGenericWriteMask.
public void testMapGenericWriteMask() {
final GENERIC_MAPPING mapping = new GENERIC_MAPPING();
mapping.genericRead = new DWORD(FILE_GENERIC_READ);
mapping.genericWrite = new DWORD(FILE_GENERIC_WRITE);
mapping.genericExecute = new DWORD(FILE_GENERIC_EXECUTE);
mapping.genericAll = new DWORD(FILE_ALL_ACCESS);
final DWORDByReference rights = new DWORDByReference(new DWORD(GENERIC_WRITE));
Advapi32.INSTANCE.MapGenericMask(rights, mapping);
assertEquals(FILE_GENERIC_WRITE, rights.getValue().intValue());
assertTrue(GENERIC_WRITE != (rights.getValue().intValue() & GENERIC_WRITE));
}
use of com.sun.jna.platform.win32.WinDef.DWORD in project jna by java-native-access.
the class Advapi32Test method testGetSetSecurityInfoForFileWithSACL.
public void testGetSetSecurityInfoForFileWithSACL() throws Exception {
boolean impersontating = false;
HANDLEByReference phToken = new HANDLEByReference();
HANDLEByReference phTokenDuplicate = new HANDLEByReference();
try {
// open thread or process token, elevate
if (!Advapi32.INSTANCE.OpenThreadToken(Kernel32.INSTANCE.GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES, false, phToken)) {
assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
// OpenThreadToken may fail with W32Errors.ERROR_NO_TOKEN if current thread is anonymous. When this happens,
// we need to open the process token to duplicate it, then set our thread token.
assertTrue(Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(), TOKEN_DUPLICATE, phToken));
// Process token opened, now duplicate
assertTrue(Advapi32.INSTANCE.DuplicateTokenEx(phToken.getValue(), TOKEN_ADJUST_PRIVILEGES | TOKEN_IMPERSONATE, null, SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, TOKEN_TYPE.TokenImpersonation, phTokenDuplicate));
// And set thread token.
assertTrue(Advapi32.INSTANCE.SetThreadToken(null, phTokenDuplicate.getValue()));
impersontating = true;
}
// Which token to adjust depends on whether we had to impersonate or not.
HANDLE tokenAdjust = impersontating ? phTokenDuplicate.getValue() : phToken.getValue();
WinNT.TOKEN_PRIVILEGES tp = new WinNT.TOKEN_PRIVILEGES(1);
WinNT.LUID pLuid = new WinNT.LUID();
assertTrue(Advapi32.INSTANCE.LookupPrivilegeValue(null, SE_SECURITY_NAME, pLuid));
tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(pLuid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED));
assertTrue(Advapi32.INSTANCE.AdjustTokenPrivileges(tokenAdjust, false, tp, 0, null, null));
assertTrue(Advapi32.INSTANCE.LookupPrivilegeValue(null, SE_RESTORE_NAME, pLuid));
tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(pLuid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED));
assertTrue(Advapi32.INSTANCE.AdjustTokenPrivileges(tokenAdjust, false, tp, 0, null, null));
// create a temp file
File file = createTempFile();
int infoType = OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION | DACL_SECURITY_INFORMATION | SACL_SECURITY_INFORMATION;
PointerByReference ppsidOwner = new PointerByReference();
PointerByReference ppsidGroup = new PointerByReference();
PointerByReference ppDacl = new PointerByReference();
PointerByReference ppSacl = new PointerByReference();
PointerByReference ppSecurityDescriptor = new PointerByReference();
String filePath = file.getAbsolutePath();
HANDLE hFile = WinBase.INVALID_HANDLE_VALUE;
try {
try {
hFile = Kernel32.INSTANCE.CreateFile(filePath, WinNT.ACCESS_SYSTEM_SECURITY | WinNT.GENERIC_WRITE | WinNT.WRITE_OWNER | WinNT.WRITE_DAC, WinNT.FILE_SHARE_READ, new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
assertEquals("GetSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.GetSecurityInfo(hFile, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner, ppsidGroup, ppDacl, ppSacl, ppSecurityDescriptor));
assertEquals("SetSecurityInfo(" + filePath + ")", 0, Advapi32.INSTANCE.SetSecurityInfo(hFile, AccCtrl.SE_OBJECT_TYPE.SE_FILE_OBJECT, infoType, ppsidOwner.getValue(), ppsidGroup.getValue(), ppDacl.getValue(), ppSacl.getValue()));
} finally {
if (hFile != WinBase.INVALID_HANDLE_VALUE)
Kernel32.INSTANCE.CloseHandle(hFile);
file.delete();
}
} finally {
Kernel32Util.freeLocalMemory(ppSecurityDescriptor.getValue());
}
if (impersontating) {
assertTrue("SetThreadToken", Advapi32.INSTANCE.SetThreadToken(null, null));
} else {
tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(pLuid, new DWORD(0));
assertTrue("AdjustTokenPrivileges", Advapi32.INSTANCE.AdjustTokenPrivileges(tokenAdjust, false, tp, 0, null, null));
}
} finally {
Kernel32Util.closeHandleRefs(phToken, phTokenDuplicate);
}
}
Aggregations