Comparar commits
2 Commits
| Autor | SHA1 | Data | |
|---|---|---|---|
| a251bf9386 | |||
| bcc1f602e1 |
@@ -1,17 +0,0 @@
|
||||
build
|
||||
build-d64
|
||||
build.eclipse
|
||||
build.number
|
||||
.metadata
|
||||
.DS_Store
|
||||
bin
|
||||
contrib/ntservice/dist
|
||||
contrib/platform/dist
|
||||
doc
|
||||
*~
|
||||
**/*~
|
||||
dist/*.asc
|
||||
dist/*-sources.jar
|
||||
dist/*-javadoc.jar
|
||||
dist/src-mvn.zip
|
||||
dist/out-of-date.jar
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>jnalib</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
-593
@@ -1,593 +0,0 @@
|
||||
Release 3.5.0
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
* `Structure.getFieldOrder()` supersedes `Structure.setFieldOrder()` and is now required - [@twall](https://github.com/twall).
|
||||
* Search `~/Library/Frameworks` and `/Library/Frameworks` on OSX - [@shaneholloway](https://github.com/shaneholloway).
|
||||
* Automatic cleanup of native threads (based on suggestions from neil smith) - [@twall](https://github.com/twall).
|
||||
* Add `android-arm` target - [@ochafik](https://github.com/ochafik), [@twall](https://github.com/twall).
|
||||
* Add `jna.tmpdir` to override temporary JNA storage location - [@twall](https://github.com/twall).
|
||||
* Add `EXTRA_MAKE_OPTS` ant property to override make variables - [@twall](https://github.com/twall).
|
||||
* Add `Library.OPTION_OPEN_FLAGS` to customize dlopen behavior - [@twall](https://github.com/twall).
|
||||
* [#113](https://github.com/twall/jna/issues/113), [#114](https://github.com/twall/jna/issues/114): Add support for GNU/kFreeBSD and debian multi-arch distros - [@twall](https://github.com/twall).
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
* Fix `Advapi32Util.registryGetValues()` tried to allocate memory for a zero-length `REG_BINARY` value - [@phailwhale22](https://github.com/phailwhale22).
|
||||
* Fix crash in direct mode callbacks with certain type conversions - [@twall](https://github.com/twall).
|
||||
* More thoroughly propagate unexpected exceptions generated in jnidispatch - [@twall](https://github.com/twall).
|
||||
* Cleanup maven poms and publishing to central repo - [@bhamail](https://github.com/bhamail).
|
||||
* [#129](https://github.com/twall/jna/issues/129): Allow `Memory` field in structure - [@twall](https://github.com/twall).
|
||||
* Preserve `PointerType` fields on `Structure.read()` if unchanged - [@twall](https://github.com/twall).
|
||||
* [#128](https://github.com/twall/jna/issues/128): Fix masking extracting DWORD upper and lower WORD values - [@twall](https://github.com/twall).
|
||||
* [#135](https://github.com/twall/jna/issues/135): Fix for `Advapi32Util.registryGetValues()` when reading zero length values - [@danwi](https://github.com/danwi).
|
||||
|
||||
Release 3.4.2
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
* Add `platform.win32.Kernel32.GetEnvironmentVariable` and `platform.win32.Kernel32Util.getEnvironmentVariable` - [@dblock](https://github.com/dblock).
|
||||
* Moved `Kernel32.dll` function definitions from `WinNT.java` into `Kernel32.java` - [@dblock](https://github.com/dblock).
|
||||
* Provide `toPointer()` methods on all `_PTR` types (platform win32) - [@twall](https://github.com/twall).
|
||||
* Provide `ant -Dskip-native` to skip platform native build - [@twall](https://github.com/twall).
|
||||
* Provide `ant -Dheadless=true` to run unit tests headless - [@twall](https://github.com/twall).
|
||||
* Added Windows dev environment instructions - [@twall](https://github.com/twall).
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
* Ensure platform win32 classes use unsigned where appropriate (`ULONG_PTR`, `UINT_PTR`, `ULONGLONG`, `WORD`, `DWORDLONG`) - [@twall](https://github.com/twall).
|
||||
* [#71](https://github.com/twall/jna/issues/71), [#73](https://github.com/twall/jna/issues/73): Fix OSGI entries in manifest - [@twall](https://github.com/twall).
|
||||
* [#78](https://github.com/twall/jna/issues/78): Fix NPE in `platform.win32.Netapi32Util.getDomainTrusts` - [@dblock](https://github.com/dblock).
|
||||
* Fix: auto-sync memory for `struct**` arguments (array of struct pointers) - [@twall](https://github.com/twall).
|
||||
* Fix: `platform.win32.Secur32.AcquireCredentialsHandle`, `InitializeSecurityContext` and `AcceptSecurityContext` on Win32 64-bit - [@dblock](https://github.com/dblock).
|
||||
* Fix: avoid overwriting native `char *` or `wchar_t *` fields within structures when unmodified (similar to current operation with pointers) - [@twall](https://github.com/twall).
|
||||
* Fix: `platform.win32.DsGetDC.DS_DOMAIN_TRUSTS` and `DsEnumerateDomainTrusts` on Win32 64-bit - [@trejkaz](https://github.com/trejkaz).
|
||||
* Fix: Crash freeing the wrong pointer in `Netapi32Util.getDomainTrusts` - [@trejkaz](https://github.com/trejkaz).
|
||||
* [#100](https://github.com/twall/jna/issues/100): Fix `platform.win32.W32FileMonitor` - [@dblock](https://github.com/dblock).
|
||||
* Return INT_PTR from `platform.win32.Shell32.ShellExecute`, since returning
|
||||
`HINSTANCE` is useless.
|
||||
* Fix runtime error in some instances where Structure.setFieldOrder is used (never return self when sharing AutoAllocated memory).
|
||||
* [#107](https://github.com/twall/jna/issues/107): `Structure.clear()` always calls `ensureAllocated()` to avoid NPE.
|
||||
* Ensure internal memory pointer is *always* allocated when calling `Structure.useMemory()`, even if layout is not yet determined.
|
||||
|
||||
Release 3.4.1
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
* Add 'unsigned' modifier to IntegerType.
|
||||
* Add to `platform.win32.User32`: `GetLastInputInfo`.
|
||||
* Add `platform.win32.WinNT.GetFileType` and `platform.win32.Kernel32Util.getFileType`.
|
||||
* Add to `platform.win32.Kernel32Util`: `getFileType`.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
* Re-build linux-amd and linux-i386 against older versions of glibc (2.2.5 and
|
||||
2.1.3 respectively).
|
||||
* Properly initialize first printer info struct in winspool library.
|
||||
* Properly support getting and setting zero-array-length `REG_MULTI_SZ` values on Win32.
|
||||
* Fixed SID in Win32 `USER_INFO_23` and `GROUP_INFO_3`.
|
||||
* Fixed passing domain name into Win32 `Netapi32Util.getUserInfo`.
|
||||
|
||||
Release 3.4.0
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
* Provide `jna.nosys=true` to avoid loading any system-provided JNA (useful for local build/development).
|
||||
* Allow override of default jnidispatch library name with `jna.boot.library.name` system property.
|
||||
* Throw an Error if a system install of JNA is incompatible or if JNA's JNI library does not match.
|
||||
* Disable automatic jnidispatch unpacking with `jna.nounpack=true`.
|
||||
* Automatically look up system error messages for LastErrorException.
|
||||
* Improved callback thread-mapping support; re-use, rename, and group callback
|
||||
threads.
|
||||
* Cache structure layout results, improving performance of structure creation.
|
||||
* linux/arm 32-bit support (hardware provided by Alex Lam).
|
||||
* linux/ppc 32-bit support (hardware provided by Fritiof Hedman).
|
||||
* Preliminary linux/ia64, linux/ppc64 support (thanks to Laurent Guerby and the GCC compile farm).
|
||||
* Windows CE/Mobile support (w32ce-arm) (resources provided by andrea antonello and Hydrologis SRL).
|
||||
* linux multi-arch support (kohsuke).
|
||||
* Added REG_QWORD registry type support
|
||||
* Add to `platform.unix.x11`: `XGrabKey`, `XUngrabKey`, `XSetErrorHandler`.
|
||||
* Add to `platform.mac.Carbon`: `GetEventDispatcherTarget`, `InstallEventHandler`, `RegisterEventHotKey`, `GetEventParameter`, `RemoveEventHandler`, `UnregisterEventHotKey`.
|
||||
* Add to `platform.win32.Kernel32`: `CopyFile`, `MoveFile`, `MoveFileEx`, `CreateProcess`, `SetEnvironmentVariables`, `GetFileTime`, `SetFileTime`, `SetFileAttributes`, `DeviceIoControl`, `GetDiskFreeSpaceEx`, `CreateToolhelp32Snapshot`, `Process32First`, `Process32Next`.
|
||||
* Add to `platform.win32.Msi`: `MsiGetComponentPath`, `MsiLocateComponent`, `MsiGetProductCode`, `MsiEnumComponents`.
|
||||
* Add to `platform.win32.User32`: `RegisterHotKey`, `UnregisterHotKey`
|
||||
* Add to `platform.win32.SetupApi`: `SetupDiGetClassDevs`, `SetupDiDestroyDeviceInfoList`, `SetupDiEnumDeviceInterfaces`, `SetupDiGetDeviceInterfaceDetail`, `SetupDiGetDeviceRegistryProperty`.
|
||||
* Add `platform.win32.Shell32.ShellExecute`.
|
||||
* Add to `platform.win32.User32`: `SetParent`, `IsWindowVisible`, `MoveWindow`, `SetWindowPos`, `AttachInputThread`, `SetForegroundWindow`, `GetForegroundWindow`, `SetFocus`, `SendInput`, `WaitForInputIdle`, `InvalidateRect`, `RedrawWindow`, `GetWindow`, `UpdateWindow`, `ShowWindow`, `CloseWindow`.
|
||||
* Add to `platform.win32.Version`: `GetFileVersionInfoSize`, `GetFileVersionInfo`, `VerQueryValue`.
|
||||
* Add to `platform.win32.Advapi32`: `GetFileSecurity`, `RegQueryValueEx(...Long...)`.
|
||||
* Add to `platform.win32.Netapi32`: `NetUserGetInfo`.
|
||||
|
||||
Bug Fixes
|
||||
--------
|
||||
* Revise cleanup of in-use temporary files on win32 (issue 6).
|
||||
* Fix structure alignment issues on linux/ppc.
|
||||
* Fix structure alignment issues on linux/arm.
|
||||
* Account for NIO Buffer position (JIRA issue 185).
|
||||
* Avoid crash with very long Strings (> 150k in length).
|
||||
* Fix bug tracking Memory with an associated direct ByteBuffer.
|
||||
* Fix bug handling structs by value when type mappers are in effect (JIRA issue 188).
|
||||
|
||||
Release 3.3.0
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Facilitate `Memory` subclasses (jbellis).
|
||||
* Allow multiple fields of the same type in Unions (Francis Barber).
|
||||
* Add `platform.win32.Advapi32.AdjustTokenPrivileges`, `platform.win32.Advapi32.LookupPrivilegeName`, `platform.win32.Advapi32.LookupPrivilegeValue`, `platform.win32.Advapi32.ImpersonateSelf`.
|
||||
* Add `platform.win32.Advapi32.DuplicateTokenEx`, `platform.win32.Advapi32.CreateProcessAsUser`, `platform.win32.Kernel32.GetExitCodeProcess`, `platform.win32.Kernel32.TerminateProcess`, `platform.win32.Kernel32.ReadFile`, `platform.win32.Kernel32.CreatePipe`, `platform.win32.Kernel32.SetHandleInformation` and related constants / structures in `platform.win32.WinBase` and `platform.win32.WinNT`. Please note that the `SECURITY_ATTRIBUTES` structure has been moved from `platform.win32.WinNT` to `platform.win32.WinBase`.
|
||||
* Add `platform.win32.Kernel32.DeleteFile` and `platform.win32.Kernel32Util.deleteFile`.
|
||||
* Add `platform.win32.Kernel32.GetFileAttributes` and `platform.win32.Kernel32Util.getFileAttributes`.
|
||||
* Add `platform.win32.Kernel32.GetTickCount`.
|
||||
* Add Win32 Service functions to `platform.win32.Advapi32`.
|
||||
* Add `platform.win32.W32ServiceManager` and `W32Service`.
|
||||
* Add Win32 Event Logging functions to `platform.win32.Advapi32` and `platform.win32.Advapi32Util.EventLogIterator`.
|
||||
* `platform.win32.Advapi32Util.registryCreateKey` returns `true` if key was created, `false` if it already exists.
|
||||
* Add `REG_BINARY`, `REG_EXPAND_SZ` and `REG_MULTI_SZ` support to `platform.win32.Advapi32Util` registry functions.
|
||||
* Reduce JNI crossings in a number of native methods, moving object creation out into pure Java code.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Move all native functions into `com.sun.jna.Native`, to ensure that all dependent classes must be disposed before the `Native` class is unloaded. Note that this change is incompatible with all previous JNA native libraries.
|
||||
* Fix `platform.win32.Kernel32.GetNativeSystemInfo` and `GetSystemInfo` AV on Win64.
|
||||
* Fix several potential minor bugs as reported by TvT.
|
||||
* Fix bug in Structure.StructureSet.toString (Blair Zajac), exposed by Tomcat ThreadLocal cleanup.
|
||||
* Fix several bugs when using Structure(Pointer) ctor and array fields (Samuel Audet).
|
||||
|
||||
Release 3.2.7
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Add native peer value accessors for Pointer
|
||||
* The `jna.library.path` property is now re-evaluated whenever a native library is loaded. Previously this value was cached when the JNA classes loaded.
|
||||
* `Native.loadLibrary` can now load `.drv` files.
|
||||
* Refactor `com.sun.jna.platform.win32.WINBASE` into `WinDef`, `WinNT` and `BaseTSD`, matching Windows SDK headers.
|
||||
* Refactor constants from `com.sun.jna.platform.win32.GDI32` into `WinGDI`, matching Windows SDK headers.
|
||||
* Refactor constants from `com.sun.jna.platform.win32.User32` into `WinUser`, matching Windows SDK headers.
|
||||
* Refactor `platform.win32.WinNT.LARGE_INTEGER` into a union.
|
||||
* Add `platform.win32.ObjBase`, `com.sun.jna.platform.win32.Ole32.CoInitializeEx`, `CoUninitialize`, and `CoCreateInstance`.
|
||||
* Add `platform.win32.Oleaut32.SysAllocString` and `SysFreeString`.
|
||||
* Add `platform.win32.Secur32.ImpersonateSecurityContext` and `RevertSecurityContext`.
|
||||
* Add `platform.win32.WinNT.WELL_KNOWN_SID_TYPE`, `SECURITY_MAX_SID_SIZE` and other related SID-related constants.
|
||||
* Add `platform.win32.Advapi32.CreateWellKnownSid` and `IsWellKnownSid` and `com.sun.jna.platform.win32.Advapi32Util.isWellKnownSid`.
|
||||
* Add `platform.win32.Kernel32.GetVersion`, `GetVersionEx`, `GetSystemInfo`, `GetNativeSystemInfo`, `GlobalMemoryStatusEx`, `GetLogicalDriveStrings` and `IsWow64Process`.
|
||||
* Add `platform.win32.Kernel32Util.getLogicalDriveStrings`.
|
||||
* Add `platform.win32.User32.GetSystemMetrics`.
|
||||
* Add `platform.win32.BaseTSD.DWORD_PTR`.
|
||||
* Add `platform.win32.WinBase.SYSTEM_INFO` and `MEMORYSTATUSEX`.
|
||||
* Add `platform.win32.WinNT.OSVERSIONINFOEX`, `VER` constants.
|
||||
* Add `platform.win32.WinDef.ULONGLONG` and `DWORDLONG`.
|
||||
* Add `platform.win32.Shell32.SHGetDesktopFolder` (prep work for Com4JNA).
|
||||
* Add `platform.win32.Winspool.GetPrinterInfo`.
|
||||
* Add `platform.win32.WinspoolUtil.getPrinterInfo1`.
|
||||
* Add `platform.win32.GDI32.GetDeviceCaps`.
|
||||
* Add `platform.win32.GDI32.GetDIBits`.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix `ClassCastException` in `Structure.equals` (issue 152).
|
||||
* Fix bug initializing a structure object from existing memory when the structure has initialized fields (issue 133).
|
||||
* Fix NPE reading an array of string from a pointer when an element of the array is `NULL` (issue 151).
|
||||
* Avoid calling `UnregisterNatives` in native code (issue 154).
|
||||
* Compare unpacked library path against canonical (long) filename (issue 156).
|
||||
* Fix `read()` of uninitialized memory in `platform.win32.Advapi32Util.getTokenGroups` and `getTokenAccount`.
|
||||
* Fix `com.sun.jna.platform.win32.Secur32.QuerySecurityContextToken` to take a `CtxtHandle` instead of `PSecHandle`.
|
||||
* Fix definition of BITMAPINFO (platform/win32).
|
||||
|
||||
Release 3.2.5
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Split code in examples.jar into a contrib platform.jar package and individual packages for demos.
|
||||
* Fix Eclipse build and added Eclipse projects for all contrib samples, import projects from jnalib and contrib.
|
||||
* Ensure Structure fields correctly ordered when inherited.
|
||||
* Use explicit Structure field whenever provided, regardless of whether the VM requires it.
|
||||
* Add Win32 mappings for two dozen functions from Kernel32.dll, Advapi32.dll, Netapi32.dll, Secur32.dll, NtDll.dll, Ole32.dll, Shell32.dll and Crypt32.dll to com.sun.jna.platform.win32.
|
||||
* Port parts of WinError.h, WinNT.h, LMAccess.h, LMCons.h, LMErr.h, LMJoin.h, NTStatus.h, ShlObj.h, WinDef.h, ShellApi.h, Wdm.h, WinReg.h, WinCrypt.h, Sspi.h, Guid.h, NtSecApi.h and DsGetDc.h.
|
||||
* Add Win32 simplified utility interfaces Kernel32Util, Advapi32Util, Netapi32Util, Crypt32Util, NtDllUtil, Shell32Util, Ole32Util and Secur32Util to com.sun.jna.platform.win32.
|
||||
* Support unicode paths in W32FileUtils.
|
||||
* Fix exception during dispose in W32FileMonitor.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Provide String.replace for 1.4 compatibility.
|
||||
* Avoid allocating memory when Structure is provided a pointer in the ctor.
|
||||
* Ensure proper value returned in Pointer.getValue() for non-null, unchanged NIO Buffer values.
|
||||
* Use 1.4-compatible URI generation (issue 149).
|
||||
|
||||
Release 3.2.4
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Make Pointer ctor public.
|
||||
* Provide access to Function objects for arbitrary Pointer values.
|
||||
* Add linux/ia64 binaries (bpiwowar). See issue 134 patch.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Use a more robust method to decode a file-based URL (issue 135).
|
||||
|
||||
Release 3.2.3
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Include version information in code in case package information lost.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix WindowUtils exception on mouse over TrayIcon.
|
||||
* Fix bug toggling windows transparent/opaque (win32/OSX).
|
||||
* Avoid overwriting unchanged Pointer values in arrays (function calls with Pointer[] and Structure.read).
|
||||
* Ensure Structure fields marked `final` are never written.
|
||||
* Fix bug preventing proper population Structure.ByReference fields on Structure read.
|
||||
* Ensure double buffering is disabled in components added to a transparent window.
|
||||
* Fix UnsatisfiedLinkError attempting to load system libraries under Web Start.
|
||||
* Fix loading Web Start-provided libraries on OSX (libraries must have a .jnilib suffix under Web Start).
|
||||
* Properly include sources in Maven zip file (Issue 129).
|
||||
|
||||
Release 3.2.2
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Provide length-specified Pointer.getStringArray()
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix crash with direct mapping if NULL struct* used (Issue 125).
|
||||
* Fix case where null-valued Structure fields would get non-null values on write.
|
||||
* Synch callback Structure/Structure[] arguments on callback return.
|
||||
* Fix NPE when mapping an interface to the current process.
|
||||
* Automatically load proper C library version from current process on Linux (avoids crashing bug on Ubuntu with libc-i686 packages active).
|
||||
* Avoid scanning structure contents in Structure.toString if contents aren't actually used.
|
||||
|
||||
Release 3.2.1
|
||||
==========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Add HRESULT, LONG mapping to W32API (marc strapetz).
|
||||
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix definition of HWND_BROADCAST in W32API.
|
||||
* Fix memory alignment checking (Issue 121).
|
||||
* Fix Structure equals/hashCode implementation, based on current Java fields rather than strictly native memory contents. Avoid using equals/hashCode when avoiding recursive reads/writes.
|
||||
|
||||
Release 3.2.0
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Handle String, Structure, Callback, Buffer, and primitive arrays in direct mappings. Handle NativeMapped and TypeMapper, with optimized paths for IntegerType and PointerType.
|
||||
* Optionally throw errno/GetLastError as an exception. This is preferred to (and more efficient than) calling Native.getLastError().
|
||||
* Unload/delete native library unpacked from jna.jar if Native class is garbage collected. Only install shutdown hook if using the system class loader.
|
||||
* Auto-write contiguous Structure arrays when first element is written.
|
||||
* Support NativeMapped[] as function arguments for interface-mapped libraries (Issue 90).
|
||||
* Enable function lookup within current process on Windows.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Restrict recursive structure reads/writes by thread instead of globally. This avoids potentially missed reads/writes with concurrent access (Issue 120).
|
||||
* Ensure Memory is not GC'd and freed if direct NIO buffers mapped to it are extant.
|
||||
* Allow types derived from java.nio.Buffer as Structure fields.
|
||||
|
||||
Release 3.1.0
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Add raw JNI mapping of static Java methods. Performance is about 10X that of traditional JNA interface mapping, although with less type conversion functionality.
|
||||
* Add library option to allow passing/return of Java Objects.
|
||||
* Allow handling of uncaught callback exceptions (Issue 63).
|
||||
* Object oriented interface to X server (see contrib/x11)
|
||||
* Make Memory class more accessible.
|
||||
* Provide Structure ctor with Pointer argument (issue 102).
|
||||
* Allow implicit library access to current process on linux (issue 98).
|
||||
* Open all shared libraries with RTLD_GLOBAL, if applicable. This was the default behavior on OSX and changes the default behavior on linux.
|
||||
* Allow NIO Buffer as Structure field (with limitations) (Issue 57)
|
||||
* Add `size_t` size.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Run tests with libjsig.so, if available, which fixes some crashes when running tests on 64-bit platforms.
|
||||
* Fix Issue 104.
|
||||
* Fix Issue 94 (Java 1.6 update 10 regression).
|
||||
* Fix Issue 51 (Java 1.6 update 10 regression).
|
||||
* Fix Issue 95.
|
||||
* Fix Issue 101.
|
||||
* Fix Issue 111, memory leak with String-returning Callback.
|
||||
* Fix missing storage of union type information (affects usage of struct/union by value as argument and return type).
|
||||
* Remove non-functional Structure ctors requiring explicit size.
|
||||
|
||||
Release 3.0.9
|
||||
=============
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix issue 93 by only manually searching jna.library.path, then falling back to passing the mapped library name to dlopen/LoadLibrary. This fixes an issue in JRUBY where the incorrect libc.so.6 was being loaded.
|
||||
|
||||
Release 3.0.8
|
||||
==========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Auto-map Pointer[]/String[]/WString[] return values.
|
||||
* Provide utility functions to convert String to primitive array.
|
||||
* Add jna.library.boot.path property to define the directory that the native stub library is loaded from
|
||||
|
||||
Release 3.0.7
|
||||
==========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Improve Win32 loading of libraries with dependencies.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix bug reading structures with PointerType fields, introduced with Pointer field preservation fix.
|
||||
|
||||
Release 3.0.6
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Allow arbitrary callback method names if only one method is defined in the class which implements Callback (colinwalters).
|
||||
* Allow specification of callback type mappers by using a TYPE_MAPPER field (colinwalters).
|
||||
* Allow uninitialized (null-valued) boxed primitives in Structures (colinwalters).
|
||||
* Add convenience methods to set active Union field and value simultaneously (xylo).
|
||||
* Augment Union read/writeField to set the active field.
|
||||
* Allow Structure auto-synch across native calls to be disabled.
|
||||
* Win64 support.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Avoid overwriting unchanged Structure fields of type Pointer.
|
||||
* Avoid more content dragging on OSX or warn if it's too late.
|
||||
* Fix UnsatisfiedLinkError using transparent window on Win2K.
|
||||
* Fix memory leak with callbacks called from native threads with no Java context (johnwallace).
|
||||
* Defer structure size calculation if type mapper not yet set, allowing type mapper to be set in derived constructors (colinwalters).
|
||||
* Ensure structure memory is allocated in Structure.read/writeField.
|
||||
|
||||
Release 3.0.5
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Allow explicit declaration of field order for VMs which have an unpredictable field order.
|
||||
* Check for w32 libraries with a "lib" prefix in addition to normal lookup.
|
||||
* Allow String[]/WString[] as callback argument/return value (assume NULL-terminated array).
|
||||
* Add Solaris8 compatibility to sunos-sparc build (Corey Puffalt).
|
||||
* Look up libraries using web start library path, if appropriate (Corey Puffalt).
|
||||
* Use constants to return integer boolean values.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Properly track cursor on alpha-masked windows.
|
||||
* Avoid searching /lib or /usr/lib on 64-bit Linux.
|
||||
* Avoid using incorrect version of a library when both 32- and 64-bit versions are found.
|
||||
* Avoid transparent window events always dragging window bug on OSX.
|
||||
* Fix division by zero error calculating structure size on OSX/ppc.
|
||||
* Avoid overwriting initialized NativeMapped Structure fields when calculating structure size.
|
||||
* Fix NPE reading back into StringArray.
|
||||
|
||||
Release 3.0.4
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Automatically write contents of Structure.ByReference fields on Structure.write().
|
||||
* Use the actual parameter type in Function invocations if no parameter type information is available (whether method is missing or untyped varargs).
|
||||
* Augmented X11 library mappings (xylo).
|
||||
* Support read/write of NativeMapped arrays within Structure (notably NativeLong).
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix library load error when /usr/lib32 and /usr/lib both exist (linux) (Marek Slama).
|
||||
* Avoid incorrect matches against libraries named with the same prefix (e.g. libc-client.so vs libc.so) (xylo).
|
||||
* Properly handle arrays of NativeMapped (e.g. NativeLong) as a Structure field (stefan endrullis).
|
||||
* Ensure structure size calculated prior to setting union active type.
|
||||
* XID is 64-bits on 64-bit X clients (xylo).
|
||||
* Ensure proper arch name is used on Debian (amd64 instead of x86_64).
|
||||
|
||||
Release 3.0.3
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Enable build/run using IBM's J9 VM (leonardo).
|
||||
* Make StdCallFunctionMapper attempt a leading underscore if the simpler mapping doesn't work.
|
||||
* Allow Structure.read to overwrite final fields (may not work on some 1.4 VMs).
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Fix NPE when passing an array of Structure.ByReference.
|
||||
* Compare entire linux library version when finding a match.
|
||||
* Don't pass struct by value unless the method signature declares it.
|
||||
* Restrict custom first element structure alignment to OSX/ppc.
|
||||
* Improve performance and reduce memory footprint for window masks. Optimize polygon-based masks on w32. Use XFillRectangles on X11.
|
||||
* Fix linkage settings on sunos-amd64 to avoid relocation errors.
|
||||
* Fix callback allocation code on w32, solaris, freebsd, darwin (libffi was misconfigured).
|
||||
* Fix bug when NativeMapped fields are used in a Structure.ByValue instance.
|
||||
* Fix NPE calling Structure.read() before memory is initialized.
|
||||
* Fix NPE calling Structure.read/write with uninitialized NativeMapped fields.
|
||||
|
||||
Release 3.0.2
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Attempt to force unload of jnidispatch library prior to deleting it (w32).
|
||||
* Added amd64 targets for OSX, FreeBSD, and Solaris.
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Reduce space allocated for invocation arguments.
|
||||
* Fix NPE when NativeMapped type is used in a Structure.
|
||||
* Fix some X11 type mappings for 64-bit.
|
||||
* Fix OSX Leopard/JRE1.5+ window transparency.
|
||||
* Fix window alpha compositing on X11.
|
||||
* Fix loading of libraries with unicode names on OSX.
|
||||
|
||||
Release 3.0.1
|
||||
=============
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Improve transparent window drawing performance on w32
|
||||
* Use closure allocation from libffi
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Ensure nested structure arrays initialized with Structure.toArray use the appropriate native memory.
|
||||
* Ensure structure size is calculated prior to converting to array
|
||||
* Avoid creating new windows when setting a window mask
|
||||
* Fix bug in Pointer.setChar.
|
||||
|
||||
Release 3.0
|
||||
===========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* More supported platforms, via GCC's libffi (wmeissner)
|
||||
* Support struct by value as parameter and return value (duncan)
|
||||
* Support struct by reference within structures
|
||||
* Provide access to native peer for java.awt.Component
|
||||
* Provide access to native peer on OS X.
|
||||
* Support MINGW32 builds (fullung)
|
||||
* Allow per-field Structure read/write by field name
|
||||
* Avoid writing Structure fields marked 'volatile'
|
||||
* Read and wrap function pointers in Structure fields when read with a Java proxy to allow easy Java-side invocation (Ken Larson)
|
||||
* Support array-backed Buffers as arguments (wmeissner)
|
||||
* Auto-conversion of custom types (wmeissner)
|
||||
* Allow pointer type-safety
|
||||
* Optional VM crash protection, via Native.setProtected(boolean)
|
||||
* Auto-convert WString[]
|
||||
* Provide library synchronization wrapper similar to Collections.synchronizedX
|
||||
* Support lookup of OSX framework libraries by name
|
||||
* Explicit access to shared library global data
|
||||
* Invocation interception to facilitate translation of C preprocessor macros and inline functions
|
||||
* Provide utility to determine Web Start native library cache location; auto-include this path if jnidispatch is included as a <nativelib> (robertengels)
|
||||
* Provide access to aligned memory
|
||||
* Versioning information embedded in jna.jar and native library
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Avoid attempts to free native library if it failed to load (wmeissner)
|
||||
* Explicitly check method signatures for varargs instead of heuristically guessing (wmeissner)
|
||||
* Disallow declaring Pointer-derived fields in Structures (Function, Memory)
|
||||
* Ensure Object.toString/hashCode/equals methods are intercepted on proxyied interfaces
|
||||
* Update X11 library for 64-bit use (wmeissner)
|
||||
* Properly map arrays of char*/wchar_t* under w32
|
||||
* Allow Pointer[] as a Structure field and Function argument
|
||||
* Fix some misleading Structure error messages
|
||||
* Properly preserve/return GetLastError/errno after native calls
|
||||
* Allocate executable memory on w32 to avoid errors with hardware-enforced data execution protection (DEP)
|
||||
* Fix VM crash on w32 stdcall callbacks
|
||||
* Use long offsets and sizes rather than ints (64-bit safe)
|
||||
* Properly clean up references and release closure memory on JNI_Unload
|
||||
* Use simpler AWT/JAWT library loading workaround
|
||||
* Avoid changing array references within a Structure on read
|
||||
|
||||
Release 2.5
|
||||
===========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Unions
|
||||
* Optimized shaped windows (chris deckers & olivier chafik); instantiation time improved by about 2-3 orders of magnitude for large, mostly contiguous shapes
|
||||
* Provide type mapping in callback arguments/results
|
||||
* Provide access to ByteBuffer direct address as a Pointer
|
||||
* Provide customization of native string encoding with jna.encoding system property
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Properly handle VMs with reversed Structure member storage
|
||||
* Avoid making window undecorated when clearing window mask on X11
|
||||
* Fix structure alignment bug on OSX/PPC when first element is > 4 bytes in size
|
||||
* Clearing OSX window mask by setting to MASK_NONE now works properly
|
||||
* Avoid index exceptions if native buffers are not NUL-terminated on string conversions
|
||||
* Write initialized Structure[] argument memory prior to function calls
|
||||
* Fix IllegalArgumentException reading WString into a Structure
|
||||
* Clear memory when allocating a structure block (fixes VM crash)
|
||||
* Remove versioned JAWT dependency on OSX, allowing use on 10.3/JRE1.4.
|
||||
|
||||
Release 2.4
|
||||
===========
|
||||
|
||||
Features
|
||||
--------
|
||||
|
||||
* Explicitly support unaligned structures
|
||||
* Auto-reallocate structure arrays
|
||||
* Automatic handling of w32 UNICODE/ASCII variants
|
||||
* Automatic mapping of decorated w32 stdcall function names
|
||||
* Customizable, automatic type conversion of arguments and results (wmeissner)
|
||||
* Support char*[] arguments as Java String[]
|
||||
* Structure supports Callback members (wmeissner)
|
||||
* getByteBuffer from Pointer/Memory (wmeissner)
|
||||
* Allow GC of native libraries
|
||||
* Facilitate use from non-Java contexts (JRuby et al.) (wmeissner)
|
||||
* Improve library path searching (wmeissner)
|
||||
* Handle Structure[] arguments
|
||||
* Handle native long arguments and return values
|
||||
* Handle direct and array-based ByteBuffer arguments (wmeissner)
|
||||
* Change default w32 build to use GCC (it's free, yo)
|
||||
|
||||
Bug Fixes
|
||||
---------
|
||||
|
||||
* Structure.toArray failed to initialize members
|
||||
* Disallow explicit free of Structure/Memory
|
||||
* Ensure native libraries are only loaded once until released
|
||||
* Properly handle NULL when the return value is a Structure
|
||||
* Proper conversion to wchar_t on linux
|
||||
* Copy full length of Java strings to C strings instead of stopping when a NUL character is encountered
|
||||
-112
@@ -1,112 +0,0 @@
|
||||

|
||||
|
||||
Java Native Access (JNA)
|
||||
========================
|
||||
|
||||
The definitive JNA reference (including an overview and usage details) is in the [JavaDoc](http://twall.github.com/jna/3.5.0/javadoc/). Please read the [overview](http://twall.github.com/jna/3.5.0/javadoc/overview-summary.html#overview_description).
|
||||
|
||||
JNA provides Java programs easy access to native shared libraries (DLLs on Windows) without writing anything but Java code—no JNI or native code is required. This functionality is comparable to Windows' Platform/Invoke and Python's ctypes. Access is dynamic at runtime without code generation.
|
||||
|
||||
JNA allows you to call directly into native functions using natural Java method invocation. The Java call looks just like it does in native code. Most calls require no special handling or configuration; no boilerplate or generated code is required.
|
||||
|
||||
The JNA library uses a small native library stub to dynamically invoke native code. The developer uses a Java interface to describe functions and structures in the target native library. This makes it quite easy to take advantage of native platform features without incurring the high overhead of configuring and building JNI code for multiple platforms.
|
||||
|
||||
While some attention is paid to performance, correctness and ease of use take priority.
|
||||
|
||||
JNA includes a platform library with many native functions already mapped as well as a set of utility interfaces that simplify native access.
|
||||
|
||||
Download
|
||||
========
|
||||
|
||||
Version 3.5.0
|
||||
|
||||
* [jna.jar](jna/blob/3.5.0/dist/jna.jar?raw=true)
|
||||
* [platform.jar](jna/blob/3.5.0/dist/platform.jar?raw=true)
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
* Automatic mapping from Java to native functions, with simple mappings for all primitive data types
|
||||
* Runs on most platforms which support Java
|
||||
* Automatic conversion between C and Java strings, with customizable encoding/decoding
|
||||
* Structure and Union arguments/return values, by reference and by value
|
||||
* Function Pointers, (callbacks from native code to Java) as arguments and/or members of a struct
|
||||
* Auto-generated Java proxies for native function pointers
|
||||
* By-reference (pointer-to-type) arguments
|
||||
* Java array and NIO Buffer arguments (primitive types and pointers) as pointer-to-buffer
|
||||
* Nested structures and arrays
|
||||
* Wide (wchar_t-based) strings
|
||||
* Native long support (32- or 64-bit as appropriate)
|
||||
* [Demo applications/examples](https://github.com/twall/jna/tree/master/contrib)
|
||||
* Supported on 1.4 or later JVMs, including JavaME (earlier VMs may work with stubbed NIO support)
|
||||
* Customizable marshalling/unmarshalling (argument and return value conversions)
|
||||
* Customizable mapping from Java method to native function name, and customizable invocation to simulate C preprocessor function macros
|
||||
* Support for automatic Windows ASCII/UNICODE function mappings
|
||||
* Varargs support
|
||||
* Type-safety for native pointers
|
||||
* VM crash protection (optional)
|
||||
* Optimized direct mapping for high-performance applications.
|
||||
|
||||
Community and Support
|
||||
=====================
|
||||
|
||||
All questions should be posted ot the [jna-users Google group](http://groups.google.com/group/jna-users). Issues can be submitted [here on Github](https://github.com/twall/jna/issues).
|
||||
|
||||
When posting to the mailing list, please include the following:
|
||||
|
||||
* What OS/CPU/architecture you're using (e.g. Windows 7 64-bit)
|
||||
* Reference to your native interface definitions (i.e. C headers), if available
|
||||
* The JNA mapping you're trying to use
|
||||
* VM crash logs, if any
|
||||
* Example native usage, and your attempted Java usage
|
||||
|
||||
It's nearly impossible to indicate proper Java usage when there's no native
|
||||
reference to work from.
|
||||
|
||||
For commercial support, please contact twalljava [at] java [dot] net.
|
||||
|
||||
Using the Library
|
||||
=================
|
||||
|
||||
* [Getting Started](https://github.com/twall/jna/blob/master/www/GettingStarted.md)
|
||||
* [Mapping between Java and Native](https://github.com/twall/jna/blob/master/www/Mappings.md)
|
||||
* [Using Pointers and Arrays](https://github.com/twall/jna/blob/master/www/PointersAndArrays.md)
|
||||
* [Using Structures and Unions](https://github.com/twall/jna/blob/master/www/StructuresAndUnions.md)
|
||||
* [Using By-Reference Arguments](https://github.com/twall/jna/blob/master/www/ByRefArguments.md)
|
||||
* [Customization of Type Mapping](https://github.com/twall/jna/blob/master/www/CustomMappings.md)
|
||||
* [Callbacks/Function Pointers/Closures](https://github.com/twall/jna/blob/master/www/CallbacksAndClosures.md)
|
||||
* [Dynamically Typed Languages (JRuby/Jython)](https://github.com/twall/jna/blob/master/www/DynamicallyTypedLanguages.md)
|
||||
* [Platform Library](https://github.com/twall/jna/blob/master/www/PlatformLibrary.md)
|
||||
* [Direct Method Mapping](https://github.com/twall/jna/blob/master/www/DirectMapping.md) (Optimization)
|
||||
* [Frequently Asked Questions (FAQ)](https://github.com/twall/jna/blob/master/www/FrequentlyAskedQuestions.md)
|
||||
* [Avoiding Crashes](http://twall.github.com/jna/3.5.0/javadoc/overview-summary.html#crash-protection)
|
||||
|
||||
Primary Documentation (JavaDoc)
|
||||
===============================
|
||||
|
||||
The definitive JNA reference is in the [JavaDoc](http://twall.github.com/jna/3.5.0/javadoc/).
|
||||
|
||||
Developers
|
||||
==========
|
||||
|
||||
* [Contributing to JNA](https://github.com/twall/jna/blob/master/www/Contributing.md).
|
||||
* [Setting up a Windows Development Environment](https://github.com/twall/jna/blob/master/www/WindowsDevelopmentEnvironment.md)
|
||||
* [Setting up an Android Development Environment](https://github.com/twall/jna/blob/master/www/AndroidDevelopmentEnvironment.md)
|
||||
* [Releasing JNA](https://github.com/twall/jna/blob/master/www/ReleasingJNA.md)
|
||||
* [Publishing to Maven Central](https://github.com/twall/jna/blob/master/www/PublishingToMavenCentral.md)
|
||||
|
||||
Contributing
|
||||
============
|
||||
|
||||
You're encouraged to contribute to JNA. Fork the code from [https://github.com/twall/jna](https://github.com/twall/jna) and submit pull requests.
|
||||
|
||||
For more information on setting up a development environment see [Contributing to JNA](https://github.com/twall/jna/blob/master/www/Contributing.md).
|
||||
|
||||
If you are interested in paid support, feel free to say so on the [jna-users mailing list](http://groups.google.com/group/jna-users). Most simple questions will be answered on the list, but more complicated work, new features or target platforms can be negotiated with any of the JNA developers (this is how several of JNA's features came into being). You may even encounter other users with the same need and be able to cost share the new development.
|
||||
|
||||
License
|
||||
=======
|
||||
|
||||
This library is provided under the LGPL, version 2.1 or later. Alternative license arrangements are negotiable.
|
||||
|
||||
*NOTE: Oracle is not sponsoring this project, even though the package name (com.sun.jna) might imply otherwise.*
|
||||
-1054
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jnalib/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>alphamaskdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,66 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.alphamaskdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.alphamaskdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-alphamask.jar"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.AlphaMaskDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5"
|
||||
encoding="UTF-8" debug="on" includeantruntime="false">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com"/>
|
||||
<!-- jna -->
|
||||
<zipfileset src="${file.reference.jna.jar}"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloonmanagerdemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloonmanagerdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloonmanagerdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-balloonmanager.jar"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.BalloonManagerDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5"
|
||||
encoding="UTF-8" debug="on" includeantruntime="false">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com"/>
|
||||
<!-- jna -->
|
||||
<zipfileset src="${file.reference.jna.jar}"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>balloontips</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.balloontipsdemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.balloontipsdemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-balloontips.jar"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.FilteredTextField" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5"
|
||||
encoding="UTF-8" debug="on" includeantruntime="false">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com"/>
|
||||
<!-- jna -->
|
||||
<zipfileset src="${file.reference.jna.jar}"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path=""/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="/jnalib/dist/jna.jar"/>
|
||||
<classpathentry kind="src" path="/platform"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>dnddemo</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,68 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="jnacontrib.dnddemo" default="jar" basedir=".">
|
||||
<description>Builds, tests, and runs the project jnacontrib.dnddemo.</description>
|
||||
<!-- Locations -->
|
||||
<property name="src" location="."/>
|
||||
<property name="build" location="build"/>
|
||||
<property name="jna-dist" location="../../dist"/>
|
||||
|
||||
<property name="classes" location="${build}/classes"/>
|
||||
<property name="jar" location="${build}/demo-dnd.jar"/>
|
||||
<property name="file.reference.jna.jar" location="../../build/jna.jar"/>
|
||||
<property name="main-class" value="com.sun.jna.contrib.demo.GhostedDragImageDemo" />
|
||||
|
||||
<path id="classpath">
|
||||
<fileset file="${file.reference.jna.jar}"/>
|
||||
<fileset dir="../platform/dist" includes="platform.jar"/>
|
||||
</path>
|
||||
|
||||
<!-- Run Demo. -->
|
||||
<target name="run" depends="compile">
|
||||
<java classname="${main-class}" fork="true">
|
||||
<classpath>
|
||||
<pathelement location="${classes}" />
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
<!-- Delete class and jar files. -->
|
||||
<target name="clean">
|
||||
<delete dir="${classes}"/>
|
||||
<delete file="${jar}"/>
|
||||
<delete dir="${build}"/>
|
||||
</target>
|
||||
|
||||
<!-- Compile all classes. -->
|
||||
<target name="compile">
|
||||
<mkdir dir="${classes}"/>
|
||||
<!-- Compile the project. -->
|
||||
<javac srcdir="${src}" destdir="${classes}" target="1.5" source="1.5"
|
||||
encoding="UTF-8" debug="on" includeantruntime="false">
|
||||
<classpath>
|
||||
<path refid="classpath"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<!-- Create jar-file. -->
|
||||
<target name="jar" depends="compile">
|
||||
|
||||
<!-- Copy all non-java files to classes. -->
|
||||
<copy todir="${classes}/com">
|
||||
<fileset dir="${src}/com">
|
||||
<exclude name="**/*.java"/>
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<jar jarfile="${jar}" basedir="${classes}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main-class}"/>
|
||||
</manifest>
|
||||
<!-- platform -->
|
||||
<fileset dir="../platform/build/classes/com"/>
|
||||
<!-- jna -->
|
||||
<zipfileset src="${file.reference.jna.jar}"/>
|
||||
</jar>
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jnalib"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="lib" path="/jnalib/dist/jna.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>ntservice</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,196 +0,0 @@
|
||||
/*
|
||||
* Advapi32.java
|
||||
*
|
||||
* Created on 6. August 2007, 11:24
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface Advapi32 extends StdCallLibrary {
|
||||
Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32",
|
||||
Advapi32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/*
|
||||
* SC_HANDLE WINAPI OpenSCManager( LPCTSTR lpMachineName, LPCTSTR
|
||||
* lpDatabaseName, DWORD dwDesiredAccess );
|
||||
*/
|
||||
public Pointer OpenSCManager(String lpMachineName, WString lpDatabaseName,
|
||||
int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI CloseServiceHandle( SC_HANDLE hSCObject );
|
||||
*/
|
||||
public boolean CloseServiceHandle(Pointer hSCObject);
|
||||
|
||||
/*
|
||||
* SC_HANDLE WINAPI OpenService( SC_HANDLE hSCManager, LPCTSTR
|
||||
* lpServiceName, DWORD dwDesiredAccess );
|
||||
*/
|
||||
public Pointer OpenService(Pointer hSCManager, String lpServiceName,
|
||||
int dwDesiredAccess);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI StartService( SC_HANDLE hService, DWORD dwNumServiceArgs,
|
||||
* LPCTSTR* lpServiceArgVectors );
|
||||
*/
|
||||
public boolean StartService(Pointer hService, int dwNumServiceArgs,
|
||||
char[] lpServiceArgVectors);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI ControlService( SC_HANDLE hService, DWORD dwControl,
|
||||
* LPSERVICE_STATUS lpServiceStatus );
|
||||
*/
|
||||
public boolean ControlService(Pointer hService, int dwControl,
|
||||
SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI StartServiceCtrlDispatcher( const SERVICE_TABLE_ENTRY*
|
||||
* lpServiceTable );
|
||||
*/
|
||||
public boolean StartServiceCtrlDispatcher(Structure[] lpServiceTable);
|
||||
|
||||
/*
|
||||
* SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandler( LPCTSTR
|
||||
* lpServiceName, LPHANDLER_FUNCTION lpHandlerProc );
|
||||
*/
|
||||
public Pointer RegisterServiceCtrlHandler(String lpServiceName,
|
||||
Handler lpHandlerProc);
|
||||
|
||||
/*
|
||||
* SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerEx( LPCTSTR
|
||||
* lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext );
|
||||
*/
|
||||
public Pointer RegisterServiceCtrlHandlerEx(String lpServiceName,
|
||||
HandlerEx lpHandlerProc, Pointer lpContext);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI SetServiceStatus( SERVICE_STATUS_HANDLE hServiceStatus,
|
||||
* LPSERVICE_STATUS lpServiceStatus );
|
||||
*/
|
||||
public boolean SetServiceStatus(Pointer hServiceStatus,
|
||||
SERVICE_STATUS lpServiceStatus);
|
||||
|
||||
/*
|
||||
* SC_HANDLE WINAPI CreateService( SC_HANDLE hSCManager, LPCTSTR
|
||||
* lpServiceName, LPCTSTR lpDisplayName, DWORD dwDesiredAccess, DWORD
|
||||
* dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCTSTR
|
||||
* lpBinaryPathName, LPCTSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCTSTR
|
||||
* lpDependencies, LPCTSTR lpServiceStartName, LPCTSTR lpPassword );
|
||||
*/
|
||||
public Pointer CreateService(Pointer hSCManager, String lpServiceName,
|
||||
String lpDisplayName, int dwDesiredAccess, int dwServiceType,
|
||||
int dwStartType, int dwErrorControl, String lpBinaryPathName,
|
||||
String lpLoadOrderGroup, IntByReference lpdwTagId,
|
||||
String lpDependencies, String lpServiceStartName, String lpPassword);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI DeleteService( SC_HANDLE hService );
|
||||
*/
|
||||
public boolean DeleteService(Pointer hService);
|
||||
|
||||
/*
|
||||
* BOOL WINAPI ChangeServiceConfig2( SC_HANDLE hService, DWORD dwInfoLevel,
|
||||
* LPVOID lpInfo );
|
||||
*/
|
||||
public boolean ChangeServiceConfig2(Pointer hService, int dwInfoLevel,
|
||||
ChangeServiceConfig2Info lpInfo);
|
||||
|
||||
/*
|
||||
* LONG WINAPI RegEnumValue( HKEY hKey, DWORD dwIndex, LPTSTR lpValueName,
|
||||
* LPDWORD lpcchValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE
|
||||
* lpData, LPDWORD lpcbData );
|
||||
*/
|
||||
public int RegEnumValue(int hKey, int dwIndex, char[] lpValueName,
|
||||
IntByReference lpcchValueName, IntByReference reserved,
|
||||
IntByReference lpType, byte[] lpData, IntByReference lpcbData);
|
||||
|
||||
interface SERVICE_MAIN_FUNCTION extends StdCallCallback {
|
||||
/*
|
||||
* VOID WINAPI ServiceMain( DWORD dwArgc, LPTSTR* lpszArgv );
|
||||
*/
|
||||
public void callback(int dwArgc, Pointer lpszArgv);
|
||||
}
|
||||
|
||||
interface Handler extends StdCallCallback {
|
||||
/*
|
||||
* VOID WINAPI Handler( DWORD fdwControl );
|
||||
*/
|
||||
public void callback(int fdwControl);
|
||||
}
|
||||
|
||||
interface HandlerEx extends StdCallCallback {
|
||||
/*
|
||||
* DWORD WINAPI HandlerEx( DWORD dwControl, DWORD dwEventType, LPVOID
|
||||
* lpEventData, LPVOID lpContext );
|
||||
*/
|
||||
public int callback(int dwControl, int dwEventType,
|
||||
Pointer lpEventData, Pointer lpContext);
|
||||
}
|
||||
|
||||
/*
|
||||
* typedef struct _SERVICE_STATUS { DWORD dwServiceType; DWORD
|
||||
* dwCurrentState; DWORD dwControlsAccepted; DWORD dwWin32ExitCode; DWORD
|
||||
* dwServiceSpecificExitCode; DWORD dwCheckPoint; DWORD dwWaitHint; }
|
||||
* SERVICE_STATUS,LPSERVICE_STATUS;
|
||||
*/
|
||||
public static class SERVICE_STATUS extends Structure {
|
||||
public int dwServiceType;
|
||||
public int dwCurrentState;
|
||||
public int dwControlsAccepted;
|
||||
public int dwWin32ExitCode;
|
||||
public int dwServiceSpecificExitCode;
|
||||
public int dwCheckPoint;
|
||||
public int dwWaitHint;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint" });
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* typedef struct _SERVICE_TABLE_ENTRY { LPTSTR lpServiceName;
|
||||
* LPSERVICE_MAIN_FUNCTION lpServiceProc; } SERVICE_TABLE_ENTRY,
|
||||
* LPSERVICE_TABLE_ENTRY;
|
||||
*/
|
||||
public static class SERVICE_TABLE_ENTRY extends Structure {
|
||||
public String lpServiceName;
|
||||
public SERVICE_MAIN_FUNCTION lpServiceProc;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "lpServiceName", "lpServiceProc" });
|
||||
}
|
||||
}
|
||||
|
||||
public static abstract class ChangeServiceConfig2Info extends Structure {
|
||||
}
|
||||
|
||||
/*
|
||||
* typedef struct _SERVICE_DESCRIPTION { LPTSTR lpDescription; }
|
||||
* SERVICE_DESCRIPTION,LPSERVICE_DESCRIPTION;
|
||||
*/
|
||||
public static class SERVICE_DESCRIPTION extends ChangeServiceConfig2Info {
|
||||
public String lpDescription;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "lpDescription" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* WINNT.java
|
||||
*
|
||||
* Created on 8. August 2007, 13:41
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package jnacontrib.jna;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author TB
|
||||
*/
|
||||
public interface WINNT {
|
||||
public final static int DELETE = 0x00010000;
|
||||
public final static int READ_CONTROL = 0x00020000;
|
||||
public final static int WRITE_DAC = 0x00040000;
|
||||
public final static int WRITE_OWNER = 0x00080000;
|
||||
public final static int SYNCHRONIZE = 0x00100000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_REQUIRED = 0x000F0000;
|
||||
|
||||
public final static int STANDARD_RIGHTS_READ = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_WRITE = READ_CONTROL;
|
||||
public final static int STANDARD_RIGHTS_EXECUTE = READ_CONTROL;
|
||||
|
||||
public final static int STANDARD_RIGHTS_ALL = 0x001F0000;
|
||||
|
||||
public final static int SPECIFIC_RIGHTS_ALL = 0x0000FFFF;
|
||||
|
||||
public final static int GENERIC_EXECUTE = 0x20000000;
|
||||
|
||||
public final static int SERVICE_WIN32_OWN_PROCESS = 0x00000010;
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
# placeholder
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" output="build.eclipse/contrib-test-classes" path="test"/>
|
||||
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/jnalib"/>
|
||||
<classpathentry kind="lib" path="/jnalib/dist/jna.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>platform</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -1,89 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="platform" default="default" basedir=".">
|
||||
<description>Builds, tests, and runs the project platform.</description>
|
||||
<import file="nbproject/build-impl.xml"/>
|
||||
<!--
|
||||
|
||||
There exist several targets which are by default empty and which can be
|
||||
used for execution of your tasks. These targets are usually executed
|
||||
before and after some main targets. They are:
|
||||
|
||||
-pre-init: called before initialization of project properties
|
||||
-post-init: called after initialization of project properties
|
||||
-pre-compile: called before javac compilation
|
||||
-post-compile: called after javac compilation
|
||||
-pre-compile-single: called before javac compilation of single file
|
||||
-post-compile-single: called after javac compilation of single file
|
||||
-pre-compile-test: called before javac compilation of JUnit tests
|
||||
-post-compile-test: called after javac compilation of JUnit tests
|
||||
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||
-pre-jar: called before JAR building
|
||||
-post-jar: called after JAR building
|
||||
-post-clean: called after cleaning build products
|
||||
|
||||
(Targets beginning with '-' are not intended to be called on their own.)
|
||||
|
||||
Example of inserting an obfuscator after compilation could look like this:
|
||||
|
||||
<target name="-post-compile">
|
||||
<obfuscate>
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
</obfuscate>
|
||||
</target>
|
||||
|
||||
For list of available properties check the imported
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
|
||||
Another way to customize the build is by overriding existing main targets.
|
||||
The targets of interest are:
|
||||
|
||||
-init-macrodef-javac: defines macro for javac compilation
|
||||
-init-macrodef-junit: defines macro for junit execution
|
||||
-init-macrodef-debug: defines macro for class debugging
|
||||
-init-macrodef-java: defines macro for class execution
|
||||
-do-jar-with-manifest: JAR building (if you are using a manifest)
|
||||
-do-jar-without-manifest: JAR building (if you are not using a manifest)
|
||||
run: execution of project
|
||||
-javadoc-build: Javadoc generation
|
||||
test-report: JUnit report generation
|
||||
|
||||
An example of overriding the target for project execution could look like this:
|
||||
|
||||
<target name="run" depends="JnaContrib-impl.jar">
|
||||
<exec dir="bin" executable="launcher.exe">
|
||||
<arg file="${dist.jar}"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
Notice that the overridden target depends on the jar target and not only on
|
||||
the compile target as the regular run target does. Again, for a list of available
|
||||
properties which you can use, check the target you are overriding in the
|
||||
nbproject/build-impl.xml file.
|
||||
|
||||
-->
|
||||
<condition property="tests.platform" value="test-win32">
|
||||
<os family="windows"/>
|
||||
</condition>
|
||||
<condition property="tests.platform" value="test-osx">
|
||||
<os family="mac"/>
|
||||
</condition>
|
||||
<target name="test" depends="init,compile-test" description="Run unit tests." if="tests.platform">
|
||||
<antcall target="${tests.platform}" />
|
||||
</target>
|
||||
<target name="test-report">
|
||||
<junitreport todir="${build.test.results.dir}">
|
||||
<fileset dir="${build.test.results.dir}">
|
||||
<include name="TEST-*.xml"/>
|
||||
</fileset>
|
||||
<report todir="${build.test.results.dir}"/>
|
||||
</junitreport>
|
||||
<property name="build.test.results.dir.abs" location="${build.test.results.dir}"/>
|
||||
<echo message="View test report in file://${build.test.results.dir.abs}/index.html" />
|
||||
</target>
|
||||
<target name="test-osx">
|
||||
<echo>No platform tests yet for OSX</echo>
|
||||
</target>
|
||||
<target name="test-win32" depends="-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" />
|
||||
</project>
|
||||
@@ -1,541 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
*** GENERATED FROM project.xml - DO NOT EDIT ***
|
||||
*** EDIT ../build.xml INSTEAD ***
|
||||
|
||||
For the purpose of easier reading the script
|
||||
is divided into following sections:
|
||||
|
||||
- initialization
|
||||
- compilation
|
||||
- jar
|
||||
- execution
|
||||
- debugging
|
||||
- javadoc
|
||||
- junit compilation
|
||||
- junit execution
|
||||
- junit debugging
|
||||
- applet
|
||||
- cleanup
|
||||
|
||||
-->
|
||||
<project name="platform-impl" default="default" basedir=".." xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:j2seproject2="http://www.netbeans.org/ns/j2se-project/2" xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:jaxws="http://www.netbeans.org/ns/jax-ws/1">
|
||||
<target name="default" depends="test,jar,javadoc" description="Build and test whole project."/>
|
||||
<!--
|
||||
======================
|
||||
INITIALIZATION SECTION
|
||||
======================
|
||||
-->
|
||||
<target name="-pre-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-private" depends="-pre-init">
|
||||
<property file="nbproject/private/private.properties"/>
|
||||
</target>
|
||||
<target name="-init-user" depends="-pre-init,-init-private">
|
||||
<property file="${user.properties.file}"/>
|
||||
<!-- The two properties below are usually overridden -->
|
||||
<!-- by the active platform. Just a fallback. -->
|
||||
<property name="default.javac.source" value="1.4"/>
|
||||
<property name="default.javac.target" value="1.4"/>
|
||||
</target>
|
||||
<target name="-init-project" depends="-pre-init,-init-private,-init-user">
|
||||
<property file="nbproject/project.properties"/>
|
||||
</target>
|
||||
<target name="-do-init" depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property">
|
||||
<available file="${manifest.file}" property="manifest.available"/>
|
||||
<condition property="manifest.available+main.class">
|
||||
<and>
|
||||
<isset property="manifest.available"/>
|
||||
<isset property="main.class"/>
|
||||
<not>
|
||||
<equals arg1="${main.class}" arg2="" trim="true"/>
|
||||
</not>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="manifest.available+main.class+mkdist.available">
|
||||
<and>
|
||||
<istrue value="${manifest.available+main.class}"/>
|
||||
<isset property="libs.CopyLibs.classpath"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="have.tests">
|
||||
<or>
|
||||
<available file="${test.src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="have.sources">
|
||||
<or>
|
||||
<available file="${src.dir}"/>
|
||||
</or>
|
||||
</condition>
|
||||
<condition property="netbeans.home+have.tests">
|
||||
<and>
|
||||
<isset property="netbeans.home"/>
|
||||
<isset property="have.tests"/>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="no.javadoc.preview">
|
||||
<isfalse value="${javadoc.preview}"/>
|
||||
</condition>
|
||||
<property name="run.jvmargs" value=""/>
|
||||
<property name="javac.compilerargs" value=""/>
|
||||
<property name="work.dir" value="${basedir}"/>
|
||||
<condition property="no.deps">
|
||||
<and>
|
||||
<istrue value="${no.dependencies}"/>
|
||||
</and>
|
||||
</condition>
|
||||
<property name="javac.debug" value="true"/>
|
||||
<property name="javadoc.preview" value="true"/>
|
||||
</target>
|
||||
<target name="-post-init">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-init-check" depends="-pre-init,-init-private,-init-user,-init-project,-do-init">
|
||||
<fail unless="src.dir">Must set src.dir</fail>
|
||||
<fail unless="test.src.dir">Must set test.src.dir</fail>
|
||||
<fail unless="build.dir">Must set build.dir</fail>
|
||||
<fail unless="dist.dir">Must set dist.dir</fail>
|
||||
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
|
||||
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
|
||||
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
|
||||
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
|
||||
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
|
||||
<fail unless="dist.jar">Must set dist.jar</fail>
|
||||
</target>
|
||||
<target name="-init-macrodef-property">
|
||||
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name"/>
|
||||
<attribute name="value"/>
|
||||
<sequential>
|
||||
<property name="@{name}" value="${@{value}}"/>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-javac">
|
||||
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="srcdir" default="${src.dir}"/>
|
||||
<attribute name="destdir" default="${build.classes.dir}"/>
|
||||
<attribute name="classpath" default="${javac.classpath}"/>
|
||||
<attribute name="debug" default="${javac.debug}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<javac srcdir="@{srcdir}" destdir="@{destdir}" debug="@{debug}" deprecation="${javac.deprecation}" source="${javac.source}" target="${javac.target}" includeantruntime="false">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<compilerarg line="${javac.compilerargs}"/>
|
||||
<customize/>
|
||||
</javac>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-junit">
|
||||
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="includes" default="**/*Test.java"/>
|
||||
<sequential>
|
||||
<junit showoutput="true" fork="true" dir="${basedir}" failureproperty="tests.failed" errorproperty="tests.failed">
|
||||
<batchtest todir="${build.test.results.dir}">
|
||||
<fileset dir="${test.src.dir}" includes="@{includes}"/>
|
||||
</batchtest>
|
||||
<classpath>
|
||||
<path path="${run.test.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="test-sys-prop."/>
|
||||
<mapper type="glob" from="test-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<formatter type="brief" usefile="false"/>
|
||||
<formatter type="xml"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
</junit>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-nbjpda">
|
||||
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="name" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<attribute name="stopclassname" default=""/>
|
||||
<sequential>
|
||||
<nbjpdastart transport="dt_socket" addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}">
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
</nbjpdastart>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="dir" default="${build.classes.dir}"/>
|
||||
<sequential>
|
||||
<nbjpdareload>
|
||||
<fileset includes="${fix.includes}*.class" dir="@{dir}"/>
|
||||
</nbjpdareload>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-debug">
|
||||
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<attribute name="classpath" default="${debug.classpath}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg value="-Xdebug"/>
|
||||
<jvmarg value="-Xnoagent"/>
|
||||
<jvmarg value="-Djava.compiler=none"/>
|
||||
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="@{classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-macrodef-java">
|
||||
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<attribute name="classname" default="${main.class}"/>
|
||||
<element name="customize" optional="true"/>
|
||||
<sequential>
|
||||
<java fork="true" classname="@{classname}" dir="${work.dir}">
|
||||
<jvmarg line="${run.jvmargs}"/>
|
||||
<classpath>
|
||||
<path path="${run.classpath}"/>
|
||||
</classpath>
|
||||
<syspropertyset>
|
||||
<propertyref prefix="run-sys-prop."/>
|
||||
<mapper type="glob" from="run-sys-prop.*" to="*"/>
|
||||
</syspropertyset>
|
||||
<customize/>
|
||||
</java>
|
||||
</sequential>
|
||||
</macrodef>
|
||||
</target>
|
||||
<target name="-init-presetdef-jar">
|
||||
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
|
||||
<jar jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<j2seproject1:fileset dir="${build.classes.dir}"/>
|
||||
</jar>
|
||||
</presetdef>
|
||||
</target>
|
||||
<target name="init" depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar"/>
|
||||
<!--
|
||||
===================
|
||||
COMPILATION SECTION
|
||||
===================
|
||||
-->
|
||||
<target name="deps-jar" depends="init" unless="no.deps"/>
|
||||
<target name="-pre-pre-compile" depends="init,deps-jar">
|
||||
<mkdir dir="${build.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile" if="have.sources">
|
||||
<j2seproject3:javac/>
|
||||
<copy todir="${build.classes.dir}">
|
||||
<fileset dir="${src.dir}" excludes="${build.classes.excludes}"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile" depends="init,deps-jar,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project."/>
|
||||
<target name="-pre-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-single" depends="init,deps-jar,-pre-pre-compile">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac>
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
</target>
|
||||
<target name="-post-compile-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-single" depends="init,deps-jar,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single"/>
|
||||
<!--
|
||||
====================
|
||||
JAR BUILDING SECTION
|
||||
====================
|
||||
-->
|
||||
<target name="-pre-pre-jar" depends="init">
|
||||
<dirname property="dist.jar.dir" file="${dist.jar}"/>
|
||||
<mkdir dir="${dist.jar.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-jar-without-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" unless="manifest.available">
|
||||
<j2seproject1:jar/>
|
||||
</target>
|
||||
<target name="-do-jar-with-manifest" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" unless="manifest.available+main.class">
|
||||
<j2seproject1:jar manifest="${manifest.file}"/>
|
||||
</target>
|
||||
<target name="-do-jar-with-mainclass" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" unless="manifest.available+main.class+mkdist.available">
|
||||
<j2seproject1:jar manifest="${manifest.file}">
|
||||
<j2seproject1:manifest>
|
||||
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
|
||||
</j2seproject1:manifest>
|
||||
</j2seproject1:jar>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<pathconvert property="run.classpath.with.dist.jar">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
|
||||
</pathconvert>
|
||||
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
|
||||
</target>
|
||||
<target name="-do-jar-with-libraries" depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available">
|
||||
<property name="build.classes.dir.resolved" location="${build.classes.dir}"/>
|
||||
<pathconvert property="run.classpath.without.build.classes.dir">
|
||||
<path path="${run.classpath}"/>
|
||||
<map from="${build.classes.dir.resolved}" to=""/>
|
||||
</pathconvert>
|
||||
<pathconvert property="jar.classpath" pathsep=" ">
|
||||
<path path="${run.classpath.without.build.classes.dir}"/>
|
||||
<chainedmapper>
|
||||
<flattenmapper/>
|
||||
<globmapper from="*" to="lib/*"/>
|
||||
</chainedmapper>
|
||||
</pathconvert>
|
||||
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" name="copylibs" classpath="${libs.CopyLibs.classpath}"/>
|
||||
<copylibs manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}" jarfile="${dist.jar}" compress="${jar.compress}">
|
||||
<fileset dir="${build.classes.dir}"/>
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="${main.class}"/>
|
||||
<attribute name="Class-Path" value="${jar.classpath}"/>
|
||||
</manifest>
|
||||
</copylibs>
|
||||
<echo>To run this application from the command line without Ant, try:</echo>
|
||||
<property name="dist.jar.resolved" location="${dist.jar}"/>
|
||||
<echo>java -jar "${dist.jar.resolved}"</echo>
|
||||
</target>
|
||||
<target name="-post-jar">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="jar" depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-post-jar" description="Build JAR."/>
|
||||
<!--
|
||||
=================
|
||||
EXECUTION SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="run" depends="init,compile" description="Run a main class.">
|
||||
<j2seproject1:java>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<target name="run-single" depends="init,compile-single">
|
||||
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
|
||||
<j2seproject1:java classname="${run.class}"/>
|
||||
</target>
|
||||
<!--
|
||||
=================
|
||||
DEBUGGING SECTION
|
||||
=================
|
||||
-->
|
||||
<target name="-debug-start-debugger" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart name="${debug.class}"/>
|
||||
</target>
|
||||
<target name="-debug-start-debuggee" depends="init,compile">
|
||||
<j2seproject3:debug>
|
||||
<customize>
|
||||
<arg line="${application.args}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug" if="netbeans.home" depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE."/>
|
||||
<target name="-debug-start-debugger-stepinto" if="netbeans.home" depends="init">
|
||||
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
|
||||
</target>
|
||||
<target name="debug-stepinto" if="netbeans.home" depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee"/>
|
||||
<target name="-debug-start-debuggee-single" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
|
||||
<j2seproject3:debug classname="${debug.class}"/>
|
||||
</target>
|
||||
<target name="debug-single" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-single"/>
|
||||
<target name="-pre-debug-fix" depends="init">
|
||||
<fail unless="fix.includes">Must set fix.includes</fail>
|
||||
<property name="javac.includes" value="${fix.includes}.java"/>
|
||||
</target>
|
||||
<target name="-do-debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,compile-single">
|
||||
<j2seproject1:nbjpdareload/>
|
||||
</target>
|
||||
<target name="debug-fix" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix"/>
|
||||
<!--
|
||||
===============
|
||||
JAVADOC SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="-javadoc-build" depends="init">
|
||||
<mkdir dir="${dist.javadoc.dir}"/>
|
||||
<javadoc destdir="${dist.javadoc.dir}" source="${javac.source}" notree="${javadoc.notree}" use="${javadoc.use}" nonavbar="${javadoc.nonavbar}" noindex="${javadoc.noindex}" splitindex="${javadoc.splitindex}" author="${javadoc.author}" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}" private="${javadoc.private}" additionalparam="${javadoc.additionalparam}" failonerror="true" useexternalfile="true">
|
||||
<classpath>
|
||||
<path path="${javac.classpath}"/>
|
||||
</classpath>
|
||||
<sourcepath>
|
||||
<pathelement location="${src.dir}"/>
|
||||
</sourcepath>
|
||||
<packageset dir="${src.dir}" includes="*/**"/>
|
||||
<fileset dir="${src.dir}" includes="*.java"/>
|
||||
</javadoc>
|
||||
</target>
|
||||
<target name="-javadoc-browse" if="netbeans.home" unless="no.javadoc.preview" depends="init,-javadoc-build">
|
||||
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
|
||||
</target>
|
||||
<target name="javadoc" depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc."/>
|
||||
<!--
|
||||
=========================
|
||||
JUNIT COMPILATION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-pre-pre-compile-test" if="have.tests" depends="init,compile">
|
||||
<mkdir dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="-pre-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test">
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}"/>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test" depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test"/>
|
||||
<target name="-pre-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="-do-compile-test-single" if="have.tests" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single">
|
||||
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
|
||||
<j2seproject3:javac srcdir="${test.src.dir}" destdir="${build.test.classes.dir}" debug="true" classpath="${javac.test.classpath}">
|
||||
<customize>
|
||||
<patternset includes="${javac.includes}"/>
|
||||
</customize>
|
||||
</j2seproject3:javac>
|
||||
<copy todir="${build.test.classes.dir}">
|
||||
<fileset dir="${test.src.dir}" excludes="**/*.java"/>
|
||||
</copy>
|
||||
</target>
|
||||
<target name="-post-compile-test-single">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="compile-test-single" depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single"/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT EXECUTION SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-pre-test-run" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run" if="have.tests" depends="init,compile-test,-pre-test-run">
|
||||
<j2seproject3:junit/>
|
||||
</target>
|
||||
<target name="-post-test-run" if="have.tests" depends="init,compile-test,-pre-test-run,-do-test-run">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-report" if="have.tests" depends="init"/>
|
||||
<target name="-test-browse" if="netbeans.home+have.tests" depends="init"/>
|
||||
<target name="test" depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests."/>
|
||||
<target name="-pre-test-run-single" if="have.tests" depends="init">
|
||||
<mkdir dir="${build.test.results.dir}"/>
|
||||
</target>
|
||||
<target name="-do-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single">
|
||||
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
|
||||
<j2seproject3:junit includes="${test.includes}"/>
|
||||
</target>
|
||||
<target name="-post-test-run-single" if="have.tests" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single">
|
||||
<fail if="tests.failed">Some tests failed; see details above.</fail>
|
||||
</target>
|
||||
<target name="test-single" depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test."/>
|
||||
<!--
|
||||
=======================
|
||||
JUNIT DEBUGGING SECTION
|
||||
=======================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-test" if="have.tests" depends="init,compile-test">
|
||||
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
|
||||
<j2seproject3:debug classname="junit.textui.TestRunner" classpath="${debug.test.classpath}">
|
||||
<customize>
|
||||
<arg line="${test.class}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="-debug-start-debugger-test" if="netbeans.home+have.tests" depends="init,compile-test">
|
||||
<j2seproject1:nbjpdastart name="${test.class}" classpath="${debug.test.classpath}"/>
|
||||
</target>
|
||||
<target name="debug-test" depends="init,compile-test,-debug-start-debugger-test,-debug-start-debuggee-test"/>
|
||||
<target name="-do-debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,compile-test-single">
|
||||
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
|
||||
</target>
|
||||
<target name="debug-fix-test" if="netbeans.home" depends="init,-pre-debug-fix,-do-debug-fix-test"/>
|
||||
<!--
|
||||
=========================
|
||||
APPLET EXECUTION SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="run-applet" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject1:java classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject1:java>
|
||||
</target>
|
||||
<!--
|
||||
=========================
|
||||
APPLET DEBUGGING SECTION
|
||||
=========================
|
||||
-->
|
||||
<target name="-debug-start-debuggee-applet" if="netbeans.home" depends="init,compile-single">
|
||||
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
|
||||
<j2seproject3:debug classname="sun.applet.AppletViewer">
|
||||
<customize>
|
||||
<arg value="${applet.url}"/>
|
||||
</customize>
|
||||
</j2seproject3:debug>
|
||||
</target>
|
||||
<target name="debug-applet" if="netbeans.home" depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet"/>
|
||||
<!--
|
||||
===============
|
||||
CLEANUP SECTION
|
||||
===============
|
||||
-->
|
||||
<target name="deps-clean" depends="init" unless="no.deps"/>
|
||||
<target name="-do-clean" depends="init">
|
||||
<delete dir="${build.dir}"/>
|
||||
<delete dir="${dist.dir}"/>
|
||||
</target>
|
||||
<target name="-post-clean">
|
||||
<!-- Empty placeholder for easier customization. -->
|
||||
<!-- You can override this target in the ../build.xml file. -->
|
||||
</target>
|
||||
<target name="clean" depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products."/>
|
||||
</project>
|
||||
@@ -1,135 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EventObject;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.platform.win32.W32FileMonitor;
|
||||
|
||||
/** Provides notification of file system changes. Actual capabilities may
|
||||
* vary slightly by platform.
|
||||
* <p>
|
||||
* Watched files which are removed from the filesystem are no longer watched.
|
||||
* @author twall
|
||||
*/
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public abstract class FileMonitor {
|
||||
|
||||
public static final int FILE_CREATED = 0x1;
|
||||
public static final int FILE_DELETED = 0x2;
|
||||
public static final int FILE_MODIFIED = 0x4;
|
||||
public static final int FILE_ACCESSED = 0x8;
|
||||
public static final int FILE_NAME_CHANGED_OLD = 0x10;
|
||||
public static final int FILE_NAME_CHANGED_NEW = 0x20;
|
||||
public static final int FILE_RENAMED = FILE_NAME_CHANGED_OLD|FILE_NAME_CHANGED_NEW;
|
||||
public static final int FILE_SIZE_CHANGED = 0x40;
|
||||
public static final int FILE_ATTRIBUTES_CHANGED = 0x80;
|
||||
public static final int FILE_SECURITY_CHANGED = 0x100;
|
||||
public static final int FILE_ANY = 0x1FF;
|
||||
|
||||
public interface FileListener {
|
||||
public void fileChanged(FileEvent e);
|
||||
}
|
||||
|
||||
public class FileEvent extends EventObject {
|
||||
private final File file;
|
||||
private final int type;
|
||||
public FileEvent(File file, int type) {
|
||||
super(FileMonitor.this);
|
||||
this.file = file;
|
||||
this.type = type;
|
||||
}
|
||||
public File getFile() { return file; }
|
||||
public int getType() { return type; }
|
||||
public String toString() {
|
||||
return "FileEvent: " + file + ":" + type;
|
||||
}
|
||||
}
|
||||
|
||||
private final Map<File, Integer> watched = new HashMap<File, Integer>();
|
||||
private List<FileListener> listeners = new ArrayList<FileListener>();
|
||||
|
||||
protected abstract void watch(File file, int mask, boolean recursive) throws IOException ;
|
||||
protected abstract void unwatch(File file);
|
||||
public abstract void dispose();
|
||||
|
||||
public void addWatch(File dir) throws IOException {
|
||||
addWatch(dir, FILE_ANY);
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask) throws IOException {
|
||||
addWatch(dir, mask, dir.isDirectory());
|
||||
}
|
||||
|
||||
public void addWatch(File dir, int mask, boolean recursive) throws IOException {
|
||||
watched.put(dir, new Integer(mask));
|
||||
watch(dir, mask, recursive);
|
||||
}
|
||||
|
||||
public void removeWatch(File file) {
|
||||
if (watched.remove(file) != null) {
|
||||
unwatch(file);
|
||||
}
|
||||
}
|
||||
|
||||
protected void notify(FileEvent e) {
|
||||
for (FileListener listener : listeners) {
|
||||
listener.fileChanged(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void addFileListener(FileListener listener) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.add(listener);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
public synchronized void removeFileListener(FileListener x) {
|
||||
List<FileListener> list = new ArrayList<FileListener>(listeners);
|
||||
list.remove(x);
|
||||
listeners = list;
|
||||
}
|
||||
|
||||
protected void finalize() {
|
||||
for (File watchedFile : watched.keySet()) {
|
||||
removeWatch(watchedFile);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
||||
/** Canonical lazy loading of a singleton. */
|
||||
private static class Holder {
|
||||
public static final FileMonitor INSTANCE;
|
||||
static {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows")) {
|
||||
INSTANCE = new W32FileMonitor();
|
||||
}
|
||||
else {
|
||||
throw new Error("FileMonitor not implemented for " + os);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FileMonitor getInstance() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Copyright (c) 2010 Timothy Wall
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<!-- One sentence summary -->
|
||||
Provides integrated, extended drag and drop functionality,
|
||||
allowing ghosted drag images to be used on all platforms.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Denis Tulskiy
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* version 3 along with this work. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sun.jna.platform.mac;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Callback;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Author: Denis Tulskiy
|
||||
* Date: 7/25/11
|
||||
*/
|
||||
public interface Carbon {
|
||||
public static Carbon INSTANCE = (Carbon) Native.loadLibrary("Carbon", Carbon.class);
|
||||
|
||||
public static final int cmdKey = 0x0100;
|
||||
public static final int shiftKey = 0x0200;
|
||||
public static final int optionKey = 0x0800;
|
||||
public static final int controlKey = 0x1000;
|
||||
|
||||
/**
|
||||
* Obtains the event target reference for the standard toolbox dispatcher
|
||||
*/
|
||||
public Pointer GetEventDispatcherTarget();
|
||||
|
||||
/**
|
||||
* Installs an event handler on a specified event target.
|
||||
*/
|
||||
public int InstallEventHandler(Pointer inTarget, EventHandlerProcPtr inHandler, int inNumTypes, EventTypeSpec[] inList, Pointer inUserData, PointerByReference outRef);
|
||||
|
||||
/**
|
||||
* Registers a global hot key.
|
||||
*/
|
||||
public int RegisterEventHotKey(int inHotKeyCode, int inHotKeyModifiers, EventHotKeyID.ByValue inHotKeyID, Pointer inTarget, int inOptions, PointerByReference outRef);
|
||||
|
||||
/**
|
||||
* Obtains a parameter from the specified event.
|
||||
*/
|
||||
public int GetEventParameter(Pointer inEvent, int inName, int inDesiredType, Pointer outActualType, int inBufferSize, IntBuffer outActualSize, EventHotKeyID outData);
|
||||
|
||||
/**
|
||||
* Removes the specified event handler
|
||||
*/
|
||||
public int RemoveEventHandler(Pointer inHandlerRef);
|
||||
|
||||
/**
|
||||
* Unregisters a global hot key.
|
||||
*/
|
||||
public int UnregisterEventHotKey(Pointer inHotKey);
|
||||
|
||||
public class EventTypeSpec extends Structure {
|
||||
public int eventClass;
|
||||
public int eventKind;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "eventClass", "eventKind" }); }
|
||||
}
|
||||
|
||||
public static class EventHotKeyID extends Structure {
|
||||
public int signature;
|
||||
public int id;
|
||||
|
||||
public static class ByValue extends EventHotKeyID implements Structure.ByValue { }
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "signature", "id" }); }
|
||||
}
|
||||
|
||||
public static interface EventHandlerProcPtr extends Callback {
|
||||
public int callback(Pointer inHandlerCallRef, Pointer inEvent, Pointer inUserData);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.mac;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Library;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
public class MacFileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() { return true; }
|
||||
|
||||
public interface FileManager extends Library {
|
||||
int kFSFileOperationDefaultOptions = 0;
|
||||
int kFSFileOperationsOverwrite = 0x01;
|
||||
int kFSFileOperationsSkipSourcePermissionErrors = 0x02;
|
||||
int kFSFileOperationsDoNotMoveAcrossVolumes = 0x04;
|
||||
int kFSFileOperationsSkipPreflight = 0x08;
|
||||
|
||||
public FileManager INSTANCE = (FileManager)Native.loadLibrary("CoreServices", FileManager.class);
|
||||
int FSPathMoveObjectToTrashSync(String src, PointerByReference target, int options);
|
||||
}
|
||||
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
File home = new File(System.getProperty("user.home"));
|
||||
File trash = new File(home, ".Trash");
|
||||
if (!trash.exists()) {
|
||||
throw new IOException("The Trash was not found in its expected location (" + trash + ")");
|
||||
}
|
||||
List<File> failed = new ArrayList<File>();
|
||||
for (int i=0;i < files.length;i++) {
|
||||
File src = files[i];
|
||||
if (FileManager.INSTANCE.FSPathMoveObjectToTrashSync(src.getAbsolutePath(), null, 0) != 0) {
|
||||
failed.add(src);
|
||||
}
|
||||
}
|
||||
if (failed.size() > 0) {
|
||||
throw new IOException("The following files could not be trashed: " + failed);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Copyright (c) 2010 Timothy Wall
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<!-- One sentence summary -->
|
||||
Provides cross-platform utilities based on platform-specific libraries.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,13 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
Copyright (c) 2010 Timothy Wall
|
||||
-->
|
||||
</head>
|
||||
<body bgcolor="white">
|
||||
|
||||
<!-- One sentence summary -->
|
||||
Provides common library mappings for Unix and X11-based platforms.
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,127 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.IntegerType;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.ByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Based on basetsd.h (various types)
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public interface BaseTSD extends StdCallLibrary {
|
||||
/**
|
||||
* Signed long type for pointer precision.
|
||||
* Use when casting a pointer to a long to perform pointer arithmetic.
|
||||
*/
|
||||
public static class LONG_PTR extends IntegerType {
|
||||
public LONG_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LONG_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
|
||||
public Pointer toPointer() {
|
||||
return Pointer.createConstant(longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed SIZE_T.
|
||||
*/
|
||||
public static class SSIZE_T extends LONG_PTR {
|
||||
public SSIZE_T() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public SSIZE_T(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsigned LONG_PTR.
|
||||
*/
|
||||
public static class ULONG_PTR extends IntegerType {
|
||||
public ULONG_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ULONG_PTR(long value) {
|
||||
super(Pointer.SIZE, value, true);
|
||||
}
|
||||
|
||||
public Pointer toPointer() {
|
||||
return Pointer.createConstant(longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PULONG_PTR
|
||||
*/
|
||||
public static class ULONG_PTRByReference extends ByReference {
|
||||
public ULONG_PTRByReference() {
|
||||
this(new ULONG_PTR(0));
|
||||
}
|
||||
public ULONG_PTRByReference(ULONG_PTR value) {
|
||||
super(Pointer.SIZE);
|
||||
setValue(value);
|
||||
}
|
||||
public void setValue(ULONG_PTR value) {
|
||||
if (Pointer.SIZE == 4) {
|
||||
getPointer().setInt(0, value.intValue());
|
||||
}
|
||||
else {
|
||||
getPointer().setLong(0, value.longValue());
|
||||
}
|
||||
}
|
||||
public ULONG_PTR getValue() {
|
||||
return new ULONG_PTR(Pointer.SIZE == 4
|
||||
? getPointer().getInt(0)
|
||||
: getPointer().getLong(0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unsigned DWORD_PTR.
|
||||
*/
|
||||
public static class DWORD_PTR extends IntegerType {
|
||||
public DWORD_PTR() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORD_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The maximum number of bytes to which a pointer can point.
|
||||
* Use for a count that must span the full range of a pointer.
|
||||
*/
|
||||
public static class SIZE_T extends ULONG_PTR {
|
||||
public SIZE_T() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public SIZE_T(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Crypt32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Crypt32 extends StdCallLibrary {
|
||||
|
||||
Crypt32 INSTANCE = (Crypt32) Native.loadLibrary("Crypt32",
|
||||
Crypt32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The CryptProtectData function performs encryption on the data in a DATA_BLOB
|
||||
* structure. Typically, only a user with the same logon credential as the encrypter
|
||||
* can decrypt the data. In addition, the encryption and decryption usually must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that contains the plaintext to be encrypted.
|
||||
* @param szDataDescr
|
||||
* String with a readable description of the data to be encrypted. This description
|
||||
* string is included with the encrypted data. This parameter is optional and can
|
||||
* be set to NULL, except on Windows 2000.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used to encrypt the data. The DATA_BLOB structure used in the encryption
|
||||
* phase must also be used in the decryption phase. This parameter can be set to NULL
|
||||
* for no additional entropy.
|
||||
* @param pvReserved
|
||||
* Reserved for future use and must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL in both the encryption and decryption
|
||||
* phases.
|
||||
* @param dwFlags
|
||||
* One of CRYPTPROTECT_LOCAL_MACHINE, CRYPTPROTECT_UI_FORBIDDEN, CRYPTPROTECT_AUDIT,
|
||||
* CRYPTPROTECT_VERIFY_PROTECTION.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure that receives the encrypted data. When you have
|
||||
* finished using the DATA_BLOB structure, free its pbData member by calling the
|
||||
* LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the function returns TRUE. If the function fails,
|
||||
* it returns FALSE. For extended error information, call GetLastError.
|
||||
*/
|
||||
public boolean CryptProtectData(DATA_BLOB pDataIn, String szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
|
||||
/**
|
||||
* The CryptUnprotectData function decrypts and does an integrity check of the data in
|
||||
* a DATA_BLOB structure. Usually, only a user with the same logon credentials as the
|
||||
* encrypter can decrypt the data. In addition, the encryption and decryption must be
|
||||
* done on the same computer.
|
||||
* @param pDataIn
|
||||
* Pointer to a DATA_BLOB structure that holds the encrypted data. The DATA_BLOB
|
||||
* structure's cbData member holds the length of the pbData member's byte string that
|
||||
* contains the text to be encrypted.
|
||||
* @param szDataDescr
|
||||
* Pointer to a string-readable description of the encrypted data included with the
|
||||
* encrypted data. This parameter can be set to NULL. When you have finished using
|
||||
* ppszDataDescr, free it by calling the LocalFree function.
|
||||
* @param pOptionalEntropy
|
||||
* Pointer to a DATA_BLOB structure that contains a password or other additional
|
||||
* entropy used when the data was encrypted. This parameter can be set to NULL;
|
||||
* however, if an optional entropy DATA_BLOB structure was used in the encryption
|
||||
* phase, that same DATA_BLOB structure must be used for the decryption phase.
|
||||
* @param pvReserved
|
||||
* Reserved for future use; must be set to NULL.
|
||||
* @param pPromptStruct
|
||||
* Pointer to a CRYPTPROTECT_PROMPTSTRUCT structure that provides information about
|
||||
* where and when prompts are to be displayed and what the content of those prompts
|
||||
* should be. This parameter can be set to NULL.
|
||||
* @param dwFlags
|
||||
* DWORD value that specifies options for this function. This parameter can be zero,
|
||||
* in which case no option is set, or CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @param pDataOut
|
||||
* Pointer to a DATA_BLOB structure where the function stores the decrypted data.
|
||||
* When you have finished using the DATA_BLOB structure, free its pbData member by
|
||||
* calling the LocalFree function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is TRUE. If the function fails, the
|
||||
* return value is FALSE.
|
||||
*/
|
||||
public boolean CryptUnprotectData(DATA_BLOB pDataIn, PointerByReference szDataDescr,
|
||||
DATA_BLOB pOptionalEntropy, Pointer pvReserved,
|
||||
CRYPTPROTECT_PROMPTSTRUCT pPromptStruct,
|
||||
int dwFlags,
|
||||
DATA_BLOB pDataOut);
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WinCrypt.CRYPTPROTECT_PROMPTSTRUCT;
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Crypt32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Crypt32Util {
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data) {
|
||||
return cryptProtectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data with optional flags.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_LOCAL_MACHINE | CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Protected data.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, int flags) {
|
||||
return cryptProtectData(data, null, flags, "", null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect a blob of data.
|
||||
* @param data
|
||||
* Data to protect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param description
|
||||
* Optional description.
|
||||
* @param prompt
|
||||
* Prompt structure.
|
||||
* @return
|
||||
* Protected bytes.
|
||||
*/
|
||||
public static byte[] cryptProtectData(byte[] data, byte[] entropy, int flags,
|
||||
String description, CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataProtected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptProtectData(pDataIn, description,
|
||||
pEntropy, null, prompt, flags, pDataProtected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataProtected.getData();
|
||||
} finally {
|
||||
if (pDataProtected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataProtected.pbData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data) {
|
||||
return cryptUnprotectData(data, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param flags
|
||||
* Optional flags, eg. CRYPTPROTECT_UI_FORBIDDEN.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, int flags) {
|
||||
return cryptUnprotectData(data, null, flags, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unprotect a blob of data.
|
||||
* @param data
|
||||
* Data to unprotect.
|
||||
* @param entropy
|
||||
* Optional entropy.
|
||||
* @param flags
|
||||
* Optional flags.
|
||||
* @param prompt
|
||||
* Optional prompt structure.
|
||||
* @return
|
||||
* Unprotected blob of data.
|
||||
*/
|
||||
public static byte[] cryptUnprotectData(byte[] data, byte[] entropy, int flags,
|
||||
CRYPTPROTECT_PROMPTSTRUCT prompt) {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB(data);
|
||||
DATA_BLOB pDataUnprotected = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = (entropy == null) ? null : new DATA_BLOB(entropy);
|
||||
PointerByReference pDescription = new PointerByReference();
|
||||
try {
|
||||
if (! Crypt32.INSTANCE.CryptUnprotectData(pDataIn, pDescription,
|
||||
pEntropy, null, prompt, flags, pDataUnprotected)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return pDataUnprotected.getData();
|
||||
} finally {
|
||||
if (pDataUnprotected.pbData != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDataUnprotected.pbData);
|
||||
}
|
||||
if (pDescription.getValue() != null) {
|
||||
Kernel32.INSTANCE.LocalFree(pDescription.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,219 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
|
||||
/**
|
||||
* Ported from DsGetDC.h.
|
||||
* Windows SDK 6.0a
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface DsGetDC extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The DOMAIN_CONTROLLER_INFO structure is used with the DsGetDcName
|
||||
* function to receive data about a domain controller.
|
||||
*/
|
||||
public static class DOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends DOMAIN_CONTROLLER_INFO implements Structure.ByReference { }
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO() { }
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the computer name
|
||||
* of the discovered domain controller. The returned computer name is
|
||||
* prefixed with "\\". The DNS-style name, for example, "\\phoenix.fabrikam.com",
|
||||
* is returned, if available. If the DNS-style name is not available, the
|
||||
* flat-style name (for example, "\\phoenix") is returned. This example would apply
|
||||
* if the domain is a Windows NT 4.0 domain or if the domain does not support the
|
||||
* IP family of protocols.
|
||||
*/
|
||||
public WString DomainControllerName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the address of the discovered
|
||||
* domain controller. The address is prefixed with "\\". This WString is one of the
|
||||
* types defined by the DomainControllerAddressType member.
|
||||
*/
|
||||
public WString DomainControllerAddress;
|
||||
/**
|
||||
* Indicates the type of WString that is contained in the DomainControllerAddress member.
|
||||
*/
|
||||
public int DomainControllerAddressType;
|
||||
/**
|
||||
* The GUID of the domain. This member is zero if the domain controller does not have
|
||||
* a Domain GUID; for example, the domain controller is not a Windows 2000 domain
|
||||
* controller.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain. The
|
||||
* DNS-style name, for example, "fabrikam.com", is returned if available. Otherwise,
|
||||
* the flat-style name, for example, "fabrikam", is returned. This name may be different
|
||||
* than the requested domain name if the domain has been renamed.
|
||||
*/
|
||||
public WString DomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the domain at the root
|
||||
* of the DS tree. The DNS-style name, for example, "fabrikam.com", is returned if
|
||||
* available. Otherwise, the flat-style name, for example, "fabrikam" is returned.
|
||||
*/
|
||||
public WString DnsForestName;
|
||||
/**
|
||||
* Contains a set of flags that describe the domain controller.
|
||||
*/
|
||||
public int Flags;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site where the
|
||||
* domain controller is located. This member may be NULL if the domain controller is
|
||||
* not in a site; for example, the domain controller is a Windows NT 4.0 domain
|
||||
* controller.
|
||||
*/
|
||||
public WString DcSiteName;
|
||||
/**
|
||||
* Pointer to a null-terminated WString that specifies the name of the site that the
|
||||
* computer belongs to. The computer is specified in the ComputerName parameter passed
|
||||
* to DsGetDcName. This member may be NULL if the site that contains the computer
|
||||
* cannot be found; for example, if the DS administrator has not associated the
|
||||
* subnet that the computer is in with a valid site.
|
||||
*/
|
||||
public WString ClientSiteName;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "DomainControllerName", "DomainControllerAddress", "DomainGuid", "DomainName", "DnsForestName", "Flags", "DcSiteName", "ClientSiteName"});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to DOMAIN_CONTROLLER_INFO.
|
||||
*/
|
||||
public static class PDOMAIN_CONTROLLER_INFO extends Structure {
|
||||
|
||||
public static class ByReference extends PDOMAIN_CONTROLLER_INFO implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public DOMAIN_CONTROLLER_INFO.ByReference dci;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dci" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Domain is a member of the forest.
|
||||
*/
|
||||
int DS_DOMAIN_IN_FOREST = 0x0001;
|
||||
/**
|
||||
* Domain is directly trusted.
|
||||
*/
|
||||
int DS_DOMAIN_DIRECT_OUTBOUND = 0x0002;
|
||||
/**
|
||||
* Domain is root of a tree in the forest.
|
||||
*/
|
||||
int DS_DOMAIN_TREE_ROOT = 0x0004;
|
||||
/**
|
||||
* Domain is the primary domain of queried server.
|
||||
*/
|
||||
int DS_DOMAIN_PRIMARY = 0x0008;
|
||||
/**
|
||||
* Primary domain is running in native mode.
|
||||
*/
|
||||
int DS_DOMAIN_NATIVE_MODE = 0x0010;
|
||||
/**
|
||||
* Domain is directly trusting.
|
||||
*/
|
||||
int DS_DOMAIN_DIRECT_INBOUND = 0x0020;
|
||||
/**
|
||||
* Valid domain flags.
|
||||
*/
|
||||
int DS_DOMAIN_VALID_FLAGS =
|
||||
DS_DOMAIN_IN_FOREST |
|
||||
DS_DOMAIN_DIRECT_OUTBOUND |
|
||||
DS_DOMAIN_TREE_ROOT |
|
||||
DS_DOMAIN_PRIMARY |
|
||||
DS_DOMAIN_NATIVE_MODE |
|
||||
DS_DOMAIN_DIRECT_INBOUND;
|
||||
|
||||
/**
|
||||
* The DS_DOMAIN_TRUSTS structure is used with the DsEnumerateDomainTrusts function to
|
||||
* contain trust data for a domain.
|
||||
*/
|
||||
public static class DS_DOMAIN_TRUSTS extends Structure {
|
||||
|
||||
public static class ByReference extends DS_DOMAIN_TRUSTS implements Structure.ByReference {
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the NetBIOS name of the domain.
|
||||
*/
|
||||
public WString NetbiosDomainName;
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the DNS name of the domain. This member may be NULL.
|
||||
*/
|
||||
public WString DnsDomainName;
|
||||
/**
|
||||
* Contains a set of flags that specify more data about the domain trust.
|
||||
*/
|
||||
public int Flags;
|
||||
/**
|
||||
* Contains the index in the Domains array returned by the DsEnumerateDomainTrusts function that
|
||||
* corresponds to the parent domain of the domain represented by this structure.
|
||||
*/
|
||||
public int ParentIndex;
|
||||
/**
|
||||
* Contains a value that indicates the type of trust represented by this structure.
|
||||
*/
|
||||
public int TrustType;
|
||||
/**
|
||||
* Contains a value that indicates the attributes of the trust represented by this structure.
|
||||
*/
|
||||
public int TrustAttributes;
|
||||
|
||||
/**
|
||||
* Contains the security identifier of the domain represented by this structure.
|
||||
*/
|
||||
public PSID.ByReference DomainSid;
|
||||
|
||||
/**
|
||||
* Contains the GUID of the domain represented by this structure.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "NetbiosDomainName", "DnsDomainName", "Flags", "ParentIndex", "TrustType", "TrustAttributes", "DomainSid", "DomainGuid" });
|
||||
}
|
||||
|
||||
public DS_DOMAIN_TRUSTS() {
|
||||
}
|
||||
|
||||
public DS_DOMAIN_TRUSTS(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -1,316 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinDef.HBITMAP;
|
||||
import com.sun.jna.platform.win32.WinDef.HDC;
|
||||
import com.sun.jna.platform.win32.WinDef.HRGN;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFOHEADER;
|
||||
import com.sun.jna.platform.win32.WinGDI.RGNDATA;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition (incomplete) of <code>gdi32.dll</code>. */
|
||||
public interface GDI32 extends StdCallLibrary {
|
||||
|
||||
GDI32 INSTANCE = (GDI32) Native.loadLibrary("gdi32", GDI32.class,
|
||||
W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
/**
|
||||
* The ExtCreateRegion function creates a region from the specified region and transformation data.
|
||||
* @param lpXform
|
||||
* Pointer to an XFORM structure that defines the transformation to be performed on the region. If this pointer is NULL,
|
||||
* the identity transformation is used.
|
||||
* @param nCount
|
||||
* Specifies the number of bytes pointed to by lpRgnData.
|
||||
* @param lpRgnData
|
||||
* Pointer to a RGNDATA structure that contains the region data in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the value of the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
public HRGN ExtCreateRegion(Pointer lpXform, int nCount, RGNDATA lpRgnData);
|
||||
|
||||
/**
|
||||
* The CombineRgn function combines two regions and stores the result in a third region.
|
||||
* The two regions are combined according to the specified mode.
|
||||
* @param hrgnDest
|
||||
* Handle to a new region with dimensions defined by combining two other regions.
|
||||
* @param hrgnSrc1
|
||||
* Handle to the first of two regions to be combined.
|
||||
* @param hrgnSrc2
|
||||
* Handle to the second of two regions to be combined.
|
||||
* @param fnCombineMode
|
||||
* Specifies a mode indicating how the two regions will be combined.
|
||||
* @return
|
||||
* The return value specifies the type of the resulting region.
|
||||
*/
|
||||
int CombineRgn(HRGN hrgnDest, HRGN hrgnSrc1, HRGN hrgnSrc2,
|
||||
int fnCombineMode);
|
||||
|
||||
/**
|
||||
* The CreateRectRgn function creates a rectangular region.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the region in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect);
|
||||
|
||||
/**
|
||||
* The CreateRoundRectRgn function creates a rectangular region with rounded corners.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the region in logical units.
|
||||
* @param nWidthEllipse
|
||||
* Specifies the width of the ellipse used to create the rounded corners in logical units.
|
||||
* @param nHeightEllipse
|
||||
* Specifies the height of the ellipse used to create the rounded corners in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect, int nWidthEllipse, int nHeightEllipse);
|
||||
|
||||
/**
|
||||
* The CreatePolyPolygonRgn function creates a region consisting of a series
|
||||
* of polygons. The polygons can overlap.
|
||||
* @param lppt
|
||||
* Pointer to an array of POINT structures that define the vertices of the polygons in logical units.
|
||||
* The polygons are specified consecutively. Each polygon is presumed closed and each vertex is
|
||||
* specified only once.
|
||||
* @param lpPolyCounts
|
||||
* Pointer to an array of integers, each of which specifies the number of points in one of the polygons
|
||||
* in the array pointed to by lppt.
|
||||
* @param nCount
|
||||
* Specifies the total number of integers in the array pointed to by lpPolyCounts.
|
||||
* @param fnPolyFillMode
|
||||
* Specifies the fill mode used to determine which pixels are in the region.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to the region.
|
||||
* If the function fails, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HRGN CreatePolyPolygonRgn(WinUser.POINT[] lppt, int[] lpPolyCounts,
|
||||
int nCount, int fnPolyFillMode);
|
||||
|
||||
/**
|
||||
* The SetRectRgn function converts a region into a rectangular region with the specified coordinates.
|
||||
* @param hrgn
|
||||
* Handle to the region.
|
||||
* @param nLeftRect
|
||||
* Specifies the x-coordinate of the upper-left corner of the rectangular region in logical units.
|
||||
* @param nTopRect
|
||||
* Specifies the y-coordinate of the upper-left corner of the rectangular region in logical units.
|
||||
* @param nRightRect
|
||||
* Specifies the x-coordinate of the lower-right corner of the rectangular region in logical units.
|
||||
* @param nBottomRect
|
||||
* Specifies the y-coordinate of the lower-right corner of the rectangular region in logical units.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean SetRectRgn(HRGN hrgn, int nLeftRect, int nTopRect, int nRightRect,
|
||||
int nBottomRect);
|
||||
|
||||
/**
|
||||
* The SetPixel function sets the pixel at the specified coordinates to the specified color.
|
||||
* @param hDC
|
||||
* Handle to the device context.
|
||||
* @param x
|
||||
* Specifies the x-coordinate, in logical units, of the point to be set.
|
||||
* @param y
|
||||
* Specifies the y-coordinate, in logical units, of the point to be set.
|
||||
* @param crColor
|
||||
* Specifies the color to be used to paint the point. To create a COLORREF color value, use the RGB macro.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the RGB value that the function sets the pixel to.
|
||||
* This value may differ from the color specified by crColor; that occurs when an exact match for the
|
||||
* specified color cannot be found. If the function fails, the return value is 1. To get extended error
|
||||
* information, call GetLastError. This can be the following value.
|
||||
*/
|
||||
int SetPixel(HDC hDC, int x, int y, int crColor);
|
||||
|
||||
/**
|
||||
* The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.
|
||||
* @param hDC
|
||||
* Handle to an existing DC. If this handle is NULL, the function creates a memory DC compatible with the
|
||||
* application's current screen.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the handle to a memory DC.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HDC CreateCompatibleDC(HDC hDC);
|
||||
|
||||
/**
|
||||
* The DeleteDC function deletes the specified device context (DC).
|
||||
* @param hDC
|
||||
* Handle to the device context.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the function fails, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean DeleteDC(HDC hDC);
|
||||
|
||||
/**
|
||||
* The CreateDIBitmap function creates a compatible bitmap (DDB) from a DIB and, optionally,
|
||||
* sets the bitmap bits.
|
||||
* @param hDC
|
||||
* Handle to a device context.
|
||||
* @param lpbmih
|
||||
* Pointer to a bitmap information header structure, which may be one of those shown in the following table.
|
||||
* @param fdwInit
|
||||
* Specifies how the system initializes the bitmap bits.
|
||||
* @param lpbInit
|
||||
* Pointer to an array of bytes containing the initial bitmap data.
|
||||
* @param lpbmi
|
||||
* Pointer to a BITMAPINFO structure that describes the dimensions and color format of
|
||||
* the array pointed to by the lpbInit parameter.
|
||||
* @param fuUsage
|
||||
* Specifies whether the bmiColors member of the BITMAPINFO structure was initialized and, if so,
|
||||
* whether bmiColors contains explicit red, green, blue (RGB) values or palette indexes. The
|
||||
* fuUsage parameter must be one of the following values.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the compatible bitmap.
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HBITMAP CreateDIBitmap(HDC hDC, BITMAPINFOHEADER lpbmih, int fdwInit,
|
||||
Pointer lpbInit, BITMAPINFO lpbmi, int fuUsage);
|
||||
|
||||
/**
|
||||
* The CreateDIBSection function creates a DIB that applications can write to directly.
|
||||
* The function gives you a pointer to the location of the bitmap bit values. You can supply
|
||||
* a handle to a file-mapping object that the function will use to create the bitmap, or you
|
||||
* can let the system allocate the memory for the bitmap.
|
||||
* @param hDC
|
||||
* Handle to a device context. If the value of iUsage is DIB_PAL_COLORS, the function uses this
|
||||
* device context's logical palette to initialize the DIB colors.
|
||||
* @param pbmi
|
||||
* Pointer to a BITMAPINFO structure that specifies various attributes of the DIB, including
|
||||
* the bitmap dimensions and colors.
|
||||
* @param iUsage
|
||||
* Specifies the type of data contained in the bmiColors array member of the BITMAPINFO structure
|
||||
* pointed to by pbmi (either logical palette indexes or literal RGB values).
|
||||
* @param ppvBits
|
||||
* Pointer to a variable that receives a pointer to the location of the DIB bit values.
|
||||
* @param hSection
|
||||
* Handle to a file-mapping object that the function will use to create the DIB. This parameter can be NULL.
|
||||
* @param dwOffset
|
||||
* Specifies the offset from the beginning of the file-mapping object referenced by hSection where storage
|
||||
* for the bitmap bit values is to begin.
|
||||
* @return
|
||||
* Specifies the offset from the beginning of the file-mapping object referenced by hSection where storage
|
||||
* for the bitmap bit values is to begin.
|
||||
*/
|
||||
HBITMAP CreateDIBSection(HDC hDC, BITMAPINFO pbmi, int iUsage,
|
||||
PointerByReference ppvBits, Pointer hSection, int dwOffset);
|
||||
|
||||
/**
|
||||
* The CreateCompatibleBitmap function creates a bitmap compatible with the device that is
|
||||
* associated with the specified device context.
|
||||
* @param hDC
|
||||
* Handle to a device context.
|
||||
* @param width
|
||||
* Specifies the bitmap width, in pixels.
|
||||
* @param height
|
||||
* Specifies the bitmap height, in pixels.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a handle to the compatible bitmap (DDB).
|
||||
* If the function fails, the return value is NULL.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
HBITMAP CreateCompatibleBitmap(HDC hDC, int width, int height);
|
||||
|
||||
/**
|
||||
* The SelectObject function selects an object into the specified device context (DC).
|
||||
* The new object replaces the previous object of the same type.
|
||||
* @param hDC
|
||||
* Handle to the DC.
|
||||
* @param hGDIObj
|
||||
* Handle to the object to be selected.
|
||||
* @return
|
||||
* If the selected object is not a region and the function succeeds, the return value
|
||||
* is a handle to the object being replaced. If the selected object is a region and the
|
||||
* function succeeds, the return value is one of the REGION values.
|
||||
*/
|
||||
HANDLE SelectObject(HDC hDC, HANDLE hGDIObj);
|
||||
|
||||
/**
|
||||
* The DeleteObject function deletes a logical pen, brush, font, bitmap, region, or palette,
|
||||
* freeing all system resources associated with the object. After the object is deleted, the
|
||||
* specified handle is no longer valid.
|
||||
* @param hObject
|
||||
* Handle to a logical pen, brush, font, bitmap, region, or palette.
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
* If the specified handle is not valid or is currently selected into a DC, the return value is zero.
|
||||
* To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean DeleteObject(HANDLE hObject);
|
||||
|
||||
/** The GetDeviceCaps function retrieves device-specific information for
|
||||
* the specified device.
|
||||
* @param hdc A handle to the DC.
|
||||
* @param nIndex The item to be returned.
|
||||
* @return
|
||||
* The return value specifies the value of the desired item. When
|
||||
* <i>nIndex</i> is <code>BITSPIXEL</code> and the device has 15bpp or
|
||||
* 16bpp, the return value is 16.
|
||||
*/
|
||||
int GetDeviceCaps(HDC hdc, int nIndex);
|
||||
|
||||
/** The GetDIBits function retrieves the bits fo the specified compatible
|
||||
* bitmap and copies them into a buffer as a DIB using the specified
|
||||
* format.
|
||||
* @param hdc A handle to the device context.
|
||||
* @param hbmp A handle to the bitmap. This must be a compatible bitmap
|
||||
* (DDB).
|
||||
* @param uStartScan The first scan line to retrieve
|
||||
* @param cScanLines The number of scan lines to retrieve.
|
||||
* @param lpvBits A pointer to a buffer to receive the bitmap data. If
|
||||
* this parameter is <code>null</code>, the function passes the dimensions
|
||||
* and format of the bitmap to the {@link BITMAPINFO} structure pointed to
|
||||
* by the <i>lpbi</i> parameter.
|
||||
* @param lpbi A pointer to a {@link BITMAPINFO} structure that specifies
|
||||
* the desired format for the DIB data.
|
||||
* @param uUsage The format of the bmiColors member of the {@link
|
||||
* BITMAPINFO} structure.
|
||||
*/
|
||||
int GetDIBits(HDC hdc, HBITMAP hbmp, int uStartScan, int cScanLines, Pointer lpvBits, BITMAPINFO lpbi, int uUsage);
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
|
||||
/**
|
||||
* Ported from Guid.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Guid {
|
||||
|
||||
public static class GUID extends Structure {
|
||||
|
||||
public static class ByReference extends GUID implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(GUID guid) {
|
||||
super(guid.getPointer());
|
||||
|
||||
Data1 = guid.Data1;
|
||||
Data2 = guid.Data2;
|
||||
Data3 = guid.Data3;
|
||||
Data4 = guid.Data4;
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public GUID() {
|
||||
|
||||
}
|
||||
|
||||
public GUID(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public GUID(byte[] data) {
|
||||
if (data.length != 16) {
|
||||
throw new IllegalArgumentException("Invalid data length: " + data.length);
|
||||
}
|
||||
|
||||
long data1Temp = data[3] & 0xff;
|
||||
data1Temp <<= 8;
|
||||
data1Temp |= data[2] & 0xff;
|
||||
data1Temp <<= 8;
|
||||
data1Temp |= data[1] & 0xff;
|
||||
data1Temp <<= 8;
|
||||
data1Temp |= data[0] & 0xff;
|
||||
Data1 = (int) data1Temp;
|
||||
|
||||
int data2Temp = data[5] & 0xff;
|
||||
data2Temp <<= 8;
|
||||
data2Temp |= data[4] & 0xff;
|
||||
Data2 = (short) data2Temp;
|
||||
|
||||
int data3Temp = data[7] & 0xff;
|
||||
data3Temp <<= 8;
|
||||
data3Temp |= data[6] & 0xff;
|
||||
Data3 = (short) data3Temp;
|
||||
|
||||
Data4[0] = data[8];
|
||||
Data4[1] = data[9];
|
||||
Data4[2] = data[10];
|
||||
Data4[3] = data[11];
|
||||
Data4[4] = data[12];
|
||||
Data4[5] = data[13];
|
||||
Data4[6] = data[14];
|
||||
Data4[7] = data[15];
|
||||
}
|
||||
|
||||
public int Data1;
|
||||
public short Data2;
|
||||
public short Data3;
|
||||
public byte[] Data4 = new byte[8];
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Data1", "Data2", "Data3", "Data4" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,228 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.LastErrorException;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Kernel32 utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Kernel32Util implements WinDef {
|
||||
|
||||
/**
|
||||
* Get current computer NetBIOS name.
|
||||
* @return
|
||||
* Netbios name.
|
||||
*/
|
||||
public static String getComputerName() {
|
||||
char buffer[] = new char[WinBase.MAX_COMPUTERNAME_LENGTH + 1];
|
||||
IntByReference lpnSize = new IntByReference(buffer.length);
|
||||
if (! Kernel32.INSTANCE.GetComputerName(buffer, lpnSize)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a message from an HRESULT.
|
||||
* @param code
|
||||
* HRESULT
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromHR(HRESULT code) {
|
||||
PointerByReference buffer = new PointerByReference();
|
||||
if (0 == Kernel32.INSTANCE.FormatMessage(
|
||||
WinBase.FORMAT_MESSAGE_ALLOCATE_BUFFER
|
||||
| WinBase.FORMAT_MESSAGE_FROM_SYSTEM
|
||||
| WinBase.FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
null,
|
||||
code.intValue(),
|
||||
0, // TODO: MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT)
|
||||
buffer,
|
||||
0,
|
||||
null)) {
|
||||
throw new LastErrorException(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
String s = buffer.getValue().getString(0, ! Boolean.getBoolean("w32.ascii"));
|
||||
Kernel32.INSTANCE.LocalFree(buffer.getValue());
|
||||
return s.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a system message from an error code.
|
||||
* @param code
|
||||
* Error code, typically a result of GetLastError.
|
||||
* @return
|
||||
* Formatted message.
|
||||
*/
|
||||
public static String formatMessageFromLastErrorCode(int code) {
|
||||
return formatMessageFromHR(W32Errors.HRESULT_FROM_WIN32(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path designated for temporary files.
|
||||
* @return
|
||||
* Path.
|
||||
*/
|
||||
public static String getTempPath() {
|
||||
DWORD nBufferLength = new DWORD(WinDef.MAX_PATH);
|
||||
char[] buffer = new char[nBufferLength.intValue()];
|
||||
if (Kernel32.INSTANCE.GetTempPath(nBufferLength, buffer).intValue() == 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
public static void deleteFile(String filename) {
|
||||
if (! Kernel32.INSTANCE.DeleteFile(filename)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns valid drives in the system.
|
||||
* @return
|
||||
* An array of valid drives.
|
||||
*/
|
||||
public static String[] getLogicalDriveStrings() {
|
||||
DWORD dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(new DWORD(0), null);
|
||||
if (dwSize.intValue() <= 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
char buf[] = new char[dwSize.intValue()];
|
||||
dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf);
|
||||
if (dwSize.intValue() <= 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
List<String> drives = new ArrayList<String>();
|
||||
String drive = "";
|
||||
// the buffer is double-null-terminated
|
||||
for(int i = 0; i < buf.length - 1; i++) {
|
||||
if (buf[i] == 0) {
|
||||
drives.add(drive);
|
||||
drive = "";
|
||||
} else {
|
||||
drive += buf[i];
|
||||
}
|
||||
}
|
||||
return drives.toArray(new String[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves file system attributes for a specified file or directory.
|
||||
* @param fileName
|
||||
* The name of the file or directory.
|
||||
* @return
|
||||
* The attributes of the specified file or directory.
|
||||
*/
|
||||
public static int getFileAttributes(String fileName) {
|
||||
int fileAttributes = Kernel32.INSTANCE.GetFileAttributes(fileName);
|
||||
if (fileAttributes == WinBase.INVALID_FILE_ATTRIBUTES) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return fileAttributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the result of GetFileType, provided the file exists.
|
||||
*/
|
||||
public static int getFileType(String fileName) throws FileNotFoundException {
|
||||
File f = new File(fileName);
|
||||
if (!f.exists()) {
|
||||
throw new FileNotFoundException(fileName);
|
||||
}
|
||||
|
||||
HANDLE hFile = null;
|
||||
try {
|
||||
hFile = Kernel32.INSTANCE.CreateFile(fileName,
|
||||
WinNT.GENERIC_READ,
|
||||
WinNT.FILE_SHARE_READ,
|
||||
new WinBase.SECURITY_ATTRIBUTES(),
|
||||
WinNT.OPEN_EXISTING,
|
||||
WinNT.FILE_ATTRIBUTE_NORMAL,
|
||||
new HANDLEByReference().getValue());
|
||||
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(hFile)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
int type = Kernel32.INSTANCE.GetFileType(hFile);
|
||||
switch(type) {
|
||||
case WinNT.FILE_TYPE_UNKNOWN:
|
||||
int err = Kernel32.INSTANCE.GetLastError();
|
||||
switch(err) {
|
||||
case W32Errors.NO_ERROR:
|
||||
break;
|
||||
default:
|
||||
throw new Win32Exception(err);
|
||||
}
|
||||
// fall-thru
|
||||
|
||||
default:
|
||||
return type;
|
||||
}
|
||||
} finally {
|
||||
if (hFile != null) {
|
||||
if (! Kernel32.INSTANCE.CloseHandle(hFile)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return One of the WinBase.DRIVE_* constants.
|
||||
*/
|
||||
public static int getDriveType(String rootName) {
|
||||
return Kernel32.INSTANCE.GetDriveType(rootName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an environment variable.
|
||||
* @param name
|
||||
* Name of the environment variable.
|
||||
* @return
|
||||
* Value of an environment variable.
|
||||
*/
|
||||
public static String getEnvironmentVariable(String name) {
|
||||
// obtain the buffer size
|
||||
int size = Kernel32.INSTANCE.GetEnvironmentVariable(name, null, 0);
|
||||
if (size == 0) {
|
||||
return null;
|
||||
} else if (size < 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
// obtain the value
|
||||
char[] buffer = new char[size];
|
||||
size = Kernel32.INSTANCE.GetEnvironmentVariable(name, buffer, buffer.length);
|
||||
if (size <= 0) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
}
|
||||
@@ -1,426 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMAccess.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMAccess extends StdCallLibrary {
|
||||
|
||||
public static class LOCALGROUP_INFO_0 extends Structure {
|
||||
public LOCALGROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_0(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui0_name;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "lgrui0_name" });
|
||||
}
|
||||
}
|
||||
|
||||
public static class LOCALGROUP_INFO_1 extends Structure {
|
||||
public LOCALGROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_INFO_1(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WString lgrui1_name;
|
||||
public WString lgrui1_comment;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "lgrui1_name", "lgrui1_comment" });
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// bit masks for the NetUserEnum filter parameter.
|
||||
//
|
||||
|
||||
int FILTER_TEMP_DUPLICATE_ACCOUNT = 0x0001;
|
||||
int FILTER_NORMAL_ACCOUNT = 0x0002;
|
||||
// int FILTER_PROXY_ACCOUNT = 0x0004;
|
||||
int FILTER_INTERDOMAIN_TRUST_ACCOUNT = 0x0008;
|
||||
int FILTER_WORKSTATION_TRUST_ACCOUNT = 0x0010;
|
||||
int FILTER_SERVER_TRUST_ACCOUNT = 0x0020;
|
||||
|
||||
/**
|
||||
* The USER_INFO_0 structure contains a user account name.
|
||||
*/
|
||||
public static class USER_INFO_0 extends Structure {
|
||||
public USER_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_0(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user account.
|
||||
*/
|
||||
public WString usri0_name;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "usri0_name" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The USER_INFO_1 structure contains information about a user account, including
|
||||
* account name, password data, privilege level, and the path to the user's home
|
||||
* directory.
|
||||
*/
|
||||
public static class USER_INFO_1 extends Structure {
|
||||
public USER_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_1(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the name of the user
|
||||
* account.
|
||||
*/
|
||||
public WString usri1_name;
|
||||
/**
|
||||
* Pointer to a Unicode string that specifies the password of the user
|
||||
* indicated by the usri1_name member.
|
||||
*/
|
||||
public WString usri1_password;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the number of seconds that have
|
||||
* elapsed since the usri1_password member was last changed.
|
||||
*/
|
||||
public int usri1_password_age;
|
||||
/**
|
||||
* Specifies a DWORD value that indicates the level of privilege assigned
|
||||
* to the usri1_name member.
|
||||
*/
|
||||
public int usri1_priv;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path of the home directory
|
||||
* for the user specified in the usri1_name member.
|
||||
*/
|
||||
public WString usri1_home_dir;
|
||||
/**
|
||||
* Pointer to a Unicode string that contains a comment to associate with
|
||||
* the user account.
|
||||
*/
|
||||
public WString usri1_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that determines several features.
|
||||
*/
|
||||
public int usri1_flags;
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the path for the user's
|
||||
* logon script file.
|
||||
*/
|
||||
public WString usri1_script_path;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "usri1_name", "usri1_password", "usri1_password_age", "usri1_priv", "usri1_home_dir", "usri1_comment", "usri1_flags", "usri1_script_path" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The USER_INFO_23 structure contains information about a user account,
|
||||
* including the account name, the user's full name, a comment associated with the account,
|
||||
* and the user's security identifier (SID).
|
||||
*
|
||||
* Note :
|
||||
* The USER_INFO_23 structure supersedes the USER_INFO_20 structure.
|
||||
* It is recommended that applications use the USER_INFO_23 structure instead of the USER_INFO_20 structure.
|
||||
*/
|
||||
public static class USER_INFO_23 extends Structure {
|
||||
public USER_INFO_23() {
|
||||
super();
|
||||
}
|
||||
|
||||
public USER_INFO_23(Pointer memory) {
|
||||
useMemory(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer to a Unicode string that specifies the name of the user account.
|
||||
* Calls to the NetUserSetInfo function ignore this member.
|
||||
*/
|
||||
public WString usri23_name;
|
||||
/**
|
||||
* A pointer to a Unicode string that contains the full name of the user.
|
||||
* This string can be a null string, or it can have any number of characters before the terminating null character.
|
||||
*/
|
||||
public WString usri23_full_name;
|
||||
/**
|
||||
* A pointer to a Unicode string that contains a comment associated with the user account.
|
||||
* This string can be a null string, or it can have any number of characters before the terminating null character.
|
||||
*/
|
||||
public WString usri23_comment;
|
||||
/**
|
||||
* This member can be one or more of the following values.
|
||||
* Note that setting user account control flags may require certain privileges and control access rights.
|
||||
* For more information, see the Remarks section of the NetUserSetInfo function.
|
||||
* Value Meaning
|
||||
* UF_SCRIPT The logon script executed. This value must be set.
|
||||
* UF_ACCOUNTDISABLE The user's account is disabled.
|
||||
* UF_HOMEDIR_REQUIRED The home directory is required. This value is ignored.
|
||||
* UF_PASSWD_NOTREQD No password is required.
|
||||
* UF_PASSWD_CANT_CHANGE The user cannot change the password.
|
||||
* UF_LOCKOUT The account is currently locked out. You can call the NetUserSetInfo function to clear this value and unlock a previously locked account. You cannot use this value to lock a previously unlocked account.
|
||||
* UF_DONT_EXPIRE_PASSWD The password should never expire on the account.
|
||||
* UF_ENCRYPTED_TEXT_PASSWORD_ALLOWED The user's password is stored under reversible encryption in the Active Directory.
|
||||
* UF_NOT_DELEGATED Marks the account as "sensitive"; other users cannot act as delegates of this user account.
|
||||
* UF_SMARTCARD_REQUIRED Requires the user to log on to the user account with a smart card.
|
||||
* UF_USE_DES_KEY_ONLY Restrict this principal to use only Data Encryption Standard (DES) encryption types for keys.
|
||||
* UF_DONT_REQUIRE_PREAUTH This account does not require Kerberos preauthentication for logon.
|
||||
* UF_TRUSTED_FOR_DELEGATION The account is enabled for delegation. This is a security-sensitive setting; accounts with this option enabled should be tightly controlled. This setting allows a service running under the account to assume a client's identity and authenticate as that user to other remote servers on the network.
|
||||
* UF_PASSWORD_EXPIRED The user's password has expired. Windows 2000: This value is not supported.
|
||||
* UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION The account is trusted to authenticate a user outside of the Kerberos security package and delegate that user through constrained delegation. This is a security-sensitive setting; accounts with this option enabled should be tightly controlled. This setting allows a service running under the account to assert a client's identity and authenticate as that user to specifically configured services on the network. Windows XP/2000: This value is not supported.
|
||||
*
|
||||
* The following values describe the account type. Only one value can be set. You cannot change the account type using the NetUserSetInfo function.
|
||||
* Value Meaning
|
||||
* UF_NORMAL_ACCOUNT This is a default account type that represents a typical user.
|
||||
* UF_TEMP_DUPLICATE_ACCOUNT This is an account for users whose primary account is in another domain. This account provides user access to this domain, but not to any domain that trusts this domain. The User Manager refers to this account type as a local user account.
|
||||
* UF_WORKSTATION_TRUST_ACCOUNT This is a computer account for a computer that is a member of this domain.
|
||||
* UF_SERVER_TRUST_ACCOUNT This is a computer account for a backup domain controller that is a member of this domain.
|
||||
* UF_INTERDOMAIN_TRUST_ACCOUNT This is a permit to trust account for a domain that trusts other domains.
|
||||
*/
|
||||
public int usri23_flags;
|
||||
/**
|
||||
* A pointer to a SID structure that contains the security identifier (SID)
|
||||
* that uniquely identifies the user. The NetUserAdd and NetUserSetInfo functions ignore this member.
|
||||
*/
|
||||
public PSID.ByReference usri23_user_sid;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "usri23_name", "usri23_full_name", "usri23_comment", "usri23_flags", "usri23_user_sid" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_USERS_INFO_0 structure contains global group member information.
|
||||
*/
|
||||
public static class GROUP_USERS_INFO_0 extends Structure {
|
||||
public GROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_USERS_INFO_0(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies a name.
|
||||
*/
|
||||
public WString grui0_name;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "grui0_name" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The LOCALGROUP_USERS_INFO_0 structure contains local group member information.
|
||||
*/
|
||||
public static class LOCALGROUP_USERS_INFO_0 extends Structure {
|
||||
public LOCALGROUP_USERS_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public LOCALGROUP_USERS_INFO_0(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a Unicode string specifying the name of a local group to which the user belongs.
|
||||
*/
|
||||
public WString lgrui0_name;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "lgrui0_name" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_0 structure contains the name of a global group in the security
|
||||
* database, which is the security accounts manager (SAM) database or, in the case
|
||||
* of domain controllers, the Active Directory.
|
||||
*/
|
||||
public static class GROUP_INFO_0 extends Structure {
|
||||
public GROUP_INFO_0() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_0(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi0_name;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "grpi0_name" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_1 structure contains a global group name and a comment to
|
||||
* associate with the group.
|
||||
*/
|
||||
public static class GROUP_INFO_1 extends Structure {
|
||||
public GROUP_INFO_1() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_1(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* the name of the global group.
|
||||
*/
|
||||
public WString grpi1_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that specifies
|
||||
* a remark associated with the global group. This member can be a null
|
||||
* string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi1_comment;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "grpi1_name", "grpi1_comment" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_2 structure contains information about a global group, including
|
||||
* name, identifier, and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_2 extends Structure {
|
||||
public GROUP_INFO_2() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_2(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi2_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that contains a
|
||||
* remark associated with the global group. This member can be a null string.
|
||||
* The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi2_comment;
|
||||
/**
|
||||
* Specifies a DWORD value that contains the relative identifier (RID) of
|
||||
* the global group.
|
||||
*/
|
||||
public int grpi2_group_id;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED,
|
||||
* and SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi2_attributes;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "grpi2_name", "grpi2_comment", "grpi2_group_id", "grpi2_attributes" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The GROUP_INFO_3 structure contains information about a global group, including
|
||||
* name, security identifier (SID), and resource attributes.
|
||||
*/
|
||||
public static class GROUP_INFO_3 extends Structure {
|
||||
public GROUP_INFO_3() {
|
||||
super();
|
||||
}
|
||||
|
||||
public GROUP_INFO_3(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* specifies the name of the global group.
|
||||
*/
|
||||
public WString grpi3_name;
|
||||
/**
|
||||
* Pointer to a null-terminated Unicode character string that
|
||||
* contains a remark associated with the global group. This member can be
|
||||
* a null string. The comment can contain MAXCOMMENTSZ characters.
|
||||
*/
|
||||
public WString grpi3_comment;
|
||||
/**
|
||||
* Pointer to a SID structure that contains the security identifier (SID) that
|
||||
* uniquely identifies the global group.
|
||||
*/
|
||||
public PSID.ByReference grpi3_group_sid;
|
||||
/**
|
||||
* These attributes are hard-coded to SE_GROUP_MANDATORY, SE_GROUP_ENABLED, and
|
||||
* SE_GROUP_ENABLED_BY_DEFAULT.
|
||||
*/
|
||||
public int grpi3_attributes;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "grpi3_name", "grpi3_comment", "grpi3_group_id", "grpi3_attributes" });
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Privilege levels (USER_INFO_X field usriX_priv (X = 0/1)).
|
||||
//
|
||||
|
||||
int USER_PRIV_MASK = 3;
|
||||
int USER_PRIV_GUEST = 0;
|
||||
int USER_PRIV_USER = 1;
|
||||
int USER_PRIV_ADMIN = 2;
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMCons.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMCons extends StdCallLibrary {
|
||||
int NETBIOS_NAME_LEN = 16; // NetBIOS net name (bytes)
|
||||
|
||||
/**
|
||||
* Value to be used with APIs which have a "preferred maximum length" parameter.
|
||||
* This value indicates that the API should just allocate "as much as it takes."
|
||||
*/
|
||||
int MAX_PREFERRED_LENGTH = -1;
|
||||
}
|
||||
@@ -1,567 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMErr.h.
|
||||
* @author dblock[at]dblock.org
|
||||
* Windows SDK 6.0A
|
||||
*/
|
||||
public interface LMErr extends StdCallLibrary {
|
||||
int NERR_Success = 0;
|
||||
int NERR_BASE = 2100;
|
||||
|
||||
int NERR_NetNotStarted = NERR_BASE + 2; /* The workstation driver is not installed. */
|
||||
int NERR_UnknownServer = NERR_BASE + 3; /* The server could not be located. */
|
||||
int NERR_ShareMem = NERR_BASE + 4; /* An internal error occurred. The network cannot access a shared memory segment. */
|
||||
|
||||
int NERR_NoNetworkResource = NERR_BASE + 5; /* A network resource shortage occurred . */
|
||||
int NERR_RemoteOnly = NERR_BASE + 6; /* This operation is not supported on workstations. */
|
||||
int NERR_DevNotRedirected = NERR_BASE + 7; /* The device is not connected. */
|
||||
/* NERR_BASE + 8 is used for ERROR_CONNECTED_OTHER_PASSWORD */
|
||||
/* NERR_BASE + 9 is used for ERROR_CONNECTED_OTHER_PASSWORD_DEFAULT */
|
||||
/* UNUSED BASE + 10 */
|
||||
/* UNUSED BASE + 11 */
|
||||
/* UNUSED BASE + 12 */
|
||||
/* UNUSED BASE + 13 */
|
||||
int NERR_ServerNotStarted = NERR_BASE + 14; /* The Server service is not started. */
|
||||
int NERR_ItemNotFound = NERR_BASE + 15; /* The queue is empty. */
|
||||
int NERR_UnknownDevDir = NERR_BASE + 16; /* The device or directory does not exist. */
|
||||
int NERR_RedirectedPath = NERR_BASE + 17; /* The operation is invalid on a redirected resource. */
|
||||
int NERR_DuplicateShare = NERR_BASE + 18; /* The name has already been shared. */
|
||||
int NERR_NoRoom = NERR_BASE + 19; /* The server is currently out of the requested resource. */
|
||||
/* UNUSED BASE + 20 */
|
||||
int NERR_TooManyItems = NERR_BASE + 21; /* Requested addition of items exceeds the maximum allowed. */
|
||||
int NERR_InvalidMaxUsers = NERR_BASE + 22; /* The Peer service supports only two simultaneous users. */
|
||||
int NERR_BufTooSmall = NERR_BASE + 23; /* The API return buffer is too small. */
|
||||
/* UNUSED BASE + 24 */
|
||||
/* UNUSED BASE + 25 */
|
||||
/* UNUSED BASE + 26 */
|
||||
int NERR_RemoteErr = NERR_BASE + 27; /* A remote API error occurred. */
|
||||
/* UNUSED BASE + 28 */
|
||||
/* UNUSED BASE + 29 */
|
||||
/* UNUSED BASE + 30 */
|
||||
int NERR_LanmanIniError = NERR_BASE + 31; /* An error occurred when opening or reading the configuration file. */
|
||||
/* UNUSED BASE + 32 */
|
||||
/* UNUSED BASE + 33 */
|
||||
/* UNUSED BASE + 34 */
|
||||
/* UNUSED BASE + 35 */
|
||||
int NERR_NetworkError = NERR_BASE + 36; /* A general network error occurred. */
|
||||
int NERR_WkstaInconsistentState = NERR_BASE + 37;
|
||||
/* The Workstation service is in an inconsistent state. Restart the computer before restarting the Workstation service. */
|
||||
int NERR_WkstaNotStarted = NERR_BASE + 38; /* The Workstation service has not been started. */
|
||||
int NERR_BrowserNotStarted = NERR_BASE + 39; /* The requested information is not available. */
|
||||
int NERR_InternalError = NERR_BASE + 40; /* An internal Windows error occurred.*/
|
||||
int NERR_BadTransactConfig = NERR_BASE + 41; /* The server is not configured for transactions. */
|
||||
int NERR_InvalidAPI = NERR_BASE + 42; /* The requested API is not supported on the remote server. */
|
||||
int NERR_BadEventName = NERR_BASE + 43; /* The event name is invalid. */
|
||||
int NERR_DupNameReboot = NERR_BASE + 44; /* The computer name already exists on the network. Change it and restart the computer. */
|
||||
/*
|
||||
* Config API related
|
||||
* Error codes from BASE + 45 to BASE + 49
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 45 */
|
||||
int NERR_CfgCompNotFound = NERR_BASE + 46; /* The specified component could not be found in the configuration information. */
|
||||
int NERR_CfgParamNotFound = NERR_BASE + 47; /* The specified parameter could not be found in the configuration information. */
|
||||
int NERR_LineTooLong = NERR_BASE + 49; /* A line in the configuration file is too long. */
|
||||
|
||||
/*
|
||||
* Spooler API related
|
||||
* Error codes from BASE + 50 to BASE + 79
|
||||
*/
|
||||
|
||||
int NERR_QNotFound = NERR_BASE + 50; /* The printer does not exist. */
|
||||
int NERR_JobNotFound = NERR_BASE + 51; /* The print job does not exist. */
|
||||
int NERR_DestNotFound = NERR_BASE + 52; /* The printer destination cannot be found. */
|
||||
int NERR_DestExists = NERR_BASE + 53; /* The printer destination already exists. */
|
||||
int NERR_QExists = NERR_BASE + 54; /* The printer queue already exists. */
|
||||
int NERR_QNoRoom = NERR_BASE + 55; /* No more printers can be added. */
|
||||
int NERR_JobNoRoom = NERR_BASE + 56; /* No more print jobs can be added. */
|
||||
int NERR_DestNoRoom = NERR_BASE + 57; /* No more printer destinations can be added. */
|
||||
int NERR_DestIdle = NERR_BASE + 58; /* This printer destination is idle and cannot accept control operations. */
|
||||
int NERR_DestInvalidOp = NERR_BASE + 59; /* This printer destination request contains an invalid control function. */
|
||||
int NERR_ProcNoRespond = NERR_BASE + 60; /* The print processor is not responding. */
|
||||
int NERR_SpoolerNotLoaded = NERR_BASE + 61; /* The spooler is not running. */
|
||||
int NERR_DestInvalidState = NERR_BASE + 62; /* This operation cannot be performed on the print destination in its current state. */
|
||||
int NERR_QInvalidState = NERR_BASE + 63; /* This operation cannot be performed on the printer queue in its current state. */
|
||||
int NERR_JobInvalidState = NERR_BASE + 64; /* This operation cannot be performed on the print job in its current state. */
|
||||
int NERR_SpoolNoMemory = NERR_BASE + 65; /* A spooler memory allocation failure occurred. */
|
||||
int NERR_DriverNotFound = NERR_BASE + 66; /* The device driver does not exist. */
|
||||
int NERR_DataTypeInvalid = NERR_BASE + 67; /* The data type is not supported by the print processor. */
|
||||
int NERR_ProcNotFound = NERR_BASE + 68; /* The print processor is not installed. */
|
||||
|
||||
/*
|
||||
* Service API related
|
||||
* Error codes from BASE + 80 to BASE + 99
|
||||
*/
|
||||
|
||||
int NERR_ServiceTableLocked = NERR_BASE + 80; /* The service database is locked. */
|
||||
int NERR_ServiceTableFull = NERR_BASE + 81; /* The service table is full. */
|
||||
int NERR_ServiceInstalled = NERR_BASE + 82; /* The requested service has already been started. */
|
||||
int NERR_ServiceEntryLocked = NERR_BASE + 83; /* The service does not respond to control actions. */
|
||||
int NERR_ServiceNotInstalled = NERR_BASE + 84; /* The service has not been started. */
|
||||
int NERR_BadServiceName = NERR_BASE + 85; /* The service name is invalid. */
|
||||
int NERR_ServiceCtlTimeout = NERR_BASE + 86; /* The service is not responding to the control function. */
|
||||
int NERR_ServiceCtlBusy = NERR_BASE + 87; /* The service control is busy. */
|
||||
int NERR_BadServiceProgName = NERR_BASE + 88; /* The configuration file contains an invalid service program name. */
|
||||
int NERR_ServiceNotCtrl = NERR_BASE + 89; /* The service could not be controlled in its present state. */
|
||||
int NERR_ServiceKillProc = NERR_BASE + 90; /* The service ended abnormally. */
|
||||
int NERR_ServiceCtlNotValid = NERR_BASE + 91; /* The requested pause, continue, or stop is not valid for this service. */
|
||||
int NERR_NotInDispatchTbl = NERR_BASE + 92; /* The service control dispatcher could not find the service name in the dispatch table. */
|
||||
int NERR_BadControlRecv = NERR_BASE + 93; /* The service control dispatcher pipe read failed. */
|
||||
int NERR_ServiceNotStarting = NERR_BASE + 94; /* A thread for the new service could not be created. */
|
||||
|
||||
/*
|
||||
* Wksta and Logon API related
|
||||
* Error codes from BASE + 100 to BASE + 118
|
||||
*/
|
||||
|
||||
int NERR_AlreadyLoggedOn = NERR_BASE + 100; /* This workstation is already logged on to the local-area network. */
|
||||
int NERR_NotLoggedOn = NERR_BASE + 101; /* The workstation is not logged on to the local-area network. */
|
||||
int NERR_BadUsername = NERR_BASE + 102; /* The user name or group name parameter is invalid. */
|
||||
int NERR_BadPassword = NERR_BASE + 103; /* The password parameter is invalid. */
|
||||
int NERR_UnableToAddName_W = NERR_BASE + 104; /* @W The logon processor did not add the message alias. */
|
||||
int NERR_UnableToAddName_F = NERR_BASE + 105; /* The logon processor did not add the message alias. */
|
||||
int NERR_UnableToDelName_W = NERR_BASE + 106; /* @W The logoff processor did not delete the message alias. */
|
||||
int NERR_UnableToDelName_F = NERR_BASE + 107; /* The logoff processor did not delete the message alias. */
|
||||
/* UNUSED BASE + 108 */
|
||||
int NERR_LogonsPaused = NERR_BASE + 109; /* Network logons are paused. */
|
||||
int NERR_LogonServerConflict = NERR_BASE + 110;/* A centralized logon-server conflict occurred. */
|
||||
int NERR_LogonNoUserPath = NERR_BASE + 111; /* The server is configured without a valid user path. */
|
||||
int NERR_LogonScriptError = NERR_BASE + 112; /* An error occurred while loading or running the logon script. */
|
||||
/* UNUSED BASE + 113 */
|
||||
int NERR_StandaloneLogon = NERR_BASE + 114; /* The logon server was not specified. Your computer will be logged on as STANDALONE. */
|
||||
int NERR_LogonServerNotFound = NERR_BASE + 115; /* The logon server could not be found. */
|
||||
int NERR_LogonDomainExists = NERR_BASE + 116; /* There is already a logon domain for this computer. */
|
||||
int NERR_NonValidatedLogon = NERR_BASE + 117; /* The logon server could not validate the logon. */
|
||||
|
||||
/*
|
||||
* ACF API related = access, user, group;
|
||||
* Error codes from BASE + 119 to BASE + 149
|
||||
*/
|
||||
|
||||
int NERR_ACFNotFound = NERR_BASE + 119; /* The security database could not be found. */
|
||||
int NERR_GroupNotFound = NERR_BASE + 120; /* The group name could not be found. */
|
||||
int NERR_UserNotFound = NERR_BASE + 121; /* The user name could not be found. */
|
||||
int NERR_ResourceNotFound = NERR_BASE + 122; /* The resource name could not be found. */
|
||||
int NERR_GroupExists = NERR_BASE + 123; /* The group already exists. */
|
||||
int NERR_UserExists = NERR_BASE + 124; /* The account already exists. */
|
||||
int NERR_ResourceExists = NERR_BASE + 125; /* The resource permission list already exists. */
|
||||
int NERR_NotPrimary = NERR_BASE + 126; /* This operation is only allowed on the primary domain controller of the domain. */
|
||||
int NERR_ACFNotLoaded = NERR_BASE + 127; /* The security database has not been started. */
|
||||
int NERR_ACFNoRoom = NERR_BASE + 128; /* There are too many names in the user accounts database. */
|
||||
int NERR_ACFFileIOFail = NERR_BASE + 129; /* A disk I/O failure occurred.*/
|
||||
int NERR_ACFTooManyLists = NERR_BASE + 130; /* The limit of 64 entries per resource was exceeded. */
|
||||
int NERR_UserLogon = NERR_BASE + 131; /* Deleting a user with a session is not allowed. */
|
||||
int NERR_ACFNoParent = NERR_BASE + 132; /* The parent directory could not be located. */
|
||||
int NERR_CanNotGrowSegment = NERR_BASE + 133; /* Unable to add to the security database session cache segment. */
|
||||
int NERR_SpeGroupOp = NERR_BASE + 134; /* This operation is not allowed on this special group. */
|
||||
int NERR_NotInCache = NERR_BASE + 135; /* This user is not cached in user accounts database session cache. */
|
||||
int NERR_UserInGroup = NERR_BASE + 136; /* The user already belongs to this group. */
|
||||
int NERR_UserNotInGroup = NERR_BASE + 137; /* The user does not belong to this group. */
|
||||
int NERR_AccountUndefined = NERR_BASE + 138; /* This user account is undefined. */
|
||||
int NERR_AccountExpired = NERR_BASE + 139; /* This user account has expired. */
|
||||
int NERR_InvalidWorkstation = NERR_BASE + 140; /* The user is not allowed to log on from this workstation. */
|
||||
int NERR_InvalidLogonHours = NERR_BASE + 141; /* The user is not allowed to log on at this time. */
|
||||
int NERR_PasswordExpired = NERR_BASE + 142; /* The password of this user has expired. */
|
||||
int NERR_PasswordCantChange = NERR_BASE + 143; /* The password of this user cannot change. */
|
||||
int NERR_PasswordHistConflict = NERR_BASE + 144; /* This password cannot be used now. */
|
||||
int NERR_PasswordTooShort = NERR_BASE + 145; /* The password does not meet the password policy requirements. Check the minimum password length, password complexity and password history requirements. */
|
||||
int NERR_PasswordTooRecent = NERR_BASE + 146; /* The password of this user is too recent to change. */
|
||||
int NERR_InvalidDatabase = NERR_BASE + 147; /* The security database is corrupted. */
|
||||
int NERR_DatabaseUpToDate = NERR_BASE + 148; /* No updates are necessary to this replicant network/local security database. */
|
||||
int NERR_SyncRequired = NERR_BASE + 149; /* This replicant database is outdated; synchronization is required. */
|
||||
|
||||
/*
|
||||
* Use API related
|
||||
* Error codes from BASE + 150 to BASE + 169
|
||||
*/
|
||||
|
||||
int NERR_UseNotFound = NERR_BASE + 150; /* The network connection could not be found. */
|
||||
int NERR_BadAsgType = NERR_BASE + 151; /* This asg_type is invalid. */
|
||||
int NERR_DeviceIsShared = NERR_BASE + 152; /* This device is currently being shared. */
|
||||
int NERR_SameAsComputerName = NERR_BASE + 153; /* The user name may not be same as computer name. */
|
||||
|
||||
|
||||
/*
|
||||
* Message Server related
|
||||
* Error codes BASE + 170 to BASE + 209
|
||||
*/
|
||||
|
||||
int NERR_NoComputerName = NERR_BASE + 170; /* The computer name could not be added as a message alias. The name may already exist on the network. */
|
||||
int NERR_MsgAlreadyStarted = NERR_BASE + 171; /* The Messenger service is already started. */
|
||||
int NERR_MsgInitFailed = NERR_BASE + 172; /* The Messenger service failed to start. */
|
||||
int NERR_NameNotFound = NERR_BASE + 173; /* The message alias could not be found on the network. */
|
||||
int NERR_AlreadyForwarded = NERR_BASE + 174; /* This message alias has already been forwarded. */
|
||||
int NERR_AddForwarded = NERR_BASE + 175; /* This message alias has been added but is still forwarded. */
|
||||
int NERR_AlreadyExists = NERR_BASE + 176; /* This message alias already exists locally. */
|
||||
int NERR_TooManyNames = NERR_BASE + 177; /* The maximum number of added message aliases has been exceeded. */
|
||||
int NERR_DelComputerName = NERR_BASE + 178; /* The computer name could not be deleted.*/
|
||||
int NERR_LocalForward = NERR_BASE + 179; /* Messages cannot be forwarded back to the same workstation. */
|
||||
int NERR_GrpMsgProcessor = NERR_BASE + 180; /* An error occurred in the domain message processor. */
|
||||
int NERR_PausedRemote = NERR_BASE + 181; /* The message was sent, but the recipient has paused the Messenger service. */
|
||||
int NERR_BadReceive = NERR_BASE + 182; /* The message was sent but not received. */
|
||||
int NERR_NameInUse = NERR_BASE + 183; /* The message alias is currently in use. Try again later. */
|
||||
int NERR_MsgNotStarted = NERR_BASE + 184; /* The Messenger service has not been started. */
|
||||
int NERR_NotLocalName = NERR_BASE + 185; /* The name is not on the local computer. */
|
||||
int NERR_NoForwardName = NERR_BASE + 186; /* The forwarded message alias could not be found on the network. */
|
||||
int NERR_RemoteFull = NERR_BASE + 187; /* The message alias table on the remote station is full. */
|
||||
int NERR_NameNotForwarded = NERR_BASE + 188; /* Messages for this alias are not currently being forwarded. */
|
||||
int NERR_TruncatedBroadcast = NERR_BASE + 189; /* The broadcast message was truncated. */
|
||||
int NERR_InvalidDevice = NERR_BASE + 194; /* This is an invalid device name. */
|
||||
int NERR_WriteFault = NERR_BASE + 195; /* A write fault occurred. */
|
||||
/* UNUSED BASE + 196 */
|
||||
int NERR_DuplicateName = NERR_BASE + 197; /* A duplicate message alias exists on the network. */
|
||||
int NERR_DeleteLater = NERR_BASE + 198; /* @W This message alias will be deleted later. */
|
||||
int NERR_IncompleteDel = NERR_BASE + 199; /* The message alias was not successfully deleted from all networks. */
|
||||
int NERR_MultipleNets = NERR_BASE + 200; /* This operation is not supported on computers with multiple networks. */
|
||||
|
||||
/*
|
||||
* Server API related
|
||||
* Error codes BASE + 210 to BASE + 229
|
||||
*/
|
||||
|
||||
int NERR_NetNameNotFound = NERR_BASE + 210; /* This shared resource does not exist.*/
|
||||
int NERR_DeviceNotShared = NERR_BASE + 211; /* This device is not shared. */
|
||||
int NERR_ClientNameNotFound = NERR_BASE + 212; /* A session does not exist with that computer name. */
|
||||
int NERR_FileIdNotFound = NERR_BASE + 214; /* There is not an open file with that identification number. */
|
||||
int NERR_ExecFailure = NERR_BASE + 215; /* A failure occurred when executing a remote administration command. */
|
||||
int NERR_TmpFile = NERR_BASE + 216; /* A failure occurred when opening a remote temporary file. */
|
||||
int NERR_TooMuchData = NERR_BASE + 217; /* The data returned from a remote administration command has been truncated to 64K. */
|
||||
int NERR_DeviceShareConflict = NERR_BASE + 218; /* This device cannot be shared as both a spooled and a non-spooled resource. */
|
||||
int NERR_BrowserTableIncomplete = NERR_BASE + 219; /* The information in the list of servers may be incorrect. */
|
||||
int NERR_NotLocalDomain = NERR_BASE + 220; /* The computer is not active in this domain. */
|
||||
int NERR_IsDfsShare = NERR_BASE + 221; /* The share must be removed from the Distributed File System before it can be deleted. */
|
||||
|
||||
/*
|
||||
* CharDev API related
|
||||
* Error codes BASE + 230 to BASE + 249
|
||||
*/
|
||||
|
||||
/* UNUSED BASE + 230 */
|
||||
int NERR_DevInvalidOpCode = NERR_BASE + 231; /* The operation is invalid for this device. */
|
||||
int NERR_DevNotFound = NERR_BASE + 232; /* This device cannot be shared. */
|
||||
int NERR_DevNotOpen = NERR_BASE + 233; /* This device was not open. */
|
||||
int NERR_BadQueueDevString = NERR_BASE + 234; /* This device name list is invalid. */
|
||||
int NERR_BadQueuePriority = NERR_BASE + 235; /* The queue priority is invalid. */
|
||||
int NERR_NoCommDevs = NERR_BASE + 237; /* There are no shared communication devices. */
|
||||
int NERR_QueueNotFound = NERR_BASE + 238; /* The queue you specified does not exist. */
|
||||
int NERR_BadDevString = NERR_BASE + 240; /* This list of devices is invalid. */
|
||||
int NERR_BadDev = NERR_BASE + 241; /* The requested device is invalid. */
|
||||
int NERR_InUseBySpooler = NERR_BASE + 242; /* This device is already in use by the spooler. */
|
||||
int NERR_CommDevInUse = NERR_BASE + 243; /* This device is already in use as a communication device. */
|
||||
|
||||
/*
|
||||
* NetICanonicalize and NetIType and NetIMakeLMFileName
|
||||
* NetIListCanon and NetINameCheck
|
||||
* Error codes BASE + 250 to BASE + 269
|
||||
*/
|
||||
|
||||
int NERR_InvalidComputer = NERR_BASE + 251; /* This computer name is invalid. */
|
||||
/* UNUSED BASE + 252 */
|
||||
/* UNUSED BASE + 253 */
|
||||
int NERR_MaxLenExceeded = NERR_BASE + 254; /* The string and prefix specified are too long. */
|
||||
/* UNUSED BASE + 255 */
|
||||
int NERR_BadComponent = NERR_BASE + 256; /* This path component is invalid. */
|
||||
int NERR_CantType = NERR_BASE + 257; /* Could not determine the type of input. */
|
||||
/* UNUSED BASE + 258 */
|
||||
/* UNUSED BASE + 259 */
|
||||
int NERR_TooManyEntries = NERR_BASE + 262; /* The buffer for types is not big enough. */
|
||||
|
||||
/*
|
||||
* NetProfile
|
||||
* Error codes BASE + 270 to BASE + 276
|
||||
*/
|
||||
|
||||
int NERR_ProfileFileTooBig = NERR_BASE + 270; /* Profile files cannot exceed 64K. */
|
||||
int NERR_ProfileOffset = NERR_BASE + 271; /* The start offset is out of range. */
|
||||
int NERR_ProfileCleanup = NERR_BASE + 272; /* The system cannot delete current connections to network resources. */
|
||||
int NERR_ProfileUnknownCmd = NERR_BASE + 273; /* The system was unable to parse the command line in this file.*/
|
||||
int NERR_ProfileLoadErr = NERR_BASE + 274; /* An error occurred while loading the profile file. */
|
||||
int NERR_ProfileSaveErr = NERR_BASE + 275; /* @W Errors occurred while saving the profile file. The profile was partially saved. */
|
||||
|
||||
|
||||
/*
|
||||
* NetAudit and NetErrorLog
|
||||
* Error codes BASE + 277 to BASE + 279
|
||||
*/
|
||||
|
||||
int NERR_LogOverflow = NERR_BASE + 277; /* Log file %1 is full. */
|
||||
int NERR_LogFileChanged = NERR_BASE + 278; /* This log file has changed between reads. */
|
||||
int NERR_LogFileCorrupt = NERR_BASE + 279; /* Log file %1 is corrupt. */
|
||||
|
||||
|
||||
/*
|
||||
* NetRemote
|
||||
* Error codes BASE + 280 to BASE + 299
|
||||
*/
|
||||
int NERR_SourceIsDir = NERR_BASE + 280; /* The source path cannot be a directory. */
|
||||
int NERR_BadSource = NERR_BASE + 281; /* The source path is illegal. */
|
||||
int NERR_BadDest = NERR_BASE + 282; /* The destination path is illegal. */
|
||||
int NERR_DifferentServers = NERR_BASE + 283; /* The source and destination paths are on different servers. */
|
||||
/* UNUSED BASE + 284 */
|
||||
int NERR_RunSrvPaused = NERR_BASE + 285; /* The Run server you requested is paused. */
|
||||
/* UNUSED BASE + 286 */
|
||||
/* UNUSED BASE + 287 */
|
||||
/* UNUSED BASE + 288 */
|
||||
int NERR_ErrCommRunSrv = NERR_BASE + 289; /* An error occurred when communicating with a Run server. */
|
||||
/* UNUSED BASE + 290 */
|
||||
int NERR_ErrorExecingGhost = NERR_BASE + 291; /* An error occurred when starting a background process. */
|
||||
int NERR_ShareNotFound = NERR_BASE + 292; /* The shared resource you are connected to could not be found.*/
|
||||
/* UNUSED BASE + 293 */
|
||||
/* UNUSED BASE + 294 */
|
||||
|
||||
|
||||
/*
|
||||
* NetWksta.sys = redir; returned error codes.
|
||||
*
|
||||
* NERR_BASE + = 300-329;
|
||||
*/
|
||||
|
||||
int NERR_InvalidLana = NERR_BASE + 300; /* The LAN adapter number is invalid. */
|
||||
int NERR_OpenFiles = NERR_BASE + 301; /* There are open files on the connection. */
|
||||
int NERR_ActiveConns = NERR_BASE + 302; /* Active connections still exist. */
|
||||
int NERR_BadPasswordCore = NERR_BASE + 303; /* This share name or password is invalid. */
|
||||
int NERR_DevInUse = NERR_BASE + 304; /* The device is being accessed by an active process. */
|
||||
int NERR_LocalDrive = NERR_BASE + 305; /* The drive letter is in use locally. */
|
||||
|
||||
/*
|
||||
* Alert error codes.
|
||||
*
|
||||
* NERR_BASE + = 330-339;
|
||||
*/
|
||||
int NERR_AlertExists = NERR_BASE + 330; /* The specified client is already registered for the specified event. */
|
||||
int NERR_TooManyAlerts = NERR_BASE + 331; /* The alert table is full. */
|
||||
int NERR_NoSuchAlert = NERR_BASE + 332; /* An invalid or nonexistent alert name was raised. */
|
||||
int NERR_BadRecipient = NERR_BASE + 333; /* The alert recipient is invalid.*/
|
||||
int NERR_AcctLimitExceeded = NERR_BASE + 334; /* A user's session with this server has been deleted
|
||||
* because the user's logon hours are no longer valid. */
|
||||
|
||||
/*
|
||||
* Additional Error and Audit log codes.
|
||||
*
|
||||
* NERR_BASE + (340-343;
|
||||
*/
|
||||
int NERR_InvalidLogSeek = NERR_BASE + 340; /* The log file does not contain the requested record number. */
|
||||
/* UNUSED BASE + 341 */
|
||||
/* UNUSED BASE + 342 */
|
||||
/* UNUSED BASE + 343 */
|
||||
|
||||
/*
|
||||
* Additional UAS and NETLOGON codes
|
||||
*
|
||||
* NERR_BASE + (350-359;
|
||||
*/
|
||||
int NERR_BadUasConfig = NERR_BASE + 350; /* The user accounts database is not configured correctly. */
|
||||
int NERR_InvalidUASOp = NERR_BASE + 351; /* This operation is not permitted when the Netlogon service is running. */
|
||||
int NERR_LastAdmin = NERR_BASE + 352; /* This operation is not allowed on the last administrative account. */
|
||||
int NERR_DCNotFound = NERR_BASE + 353; /* Could not find domain controller for this domain. */
|
||||
int NERR_LogonTrackingError = NERR_BASE + 354; /* Could not set logon information for this user. */
|
||||
int NERR_NetlogonNotStarted = NERR_BASE + 355; /* The Netlogon service has not been started. */
|
||||
int NERR_CanNotGrowUASFile = NERR_BASE + 356; /* Unable to add to the user accounts database. */
|
||||
int NERR_TimeDiffAtDC = NERR_BASE + 357; /* This server's clock is not synchronized with the primary domain controller's clock. */
|
||||
int NERR_PasswordMismatch = NERR_BASE + 358; /* A password mismatch has been detected. */
|
||||
|
||||
|
||||
/*
|
||||
* Server Integration error codes.
|
||||
*
|
||||
* NERR_BASE + (360-369;
|
||||
*/
|
||||
int NERR_NoSuchServer = NERR_BASE + 360; /* The server identification does not specify a valid server. */
|
||||
int NERR_NoSuchSession = NERR_BASE + 361; /* The session identification does not specify a valid session. */
|
||||
int NERR_NoSuchConnection = NERR_BASE + 362; /* The connection identification does not specify a valid connection. */
|
||||
int NERR_TooManyServers = NERR_BASE + 363; /* There is no space for another entry in the table of available servers. */
|
||||
int NERR_TooManySessions = NERR_BASE + 364; /* The server has reached the maximum number of sessions it supports. */
|
||||
int NERR_TooManyConnections = NERR_BASE + 365; /* The server has reached the maximum number of connections it supports. */
|
||||
int NERR_TooManyFiles = NERR_BASE + 366; /* The server cannot open more files because it has reached its maximum number. */
|
||||
int NERR_NoAlternateServers = NERR_BASE + 367; /* There are no alternate servers registered on this server. */
|
||||
/* UNUSED BASE + 368 */
|
||||
/* UNUSED BASE + 369 */
|
||||
|
||||
int NERR_TryDownLevel = NERR_BASE + 370; /* Try down-level = remote admin protocol; version of API instead. */
|
||||
|
||||
/*
|
||||
* UPS error codes.
|
||||
*
|
||||
* NERR_BASE + = 380-384;
|
||||
*/
|
||||
int NERR_UPSDriverNotStarted = NERR_BASE + 380; /* The UPS driver could not be accessed by the UPS service. */
|
||||
int NERR_UPSInvalidConfig = NERR_BASE + 381; /* The UPS service is not configured correctly. */
|
||||
int NERR_UPSInvalidCommPort = NERR_BASE + 382; /* The UPS service could not access the specified Comm Port. */
|
||||
int NERR_UPSSignalAsserted = NERR_BASE + 383; /* The UPS indicated a line fail or low battery situation. Service not started. */
|
||||
int NERR_UPSShutdownFailed = NERR_BASE + 384; /* The UPS service failed to perform a system shut down. */
|
||||
|
||||
/*
|
||||
* Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 400-419;
|
||||
* Error codes 400 - 405 are used by RPLBOOT.SYS.
|
||||
* Error codes 403, 407 - 416 are used by RPLLOADR.COM,
|
||||
* Error code 417 is the alerter message of REMOTEBOOT = RPLSERVR.EXE;.
|
||||
* Error code 418 is for when REMOTEBOOT can't start
|
||||
* Error code 419 is for a disallowed 2nd rpl connection
|
||||
*
|
||||
*/
|
||||
int NERR_BadDosRetCode = NERR_BASE + 400; /* The program below returned an MS-DOS error code:*/
|
||||
int NERR_ProgNeedsExtraMem = NERR_BASE + 401; /* The program below needs more memory:*/
|
||||
int NERR_BadDosFunction = NERR_BASE + 402; /* The program below called an unsupported MS-DOS function:*/
|
||||
int NERR_RemoteBootFailed = NERR_BASE + 403; /* The workstation failed to boot.*/
|
||||
int NERR_BadFileCheckSum = NERR_BASE + 404; /* The file below is corrupt.*/
|
||||
int NERR_NoRplBootSystem = NERR_BASE + 405; /* No loader is specified in the boot-block definition file.*/
|
||||
int NERR_RplLoadrNetBiosErr = NERR_BASE + 406; /* NetBIOS returned an error: The NCB and SMB are dumped above.*/
|
||||
int NERR_RplLoadrDiskErr = NERR_BASE + 407; /* A disk I/O error occurred.*/
|
||||
int NERR_ImageParamErr = NERR_BASE + 408; /* Image parameter substitution failed.*/
|
||||
int NERR_TooManyImageParams = NERR_BASE + 409; /* Too many image parameters cross disk sector boundaries.*/
|
||||
int NERR_NonDosFloppyUsed = NERR_BASE + 410; /* The image was not generated from an MS-DOS diskette formatted with /S.*/
|
||||
int NERR_RplBootRestart = NERR_BASE + 411; /* Remote boot will be restarted later.*/
|
||||
int NERR_RplSrvrCallFailed = NERR_BASE + 412; /* The call to the Remoteboot server failed.*/
|
||||
int NERR_CantConnectRplSrvr = NERR_BASE + 413; /* Cannot connect to the Remoteboot server.*/
|
||||
int NERR_CantOpenImageFile = NERR_BASE + 414; /* Cannot open image file on the Remoteboot server.*/
|
||||
int NERR_CallingRplSrvr = NERR_BASE + 415; /* Connecting to the Remoteboot server...*/
|
||||
int NERR_StartingRplBoot = NERR_BASE + 416; /* Connecting to the Remoteboot server...*/
|
||||
int NERR_RplBootServiceTerm = NERR_BASE + 417; /* Remote boot service was stopped; check the error log for the cause of the problem.*/
|
||||
int NERR_RplBootStartFailed = NERR_BASE + 418; /* Remote boot startup failed; check the error log for the cause of the problem.*/
|
||||
int NERR_RPL_CONNECTED = NERR_BASE + 419; /* A second connection to a Remoteboot resource is not allowed.*/
|
||||
|
||||
/*
|
||||
* FTADMIN API error codes
|
||||
*
|
||||
* NERR_BASE + = 425-434;
|
||||
*
|
||||
* = Currently not used in NT;
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Browser service API error codes
|
||||
*
|
||||
* NERR_BASE + = 450-475;
|
||||
*
|
||||
*/
|
||||
int NERR_BrowserConfiguredToNotRun = NERR_BASE + 450; /* The browser service was configured with MaintainServerList = No. */
|
||||
|
||||
/*
|
||||
* Additional Remoteboot error codes.
|
||||
*
|
||||
* NERR_BASE + = 510-550;
|
||||
*/
|
||||
int NERR_RplNoAdaptersStarted = NERR_BASE + 510; /*Service failed to start since none of the network adapters started with this service.*/
|
||||
int NERR_RplBadRegistry = NERR_BASE + 511; /*Service failed to start due to bad startup information in the registry.*/
|
||||
int NERR_RplBadDatabase = NERR_BASE + 512; /*Service failed to start because its database is absent or corrupt.*/
|
||||
int NERR_RplRplfilesShare = NERR_BASE + 513; /*Service failed to start because RPLFILES share is absent.*/
|
||||
int NERR_RplNotRplServer = NERR_BASE + 514; /*Service failed to start because RPLUSER group is absent.*/
|
||||
int NERR_RplCannotEnum = NERR_BASE + 515; /*Cannot enumerate service records.*/
|
||||
int NERR_RplWkstaInfoCorrupted = NERR_BASE + 516; /*Workstation record information has been corrupted.*/
|
||||
int NERR_RplWkstaNotFound = NERR_BASE + 517; /*Workstation record was not found.*/
|
||||
int NERR_RplWkstaNameUnavailable = NERR_BASE + 518; /*Workstation name is in use by some other workstation.*/
|
||||
int NERR_RplProfileInfoCorrupted = NERR_BASE + 519; /*Profile record information has been corrupted.*/
|
||||
int NERR_RplProfileNotFound = NERR_BASE + 520; /*Profile record was not found.*/
|
||||
int NERR_RplProfileNameUnavailable = NERR_BASE + 521; /*Profile name is in use by some other profile.*/
|
||||
int NERR_RplProfileNotEmpty = NERR_BASE + 522; /*There are workstations using this profile.*/
|
||||
int NERR_RplConfigInfoCorrupted = NERR_BASE + 523; /*Configuration record information has been corrupted.*/
|
||||
int NERR_RplConfigNotFound = NERR_BASE + 524; /*Configuration record was not found.*/
|
||||
int NERR_RplAdapterInfoCorrupted = NERR_BASE + 525; /*Adapter id record information has been corrupted.*/
|
||||
int NERR_RplInternal = NERR_BASE + 526; /*An internal service error has occurred.*/
|
||||
int NERR_RplVendorInfoCorrupted = NERR_BASE + 527; /*Vendor id record information has been corrupted.*/
|
||||
int NERR_RplBootInfoCorrupted = NERR_BASE + 528; /*Boot block record information has been corrupted.*/
|
||||
int NERR_RplWkstaNeedsUserAcct = NERR_BASE + 529; /*The user account for this workstation record is missing.*/
|
||||
int NERR_RplNeedsRPLUSERAcct = NERR_BASE + 530; /*The RPLUSER local group could not be found.*/
|
||||
int NERR_RplBootNotFound = NERR_BASE + 531; /*Boot block record was not found.*/
|
||||
int NERR_RplIncompatibleProfile = NERR_BASE + 532; /*Chosen profile is incompatible with this workstation.*/
|
||||
int NERR_RplAdapterNameUnavailable = NERR_BASE + 533; /*Chosen network adapter id is in use by some other workstation.*/
|
||||
int NERR_RplConfigNotEmpty = NERR_BASE + 534; /*There are profiles using this configuration.*/
|
||||
int NERR_RplBootInUse = NERR_BASE + 535; /*There are workstations, profiles or configurations using this boot block.*/
|
||||
int NERR_RplBackupDatabase = NERR_BASE + 536; /*Service failed to backup Remoteboot database.*/
|
||||
int NERR_RplAdapterNotFound = NERR_BASE + 537; /*Adapter record was not found.*/
|
||||
int NERR_RplVendorNotFound = NERR_BASE + 538; /*Vendor record was not found.*/
|
||||
int NERR_RplVendorNameUnavailable = NERR_BASE + 539; /*Vendor name is in use by some other vendor record.*/
|
||||
int NERR_RplBootNameUnavailable = NERR_BASE + 540; /*(boot name, vendor id; is in use by some other boot block record.*/
|
||||
int NERR_RplConfigNameUnavailable = NERR_BASE + 541; /*Configuration name is in use by some other configuration.*/
|
||||
|
||||
/**INTERNAL_ONLY**/
|
||||
|
||||
/*
|
||||
* Dfs API error codes.
|
||||
*
|
||||
* NERR_BASE + = 560-590;
|
||||
*/
|
||||
|
||||
int NERR_DfsInternalCorruption = NERR_BASE + 560; /*The internal database maintained by the DFS service is corrupt*/
|
||||
int NERR_DfsVolumeDataCorrupt = NERR_BASE + 561; /*One of the records in the internal DFS database is corrupt*/
|
||||
int NERR_DfsNoSuchVolume = NERR_BASE + 562; /*There is no DFS name whose entry path matches the input Entry Path*/
|
||||
int NERR_DfsVolumeAlreadyExists = NERR_BASE + 563; /*A root or link with the given name already exists*/
|
||||
int NERR_DfsAlreadyShared = NERR_BASE + 564; /*The server share specified is already shared in the DFS*/
|
||||
int NERR_DfsNoSuchShare = NERR_BASE + 565; /*The indicated server share does not support the indicated DFS namespace*/
|
||||
int NERR_DfsNotALeafVolume = NERR_BASE + 566; /*The operation is not valid on this portion of the namespace*/
|
||||
int NERR_DfsLeafVolume = NERR_BASE + 567; /*The operation is not valid on this portion of the namespace*/
|
||||
int NERR_DfsVolumeHasMultipleServers = NERR_BASE + 568; /*The operation is ambiguous because the link has multiple servers*/
|
||||
int NERR_DfsCantCreateJunctionPoint = NERR_BASE + 569; /*Unable to create a link*/
|
||||
int NERR_DfsServerNotDfsAware = NERR_BASE + 570; /*The server is not DFS Aware*/
|
||||
int NERR_DfsBadRenamePath = NERR_BASE + 571; /*The specified rename target path is invalid*/
|
||||
int NERR_DfsVolumeIsOffline = NERR_BASE + 572; /*The specified DFS link is offline*/
|
||||
int NERR_DfsNoSuchServer = NERR_BASE + 573; /*The specified server is not a server for this link*/
|
||||
int NERR_DfsCyclicalName = NERR_BASE + 574; /*A cycle in the DFS name was detected*/
|
||||
int NERR_DfsNotSupportedInServerDfs = NERR_BASE + 575; /*The operation is not supported on a server-based DFS*/
|
||||
int NERR_DfsDuplicateService = NERR_BASE + 576; /*This link is already supported by the specified server-share*/
|
||||
int NERR_DfsCantRemoveLastServerShare = NERR_BASE + 577; /*Can't remove the last server-share supporting this root or link*/
|
||||
int NERR_DfsVolumeIsInterDfs = NERR_BASE + 578; /*The operation is not supported for an Inter-DFS link*/
|
||||
int NERR_DfsInconsistent = NERR_BASE + 579; /*The internal state of the DFS Service has become inconsistent*/
|
||||
int NERR_DfsServerUpgraded = NERR_BASE + 580; /*The DFS Service has been installed on the specified server*/
|
||||
int NERR_DfsDataIsIdentical = NERR_BASE + 581; /*The DFS data being reconciled is identical*/
|
||||
int NERR_DfsCantRemoveDfsRoot = NERR_BASE + 582; /*The DFS root cannot be deleted - Uninstall DFS if required*/
|
||||
int NERR_DfsChildOrParentInDfs = NERR_BASE + 583; /*A child or parent directory of the share is already in a DFS*/
|
||||
int NERR_DfsInternalError = NERR_BASE + 590; /*DFS internal error*/
|
||||
|
||||
/*
|
||||
* Net setup error codes.
|
||||
*
|
||||
* NERR_BASE + = 591-600;
|
||||
*/
|
||||
int NERR_SetupAlreadyJoined = NERR_BASE + 591; /*This machine is already joined to a domain.*/
|
||||
int NERR_SetupNotJoined = NERR_BASE + 592; /*This machine is not currently joined to a domain.*/
|
||||
int NERR_SetupDomainController = NERR_BASE + 593; /*This machine is a domain controller and cannot be unjoined from a domain.*/
|
||||
int NERR_DefaultJoinRequired = NERR_BASE + 594; /*The destination domain controller does not support creating machine accounts in OUs.*/
|
||||
int NERR_InvalidWorkgroupName = NERR_BASE + 595; /*The specified workgroup name is invalid.*/
|
||||
int NERR_NameUsesIncompatibleCodePage = NERR_BASE + 596; /*The specified computer name is incompatible with the default language used on the domain controller.*/
|
||||
int NERR_ComputerAccountNotFound = NERR_BASE + 597; /*The specified computer account could not be found. Contact an administrator to verify the account is in the domain. If the account has been deleted unjoin, reboot, and rejoin the domain.*/
|
||||
int NERR_PersonalSku = NERR_BASE + 598; /*This version of Windows cannot be joined to a domain.*/
|
||||
int NERR_SetupCheckDNSConfig = NERR_BASE + 599; /*An attempt to resolve the DNS name of a DC in the domain being joined has failed. Please verify this client is configured to reach a DNS server that can resolve DNS names in the target domain.*/
|
||||
|
||||
/*
|
||||
* Some Password and account error results
|
||||
*
|
||||
* NERR_BASE + = 601 - 608;
|
||||
*/
|
||||
int NERR_PasswordMustChange = NERR_BASE + 601; /* Password must change at next logon */
|
||||
int NERR_AccountLockedOut = NERR_BASE + 602; /* Account is locked out */
|
||||
int NERR_PasswordTooLong = NERR_BASE + 603; /* Password is too long */
|
||||
int NERR_PasswordNotComplexEnough = NERR_BASE + 604; /* Password doesn't meet the complexity policy */
|
||||
int NERR_PasswordFilterError = NERR_BASE + 605; /* Password doesn't meet the requirements of the filter dll's */
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2750-2799 has been *
|
||||
*allocated to the IBM LAN Server *
|
||||
***********************************/
|
||||
|
||||
/***********WARNING ****************
|
||||
*The range 2900-2999 has been *
|
||||
*reserved for Microsoft OEMs *
|
||||
***********************************/
|
||||
|
||||
int MAX_NERR = NERR_BASE + 899; /* This is the last error in NERR range. */
|
||||
}
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from LMJoin.h.
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface LMJoin extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Status of a workstation.
|
||||
*/
|
||||
public abstract class NETSETUP_JOIN_STATUS {
|
||||
public static final int NetSetupUnknownStatus = 0;
|
||||
public static final int NetSetupUnjoined = 1;
|
||||
public static final int NetSetupWorkgroupName = 2;
|
||||
public static final int NetSetupDomainName = 3;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -1,210 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Provides access to the w32 MSI installer library.
|
||||
*/
|
||||
public interface Msi extends StdCallLibrary {
|
||||
|
||||
Msi INSTANCE = (Msi)
|
||||
Native.loadLibrary("msi", Msi.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The component being requested is disabled on the computer.
|
||||
*/
|
||||
static int INSTALLSTATE_NOTUSED = -7;
|
||||
|
||||
/**
|
||||
* The configuration data is corrupt.
|
||||
*/
|
||||
static int INSTALLSTATE_BADCONFIG = -6;
|
||||
|
||||
/**
|
||||
* The installation is suspended or in progress.
|
||||
*/
|
||||
static int INSTALLSTATE_INCOMPLETE = -5;
|
||||
|
||||
/**
|
||||
* The feature must run from the source, and the source is unavailable.
|
||||
*/
|
||||
static int INSTALLSTATE_SOURCEABSENT = -4;
|
||||
|
||||
/**
|
||||
* The return buffer is full.
|
||||
*/
|
||||
static int INSTALLSTATE_MOREDATA = -3;
|
||||
|
||||
/**
|
||||
* An invalid parameter was passed to the function.
|
||||
*/
|
||||
static int INSTALLSTATE_INVALIDARG = -2;
|
||||
|
||||
/**
|
||||
* An unrecognized product or feature was specified.
|
||||
*/
|
||||
static int INSTALLSTATE_UNKNOWN = -1;
|
||||
|
||||
/**
|
||||
* The feature is broken.
|
||||
*/
|
||||
static int INSTALLSTATE_BROKEN = 0;
|
||||
|
||||
/**
|
||||
* The advertised feature.
|
||||
*/
|
||||
static int INSTALLSTATE_ADVERTISED = 1;
|
||||
|
||||
/**
|
||||
* The component is being removed.
|
||||
*/
|
||||
static int INSTALLSTATE_REMOVED = 1;
|
||||
|
||||
/**
|
||||
* The feature was uninstalled.
|
||||
*/
|
||||
static int INSTALLSTATE_ABSENT = 2;
|
||||
|
||||
/**
|
||||
* The feature was installed on the local drive.
|
||||
*/
|
||||
static int INSTALLSTATE_LOCAL = 3;
|
||||
|
||||
/**
|
||||
* The feature must run from the source, CD-ROM, or network.
|
||||
*/
|
||||
static int INSTALLSTATE_SOURCE = 4;
|
||||
|
||||
/**
|
||||
* The feature is installed in the default location: local or source.
|
||||
*/
|
||||
static int INSTALLSTATE_DEFAULT = 5;
|
||||
|
||||
/**
|
||||
* The MsiGetComponentPath function returns the full path to an installed component. If the key path for the
|
||||
* component is a registry key then the registry key is returned.
|
||||
*
|
||||
* @param szProduct
|
||||
* Specifies the product code for the client product.
|
||||
*
|
||||
* @param szComponent
|
||||
* Specifies the component ID of the component to be located.
|
||||
*
|
||||
* @param lpPathBuf
|
||||
* Pointer to a variable that receives the path to the component. This parameter can be null. If the component is
|
||||
* a registry key, the registry roots are represented numerically. If this is a registry subkey path, there is a
|
||||
* backslash at the end of the Key Path. If this is a registry value key path, there is no backslash at the end.
|
||||
* For example, a registry path on a 32-bit operating system of HKEY_CURRENT_USER\SOFTWARE\Microsoft is returned
|
||||
* as "01:\SOFTWARE\Microsoft\".
|
||||
*
|
||||
* @param pcchBuf
|
||||
* Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpPathBuf
|
||||
* parameter. On input, this is the full size of the buffer, including a space for a terminating null character.
|
||||
* If the buffer passed in is too small, the count returned does not include the terminating null character.
|
||||
*
|
||||
* If lpPathBuf is null, pcchBuf can be null.
|
||||
*
|
||||
* @return
|
||||
* The MsiGetComponentPath function returns the following values.
|
||||
* INSTALLSTATE_NOTUSED - The component being requested is disabled on the computer.
|
||||
* INSTALLSTATE_ABSENT - The component is not installed.
|
||||
* INSTALLSTATE_INVALIDARG - One of the function parameters is invalid.
|
||||
* INSTALLSTATE_LOCAL - The component is installed locally.
|
||||
* INSTALLSTATE_SOURCE - The component is installed to run from source.
|
||||
* INSTALLSTATE_SOURCEABSENT - The component source is inaccessible.
|
||||
* INSTALLSTATE_UNKNOWN - The product code or component ID is unknown.
|
||||
*/
|
||||
int MsiGetComponentPath(String szProduct, String szComponent, char[] lpPathBuf, IntByReference pcchBuf);
|
||||
|
||||
/**
|
||||
* The MsiLocateComponent function returns the full path to an installed component without a product code. This
|
||||
* function attempts to determine the product using MsiGetProductCode, but is not guaranteed to find the correct
|
||||
* product for the caller. MsiGetComponentPath should always be called when possible.
|
||||
*
|
||||
* @param szComponent
|
||||
* Specifies the component ID of the component to be located.
|
||||
*
|
||||
* @param lpPathBuf
|
||||
* Pointer to a variable that receives the path to the component. The variable includes the terminating null
|
||||
* character.
|
||||
*
|
||||
* @param pcchBuf
|
||||
* Pointer to a variable that specifies the size, in characters, of the buffer pointed to by the lpPathBuf
|
||||
* parameter. On input, this is the full size of the buffer, including a space for a terminating null character.
|
||||
* Upon success of the MsiLocateComponent function, the variable pointed to by pcchBuf contains the count of
|
||||
* characters not including the terminating null character. If the size of the buffer passed in is too small, the
|
||||
* function returns INSTALLSTATE_MOREDATA.
|
||||
*
|
||||
* If lpPathBuf is null, pcchBuf can be null.
|
||||
*
|
||||
* @return
|
||||
* The MsiGetComponentPath function returns the following values.
|
||||
* INSTALLSTATE_NOTUSED - The component being requested is disabled on the computer.
|
||||
* INSTALLSTATE_ABSENT - The component is not installed.
|
||||
* INSTALLSTATE_INVALIDARG - One of the function parameters is invalid.
|
||||
* INSTALLSTATE_LOCAL - The component is installed locally.
|
||||
* INSTALLSTATE_MOREDATA - The buffer provided was too small.
|
||||
* INSTALLSTATE_SOURCE - The component is installed to run from source.
|
||||
* INSTALLSTATE_SOURCEABSENT - The component source is inaccessible.
|
||||
* INSTALLSTATE_UNKNOWN - The product code or component ID is unknown.
|
||||
*/
|
||||
int MsiLocateComponent(String szComponent, char[] lpPathBuf, IntByReference pcchBuf);
|
||||
|
||||
/**
|
||||
* The MsiGetProductCode function returns the product code of an application by using the component code of an
|
||||
* installed or advertised component of the application. During initialization, an application must determine under
|
||||
* which product code it has been installed or advertised.
|
||||
*
|
||||
* @param szComponent
|
||||
* This parameter specifies the component code of a component that has been installed by the application. This
|
||||
* will be typically the component code of the component containing the executable file of the application.
|
||||
*
|
||||
* @param lpProductBuf
|
||||
* Pointer to a buffer that receives the product code. This buffer must be 39 characters long. The first 38
|
||||
* characters are for the GUID, and the last character is for the terminating null character.
|
||||
*
|
||||
* @return
|
||||
* ERROR_BAD_CONFIGURATION - The configuration data is corrupt.
|
||||
* ERROR_INSTALL_FAILURE - The product code could not be determined.
|
||||
* ERROR_INVALID_PARAMETER - An invalid parameter was passed to the function.
|
||||
* ERROR_SUCCESS - The function completed successfully.
|
||||
* ERROR_UNKNOWN_COMPONENT - The specified component is unknown.
|
||||
*/
|
||||
int MsiGetProductCode(String szComponent, char[] lpProductBuf);
|
||||
|
||||
/**
|
||||
* The MsiEnumComponents function enumerates the installed components for all products. This function retrieves one
|
||||
* component code each time it is called.
|
||||
*
|
||||
* @param iComponentIndex
|
||||
* Specifies the index of the component to retrieve. This parameter should be zero for the first call to the
|
||||
* MsiEnumComponents function and then incremented for subsequent calls. Because components are not ordered, any
|
||||
* new component has an arbitrary index. This means that the function can return components in any order.
|
||||
*
|
||||
* @param lpComponentBuf
|
||||
* Pointer to a buffer that receives the component code. This buffer must be 39 characters long. The first 38
|
||||
* characters are for the GUID, and the last character is for the terminating null character.
|
||||
*
|
||||
* @return
|
||||
* ERROR_BAD_CONFIGURATION - The configuration data is corrupt.
|
||||
* ERROR_INVALID_PARAMETER - An invalid parameter was passed to the function.
|
||||
* ERROR_NO_MORE_ITEMS - There are no components to return.
|
||||
* ERROR_NOT_ENOUGH_MEMORY - The system does not have enough memory to complete the operation. Available with
|
||||
* Windows Server 2003.
|
||||
* ERROR_SUCCESS - A value was enumerated.
|
||||
*/
|
||||
int MsiEnumComponents(WinDef.DWORD iComponentIndex, char[] lpComponentBuf);
|
||||
}
|
||||
@@ -1,244 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Union;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from NTSecApi.h
|
||||
* Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface NTSecApi extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The LSA_UNICODE_STRING structure is used by various Local Security Authority (LSA)
|
||||
* functions to specify a Unicode string.
|
||||
*/
|
||||
public static class LSA_UNICODE_STRING extends Structure {
|
||||
public static class ByReference extends LSA_UNICODE_STRING implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the length, in bytes, of the string pointed to by the Buffer member,
|
||||
* not including the terminating null character, if any.
|
||||
*/
|
||||
public short Length;
|
||||
/**
|
||||
* Specifies the total size, in bytes, of the memory allocated for Buffer. Up to
|
||||
* MaximumLength bytes can be written into the buffer without trampling memory.
|
||||
*/
|
||||
public short MaximumLength;
|
||||
/**
|
||||
* Pointer to a wide character string. Note that the strings returned by the
|
||||
* various LSA functions might not be null terminated.
|
||||
*/
|
||||
public Pointer Buffer;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Length", "MaximumLength", "Buffer" });
|
||||
}
|
||||
|
||||
/**
|
||||
* String representation of the buffer.
|
||||
* @return
|
||||
* Unicode string.
|
||||
*/
|
||||
public String getString() {
|
||||
byte[] data = Buffer.getByteArray(0, Length);
|
||||
if (data.length < 2 || data[data.length - 1] != 0) {
|
||||
Memory newdata = new Memory(data.length + 2);
|
||||
newdata.write(0, data, 0, data.length);
|
||||
return newdata.getString(0, true);
|
||||
}
|
||||
return Buffer.getString(0, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pointer to an LSA_UNICODE_STRING.
|
||||
*/
|
||||
public static class PLSA_UNICODE_STRING {
|
||||
public static class ByReference extends PLSA_UNICODE_STRING
|
||||
implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_UNICODE_STRING.ByReference s;
|
||||
}
|
||||
|
||||
/**
|
||||
* Record contains an included top-level name.
|
||||
*/
|
||||
int ForestTrustTopLevelName = 0;
|
||||
/**
|
||||
* Record contains an excluded top-level name.
|
||||
*/
|
||||
int ForestTrustTopLevelNameEx = 1;
|
||||
/**
|
||||
* Record contains an LSA_FOREST_TRUST_DOMAIN_INFO structure.
|
||||
*/
|
||||
int ForestTrustDomainInfo = 2;
|
||||
|
||||
public static class LSA_FOREST_TRUST_DOMAIN_INFO extends Structure {
|
||||
public PSID.ByReference Sid;
|
||||
public LSA_UNICODE_STRING DnsName;
|
||||
public LSA_UNICODE_STRING NetbiosName;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Sid", "DnsName", "NetbiosName" });
|
||||
}
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_BINARY_DATA extends Structure {
|
||||
public int Length;
|
||||
public Pointer Buffer;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Length", "Buffer" });
|
||||
}
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_RECORD extends Structure {
|
||||
|
||||
public static class ByReference extends LSA_FOREST_TRUST_RECORD implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public static class UNION extends Union {
|
||||
public static class ByReference extends UNION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_UNICODE_STRING TopLevelName;
|
||||
public LSA_FOREST_TRUST_DOMAIN_INFO DomainInfo;
|
||||
public LSA_FOREST_TRUST_BINARY_DATA Data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags that control the behavior of the operation.
|
||||
*/
|
||||
public int Flags;
|
||||
|
||||
/**
|
||||
* LSA_FOREST_TRUST_RECORD_TYPE enumeration that indicates the type of the record.
|
||||
* The following table shows the possible values.
|
||||
* ForestTrustTopLevelName
|
||||
* Record contains an included top-level name.
|
||||
* ForestTrustTopLevelNameEx
|
||||
* Record contains an excluded top-level name.
|
||||
* ForestTrustDomainInfo
|
||||
* Record contains an LSA_FOREST_TRUST_DOMAIN_INFO structure.
|
||||
* ForestTrustRecordTypeLast
|
||||
* Marks the end of an enumeration.
|
||||
*/
|
||||
public int ForestTrustType;
|
||||
public LARGE_INTEGER Time;
|
||||
|
||||
/**
|
||||
* Data type depending on ForestTrustType.
|
||||
*/
|
||||
public UNION u;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Flags", "ForestTrustType", "Time", "u" });
|
||||
}
|
||||
|
||||
public void read() {
|
||||
super.read();
|
||||
|
||||
switch(ForestTrustType) {
|
||||
case NTSecApi.ForestTrustTopLevelName:
|
||||
case NTSecApi.ForestTrustTopLevelNameEx:
|
||||
u.setType(LSA_UNICODE_STRING.class);
|
||||
break;
|
||||
case NTSecApi.ForestTrustDomainInfo:
|
||||
u.setType(LSA_FOREST_TRUST_DOMAIN_INFO.class);
|
||||
break;
|
||||
default:
|
||||
u.setType(LSA_FOREST_TRUST_BINARY_DATA.class);
|
||||
break;
|
||||
}
|
||||
|
||||
u.read();
|
||||
}
|
||||
}
|
||||
|
||||
public static class PLSA_FOREST_TRUST_RECORD extends Structure {
|
||||
public static class ByReference extends PLSA_FOREST_TRUST_RECORD implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_FOREST_TRUST_RECORD.ByReference tr;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "tr" });
|
||||
}
|
||||
}
|
||||
|
||||
public static class LSA_FOREST_TRUST_INFORMATION extends Structure {
|
||||
|
||||
public static class ByReference extends LSA_FOREST_TRUST_INFORMATION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of LSA_FOREST_TRUST_RECORD structures in the array pointed to by the
|
||||
* Entries member.
|
||||
*/
|
||||
public int RecordCount;
|
||||
/**
|
||||
* Pointer to a pointer to an array of LSA_FOREST_TRUST_RECORD structures,
|
||||
* each of which contains one piece of forest trust information.
|
||||
*/
|
||||
public PLSA_FOREST_TRUST_RECORD.ByReference Entries;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "RecordCount", "Entries" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of LSA_FOREST_TRUST_RECORD entries.
|
||||
* @return
|
||||
* An array of forest trust records.
|
||||
*/
|
||||
public PLSA_FOREST_TRUST_RECORD[] getEntries() {
|
||||
return (PLSA_FOREST_TRUST_RECORD[]) Entries.toArray(RecordCount);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The LSA_FOREST_TRUST_INFORMATION structure contains Local Security Authority
|
||||
* forest trust information.
|
||||
*/
|
||||
public static class PLSA_FOREST_TRUST_INFORMATION extends Structure {
|
||||
|
||||
public static class ByReference extends PLSA_FOREST_TRUST_INFORMATION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
public LSA_FOREST_TRUST_INFORMATION.ByReference fti;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "fti" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
public interface NTStatus {
|
||||
|
||||
int STATUS_SUCCESS = 0x00000000; // ntsubauth
|
||||
int STATUS_BUFFER_TOO_SMALL = 0xC0000023;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_0
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_0
|
||||
//
|
||||
int STATUS_WAIT_0 = 0x00000000; // winnt
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_1
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_1
|
||||
//
|
||||
int STATUS_WAIT_1 = 0x00000001;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_2
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_2
|
||||
//
|
||||
int STATUS_WAIT_2 = 0x00000002;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_3
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_3
|
||||
//
|
||||
int STATUS_WAIT_3 = 0x00000003;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_WAIT_63
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_WAIT_63
|
||||
//
|
||||
int STATUS_WAIT_63 = 0x0000003F;
|
||||
|
||||
//
|
||||
// The success status codes 128 - 191 are reserved for wait completion
|
||||
// status with an abandoned mutant object.
|
||||
//
|
||||
int STATUS_ABANDONED = 0x00000080;
|
||||
|
||||
//
|
||||
// MessageId: STATUS_ABANDONED_WAIT_0
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_ABANDONED_WAIT_0
|
||||
//
|
||||
int STATUS_ABANDONED_WAIT_0 = 0x00000080; // winnt
|
||||
|
||||
//
|
||||
// MessageId: STATUS_ABANDONED_WAIT_63
|
||||
//
|
||||
// MessageText:
|
||||
//
|
||||
// STATUS_ABANDONED_WAIT_63
|
||||
//
|
||||
int STATUS_ABANDONED_WAIT_63 = 0x000000BF;
|
||||
}
|
||||
|
||||
@@ -1,431 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDOMAIN_CONTROLLER_INFO;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_INFORMATION;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Netapi32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Netapi32 extends StdCallLibrary {
|
||||
|
||||
Netapi32 INSTANCE = (Netapi32) Native.loadLibrary("Netapi32",
|
||||
Netapi32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Retrieves join status information for the specified computer.
|
||||
*
|
||||
* @param lpServer
|
||||
* Specifies the DNS or NetBIOS name of the computer on which to
|
||||
* call the function.
|
||||
* @param lpNameBuffer
|
||||
* Receives the NetBIOS name of the domain or workgroup to which
|
||||
* the computer is joined.
|
||||
* @param BufferType
|
||||
* Join status of the specified computer.
|
||||
* @return If the function succeeds, the return value is NERR_Success. If
|
||||
* the function fails, the return value is a system error code.
|
||||
*/
|
||||
public int NetGetJoinInformation(String lpServer,
|
||||
PointerByReference lpNameBuffer, IntByReference BufferType);
|
||||
|
||||
/**
|
||||
* Frees the memory that the NetApiBufferAllocate function allocates.
|
||||
*
|
||||
* @param buffer
|
||||
* @return If the function succeeds, the return value is NERR_Success. If
|
||||
* the function fails, the return value is a system error code.
|
||||
*/
|
||||
public int NetApiBufferFree(Pointer buffer);
|
||||
|
||||
/**
|
||||
* Returns information about each local group account on the specified
|
||||
* server.
|
||||
*
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on
|
||||
* which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the address of the buffer that receives the
|
||||
* information structure.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in
|
||||
* bytes.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements
|
||||
* actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the approximate total number
|
||||
* of entries that could have been enumerated from the current
|
||||
* resume position.
|
||||
* @param resume_handle
|
||||
* Pointer to a value that contains a resume handle that is used
|
||||
* to continue an existing local group search.
|
||||
* @return If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetLocalGroupEnum(String serverName, int level,
|
||||
PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC).
|
||||
*
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on which the function is
|
||||
* to execute. If this parameter is NULL, the local computer is used.
|
||||
* @param domainName
|
||||
* Specifies the name of the domain.
|
||||
* @param bufptr
|
||||
* Receives a string that specifies the server name of the PDC of the domain.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetGetDCName(String serverName, String domainName,
|
||||
PointerByReference bufptr);
|
||||
|
||||
/**
|
||||
* The NetGroupEnum function retrieves information about each global group
|
||||
* in the security database, which is the security accounts manager (SAM) database or,
|
||||
* in the case of domain controllers, the Active Directory.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer to receive the global group information structure.
|
||||
* The format of this data depends on the value of the level parameter.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of the returned data, in bytes.
|
||||
* If you specify MAX_PREFERRED_LENGTH, the function allocates the amount of
|
||||
* memory required to hold the data. If you specify another value in this
|
||||
* parameter, it can restrict the number of bytes that the function returns.
|
||||
* If the buffer size is insufficient to hold all entries, the function
|
||||
* returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have
|
||||
* been enumerated from the current resume position. The total number of entries
|
||||
* is only a hint.
|
||||
* @param resume_handle
|
||||
* Pointer to a variable that contains a resume handle that is used to continue
|
||||
* the global group enumeration. The handle should be zero on the first call and
|
||||
* left unchanged for subsequent calls. If resume_handle is NULL, no resume handle
|
||||
* is stored.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetGroupEnum(String servername, int level, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* The NetUserEnum function provides information about all user accounts on a server.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param filter
|
||||
* Specifies a value that filters the account types for enumeration.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. The format of this data depends
|
||||
* on the value of the level parameter. This buffer is allocated by the system and
|
||||
* must be freed using the NetApiBufferFree function. Note that you must free the
|
||||
* buffer even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length, in 8-bit bytes of returned data. If you
|
||||
* specify MAX_PREFERRED_LENGTH, the function allocates the amount of memory
|
||||
* required for the data. If you specify another value in this parameter, it can
|
||||
* restrict the number of bytes that the function returns. If the buffer size is
|
||||
* insufficient to hold all entries, the function returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have
|
||||
* been enumerated from the current resume position. Note that applications should
|
||||
* consider this value only as a hint.
|
||||
* @param resume_handle
|
||||
* Pointer to a value that contains a resume handle which is used to continue an
|
||||
* existing user search. The handle should be zero on the first call and left
|
||||
* unchanged for subsequent calls. If resume_handle is NULL, then no resume
|
||||
* handle is stored.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserEnum(String servername, int level, int filter, PointerByReference bufptr,
|
||||
int prefmaxlen, IntByReference entriesread, IntByReference totalentries,
|
||||
IntByReference resume_handle);
|
||||
|
||||
/**
|
||||
* The NetUserGetGroups function retrieves a list of global groups to which a
|
||||
* specified user belongs.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the
|
||||
* remote server on which the function is to execute. If this parameter is NULL,
|
||||
* the local computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user to search for
|
||||
* in each group account. For more information, see the following Remarks section.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. This buffer is allocated by the
|
||||
* system and must be freed using the NetApiBufferFree function. Note that you must
|
||||
* free the buffer even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in bytes. If you specify
|
||||
* MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the
|
||||
* data. If you specify another value in this parameter, it can restrict the number
|
||||
* of bytes that the function returns. If the buffer size is insufficient to hold
|
||||
* all entries, the function returns ERROR_MORE_DATA.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually retrieved.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have been retrieved.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserGetGroups(String servername, String username, int level,
|
||||
PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/**
|
||||
* The NetUserGetLocalGroups function retrieves a list of local groups to which a
|
||||
* specified user belongs.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote
|
||||
* server on which the function is to execute. If this parameter is NULL, the local
|
||||
* computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user for which to return
|
||||
* local group membership information. If the string is of the form DomainName\UserName
|
||||
* the user name is expected to be found on that domain. If the string is of the form
|
||||
* UserName, the user name is expected to be found on the server specified by the
|
||||
* servername parameter.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param flags
|
||||
* Specifies a bitmask of flags. Currently, only the value LG_INCLUDE_INDIRECT is
|
||||
* defined. If this bit is set, the function also returns the names of the local
|
||||
* groups in which the user is indirectly a member (that is, the user has membership
|
||||
* in a global group that is itself a member of one or more local groups).
|
||||
* @param bufptr
|
||||
* Pointer to the buffer that receives the data. The format of this data depends on
|
||||
* the value of the level parameter. This buffer is allocated by the system and must
|
||||
* be freed using the NetApiBufferFree function. Note that you must free the buffer
|
||||
* even if the function fails with ERROR_MORE_DATA.
|
||||
* @param prefmaxlen
|
||||
* Specifies the preferred maximum length of returned data, in bytes. If you specify
|
||||
* MAX_PREFERRED_LENGTH, the function allocates the amount of memory required for the
|
||||
* data. If you specify another value in this parameter, it can restrict the number of
|
||||
* bytes that the function returns. If the buffer size is insufficient to hold all
|
||||
* entries, the function returns ERROR_MORE_DATA. For more information, see Network
|
||||
* Management Function Buffers and Network Management Function Buffer Lengths.
|
||||
* @param entriesread
|
||||
* Pointer to a value that receives the count of elements actually enumerated.
|
||||
* @param totalentries
|
||||
* Pointer to a value that receives the total number of entries that could have been enumerated.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserGetLocalGroups(String servername, String username, int level,
|
||||
int flags, PointerByReference bufptr, int prefmaxlen,
|
||||
IntByReference entriesread, IntByReference totalentries);
|
||||
|
||||
/**
|
||||
* The NetUserAdd function adds a user account and assigns a password and privilege level.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server
|
||||
* on which the function is to execute.
|
||||
* @param level
|
||||
* Specifies the information level of the data.
|
||||
* @param buf
|
||||
* Pointer to the buffer that specifies the data. The format of this data depends on the
|
||||
* value of the level parameter.
|
||||
* @param parm_err
|
||||
* Pointer to a value that receives the index of the first member of the user information
|
||||
* structure that causes ERROR_INVALID_PARAMETER. If this parameter is NULL, the index is
|
||||
* not returned on error.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserAdd(String servername, int level,
|
||||
Structure buf, IntByReference parm_err);
|
||||
|
||||
|
||||
/**
|
||||
* The NetUserDel function deletes a user account from a server.
|
||||
* @param servername
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of the remote
|
||||
* server on which the function is to execute. If this parameter is NULL, the local
|
||||
* computer is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies the name of the user account to delete.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserDel(String servername, String username);
|
||||
|
||||
/**
|
||||
* The NetUserChangePassword function changes a user's password for a specified
|
||||
* network server or domain.
|
||||
* @param domainname
|
||||
* Pointer to a constant string that specifies the DNS or NetBIOS name of a remote
|
||||
* server or domain on which the function is to execute. If this parameter is NULL,
|
||||
* the logon domain of the caller is used.
|
||||
* @param username
|
||||
* Pointer to a constant string that specifies a user name. The NetUserChangePassword
|
||||
* function changes the password for the specified user. If this parameter is NULL,
|
||||
* the logon name of the caller is used.
|
||||
* @param oldpassword
|
||||
* Pointer to a constant string that specifies the user's old password.
|
||||
* @param newpassword
|
||||
* Pointer to a constant string that specifies the user's new password.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserChangePassword(String domainname, String username,
|
||||
String oldpassword, String newpassword);
|
||||
|
||||
/**
|
||||
* The DsGetDcName function returns the name of a domain controller in a specified domain.
|
||||
* This function accepts additional domain controller selection criteria to indicate
|
||||
* preference for a domain controller with particular characteristics.
|
||||
* @param ComputerName
|
||||
* Pointer to a null-terminated string that specifies the name of the server to process
|
||||
* this function. Typically, this parameter is NULL, which indicates that the local
|
||||
* computer is used.
|
||||
* @param DomainName
|
||||
* Pointer to a null-terminated string that specifies the name of the domain or application
|
||||
* partition to query. This name can either be a DNS style name, for example, fabrikam.com,
|
||||
* or a flat-style name, for example, Fabrikam. If a DNS style name is specified, the name
|
||||
* may be specified with or without a trailing period.
|
||||
* @param DomainGuid
|
||||
* Pointer to a GUID structure that specifies the GUID of the domain queried. If DomainGuid
|
||||
* is not NULL and the domain specified by DomainName or ComputerName cannot be found,
|
||||
* DsGetDcName attempts to locate a domain controller in the domain having the GUID specified
|
||||
* by DomainGuid.
|
||||
* @param SiteName
|
||||
* Pointer to a null-terminated string that specifies the name of the site where the returned
|
||||
* domain controller should physically exist. If this parameter is NULL, DsGetDcName attempts
|
||||
* to return a domain controller in the site closest to the site of the computer specified by
|
||||
* ComputerName. This parameter should be NULL, by default.
|
||||
* @param Flags
|
||||
* Contains a set of flags that provide additional data used to process the request.
|
||||
* @param DomainControllerInfo
|
||||
* Pointer to a PDOMAIN_CONTROLLER_INFO value that receives a pointer to a
|
||||
* DOMAIN_CONTROLLER_INFO structure that contains data about the domain controller selected.
|
||||
* This structure is allocated by DsGetDcName. The caller must free the structure using
|
||||
* the NetApiBufferFree function when it is no longer required.
|
||||
* @return
|
||||
* If the function returns domain controller data, the return value is ERROR_SUCCESS.
|
||||
* If the function fails, the return code is one of ERROR_* values.
|
||||
*/
|
||||
public int DsGetDcName(String ComputerName, String DomainName, GUID DomainGuid,
|
||||
String SiteName, int Flags, PDOMAIN_CONTROLLER_INFO.ByReference DomainControllerInfo);
|
||||
|
||||
/**
|
||||
* The DsGetForestTrustInformationW function obtains forest trust data for a specified domain.
|
||||
* @param serverName
|
||||
* Contains the name of the domain controller that DsGetForestTrustInformationW
|
||||
* is connected to remotely. The caller must be an authenticated user on this server.
|
||||
* If this parameter is NULL, the local server is used.
|
||||
* @param trustedDomainName
|
||||
* Contains the NETBIOS or DNS name of the trusted domain that the forest trust data
|
||||
* is to be retrieved for. This domain must have the TRUST_ATTRIBUTE_FOREST_TRANSITIVE
|
||||
* trust attribute. If this parameter is NULL, the forest trust data for the domain
|
||||
* hosted by ServerName is retrieved.
|
||||
* @param Flags
|
||||
* Contains a set of flags that modify the behavior of this function.
|
||||
* DS_GFTI_UPDATE_TDO: If this flag is set, DsGetForestTrustInformationW will update the
|
||||
* forest trust data of the trusted domain identified by the TrustedDomainName parameter.
|
||||
* @param ForestTrustInfo
|
||||
* Pointer to an LSA_FOREST_TRUST_INFORMATION structure pointer that receives the forest
|
||||
* trust data that describes the namespaces claimed by the domain specified by
|
||||
* TrustedDomainName. The Time member of all returned records will be zero.
|
||||
* @return
|
||||
* Returns NO_ERROR if successful or a Win32 error code otherwise.
|
||||
*/
|
||||
public int DsGetForestTrustInformation(String serverName, String trustedDomainName, int Flags,
|
||||
PLSA_FOREST_TRUST_INFORMATION.ByReference ForestTrustInfo);
|
||||
|
||||
/**
|
||||
* The DsEnumerateDomainTrusts function obtains domain trust data for a specified domain.
|
||||
* @param serverName
|
||||
* Pointer to a null-terminated string that specifies the name of a computer in the domain to
|
||||
* obtain the trust information for. This computer must be running the Windows 2000 or later
|
||||
* operating system. If this parameter is NULL, the name of the local computer is used.
|
||||
* The caller must be an authenticated user in this domain.
|
||||
* @param Flags
|
||||
* Contains a set of flags that determines which domain trusts to enumerate.
|
||||
* @param Domains
|
||||
* Receives a pointer which points to an array of DS_DOMAIN_TRUSTS structures.
|
||||
* Each structure in this array contains trust data about a domain. The caller must free this
|
||||
* memory when it is no longer required by calling NetApiBufferFree.
|
||||
* @param DomainCount
|
||||
* Pointer to a ULONG value that receives the number of elements returned in the Domains array.
|
||||
* @return
|
||||
* Returns ERROR_SUCCESS if successful or a Win32 error code otherwise.
|
||||
*/
|
||||
public int DsEnumerateDomainTrusts(String serverName, int Flags,
|
||||
PointerByReference Domains, IntByReference DomainCount);
|
||||
|
||||
/**
|
||||
* The NetUserGetInfo function retrieves information about a particular user account on a server.
|
||||
* @param servername
|
||||
* A pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on
|
||||
* which the function is to execute. If this parameter is NULL, the local computer is used.
|
||||
* @param username
|
||||
* A pointer to a constant string that specifies the name of the user account for which to return information.
|
||||
* For more information, see the following Remarks section.
|
||||
* @param level
|
||||
* The information level of the data. This parameter can be one of the following values.
|
||||
* Value Meaning
|
||||
* 0 Return the user account name. The bufptr parameter points to a USER_INFO_0 structure.
|
||||
* 1 Return detailed information about the user account. The bufptr parameter points to a USER_INFO_1 structure.
|
||||
* 2 Return detailed information and additional attributes about the user account. The bufptr parameter points to a USER_INFO_2 structure.
|
||||
* 3 Return detailed information and additional attributes about the user account. This level is valid only on servers. The bufptr parameter points to a USER_INFO_3 structure. Note that it is recommended that you use USER_INFO_4 instead.
|
||||
* 4 Return detailed information and additional attributes about the user account. This level is valid only on servers. The bufptr parameter points to a USER_INFO_4 structure. Windows 2000: This level is not supported.
|
||||
* 10 Return user and account names and comments. The bufptr parameter points to a USER_INFO_10 structure.
|
||||
* 11 Return detailed information about the user account. The bufptr parameter points to a USER_INFO_11 structure.
|
||||
* 20 Return the user's name and identifier and various account attributes. The bufptr parameter points to a USER_INFO_20 structure. Note that on Windows XP and later, it is recommended that you use USER_INFO_23 instead.
|
||||
* 23 Return the user's name and identifier and various account attributes. The bufptr parameter points to a USER_INFO_23 structure. Windows 2000: This level is not supported.
|
||||
* @param bufptr
|
||||
* A pointer to the buffer that receives the data.
|
||||
* The format of this data depends on the value of the level parameter.
|
||||
* This buffer is allocated by the system and must be freed using the NetApiBufferFree function.
|
||||
* For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.
|
||||
* @return
|
||||
* If the function succeeds, the return value is NERR_Success.
|
||||
*/
|
||||
public int NetUserGetInfo( String servername, String username, int level, PointerByReference bufptr );
|
||||
|
||||
}
|
||||
@@ -1,695 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.DsGetDC.DS_DOMAIN_TRUSTS;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDOMAIN_CONTROLLER_INFO;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.LMAccess.GROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_INFO_1;
|
||||
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.LMAccess.USER_INFO_23;
|
||||
import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* Netapi32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Netapi32Util {
|
||||
|
||||
/**
|
||||
* A group.
|
||||
*/
|
||||
public static class Group {
|
||||
/**
|
||||
* Group name.
|
||||
*/
|
||||
public String name;
|
||||
}
|
||||
|
||||
/**
|
||||
* A user.
|
||||
*/
|
||||
public static class User {
|
||||
/**
|
||||
* The name of the user account.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Contains a comment associated with the user account.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
|
||||
public static class UserInfo extends User {
|
||||
/**
|
||||
* The full name belonging to the user account
|
||||
*/
|
||||
public String fullName;
|
||||
/**
|
||||
* The SID of the user account
|
||||
*/
|
||||
public String sidString;
|
||||
/**
|
||||
* The SID of the user account
|
||||
*/
|
||||
public PSID sid;
|
||||
/**
|
||||
* The flags of the user account
|
||||
*/
|
||||
public int flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* A local group.
|
||||
*/
|
||||
public static class LocalGroup extends Group {
|
||||
/**
|
||||
* Group comment.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC) on the current computer.
|
||||
* @return The name of the primary domain controller.
|
||||
*/
|
||||
public static String getDCName() {
|
||||
return getDCName(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the primary domain controller (PDC).
|
||||
* @param serverName
|
||||
* Specifies the DNS or NetBIOS name of the remote server on which the function is
|
||||
* to execute.
|
||||
* @param domainName
|
||||
* Specifies the name of the domain.
|
||||
* @return
|
||||
* Name of the primary domain controller.
|
||||
*/
|
||||
public static String getDCName(String serverName, String domainName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetDCName(domainName, serverName, bufptr);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return bufptr.getValue().getString(0, true);
|
||||
} finally {
|
||||
if (W32Errors.ERROR_SUCCESS != Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain/workgroup join status for a computer.
|
||||
* @return Join status.
|
||||
*/
|
||||
public static int getJoinStatus() {
|
||||
return getJoinStatus(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain/workgroup join status for a computer.
|
||||
* @param computerName Computer name.
|
||||
* @return Join status.
|
||||
*/
|
||||
public static int getJoinStatus(String computerName) {
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
IntByReference bufferType = new IntByReference();
|
||||
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return bufferType.getValue();
|
||||
} finally {
|
||||
if (lpNameBuffer.getPointer() != null) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information about a computer.
|
||||
* @param computerName
|
||||
* @return Domain or workgroup name.
|
||||
*/
|
||||
public static String getDomainName(String computerName) {
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
IntByReference bufferType = new IntByReference();
|
||||
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGetJoinInformation(computerName, lpNameBuffer, bufferType);
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
// type of domain: bufferType.getValue()
|
||||
return lpNameBuffer.getValue().getString(0, true);
|
||||
} finally {
|
||||
if (lpNameBuffer.getPointer() != null) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of local groups on the current computer.
|
||||
* @return An array of local group names.
|
||||
*/
|
||||
public static LocalGroup[] getLocalGroups() {
|
||||
return getLocalGroups(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of local groups on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of local group names.
|
||||
*/
|
||||
public static LocalGroup[] getLocalGroups(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetLocalGroupEnum(serverName, 1, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesRead, totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.LOCALGROUP_INFO_1 group = new LMAccess.LOCALGROUP_INFO_1(bufptr.getValue());
|
||||
LMAccess.LOCALGROUP_INFO_1[] groups = (LOCALGROUP_INFO_1[]) group.toArray(entriesRead.getValue());
|
||||
|
||||
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
|
||||
for(LOCALGROUP_INFO_1 lgpi : groups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
if (lgpi.lgrui1_name != null) {
|
||||
lgp.name = lgpi.lgrui1_name.toString();
|
||||
}
|
||||
if (lgpi.lgrui1_comment != null) {
|
||||
lgp.comment = lgpi.lgrui1_comment.toString();
|
||||
}
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new LocalGroup[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of global groups on a computer.
|
||||
* @return An array of group names.
|
||||
*/
|
||||
public static Group[] getGlobalGroups() {
|
||||
return getGlobalGroups(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of global groups on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of group names.
|
||||
*/
|
||||
public static Group[] getGlobalGroups(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetGroupEnum(serverName, 1, bufptr,
|
||||
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
|
||||
totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.GROUP_INFO_1 group = new LMAccess.GROUP_INFO_1(bufptr.getValue());
|
||||
LMAccess.GROUP_INFO_1[] groups = (LMAccess.GROUP_INFO_1[]) group.toArray(entriesRead.getValue());
|
||||
|
||||
ArrayList<LocalGroup> result = new ArrayList<LocalGroup>();
|
||||
for(LMAccess.GROUP_INFO_1 lgpi : groups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
if (lgpi.grpi1_name != null) {
|
||||
lgp.name = lgpi.grpi1_name.toString();
|
||||
}
|
||||
if (lgpi.grpi1_comment != null) {
|
||||
lgp.comment = lgpi.grpi1_comment.toString();
|
||||
}
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new LocalGroup[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of users on a local computer.
|
||||
* @return Users.
|
||||
*/
|
||||
public static User[] getUsers() {
|
||||
return getUsers(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of users on a computer.
|
||||
* @param serverName Name of the computer.
|
||||
* @return An array of users.
|
||||
*/
|
||||
public static User[] getUsers(String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserEnum(
|
||||
serverName, 1, 0, bufptr,
|
||||
LMCons.MAX_PREFERRED_LENGTH, entriesRead,
|
||||
totalEntries, null);
|
||||
if (LMErr.NERR_Success != rc || bufptr.getValue() == Pointer.NULL) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LMAccess.USER_INFO_1 user = new LMAccess.USER_INFO_1(bufptr.getValue());
|
||||
LMAccess.USER_INFO_1[] users = (LMAccess.USER_INFO_1[]) user.toArray(entriesRead.getValue());
|
||||
ArrayList<User> result = new ArrayList<User>();
|
||||
for(LMAccess.USER_INFO_1 lu : users) {
|
||||
User auser = new User();
|
||||
if (lu.usri1_name != null) {
|
||||
auser.name = lu.usri1_name.toString();
|
||||
}
|
||||
result.add(auser);
|
||||
}
|
||||
return result.toArray(new User[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of the current user.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getCurrentUserLocalGroups() {
|
||||
return getUserLocalGroups(Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of a given user.
|
||||
* @param userName User name.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getUserLocalGroups(String userName) {
|
||||
return getUserLocalGroups(userName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get local groups of a given user on a given system.
|
||||
* @param userName User name.
|
||||
* @param serverName Server name.
|
||||
* @return Local groups.
|
||||
*/
|
||||
public static Group[] getUserLocalGroups(String userName, String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserGetLocalGroups(
|
||||
serverName, userName,
|
||||
0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
|
||||
if (rc != LMErr.NERR_Success) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
|
||||
LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
ArrayList<Group> result = new ArrayList<Group>();
|
||||
for (LOCALGROUP_USERS_INFO_0 lgpi : lgroups) {
|
||||
LocalGroup lgp = new LocalGroup();
|
||||
if (lgpi.lgrui0_name != null) {
|
||||
lgp.name = lgpi.lgrui0_name.toString();
|
||||
}
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new Group[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups of a given user.
|
||||
* @param userName User name.
|
||||
* @return Groups.
|
||||
*/
|
||||
public static Group[] getUserGroups(String userName) {
|
||||
return getUserGroups(userName, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get groups of a given user on a given system.
|
||||
* @param userName User name.
|
||||
* @param serverName Server name.
|
||||
* @return Groups.
|
||||
*/
|
||||
public static Group[] getUserGroups(String userName, String serverName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
try {
|
||||
int rc = Netapi32.INSTANCE.NetUserGetGroups(
|
||||
serverName, userName,
|
||||
0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries);
|
||||
if (rc != LMErr.NERR_Success) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue());
|
||||
GROUP_USERS_INFO_0[] lgroups = (GROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
ArrayList<Group> result = new ArrayList<Group>();
|
||||
for (GROUP_USERS_INFO_0 lgpi : lgroups) {
|
||||
Group lgp = new Group();
|
||||
if (lgpi.grui0_name != null) {
|
||||
lgp.name = lgpi.grui0_name.toString();
|
||||
}
|
||||
result.add(lgp);
|
||||
}
|
||||
return result.toArray(new Group[0]);
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
int rc = Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain controller.
|
||||
*/
|
||||
public static class DomainController {
|
||||
/**
|
||||
* Specifies the computer name of the discovered domain controller.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Specifies the address of the discovered domain controller.
|
||||
*/
|
||||
public String address;
|
||||
/**
|
||||
* Indicates the type of string that is contained in the
|
||||
* DomainControllerAddress member.
|
||||
*/
|
||||
public int addressType;
|
||||
/**
|
||||
* The GUID of the domain.
|
||||
*/
|
||||
public GUID domainGuid;
|
||||
/**
|
||||
* Pointer to a null-terminated string that specifies the name of the domain.
|
||||
*/
|
||||
public String domainName;
|
||||
/**
|
||||
* Pointer to a null-terminated string that specifies the name of the domain at the root
|
||||
* of the DS tree.
|
||||
*/
|
||||
public String dnsForestName;
|
||||
/**
|
||||
* Contains a set of flags that describe the domain controller.
|
||||
*/
|
||||
public int flags;
|
||||
/**
|
||||
* The name of the site that the computer belongs to.
|
||||
*/
|
||||
public String clientSiteName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the domain controller for a current computer.
|
||||
* @return
|
||||
* Domain controller information.
|
||||
*/
|
||||
public static DomainController getDC() {
|
||||
PDOMAIN_CONTROLLER_INFO.ByReference pdci = new PDOMAIN_CONTROLLER_INFO.ByReference();
|
||||
int rc = Netapi32.INSTANCE.DsGetDcName(null, null, null, null, 0, pdci);
|
||||
if (W32Errors.ERROR_SUCCESS != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
DomainController dc = new DomainController();
|
||||
if (pdci.dci.DomainControllerAddress != null) {
|
||||
dc.address = pdci.dci.DomainControllerAddress.toString();
|
||||
}
|
||||
dc.addressType = pdci.dci.DomainControllerAddressType;
|
||||
if (pdci.dci.ClientSiteName != null) {
|
||||
dc.clientSiteName = pdci.dci.ClientSiteName.toString();
|
||||
}
|
||||
if (pdci.dci.DnsForestName != null) {
|
||||
dc.dnsForestName = pdci.dci.DnsForestName.toString();
|
||||
}
|
||||
dc.domainGuid = pdci.dci.DomainGuid;
|
||||
if (pdci.dci.DomainName != null) {
|
||||
dc.domainName = pdci.dci.DomainName.toString();
|
||||
}
|
||||
dc.flags = pdci.dci.Flags;
|
||||
if (pdci.dci.DomainControllerName != null) {
|
||||
dc.name = pdci.dci.DomainControllerName.toString();
|
||||
}
|
||||
rc = Netapi32.INSTANCE.NetApiBufferFree(pdci.dci.getPointer());
|
||||
if (LMErr.NERR_Success != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return dc;
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain trust relationship.
|
||||
*/
|
||||
public static class DomainTrust {
|
||||
/**
|
||||
* NetBIOS name of the domain.
|
||||
*/
|
||||
public String NetbiosDomainName;
|
||||
/**
|
||||
* DNS name of the domain.
|
||||
*/
|
||||
public String DnsDomainName;
|
||||
/**
|
||||
* Contains the security identifier of the domain represented by this structure.
|
||||
*/
|
||||
public PSID DomainSid;
|
||||
/**
|
||||
* Contains the string representation of the security identifier of the domain
|
||||
* represented by this structure.
|
||||
*/
|
||||
public String DomainSidString;
|
||||
/**
|
||||
* Contains the GUID of the domain represented by this structure.
|
||||
*/
|
||||
public GUID DomainGuid;
|
||||
/**
|
||||
* Contains the string representation of the GUID of the domain represented by
|
||||
* this structure.
|
||||
*/
|
||||
public String DomainGuidString;
|
||||
|
||||
/**
|
||||
* Contains a set of flags that specify more data about the domain trust.
|
||||
*/
|
||||
private int flags;
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is a member of the same forest
|
||||
* as the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isInForest() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_IN_FOREST) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is directly trusted by the domain
|
||||
* that the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function is a member of.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isOutbound() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_DIRECT_OUTBOUND) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is the root of a tree and a member
|
||||
* of the same forest as the server specified in the ServerName parameter of the
|
||||
* DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isRoot() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_TREE_ROOT) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is the primary domain of the server
|
||||
* specified in the ServerName parameter of the DsEnumerateDomainTrusts function.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isPrimary() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_PRIMARY) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure is running in the Windows 2000 native mode.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isNativeMode() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_NATIVE_MODE) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The domain represented by this structure directly trusts the domain that
|
||||
* the server specified in the ServerName parameter of the DsEnumerateDomainTrusts
|
||||
* function is a member of.
|
||||
* @return
|
||||
* True or false.
|
||||
*/
|
||||
public boolean isInbound() {
|
||||
return (flags & DsGetDC.DS_DOMAIN_DIRECT_INBOUND) != 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all domain trusts.
|
||||
* @return
|
||||
* An array of domain trusts.
|
||||
*/
|
||||
public static DomainTrust[] getDomainTrusts() {
|
||||
return getDomainTrusts(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all domain trusts for a given server.
|
||||
* @param serverName
|
||||
* Server name.
|
||||
* @return
|
||||
* An array of domain trusts.
|
||||
*/
|
||||
public static DomainTrust[] getDomainTrusts(String serverName) {
|
||||
IntByReference domainTrustCount = new IntByReference();
|
||||
PointerByReference domainsPointerRef = new PointerByReference();
|
||||
int rc = Netapi32.INSTANCE.DsEnumerateDomainTrusts(serverName,
|
||||
DsGetDC.DS_DOMAIN_VALID_FLAGS, domainsPointerRef, domainTrustCount);
|
||||
if(W32Errors.NO_ERROR != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue());
|
||||
DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]);
|
||||
ArrayList<DomainTrust> trusts = new ArrayList<DomainTrust>(domainTrustCount.getValue());
|
||||
for(DS_DOMAIN_TRUSTS domainTrust : domainTrusts) {
|
||||
DomainTrust t = new DomainTrust();
|
||||
if (domainTrust.DnsDomainName != null) {
|
||||
t.DnsDomainName = domainTrust.DnsDomainName.toString();
|
||||
}
|
||||
if (domainTrust.NetbiosDomainName != null) {
|
||||
t.NetbiosDomainName = domainTrust.NetbiosDomainName.toString();
|
||||
}
|
||||
t.DomainSid = domainTrust.DomainSid;
|
||||
if (domainTrust.DomainSid != null) {
|
||||
t.DomainSidString = Advapi32Util.convertSidToStringSid(domainTrust.DomainSid);
|
||||
}
|
||||
t.DomainGuid = domainTrust.DomainGuid;
|
||||
if (domainTrust.DomainGuid != null) {
|
||||
t.DomainGuidString = Ole32Util.getStringFromGUID(domainTrust.DomainGuid);
|
||||
}
|
||||
t.flags = domainTrust.Flags;
|
||||
trusts.add(t);
|
||||
}
|
||||
return trusts.toArray(new DomainTrust[0]);
|
||||
} finally {
|
||||
rc = Netapi32.INSTANCE.NetApiBufferFree(domainsPointerRef.getValue());
|
||||
if(W32Errors.NO_ERROR != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static UserInfo getUserInfo(String accountName) {
|
||||
return getUserInfo(accountName, Netapi32Util.getDCName());
|
||||
}
|
||||
|
||||
public static UserInfo getUserInfo(String accountName, String domainName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
int rc = -1;
|
||||
try {
|
||||
rc = Netapi32.INSTANCE.NetUserGetInfo(domainName, accountName, (short)23, bufptr);
|
||||
if (rc == LMErr.NERR_Success) {
|
||||
USER_INFO_23 info_23 = new USER_INFO_23(bufptr.getValue());
|
||||
UserInfo userInfo = new UserInfo();
|
||||
if (info_23.usri23_comment != null) {
|
||||
userInfo.comment = info_23.usri23_comment.toString();
|
||||
}
|
||||
userInfo.flags = info_23.usri23_flags;
|
||||
if (info_23.usri23_full_name != null) {
|
||||
userInfo.fullName = info_23.usri23_full_name.toString();
|
||||
}
|
||||
if (info_23.usri23_name != null) {
|
||||
userInfo.name = info_23.usri23_name.toString();
|
||||
}
|
||||
if (info_23.usri23_user_sid != null) {
|
||||
userInfo.sidString = Advapi32Util.convertSidToStringSid(info_23.usri23_user_sid);
|
||||
}
|
||||
userInfo.sid = info_23.usri23_user_sid;
|
||||
return userInfo;
|
||||
} else {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
} finally {
|
||||
if (bufptr.getValue() != Pointer.NULL) {
|
||||
Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* ntdll.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface NtDll extends StdCallLibrary {
|
||||
|
||||
NtDll INSTANCE = (NtDll) Native.loadLibrary("NtDll",
|
||||
NtDll.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The ZwQueryKey routine provides information about the class of a registry key,
|
||||
* and the number and sizes of its subkeys.
|
||||
* @param KeyHandle
|
||||
* Handle to the registry key to obtain information about. This handle is created by
|
||||
* a successful call to ZwCreateKey or ZwOpenKey.
|
||||
* @param KeyInformationClass
|
||||
* Specifies a KEY_INFORMATION_CLASS value that determines the type of information
|
||||
* returned in the KeyInformation buffer.
|
||||
* @param KeyInformation
|
||||
* Pointer to a caller-allocated buffer that receives the requested information.
|
||||
* @param Length
|
||||
* Specifies the size, in bytes, of the KeyInformation buffer.
|
||||
* @param ResultLength
|
||||
* Pointer to a variable that receives the size, in bytes, of the requested key
|
||||
* information. If ZwQueryKey returns STATUS_SUCCESS, the variable contains the amount
|
||||
* of data returned. If ZwQueryKey returns STATUS_BUFFER_OVERFLOW or
|
||||
* STATUS_BUFFER_TOO_SMALL, you can use the value of the variable to determine the
|
||||
* required buffer size.
|
||||
* @return
|
||||
* ZwQueryKey returns STATUS_SUCCESS on success, or the appropriate error code on failure.
|
||||
*/
|
||||
public int ZwQueryKey(HANDLE KeyHandle, int KeyInformationClass,
|
||||
Structure KeyInformation, int Length, IntByReference ResultLength);
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.Wdm.KEY_BASIC_INFORMATION;
|
||||
import com.sun.jna.platform.win32.Wdm.KEY_INFORMATION_CLASS;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* NtDll Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class NtDllUtil {
|
||||
|
||||
/**
|
||||
* Retrieve the name of an opened registry key.
|
||||
* @param hkey Opened registry key.
|
||||
* @return Basic key name, not including node information.
|
||||
*/
|
||||
public static String getKeyName(HKEY hkey) {
|
||||
IntByReference resultLength = new IntByReference();
|
||||
int rc = NtDll.INSTANCE.ZwQueryKey(hkey, KEY_INFORMATION_CLASS.KeyBasicInformation,
|
||||
null, 0, resultLength);
|
||||
if (rc != NTStatus.STATUS_BUFFER_TOO_SMALL || resultLength.getValue() <= 0) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
KEY_BASIC_INFORMATION keyInformation = new KEY_BASIC_INFORMATION(
|
||||
resultLength.getValue());
|
||||
rc = NtDll.INSTANCE.ZwQueryKey(hkey, KEY_INFORMATION_CLASS.KeyBasicInformation,
|
||||
keyInformation, resultLength.getValue(), resultLength);
|
||||
if (rc != NTStatus.STATUS_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return keyInformation.getName();
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Digital Rapids Corp.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 Timothy Wall, All Rights Reserved
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WTypes;
|
||||
|
||||
/**
|
||||
* Definitions from ObjBase.h
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface ObjBase {
|
||||
|
||||
int CLSCTX_INPROC = (WTypes.CLSCTX_INPROC_SERVER | WTypes.CLSCTX_INPROC_HANDLER);
|
||||
|
||||
// With DCOM, CLSCTX_REMOTE_SERVER should be included
|
||||
int CLSCTX_ALL = (WTypes.CLSCTX_INPROC_SERVER
|
||||
| WTypes.CLSCTX_INPROC_HANDLER
|
||||
| WTypes.CLSCTX_LOCAL_SERVER
|
||||
| WTypes.CLSCTX_REMOTE_SERVER);
|
||||
|
||||
int CLSCTX_SERVER = (WTypes.CLSCTX_INPROC_SERVER
|
||||
| WTypes.CLSCTX_LOCAL_SERVER
|
||||
| WTypes.CLSCTX_REMOTE_SERVER);
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Ole32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Ole32 extends StdCallLibrary {
|
||||
|
||||
Ole32 INSTANCE = (Ole32) Native.loadLibrary(
|
||||
"Ole32", Ole32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Creates a GUID, a unique 128-bit integer used for CLSIDs and interface identifiers.
|
||||
* @param pguid
|
||||
* A pointer to the requested GUID.
|
||||
* @return
|
||||
* S_OK if the GUID was successfully created.
|
||||
*/
|
||||
HRESULT CoCreateGuid(GUID.ByReference pguid);
|
||||
|
||||
/**
|
||||
* Converts a globally unique identifier (GUID) into a string of printable characters.
|
||||
* @param rguid
|
||||
* The GUID to be converted.
|
||||
* @param lpsz
|
||||
* A pointer to a caller-allocated string variable to receive the resulting string.
|
||||
* @param cchMax
|
||||
* The number of characters available in the lpsz buffer.
|
||||
* @return
|
||||
* If the function succeeds, the return value is the number of characters in the
|
||||
* returned string, including the null terminator. If the buffer is too small to contain
|
||||
* the string, the return value is 0.
|
||||
*/
|
||||
int StringFromGUID2(GUID.ByReference rguid, char[] lpsz, int cchMax);
|
||||
|
||||
/**
|
||||
* Converts a string generated by the StringFromIID function back into the
|
||||
* original interface identifier (IID).
|
||||
* @param lpsz
|
||||
* A pointer to the string representation of the IID.
|
||||
* @param lpiid
|
||||
* A pointer to the requested IID on return.
|
||||
* @return
|
||||
* This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY,
|
||||
* and S_OK.
|
||||
*/
|
||||
HRESULT IIDFromString(String lpsz, GUID.ByReference lpiid);
|
||||
|
||||
/**
|
||||
* Initializes the COM library for use by the calling thread, sets the thread's
|
||||
* concurrency model, and creates a new apartment for the thread if one is required.
|
||||
* @param reserved This parameter is reserved and must be NULL.
|
||||
* @param dwCoInit The concurrency model and initialization options for the
|
||||
* thread. Values for this parameter are taken from the COINIT enumeration.
|
||||
* Any combination of values from COINIT can be used, except that the
|
||||
* COINIT_APARTMENTTHREADED and COINIT_MULTITHREADED flags cannot both be
|
||||
* set. The default (and only sane choice) is COINIT_MULTITHREADED.
|
||||
* @return This function can return the standard return values E_INVALIDARG, E_OUTOFMEMORY, and E_UNEXPECTED, as well as the following values. S_OK, S_FALSE, RPC_E_CHANGED_MODE
|
||||
*/
|
||||
HRESULT CoInitializeEx(Pointer reserved, int dwCoInit);
|
||||
|
||||
/**
|
||||
* Closes the COM library on the current thread, unloads all DLLs loaded by
|
||||
* the thread, frees any other resources that the thread maintains, and
|
||||
* forces all RPC connections on the thread to close.
|
||||
*
|
||||
*/
|
||||
void CoUninitialize();
|
||||
|
||||
/**
|
||||
* Creates a single uninitialized object of the class associated with a specified CLSID.
|
||||
* @param rclsid The CLSID associated with the data and code that will be used to create the object.
|
||||
* @param pUnkOuter If NULL, indicates that the object is not being created as part of an aggregate. If non-NULL, pointer to the aggregate object's IUnknown interface (the controlling IUnknown).
|
||||
* @param dwClsContext Context in which the code that manages the newly created object will run. The values are taken from the enumeration CLSCTX defined in WTypes.
|
||||
* @param riid A reference to the identifier of the interface to be used to communicate with the object.
|
||||
* @param ppv Address of pointer variable that receives the interface pointer requested in riid. Upon successful return, *ppv contains the requested interface pointer. Upon failure, *ppv contains NULL.
|
||||
* @return an HRESULT
|
||||
*/
|
||||
HRESULT CoCreateInstance(
|
||||
GUID rclsid,
|
||||
Pointer pUnkOuter,
|
||||
int dwClsContext,
|
||||
GUID riid,
|
||||
PointerByReference ppv);
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.Guid.GUID;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Ole32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Ole32Util {
|
||||
|
||||
/**
|
||||
* Convert a string to a GUID.
|
||||
* @param guidString
|
||||
* String representation of a GUID, including { }.
|
||||
* @return
|
||||
* A GUID.
|
||||
*/
|
||||
public static GUID getGUIDFromString(String guidString) {
|
||||
GUID.ByReference lpiid = new GUID.ByReference();
|
||||
HRESULT hr = Ole32.INSTANCE.IIDFromString(guidString, lpiid);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new RuntimeException(hr.toString());
|
||||
}
|
||||
return lpiid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a GUID into a string.
|
||||
* @param guid
|
||||
* GUID.
|
||||
* @return
|
||||
* String representation of a GUID.
|
||||
*/
|
||||
public static String getStringFromGUID(GUID guid) {
|
||||
GUID.ByReference pguid = new GUID.ByReference(guid.getPointer());
|
||||
int max = 39;
|
||||
char[] lpsz = new char[max];
|
||||
int len = Ole32.INSTANCE.StringFromGUID2(pguid, lpsz, max);
|
||||
if (len == 0) {
|
||||
throw new RuntimeException("StringFromGUID2");
|
||||
}
|
||||
lpsz[len - 1] = 0;
|
||||
return Native.toString(lpsz);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new GUID.
|
||||
* @return
|
||||
* New GUID.
|
||||
*/
|
||||
public static GUID generateGUID() {
|
||||
GUID.ByReference pguid = new GUID.ByReference();
|
||||
HRESULT hr = Ole32.INSTANCE.CoCreateGuid(pguid);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new RuntimeException(hr.toString());
|
||||
}
|
||||
return pguid;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010 Digital Rapids Corp., All rights reserved.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Oleaut32.dll Interface.
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface Oleaut32 extends StdCallLibrary {
|
||||
|
||||
Oleaut32 INSTANCE = (Oleaut32) Native.loadLibrary(
|
||||
"Oleaut32", Oleaut32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* This function allocates a new string and copies the passed string into it.
|
||||
* @param sz
|
||||
* Null-terminated UNICODE string to copy.
|
||||
* @return
|
||||
* Null if there is insufficient memory or if a null pointer is passed in.
|
||||
*/
|
||||
Pointer SysAllocString(String sz);
|
||||
|
||||
/**
|
||||
* This function frees a string allocated previously by SysAllocString,
|
||||
* SysAllocStringByteLen, SysReAllocString, SysAllocStringLen, or
|
||||
* SysReAllocStringLen.
|
||||
* @param bstr
|
||||
* Unicode string that was allocated previously, or NULL. Setting this parameter
|
||||
* to NULL causes the function to simply return.
|
||||
*/
|
||||
void SysFreeString(Pointer bstr);
|
||||
}
|
||||
@@ -1,313 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.Sspi.CredHandle;
|
||||
import com.sun.jna.platform.win32.Sspi.CtxtHandle;
|
||||
import com.sun.jna.platform.win32.Sspi.PSecPkgInfo;
|
||||
import com.sun.jna.platform.win32.Sspi.SecBufferDesc;
|
||||
import com.sun.jna.platform.win32.Sspi.TimeStamp;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.LUID;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Secur32.dll Interface.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Secur32 extends StdCallLibrary {
|
||||
Secur32 INSTANCE = (Secur32) Native.loadLibrary("Secur32", Secur32.class, W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* Specifies a format for a directory service object name.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724268(VS.85).aspx
|
||||
*/
|
||||
public abstract class EXTENDED_NAME_FORMAT {
|
||||
public static final int NameUnknown = 0;
|
||||
public static final int NameFullyQualifiedDN = 1;
|
||||
public static final int NameSamCompatible = 2;
|
||||
public static final int NameDisplay = 3;
|
||||
public static final int NameUniqueId = 6;
|
||||
public static final int NameCanonical = 7;
|
||||
public static final int NameUserPrincipal = 8;
|
||||
public static final int NameCanonicalEx = 9;
|
||||
public static final int NameServicePrincipal = 10;
|
||||
public static final int NameDnsDomain = 12;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user or other security principal associated with
|
||||
* the calling thread. You can specify the format of the returned name.
|
||||
* @param nameFormat The format of the name.
|
||||
* @param lpNameBuffer A pointer to a buffer that receives the name in the specified format.
|
||||
* @param len On input, the size of the buffer, on output the number of characters copied into the buffer, not including the terminating null character.
|
||||
* @return True if the function succeeds. False otherwise.
|
||||
*/
|
||||
public boolean GetUserNameEx(int nameFormat, char[] lpNameBuffer, IntByReference len);
|
||||
|
||||
/**
|
||||
* The AcquireCredentialsHandle function acquires a handle to preexisting credentials
|
||||
* of a security principal. This handle is required by the AcceptSecurityContext
|
||||
* and InitializeSecurityContext functions. These can be either preexisting credentials,
|
||||
* which are established through a system logon that is not described here, or the
|
||||
* caller can provide alternative credentials.
|
||||
* @param pszPrincipal
|
||||
* A pointer to a null-terminated string that specifies the name of the principal whose
|
||||
* credentials the handle will reference.
|
||||
* @param pszPackage
|
||||
* A pointer to a null-terminated string that specifies the name of the security package
|
||||
* with which these credentials will be used.
|
||||
* @param fCredentialUse
|
||||
* A flag that indicates how these credentials will be used.
|
||||
* @param pvLogonID
|
||||
* A pointer to a locally unique identifier (LUID) that identifies the user.
|
||||
* @param pAuthData
|
||||
* A pointer to package-specific data. This parameter can be NULL, which indicates
|
||||
* that the default credentials for that package must be used. To use supplied
|
||||
* credentials, pass a SEC_WINNT_AUTH_IDENTITY structure that includes those credentials
|
||||
* in this parameter.
|
||||
* @param pGetKeyFn
|
||||
* This parameter is not used and should be set to NULL.
|
||||
* @param pvGetKeyArgument
|
||||
* This parameter is not used and should be set to NULL.
|
||||
* @param phCredential
|
||||
* A pointer to a CredHandle structure to receive the credential handle.
|
||||
* @param ptsExpiry
|
||||
* A pointer to a TimeStamp structure that receives the time at which the returned
|
||||
* credentials expire. The value returned in this TimeStamp structure depends on
|
||||
* the security package. The security package must return this value in local time.
|
||||
* @return
|
||||
* If the function succeeds, the function returns one of the SEC_I_ success codes.
|
||||
* If the function fails, the function returns one of the SEC_E_ error codes.
|
||||
*/
|
||||
public int AcquireCredentialsHandle(String pszPrincipal, String pszPackage,
|
||||
int fCredentialUse, LUID pvLogonID,
|
||||
Pointer pAuthData, Pointer pGetKeyFn, // TODO: SEC_GET_KEY_FN
|
||||
Pointer pvGetKeyArgument, CredHandle phCredential,
|
||||
TimeStamp ptsExpiry);
|
||||
|
||||
/**
|
||||
* The InitializeSecurityContext function initiates the client side, outbound security
|
||||
* context from a credential handle. The function is used to build a security context
|
||||
* between the client application and a remote peer. InitializeSecurityContext returns
|
||||
* a token that the client must pass to the remote peer, which the peer in turn submits
|
||||
* to the local security implementation through the AcceptSecurityContext call. The
|
||||
* token generated should be considered opaque by all callers.
|
||||
*
|
||||
* Typically, the InitializeSecurityContext function is called in a loop until a
|
||||
* sufficient security context is established.
|
||||
*
|
||||
* @param phCredential
|
||||
* A handle to the credentials returned by AcquireCredentialsHandle. This handle is
|
||||
* used to build the security context. The InitializeSecurityContext function requires
|
||||
* at least OUTBOUND credentials.
|
||||
* @param phContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to InitializeSecurityContext,
|
||||
* this pointer is NULL. On the second call, this parameter is a pointer to the handle
|
||||
* to the partially formed context returned in the phNewContext parameter by the first
|
||||
* call.
|
||||
* @param pszTargetName
|
||||
* A pointer to a null-terminated string that indicates the target of the context.
|
||||
* The string contents are security-package specific.
|
||||
* @param fContextReq
|
||||
* Bit flags that indicate requests for the context. Not all packages can support all
|
||||
* requirements. Flags used for this parameter are prefixed with ISC_REQ_, for example,
|
||||
* ISC_REQ_DELEGATE.
|
||||
* @param Reserved1
|
||||
* This parameter is reserved and must be set to zero.
|
||||
* @param TargetDataRep
|
||||
* The data representation, such as byte ordering, on the target. This parameter can be
|
||||
* either SECURITY_NATIVE_DREP or SECURITY_NETWORK_DREP.
|
||||
* @param pInput
|
||||
* A pointer to a SecBufferDesc structure that contains pointers to the buffers supplied
|
||||
* as input to the package. The pointer must be NULL on the first call to the function.
|
||||
* On subsequent calls to the function, it is a pointer to a buffer allocated with enough
|
||||
* memory to hold the token returned by the remote peer.
|
||||
* @param Reserved2
|
||||
* This parameter is reserved and must be set to zero.
|
||||
* @param phNewContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to InitializeSecurityContext,
|
||||
* this pointer receives the new context handle. On the second call, phNewContext can be
|
||||
* the same as the handle specified in the phContext parameter.
|
||||
* @param pOutput
|
||||
* A pointer to a SecBufferDesc structure that contains pointers to the SecBuffer structure
|
||||
* that receives the output data. If a buffer was typed as SEC_READWRITE in the input, it
|
||||
* will be there on output. The system will allocate a buffer for the security token if
|
||||
* requested (through ISC_REQ_ALLOCATE_MEMORY) and fill in the address in the buffer
|
||||
* descriptor for the security token.
|
||||
* @param pfContextAttr
|
||||
* A pointer to a variable to receive a set of bit flags that indicate the attributes of
|
||||
* the established context. Flags used for this parameter are prefixed with ISC_RET,
|
||||
* such as ISC_RET_DELEGATE.
|
||||
* @param ptsExpiry
|
||||
* A pointer to a TimeStamp structure that receives the expiration time of the context.
|
||||
* It is recommended that the security package always return this value in local time.
|
||||
* This parameter is optional and NULL should be passed for short-lived clients.
|
||||
* @return
|
||||
* If the function succeeds, the function returns one of the SEC_I_ success codes.
|
||||
* If the function fails, the function returns one of the SEC_E_ error codes.
|
||||
*/
|
||||
public int InitializeSecurityContext(CredHandle phCredential, CtxtHandle phContext,
|
||||
String pszTargetName, int fContextReq, int Reserved1,
|
||||
int TargetDataRep, SecBufferDesc pInput, int Reserved2,
|
||||
CtxtHandle phNewContext, SecBufferDesc pOutput, IntByReference pfContextAttr,
|
||||
TimeStamp ptsExpiry);
|
||||
|
||||
/**
|
||||
* The DeleteSecurityContext function deletes the local data structures associated
|
||||
* with the specified security context.
|
||||
* @param phContext
|
||||
* Handle of the security context to delete.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value is SEC_E_INVALID_HANDLE;
|
||||
*/
|
||||
public int DeleteSecurityContext(CtxtHandle phContext);
|
||||
|
||||
/**
|
||||
* The FreeCredentialsHandle function notifies the security system that the
|
||||
* credentials are no longer needed. An application calls this function to free
|
||||
* the credential handle acquired in the call to the AcquireCredentialsHandle
|
||||
* function. When all references to this credential set have been removed, the
|
||||
* credentials themselves can be removed.
|
||||
* @param phCredential
|
||||
* A pointer to the credential handle obtained by using the AcquireCredentialsHandle
|
||||
* function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value is SEC_E_INVALID_HANDLE;
|
||||
*/
|
||||
public int FreeCredentialsHandle(CredHandle phCredential);
|
||||
|
||||
/**
|
||||
* The AcceptSecurityContext function enables the server component of a transport
|
||||
* application to establish a security context between the server and a remote client.
|
||||
* The remote client uses the InitializeSecurityContext function to start the process
|
||||
* of establishing a security context. The server can require one or more reply tokens
|
||||
* from the remote client to complete establishing the security context.
|
||||
* @param phCredential
|
||||
* A handle to the credentials of the server. The server calls the AcquireCredentialsHandle
|
||||
* function with either the SECPKG_CRED_INBOUND or SECPKG_CRED_BOTH flag set to retrieve
|
||||
* this handle.
|
||||
* @param phContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to AcceptSecurityContext,
|
||||
* this pointer is NULL. On subsequent calls, phContext is the handle to the partially
|
||||
* formed context that was returned in the phNewContext parameter by the first call.
|
||||
* @param pInput
|
||||
* A pointer to a SecBufferDesc structure generated by a client call to
|
||||
* InitializeSecurityContext that contains the input buffer descriptor.
|
||||
* @param fContextReq
|
||||
* Bit flags that specify the attributes required by the server to establish the
|
||||
* context. Bit flags can be combined by using bitwise-OR operations.
|
||||
* @param TargetDataRep
|
||||
* The data representation, such as byte ordering, on the target. This parameter can
|
||||
* be either SECURITY_NATIVE_DREP or SECURITY_NETWORK_DREP.
|
||||
* @param phNewContext
|
||||
* A pointer to a CtxtHandle structure. On the first call to AcceptSecurityContext,
|
||||
* this pointer receives the new context handle. On subsequent calls, phNewContext
|
||||
* can be the same as the handle specified in the phContext parameter.
|
||||
* @param pOutput
|
||||
* A pointer to a SecBufferDesc structure that contains the output buffer descriptor.
|
||||
* This buffer is sent to the client for input into additional calls to
|
||||
* InitializeSecurityContext. An output buffer may be generated even if the function
|
||||
* returns SEC_E_OK. Any buffer generated must be sent back to the client application.
|
||||
* @param pfContextAttr
|
||||
* A pointer to a variable that receives a set of bit flags that indicate the
|
||||
* attributes of the established context. For a description of the various attributes,
|
||||
* see Context Requirements. Flags used for this parameter are prefixed with ASC_RET,
|
||||
* for example, ASC_RET_DELEGATE.
|
||||
* @param ptsTimeStamp
|
||||
* A pointer to a TimeStamp structure that receives the expiration time of the context.
|
||||
* @return
|
||||
* This function returns one of SEC_* values.
|
||||
*/
|
||||
public int AcceptSecurityContext(CredHandle phCredential, CtxtHandle phContext,
|
||||
SecBufferDesc pInput, int fContextReq, int TargetDataRep,
|
||||
CtxtHandle phNewContext, SecBufferDesc pOutput, IntByReference pfContextAttr,
|
||||
TimeStamp ptsTimeStamp);
|
||||
|
||||
/**
|
||||
* The EnumerateSecurityPackages function returns an array of SecPkgInfo structures that
|
||||
* describe the security packages available to the client.
|
||||
* @param pcPackages
|
||||
* A pointer to a int variable that receives the number of packages returned.
|
||||
* @param ppPackageInfo
|
||||
* A pointer to a variable that receives a pointer to an array of SecPkgInfo structures.
|
||||
* Each structure contains information from the security support provider (SSP) that
|
||||
* describes a security package that is available within that SSP.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code.
|
||||
*/
|
||||
public int EnumerateSecurityPackages(IntByReference pcPackages,
|
||||
PSecPkgInfo.ByReference ppPackageInfo);
|
||||
|
||||
/**
|
||||
* The FreeContextBuffer function enables callers of security package functions to free a memory
|
||||
* buffer that was allocated by the security package as a result of calls to InitializeSecurityContext
|
||||
* and AcceptSecurityContext.
|
||||
* @param buffer
|
||||
* A pointer to memory allocated by the security package.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code.
|
||||
*/
|
||||
public int FreeContextBuffer(Pointer buffer);
|
||||
|
||||
/**
|
||||
* The QuerySecurityContextToken function obtains the access token for a client security context
|
||||
* and uses it directly.
|
||||
* @param phContext
|
||||
* Handle of the context to query.
|
||||
* @param phToken
|
||||
* Returned handle to the access token.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a nonzero error code. One possible error code return is
|
||||
* SEC_E_INVALID_HANDLE.
|
||||
*/
|
||||
public int QuerySecurityContextToken(CtxtHandle phContext,
|
||||
HANDLEByReference phToken);
|
||||
|
||||
/**
|
||||
* The ImpersonateSecurityContext function allows a server to impersonate a client by using
|
||||
* a token previously obtained by a call to AcceptSecurityContext or QuerySecurityContextToken.
|
||||
* This function allows the application server to act as the client, and thus all necessary
|
||||
* access controls are enforced.
|
||||
* @param phContext
|
||||
* The handle of the context to impersonate. This handle must have been obtained by a call
|
||||
* to the AcceptSecurityContext function.
|
||||
* @return
|
||||
* If the function succeeds, the function returns SEC_E_OK.
|
||||
* If the function fails, it returns a SEC_E_INVALID_HANDLE, SEC_E_NO_IMPERSONATION or
|
||||
* SEC_E_UNSUPPORTED_FUNCTION error code.
|
||||
*/
|
||||
public int ImpersonateSecurityContext(CtxtHandle phContext);
|
||||
|
||||
/**
|
||||
* Allows a security package to discontinue the impersonation of the caller and restore its
|
||||
* own security context.
|
||||
* @param phContext
|
||||
* Handle of the security context being impersonated. This handle must have been obtained in
|
||||
* the call to the AcceptSecurityContext function and used in the call to the
|
||||
* ImpersonateSecurityContext function.
|
||||
* @return
|
||||
* If the function succeeds, the return value is SEC_E_OK.
|
||||
* If the function fails, the return value can be either SEC_E_INVALID_HANDLE or SEC_E_UNSUPPORTED_FUNCTION.
|
||||
*/
|
||||
public int RevertSecurityContext(CtxtHandle phContext);
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.Sspi.PSecPkgInfo;
|
||||
import com.sun.jna.platform.win32.Sspi.SecPkgInfo;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Secur32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Secur32Util {
|
||||
|
||||
/**
|
||||
* An SSPI package.
|
||||
*/
|
||||
public static class SecurityPackage {
|
||||
/**
|
||||
* Package name.
|
||||
*/
|
||||
public String name;
|
||||
/**
|
||||
* Package comment.
|
||||
*/
|
||||
public String comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the name of the user or other security principal associated
|
||||
* with the calling thread.
|
||||
*
|
||||
* @param format User name format.
|
||||
* @return User name in a given format.
|
||||
*/
|
||||
public static String getUserNameEx(int format) {
|
||||
char[] buffer = new char[128];
|
||||
IntByReference len = new IntByReference(buffer.length);
|
||||
boolean result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
|
||||
|
||||
if (! result) {
|
||||
|
||||
int rc = Kernel32.INSTANCE.GetLastError();
|
||||
|
||||
switch(rc) {
|
||||
case W32Errors.ERROR_MORE_DATA:
|
||||
buffer = new char[len.getValue() + 1];
|
||||
break;
|
||||
default:
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
result = Secur32.INSTANCE.GetUserNameEx(format, buffer, len);
|
||||
}
|
||||
|
||||
if (! result) {
|
||||
throw new Win32Exception(Native.getLastError());
|
||||
}
|
||||
|
||||
return Native.toString(buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the security packages installed on the current computer.
|
||||
* @return
|
||||
* An array of SSPI security packages.
|
||||
*/
|
||||
public static SecurityPackage[] getSecurityPackages() {
|
||||
IntByReference pcPackages = new IntByReference();
|
||||
PSecPkgInfo.ByReference pPackageInfo = new PSecPkgInfo.ByReference();
|
||||
int rc = Secur32.INSTANCE.EnumerateSecurityPackages(pcPackages, pPackageInfo);
|
||||
if(W32Errors.SEC_E_OK != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
SecPkgInfo[] packagesInfo = pPackageInfo.toArray(pcPackages.getValue());
|
||||
ArrayList<SecurityPackage> packages = new ArrayList<SecurityPackage>(pcPackages.getValue());
|
||||
for(SecPkgInfo packageInfo : packagesInfo) {
|
||||
SecurityPackage securityPackage = new SecurityPackage();
|
||||
securityPackage.name = packageInfo.Name.toString();
|
||||
securityPackage.comment = packageInfo.Comment.toString();
|
||||
packages.add(securityPackage);
|
||||
}
|
||||
rc = Secur32.INSTANCE.FreeContextBuffer(pPackageInfo.pPkgInfo.getPointer());
|
||||
if(W32Errors.SEC_E_OK != rc) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
return packages.toArray(new SecurityPackage[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,345 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* The interface for the w32 setup API.
|
||||
*/
|
||||
public interface SetupApi extends StdCallLibrary {
|
||||
|
||||
SetupApi INSTANCE = (SetupApi)
|
||||
Native.loadLibrary("setupapi", SetupApi.class, W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
/**
|
||||
* The GUID_DEVINTERFACE_DISK device interface class is defined for hard disk storage devices.
|
||||
*/
|
||||
public static Guid.GUID GUID_DEVINTERFACE_DISK = new Guid.GUID(new byte[]
|
||||
{
|
||||
0x07, 0x63, (byte) 0xf5, 0x53, (byte) 0xbf, (byte) 0xb6, (byte) 0xd0, 0x11,
|
||||
(byte) 0x94, (byte) 0xf2, 0x00, (byte) 0xa0, (byte) 0xc9, (byte) 0x1e, (byte) 0xfb, (byte) 0x8b
|
||||
});
|
||||
|
||||
/**
|
||||
* Return only the device that is associated with the system default device interface, if one is set, for the
|
||||
* specified device interface classes.
|
||||
*/
|
||||
public int DIGCF_DEFAULT = 0x1;
|
||||
|
||||
/**
|
||||
* Return only devices that are currently present in a system.
|
||||
*/
|
||||
public int DIGCF_PRESENT = 0x2;
|
||||
|
||||
/**
|
||||
* Return a list of installed devices for all device setup classes or all device interface classes.
|
||||
*/
|
||||
public int DIGCF_ALLCLASSES = 0x4;
|
||||
|
||||
/**
|
||||
* Return only devices that are a part of the current hardware profile.
|
||||
*/
|
||||
public int DIGCF_PROFILE = 0x8;
|
||||
|
||||
/**
|
||||
* Return devices that support device interfaces for the specified device interface classes. This flag must be set
|
||||
* in the Flags parameter if the Enumerator parameter specifies a device instance ID.
|
||||
*/
|
||||
public int DIGCF_DEVICEINTERFACE = 0x10;
|
||||
|
||||
/**
|
||||
* (Windows XP and later) The function retrieves the device's current removal policy as a DWORD that contains one of
|
||||
* the CM_REMOVAL_POLICY_Xxx values that are defined in Cfgmgr32.h.
|
||||
*/
|
||||
public int SPDRP_REMOVAL_POLICY = 0x0000001F;
|
||||
|
||||
/**
|
||||
* Removable.
|
||||
*/
|
||||
public int CM_DEVCAP_REMOVABLE = 0x00000004;
|
||||
|
||||
/**
|
||||
* The SetupDiGetClassDevs function returns a handle to a device information set that contains requested device
|
||||
* information elements for a local computer.
|
||||
*
|
||||
* @param classGuid
|
||||
* A pointer to the GUID for a device setup class or a device interface class. This pointer is optional and can be
|
||||
* NULL. For more information about how to set ClassGuid, see the following Remarks section.
|
||||
*
|
||||
* @param enumerator
|
||||
* A pointer to a NULL-terminated string that specifies:
|
||||
*
|
||||
* An identifier (ID) of a Plug and Play (PnP) enumerator. This ID can either be the value's globally unique
|
||||
* identifier (GUID) or symbolic name. For example, "PCI" can be used to specify the PCI PnP value. Other examples
|
||||
* of symbolic names for PnP values include "USB," "PCMCIA," and "SCSI".
|
||||
*
|
||||
* A PnP device instance ID. When specifying a PnP device instance ID, DIGCF_DEVICEINTERFACE must be set in the
|
||||
* Flags parameter.
|
||||
*
|
||||
* This pointer is optional and can be NULL. If an enumeration value is not used to select devices, set Enumerator
|
||||
* to NULL.
|
||||
*
|
||||
* @param hwndParent
|
||||
* A handle to the top-level window to be used for a user interface that is associated with installing a device
|
||||
* instance in the device information set. This handle is optional and can be NULL.
|
||||
*
|
||||
* @param flags
|
||||
* A variable of type DWORD that specifies control options that filter the device information elements that are
|
||||
* added to the device information set.
|
||||
*
|
||||
* @return
|
||||
* If the operation succeeds, SetupDiGetClassDevs returns a handle to a device information set that contains all
|
||||
* installed devices that matched the supplied parameters. If the operation fails, the function returns
|
||||
* INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
|
||||
*/
|
||||
WinNT.HANDLE SetupDiGetClassDevs(Guid.GUID.ByReference classGuid, Pointer enumerator, Pointer hwndParent, int flags);
|
||||
|
||||
/**
|
||||
* The SetupDiDestroyDeviceInfoList function deletes a device information set and frees all associated memory.
|
||||
*
|
||||
* @param hDevInfo A handle to the device information set to delete.
|
||||
* @return The function returns TRUE if it is successful. Otherwise, it returns FALSE and the logged error can be
|
||||
* retrieved with a call to GetLastError.
|
||||
*/
|
||||
boolean SetupDiDestroyDeviceInfoList(WinNT.HANDLE hDevInfo);
|
||||
|
||||
/**
|
||||
* The SetupDiEnumDeviceInterfaces function enumerates the device interfaces that are contained in a device
|
||||
* information set.
|
||||
*
|
||||
* @param hDevInfo
|
||||
* A pointer to a device information set that contains the device interfaces for which to return information. This
|
||||
* handle is typically returned by SetupDiGetClassDevs.
|
||||
*
|
||||
* @param devInfo
|
||||
* A pointer to an SP_DEVINFO_DATA structure that specifies a device information element in DeviceInfoSet. This
|
||||
* parameter is optional and can be NULL. If this parameter is specified, SetupDiEnumDeviceInterfaces constrains
|
||||
* the enumeration to the interfaces that are supported by the specified device. If this parameter is NULL,
|
||||
* repeated calls to SetupDiEnumDeviceInterfaces return information about the interfaces that are associated with
|
||||
* all the device information elements in DeviceInfoSet. This pointer is typically returned by
|
||||
* SetupDiEnumDeviceInfo.
|
||||
*
|
||||
* @param interfaceClassGuid
|
||||
* A pointer to a GUID that specifies the device interface class for the requested interface.
|
||||
*
|
||||
* @param memberIndex
|
||||
* A zero-based index into the list of interfaces in the device information set. The caller should call this
|
||||
* function first with MemberIndex set to zero to obtain the first interface. Then, repeatedly increment
|
||||
* MemberIndex and retrieve an interface until this function fails and GetLastError returns ERROR_NO_MORE_ITEMS.
|
||||
*
|
||||
* If DeviceInfoData specifies a particular device, the MemberIndex is relative to only the interfaces exposed by
|
||||
* that device.
|
||||
*
|
||||
* @param deviceInterfaceData
|
||||
* A pointer to a caller-allocated buffer that contains, on successful return, a completed
|
||||
* SP_DEVICE_INTERFACE_DATA structure that identifies an interface that meets the search parameters. The caller
|
||||
* must set DeviceInterfaceData.cbSize to sizeof(SP_DEVICE_INTERFACE_DATA) before calling this function.
|
||||
*
|
||||
* @return
|
||||
* SetupDiEnumDeviceInterfaces returns TRUE if the function completed without error. If the function completed
|
||||
* with an error, FALSE is returned and the error code for the failure can be retrieved by calling GetLastError.
|
||||
*/
|
||||
boolean SetupDiEnumDeviceInterfaces(WinNT.HANDLE hDevInfo, Pointer devInfo,
|
||||
Guid.GUID.ByReference interfaceClassGuid, int memberIndex,
|
||||
SP_DEVICE_INTERFACE_DATA.ByReference deviceInterfaceData);
|
||||
|
||||
/**
|
||||
* The SetupDiGetDeviceInterfaceDetail function returns details about a device interface.
|
||||
*
|
||||
* @param hDevInfo
|
||||
* A pointer to the device information set that contains the interface for which to retrieve details. This handle
|
||||
* is typically returned by SetupDiGetClassDevs.
|
||||
*
|
||||
* @param deviceInterfaceData
|
||||
* A pointer to an SP_DEVICE_INTERFACE_DATA structure that specifies the interface in DeviceInfoSet for which to
|
||||
* retrieve details. A pointer of this type is typically returned by SetupDiEnumDeviceInterfaces.
|
||||
*
|
||||
* @param deviceInterfaceDetailData
|
||||
* A pointer to an SP_DEVICE_INTERFACE_DETAIL_DATA structure to receive information about the specified interface.
|
||||
* This parameter is optional and can be NULL. This parameter must be NULL if DeviceInterfaceDetailSize is zero.
|
||||
* If this parameter is specified, the caller must set DeviceInterfaceDetailData.cbSize to
|
||||
* sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA) before calling this function. The cbSize member always contains the
|
||||
* size of the fixed part of the data structure, not a size reflecting the variable-length string at the end.
|
||||
*
|
||||
* @param deviceInterfaceDetailDataSize
|
||||
* The size of the DeviceInterfaceDetailData buffer. The buffer must be at least
|
||||
* (offsetof(SP_DEVICE_INTERFACE_DETAIL_DATA, DevicePath) + sizeof(TCHAR)) bytes, to contain the fixed part of the
|
||||
* structure and a single NULL to terminate an empty MULTI_SZ string.
|
||||
*
|
||||
* This parameter must be zero if DeviceInterfaceDetailData is NULL.
|
||||
*
|
||||
* @param requiredSize
|
||||
* A pointer to a variable of type DWORD that receives the required size of the DeviceInterfaceDetailData buffer.
|
||||
* This size includes the size of the fixed part of the structure plus the number of bytes required for the
|
||||
* variable-length device path string. This parameter is optional and can be NULL.
|
||||
*
|
||||
* @param deviceInfoData
|
||||
* A pointer to a buffer that receives information about the device that supports the requested interface. The
|
||||
* caller must set DeviceInfoData.cbSize to sizeof(SP_DEVINFO_DATA). This parameter is optional and can be NULL.
|
||||
*
|
||||
* @return
|
||||
* SetupDiGetDeviceInterfaceDetail returns TRUE if the function completed without error. If the function completed
|
||||
* with an error, FALSE is returned and the error code for the failure can be retrieved by calling GetLastError.
|
||||
*/
|
||||
boolean SetupDiGetDeviceInterfaceDetail(WinNT.HANDLE hDevInfo,
|
||||
SP_DEVICE_INTERFACE_DATA.ByReference deviceInterfaceData, Pointer deviceInterfaceDetailData,
|
||||
int deviceInterfaceDetailDataSize, IntByReference requiredSize, SP_DEVINFO_DATA.ByReference deviceInfoData);
|
||||
|
||||
/**
|
||||
* The SetupDiGetDeviceRegistryProperty function retrieves a specified Plug and Play device property.
|
||||
*
|
||||
* @param DeviceInfoSet
|
||||
* A handle to a device information set that contains a device information element that represents the device for
|
||||
* which to retrieve a Plug and Play property.
|
||||
*
|
||||
* @param DeviceInfoData
|
||||
* A pointer to an SP_DEVINFO_DATA structure that specifies the device information element in DeviceInfoSet.
|
||||
*
|
||||
* @param Property
|
||||
* Specifies the property to be retrieved.
|
||||
*
|
||||
* @param PropertyRegDataType
|
||||
* A pointer to a variable that receives the data type of the property that is being retrieved. This is one of the
|
||||
* standard registry data types. This parameter is optional and can be NULL.
|
||||
*
|
||||
* @param PropertyBuffer
|
||||
* A pointer to a buffer that receives the property that is being retrieved. If this parameter is set to NULL, and
|
||||
* PropertyBufferSize is also set to zero, the function returns the required size for the buffer in RequiredSize.
|
||||
*
|
||||
* @param PropertyBufferSize
|
||||
* The size, in bytes, of the PropertyBuffer buffer.
|
||||
*
|
||||
* @param RequiredSize
|
||||
* A pointer to a variable of type DWORD that receives the required size, in bytes, of the PropertyBuffer buffer
|
||||
* that is required to hold the data for the requested property. This parameter is optional and can be NULL.
|
||||
*
|
||||
* @return
|
||||
* SetupDiGetDeviceRegistryProperty returns TRUE if the call was successful. Otherwise, it returns FALSE and the
|
||||
* logged error can be retrieved by making a call to GetLastError. SetupDiGetDeviceRegistryProperty returns the
|
||||
* ERROR_INVALID_DATA error code if the requested property does not exist for a device or if the property data is
|
||||
* not valid.
|
||||
*/
|
||||
boolean SetupDiGetDeviceRegistryProperty(WinNT.HANDLE DeviceInfoSet, SP_DEVINFO_DATA.ByReference DeviceInfoData,
|
||||
int Property, IntByReference PropertyRegDataType, Pointer PropertyBuffer, int PropertyBufferSize,
|
||||
IntByReference RequiredSize);
|
||||
|
||||
/**
|
||||
* An SP_DEVICE_INTERFACE_DATA structure defines a device interface in a device information set.
|
||||
*/
|
||||
public static class SP_DEVICE_INTERFACE_DATA extends Structure {
|
||||
|
||||
public static class ByReference extends SP_DEVINFO_DATA implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public SP_DEVICE_INTERFACE_DATA() {
|
||||
cbSize = size();
|
||||
}
|
||||
|
||||
public SP_DEVICE_INTERFACE_DATA(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The size, in bytes, of the SP_DEVICE_INTERFACE_DATA structure.
|
||||
*/
|
||||
public int cbSize;
|
||||
|
||||
/**
|
||||
* The GUID for the class to which the device interface belongs.
|
||||
*/
|
||||
public Guid.GUID InterfaceClassGuid;
|
||||
|
||||
/**
|
||||
* Can be one or more of the following:
|
||||
* SPINT_ACTIVE - The interface is active (enabled).
|
||||
* SPINT_DEFAULT - The interface is the default interface for the device class.
|
||||
* SPINT_REMOVED - The interface is removed.
|
||||
*/
|
||||
public int Flags;
|
||||
|
||||
/**
|
||||
* Reserved. Do not use.
|
||||
*/
|
||||
public Pointer Reserved;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "InterfaceClassGuid", "Flags", "Reserved" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An SP_DEVINFO_DATA structure defines a device instance that is a member of a device information set.
|
||||
*/
|
||||
public static class SP_DEVINFO_DATA extends Structure {
|
||||
|
||||
public static class ByReference extends SP_DEVINFO_DATA implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public SP_DEVINFO_DATA() {
|
||||
cbSize = size();
|
||||
}
|
||||
|
||||
public SP_DEVINFO_DATA(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The size, in bytes, of the SP_DEVINFO_DATA structure.
|
||||
*/
|
||||
public int cbSize;
|
||||
|
||||
/**
|
||||
* The GUID of the device's setup class.
|
||||
*/
|
||||
public Guid.GUID InterfaceClassGuid;
|
||||
|
||||
/**
|
||||
* An opaque handle to the device instance (also known as a handle to the devnode).
|
||||
*
|
||||
* Some functions, such as SetupDiXxx functions, take the whole SP_DEVINFO_DATA structure as input to identify a
|
||||
* device in a device information set. Other functions, such as CM_Xxx functions like CM_Get_DevNode_Status,
|
||||
* take this DevInst handle as input.
|
||||
*/
|
||||
public int DevInst;
|
||||
|
||||
/**
|
||||
* Reserved. For internal use only.
|
||||
*/
|
||||
public Pointer Reserved;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "InterfaceClassGuid", "DevInst", "Reserved" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinDef.INT_PTR;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Shell32.dll Interface.
|
||||
*/
|
||||
public interface Shell32 extends ShellAPI, StdCallLibrary {
|
||||
|
||||
Shell32 INSTANCE = (Shell32) Native.loadLibrary("shell32", Shell32.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* This function can be used to copy, move, rename, or delete a file system object.
|
||||
* @param fileop
|
||||
* Address of an SHFILEOPSTRUCT structure that contains information this function
|
||||
* needs to carry out the specified operation.
|
||||
* @return
|
||||
* Returns zero if successful, or nonzero otherwise.
|
||||
*/
|
||||
int SHFileOperation(SHFILEOPSTRUCT fileop);
|
||||
|
||||
/**
|
||||
* Takes the CSIDL of a folder and returns the path.
|
||||
* @param hwndOwner
|
||||
* Handle to an owner window. This parameter is typically set to NULL. If it is not NULL,
|
||||
* and a dial-up connection needs to be made to access the folder, a user interface (UI)
|
||||
* prompt will appear in this window.
|
||||
* @param nFolder
|
||||
* A CSIDL value that identifies the folder whose path is to be retrieved. Only real
|
||||
* folders are valid. If a virtual folder is specified, this function will fail. You can
|
||||
* force creation of a folder with SHGetFolderPath by combining the folder's CSIDL with
|
||||
* CSIDL_FLAG_CREATE.
|
||||
* @param hToken
|
||||
* An access token that can be used to represent a particular user.
|
||||
* @param dwFlags
|
||||
* Flags to specify which path is to be returned.
|
||||
* @param pszPath
|
||||
* Pointer to a null-terminated string of length MAX_PATH which will receive the path.
|
||||
* If an error occurs or S_FALSE is returned, this string will be empty.
|
||||
* @return
|
||||
* Returns standard HRESULT codes.
|
||||
*/
|
||||
HRESULT SHGetFolderPath(HWND hwndOwner, int nFolder, HANDLE hToken, DWORD dwFlags,
|
||||
char[] pszPath);
|
||||
|
||||
/**
|
||||
* Retrieves the IShellFolder interface for the desktop folder, which is the root of the Shell's namespace.
|
||||
* The retrieved COM interface pointer can be used via Com4JNA's ComObject.wrapNativeInterface call
|
||||
* given a suitable interface definition for IShellFolder
|
||||
* @param ppshf A place to put the IShellFolder interface pointer
|
||||
* @return If the function succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
|
||||
*/
|
||||
HRESULT SHGetDesktopFolder( PointerByReference ppshf );
|
||||
|
||||
/**
|
||||
* Performs an operation on a specified file.
|
||||
*
|
||||
* @param hwnd
|
||||
* A handle to the owner window used for displaying a UI or error messages. This value can be NULL if the
|
||||
* operation is not associated with a window.
|
||||
*
|
||||
* @param lpOperation
|
||||
* A pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be
|
||||
* performed. The set of available verbs depends on the particular file or folder. Generally, the actions
|
||||
* available from an object's shortcut menu are available verbs. The following verbs are commonly used:
|
||||
*
|
||||
* edit
|
||||
* Launches an editor and opens the document for editing. If lpFile is not a document file, the function will
|
||||
* fail.
|
||||
* explore
|
||||
* Explores a folder specified by lpFile.
|
||||
* find
|
||||
* Initiates a search beginning in the directory specified by lpDirectory.
|
||||
* open
|
||||
* Opens the item specified by the lpFile parameter. The item can be a file or folder.
|
||||
* print
|
||||
* Prints the file specified by lpFile. If lpFile is not a document file, the function fails.
|
||||
* NULL
|
||||
* In systems prior to Windows 2000, the default verb is used if it is valid and available in the registry. If
|
||||
* not, the "open" verb is used.
|
||||
* In Windows 2000 and later, the default verb is used if available. If not, the "open" verb is used. If neither
|
||||
* verb is available, the system uses the first verb listed in the registry.
|
||||
*
|
||||
* @param lpFile
|
||||
* A pointer to a null-terminated string that specifies the file or object on which to execute the specified verb.
|
||||
* To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported
|
||||
* on all objects. For example, not all document types support the "print" verb. If a relative path is used for
|
||||
* the lpDirectory parameter do not use a relative path for lpFile.
|
||||
*
|
||||
* @param lpParameters
|
||||
* If lpFile specifies an executable file, this parameter is a pointer to a null-terminated string that specifies
|
||||
* the parameters to be passed to the application. The format of this string is determined by the verb that is to
|
||||
* be invoked. If lpFile specifies a document file, lpParameters should be NULL.
|
||||
*
|
||||
* @param lpDirectory
|
||||
* A pointer to a null-terminated string that specifies the default (working) directory for the action. If this
|
||||
* value is NULL, the current working directory is used. If a relative path is provided at lpFile, do not use a
|
||||
* relative path for lpDirectory.
|
||||
*
|
||||
* @param nShowCmd
|
||||
* The flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document
|
||||
* file, the flag is simply passed to the associated application. It is up to the application to decide how to
|
||||
* handle it.
|
||||
*
|
||||
* @return
|
||||
* If the function succeeds, it returns a value greater than 32. If the function fails, it returns an error value
|
||||
* that indicates the cause of the failure. The return value is cast as an HINSTANCE for backward compatibility
|
||||
* with 16-bit Windows applications. It is not a true HINSTANCE, however. It can be cast only to an int and
|
||||
* compared to either 32 or the following error codes below.
|
||||
* <p/>
|
||||
* NOTE: {@link WinDef.INT_PTR} is used instead of HINSTANCE here, since
|
||||
* the former fits the reutrn type's actual usage more closely.
|
||||
*
|
||||
* 0 The operating system is out of memory or resources.
|
||||
* ERROR_FILE_NOT_FOUND The specified file was not found.
|
||||
* ERROR_PATH_NOT_FOUND The specified path was not found.
|
||||
* ERROR_BAD_FORMAT The .exe file is invalid (non-Win32 .exe or error in .exe image).
|
||||
* SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
|
||||
* SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
|
||||
* SE_ERR_DDEBUSY The DDE transaction could not be completed because other DDE transactions were being processed.
|
||||
* SE_ERR_DDEFAIL The DDE transaction failed.
|
||||
* SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
|
||||
* SE_ERR_DLLNOTFOUND The specified DLL was not found.
|
||||
* SE_ERR_FNF The specified file was not found.
|
||||
* SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be
|
||||
* returned if you attempt to print a file that is not printable.
|
||||
* SE_ERR_OOM There was not enough memory to complete the operation.
|
||||
* SE_ERR_PNF The specified path was not found.
|
||||
* SE_ERR_SHARE A sharing violation occurred.
|
||||
*/
|
||||
INT_PTR ShellExecute(HWND hwnd, String lpOperation, String lpFile, String lpParameters, String lpDirectory,
|
||||
int nShowCmd);
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Shell32 Utility API.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class Shell32Util {
|
||||
|
||||
/**
|
||||
* Get a special folder path.
|
||||
* @param hwnd
|
||||
* Parent window.
|
||||
* @param nFolder
|
||||
* Folder CSLID.
|
||||
* @param dwFlags
|
||||
* Flags.
|
||||
* @return
|
||||
* Special folder.
|
||||
*/
|
||||
public static String getFolderPath(HWND hwnd, int nFolder, DWORD dwFlags) {
|
||||
char[] pszPath = new char[WinDef.MAX_PATH];
|
||||
HRESULT hr = Shell32.INSTANCE.SHGetFolderPath(hwnd,
|
||||
nFolder, null, dwFlags,
|
||||
pszPath);
|
||||
if (! hr.equals(W32Errors.S_OK)) {
|
||||
throw new Win32Exception(hr);
|
||||
}
|
||||
return Native.toString(pszPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a special folder path.
|
||||
* @param nFolder
|
||||
* Folder CSLID.
|
||||
* @return
|
||||
* Special folder path.
|
||||
*/
|
||||
public static String getFolderPath(int nFolder) {
|
||||
return getFolderPath(null, nFolder, ShlObj.SHGFP_TYPE_CURRENT);
|
||||
}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from ShellAPI.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface ShellAPI extends StdCallLibrary {
|
||||
|
||||
int STRUCTURE_ALIGNMENT = Platform.is64Bit() ? Structure.ALIGN_DEFAULT : Structure.ALIGN_NONE;
|
||||
|
||||
int FO_MOVE = 0x0001;
|
||||
int FO_COPY = 0x0002;
|
||||
int FO_DELETE = 0x0003;
|
||||
int FO_RENAME = 0x0004;
|
||||
|
||||
int FOF_MULTIDESTFILES = 0x0001;
|
||||
int FOF_CONFIRMMOUSE = 0x0002;
|
||||
int FOF_SILENT = 0x0004; // don't display progress UI (confirm prompts may be displayed still)
|
||||
int FOF_RENAMEONCOLLISION = 0x0008; // automatically rename the source files to avoid the collisions
|
||||
int FOF_NOCONFIRMATION = 0x0010; // don't display confirmation UI, assume "yes" for cases that can be bypassed, "no" for those that can not
|
||||
int FOF_WANTMAPPINGHANDLE = 0x0020; // Fill in SHFILEOPSTRUCT.hNameMappings
|
||||
int FOF_ALLOWUNDO = 0x0040; // enable undo including Recycle behavior for IFileOperation::Delete()
|
||||
int FOF_FILESONLY = 0x0080; // only operate on the files (non folders), both files and folders are assumed without this
|
||||
int FOF_SIMPLEPROGRESS = 0x0100; // means don't show names of files
|
||||
int FOF_NOCONFIRMMKDIR = 0x0200; // don't dispplay confirmatino UI before making any needed directories, assume "Yes" in these cases
|
||||
int FOF_NOERRORUI = 0x0400; // don't put up error UI, other UI may be displayed, progress, confirmations
|
||||
int FOF_NOCOPYSECURITYATTRIBS = 0x0800; // dont copy file security attributes (ACLs)
|
||||
int FOF_NORECURSION = 0x1000; // don't recurse into directories for operations that would recurse
|
||||
int FOF_NO_CONNECTED_ELEMENTS = 0x2000; // don't operate on connected elements ("xxx_files" folders that go with .htm files)
|
||||
int FOF_WANTNUKEWARNING = 0x4000; // during delete operation, warn if nuking instead of recycling (partially overrides FOF_NOCONFIRMATION)
|
||||
int FOF_NORECURSEREPARSE = 0x8000; // deprecated; the operations engine always does the right thing on FolderLink objects (symlinks, reparse points, folder shortcuts)
|
||||
int FOF_NO_UI = (FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_NOCONFIRMMKDIR); // don't display any UI at all
|
||||
|
||||
int PO_DELETE = 0x0013; // printer is being deleted
|
||||
int PO_RENAME = 0x0014; // printer is being renamed
|
||||
int PO_PORTCHANGE = 0x0020; // port this printer connected to is being changed
|
||||
int PO_REN_PORT = 0x0034; // PO_RENAME and PO_PORTCHANGE at same time.
|
||||
|
||||
/**
|
||||
* Contains information that the SHFileOperation function uses to perform file operations.
|
||||
*/
|
||||
public static class SHFILEOPSTRUCT extends Structure {
|
||||
/**
|
||||
* A window handle to the dialog box to display information about
|
||||
* the status of the file operation.
|
||||
*/
|
||||
public HANDLE hwnd;
|
||||
/**
|
||||
* An FO_* value that indicates which operation to perform.
|
||||
*/
|
||||
public int wFunc;
|
||||
/**
|
||||
* A pointer to one or more source file names, double null-terminated.
|
||||
*/
|
||||
public WString pFrom;
|
||||
/**
|
||||
* A pointer to the destination file or directory name.
|
||||
*/
|
||||
public WString pTo;
|
||||
/**
|
||||
* Flags that control the file operation.
|
||||
*/
|
||||
public short fFlags;
|
||||
/**
|
||||
* When the function returns, this member contains TRUE if any file operations
|
||||
* were aborted before they were completed; otherwise, FALSE. An operation can
|
||||
* be manually aborted by the user through UI or it can be silently aborted by
|
||||
* the system if the FOF_NOERRORUI or FOF_NOCONFIRMATION flags were set.
|
||||
*/
|
||||
public boolean fAnyOperationsAborted;
|
||||
/**
|
||||
* When the function returns, this member contains a handle to a name mapping
|
||||
* object that contains the old and new names of the renamed files. This member
|
||||
* is used only if the fFlags member includes the FOF_WANTMAPPINGHANDLE flag.
|
||||
*/
|
||||
public Pointer pNameMappings;
|
||||
/**
|
||||
* A pointer to the title of a progress dialog box. This is a null-terminated string.
|
||||
*/
|
||||
public WString lpszProgressTitle;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "hwnd", "wFunc", "pFrom", "pTo", "fFlags", "fAnyOperationsAborted", "pNameMappings", "lpszProgressTitle" });
|
||||
}
|
||||
|
||||
/** Use this to encode <code>pFrom/pTo</code> paths. */
|
||||
public String encodePaths(String[] paths) {
|
||||
String encoded = "";
|
||||
for (int i=0; i < paths.length;i++) {
|
||||
encoded += paths[i];
|
||||
encoded += "\0";
|
||||
}
|
||||
return encoded + "\0";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
|
||||
/**
|
||||
* Ported from ShlObj.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface ShlObj {
|
||||
|
||||
DWORD SHGFP_TYPE_CURRENT = new DWORD(0); // current value for user, verify it exists
|
||||
DWORD SHGFP_TYPE_DEFAULT = new DWORD(1); // default value, may not exist
|
||||
|
||||
int CSIDL_DESKTOP = 0x0000; // <desktop>
|
||||
int CSIDL_INTERNET = 0x0001; // Internet Explorer (icon on desktop)
|
||||
int CSIDL_PROGRAMS = 0x0002; // Start Menu\Programs
|
||||
int CSIDL_CONTROLS = 0x0003; // My Computer\Control Panel
|
||||
int CSIDL_PRINTERS = 0x0004; // My Computer\Printers
|
||||
int CSIDL_PERSONAL = 0x0005; // My Documents
|
||||
int CSIDL_FAVORITES = 0x0006; // <user name>\Favorites
|
||||
int CSIDL_STARTUP = 0x0007; // Start Menu\Programs\Startup
|
||||
int CSIDL_RECENT = 0x0008; // <user name>\Recent
|
||||
int CSIDL_SENDTO = 0x0009; // <user name>\SendTo
|
||||
int CSIDL_BITBUCKET = 0x000a; // <desktop>\Recycle Bin
|
||||
int CSIDL_STARTMENU = 0x000b; // <user name>\Start Menu
|
||||
int CSIDL_MYDOCUMENTS = CSIDL_PERSONAL; // Personal was just a silly name for My Documents
|
||||
int CSIDL_MYMUSIC = 0x000d; // "My Music" folder
|
||||
int CSIDL_MYVIDEO = 0x000e; // "My Videos" folder
|
||||
int CSIDL_DESKTOPDIRECTORY = 0x0010; // <user name>\Desktop
|
||||
int CSIDL_DRIVES = 0x0011; // My Computer
|
||||
int CSIDL_NETWORK = 0x0012; // Network Neighborhood (My Network Places)
|
||||
int CSIDL_NETHOOD = 0x0013; // <user name>\nethood
|
||||
int CSIDL_FONTS = 0x0014; // windows\fonts
|
||||
int CSIDL_TEMPLATES = 0x0015;
|
||||
int CSIDL_COMMON_STARTMENU = 0x0016; // All Users\Start Menu
|
||||
int CSIDL_COMMON_PROGRAMS = 0X0017; // All Users\Start Menu\Programs
|
||||
int CSIDL_COMMON_STARTUP = 0x0018; // All Users\Startup
|
||||
int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019; // All Users\Desktop
|
||||
int CSIDL_APPDATA = 0x001a; // <user name>\Application Data
|
||||
int CSIDL_PRINTHOOD = 0x001b; // <user name>\PrintHood
|
||||
int CSIDL_LOCAL_APPDATA = 0x001c; // <user name>\Local Settings\Applicaiton Data (non roaming)
|
||||
int CSIDL_ALTSTARTUP = 0x001d; // non localized startup
|
||||
int CSIDL_COMMON_ALTSTARTUP = 0x001e; // non localized common startup
|
||||
int CSIDL_COMMON_FAVORITES = 0x001f;
|
||||
int CSIDL_INTERNET_CACHE = 0x0020;
|
||||
int CSIDL_COOKIES = 0x0021;
|
||||
int CSIDL_HISTORY = 0x0022;
|
||||
int CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data
|
||||
int CSIDL_WINDOWS = 0x0024; // GetWindowsDirectory()
|
||||
int CSIDL_SYSTEM = 0x0025; // GetSystemDirectory()
|
||||
int CSIDL_PROGRAM_FILES = 0x0026; // C:\Program Files
|
||||
int CSIDL_MYPICTURES = 0x0027; // C:\Program Files\My Pictures
|
||||
int CSIDL_PROFILE = 0x0028; // USERPROFILE
|
||||
int CSIDL_SYSTEMX86 = 0x0029; // x86 system directory on RISC
|
||||
int CSIDL_PROGRAM_FILESX86 = 0x002a; // x86 C:\Program Files on RISC
|
||||
int CSIDL_PROGRAM_FILES_COMMON = 0x002b; // C:\Program Files\Common
|
||||
int CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c; // x86 Program Files\Common on RISC
|
||||
int CSIDL_COMMON_TEMPLATES = 0x002d; // All Users\Templates
|
||||
int CSIDL_COMMON_DOCUMENTS = 0x002e; // All Users\Documents
|
||||
int CSIDL_COMMON_ADMINTOOLS = 0x002f; // All Users\Start Menu\Programs\Administrative Tools
|
||||
int CSIDL_ADMINTOOLS = 0x0030; // <user name>\Start Menu\Programs\Administrative Tools
|
||||
int CSIDL_CONNECTIONS = 0x0031; // Network and Dial-up Connections
|
||||
int CSIDL_COMMON_MUSIC = 0x0035; // All Users\My Music
|
||||
int CSIDL_COMMON_PICTURES = 0x0036; // All Users\My Pictures
|
||||
int CSIDL_COMMON_VIDEO = 0x0037; // All Users\My Video
|
||||
int CSIDL_RESOURCES = 0x0038; // Resource Direcotry
|
||||
int CSIDL_RESOURCES_LOCALIZED = 0x0039; // Localized Resource Direcotry
|
||||
int CSIDL_COMMON_OEM_LINKS = 0x003a; // Links to All Users OEM specific apps
|
||||
int CSIDL_CDBURN_AREA = 0x003b; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
|
||||
int CSIDL_COMPUTERSNEARME = 0x003d; // Computers Near Me (computered from Workgroup membership)
|
||||
}
|
||||
@@ -1,477 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Sspi.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Sspi extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Maximum size in bytes of a security token.
|
||||
*/
|
||||
int MAX_TOKEN_SIZE = 12288;
|
||||
|
||||
// Flags for the fCredentialUse parameter of AcquireCredentialsHandle
|
||||
|
||||
/**
|
||||
* Validate an incoming server credential. Inbound credentials might be validated
|
||||
* by using an authenticating authority when InitializeSecurityContext or
|
||||
* AcceptSecurityContext is called. If such an authority is not available, the function will
|
||||
* fail and return SEC_E_NO_AUTHENTICATING_AUTHORITY. Validation is package specific.
|
||||
*/
|
||||
int SECPKG_CRED_INBOUND = 1;
|
||||
|
||||
/**
|
||||
* Allow a local client credential to prepare an outgoing token.
|
||||
*/
|
||||
int SECPKG_CRED_OUTBOUND = 2;
|
||||
|
||||
|
||||
// Flags for the TargetDataRep parameter of AcceptSecurityContext and InitializeSecurityContext
|
||||
|
||||
/**
|
||||
* Specifies Native data representation.
|
||||
*/
|
||||
int SECURITY_NATIVE_DREP = 0x10;
|
||||
|
||||
|
||||
// Flags for the fContextReq parameter of InitializeSecurityContext or AcceptSecurityContext.
|
||||
|
||||
/**
|
||||
* The security package allocates output buffers for you.
|
||||
* When you have finished using the output buffers, free them by calling the FreeContextBuffer function.
|
||||
*/
|
||||
int ISC_REQ_ALLOCATE_MEMORY = 0x00000100;
|
||||
|
||||
/**
|
||||
* Encrypt messages by using the EncryptMessage function.
|
||||
*/
|
||||
int ISC_REQ_CONFIDENTIALITY = 0x00000010;
|
||||
|
||||
/**
|
||||
* The security context will not handle formatting messages. This value is the default.
|
||||
*/
|
||||
int ISC_REQ_CONNECTION = 0x00000800;
|
||||
|
||||
/**
|
||||
* The server can use the context to authenticate to other servers as the client.
|
||||
* The ISC_REQ_MUTUAL_AUTH flag must be set for this flag to work. Valid for Kerberos.
|
||||
* Ignore this flag for constrained delegation.
|
||||
*/
|
||||
int ISC_REQ_DELEGATE = 0x00000001;
|
||||
|
||||
/**
|
||||
* When errors occur, the remote party will be notified.
|
||||
*/
|
||||
int ISC_REQ_EXTENDED_ERROR = 0x00004000;
|
||||
|
||||
/**
|
||||
* Sign messages and verify signatures by using the EncryptMessage and MakeSignature functions.
|
||||
*/
|
||||
int ISC_REQ_INTEGRITY = 0x00010000;
|
||||
|
||||
/**
|
||||
* The mutual authentication policy of the service will be satisfied.
|
||||
*/
|
||||
int ISC_REQ_MUTUAL_AUTH = 0x00000002;
|
||||
|
||||
/**
|
||||
* Detect replayed messages that have been encoded by using the
|
||||
* EncryptMessage or MakeSignature functions.
|
||||
*/
|
||||
int ISC_REQ_REPLAY_DETECT = 0x00000004;
|
||||
|
||||
/**
|
||||
* Detect messages received out of sequence.
|
||||
*/
|
||||
int ISC_REQ_SEQUENCE_DETECT = 0x00000008;
|
||||
|
||||
/**
|
||||
* Support a stream-oriented connection.
|
||||
*/
|
||||
int ISC_REQ_STREAM = 0x00008000;
|
||||
|
||||
/**
|
||||
* Version of the SecBuffer struct.
|
||||
*/
|
||||
int SECBUFFER_VERSION = 0;
|
||||
|
||||
/**
|
||||
* This is a placeholder in the buffer array.
|
||||
*/
|
||||
int SECBUFFER_EMPTY = 0;
|
||||
/**
|
||||
* This buffer type is used for common data. The security package can read
|
||||
* and write this data.
|
||||
*/
|
||||
int SECBUFFER_DATA = 1;
|
||||
/**
|
||||
* This buffer type is used to indicate the security token portion of the message.
|
||||
* This is read-only for input parameters or read/write for output parameters.
|
||||
*/
|
||||
int SECBUFFER_TOKEN = 2;
|
||||
|
||||
/**
|
||||
* Security handle.
|
||||
*/
|
||||
public static class SecHandle extends Structure {
|
||||
public Pointer dwLower;
|
||||
public Pointer dwUpper;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwLower", "dwUpper" });
|
||||
}
|
||||
|
||||
public static class ByReference extends SecHandle implements Structure.ByReference {
|
||||
}
|
||||
|
||||
/**
|
||||
* An empty SecHandle.
|
||||
*/
|
||||
public SecHandle() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the handle is NULL.
|
||||
* @return
|
||||
* True if NULL, False otherwise.
|
||||
*/
|
||||
public boolean isNull() {
|
||||
return dwLower == null && dwUpper == null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer to a SecHandle
|
||||
*/
|
||||
public static class PSecHandle extends Structure {
|
||||
|
||||
public static class ByReference extends PSecHandle implements Structure.ByReference {
|
||||
}
|
||||
|
||||
/**
|
||||
* The first entry in an array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecHandle.ByReference secHandle;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "secHandle" });
|
||||
}
|
||||
|
||||
public PSecHandle() {
|
||||
}
|
||||
|
||||
public PSecHandle(SecHandle h) {
|
||||
super(h.getPointer());
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Credentials handle.
|
||||
*/
|
||||
public static class CredHandle extends SecHandle {
|
||||
}
|
||||
|
||||
/**
|
||||
* Security context handle.
|
||||
*/
|
||||
public static class CtxtHandle extends SecHandle {
|
||||
}
|
||||
|
||||
/**
|
||||
* The SecBuffer structure describes a buffer allocated by a transport application
|
||||
* to pass to a security package.
|
||||
*/
|
||||
public static class SecBuffer extends Structure {
|
||||
|
||||
/**
|
||||
* A ByReference SecBuffer.
|
||||
*/
|
||||
public static class ByReference extends SecBuffer implements Structure.ByReference {
|
||||
/**
|
||||
* Create a SECBUFFER_EMPTY SecBuffer.
|
||||
*/
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param size
|
||||
* Buffer size, eg. MAX_TOKEN_SIZE.
|
||||
*/
|
||||
public ByReference(int type, int size) {
|
||||
super(type, size);
|
||||
}
|
||||
|
||||
public ByReference(int type, byte[] token) {
|
||||
super(type, token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buffer bytes.
|
||||
* @return
|
||||
* Raw buffer bytes.
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return super.getBytes();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the size, in bytes, of the buffer pointed to by the pvBuffer member.
|
||||
*/
|
||||
public int cbBuffer;
|
||||
/**
|
||||
* Bit flags that indicate the type of buffer. Must be one of the values of
|
||||
* the SecBufferType enumeration.
|
||||
*/
|
||||
public int BufferType = SECBUFFER_EMPTY;
|
||||
/**
|
||||
* A pointer to a buffer.
|
||||
*/
|
||||
public Pointer pvBuffer;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbBuffer", "BufferType", "pvBuffer" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SECBUFFER_EMPTY buffer.
|
||||
*/
|
||||
public SecBuffer() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param size
|
||||
* Buffer size, eg. MAX_TOKEN_SIZE.
|
||||
*/
|
||||
public SecBuffer(int type, int size) {
|
||||
cbBuffer = size;
|
||||
pvBuffer = new Memory(size);
|
||||
BufferType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a SecBuffer of a given type with initial data.
|
||||
* @param type
|
||||
* Buffer type, one of SECBUFFER_EMTPY, etc.
|
||||
* @param token
|
||||
* Existing token.
|
||||
*/
|
||||
public SecBuffer(int type, byte[] token) {
|
||||
cbBuffer = token.length;
|
||||
pvBuffer = new Memory(token.length);
|
||||
pvBuffer.write(0, token, 0, token.length);
|
||||
BufferType = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get buffer bytes.
|
||||
* @return
|
||||
* Raw buffer bytes.
|
||||
*/
|
||||
public byte[] getBytes() {
|
||||
return pvBuffer == null ? null : pvBuffer.getByteArray(0, cbBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SecBufferDesc extends Structure {
|
||||
|
||||
/**
|
||||
* Version number.
|
||||
*/
|
||||
public int ulVersion;
|
||||
/**
|
||||
* Number of buffers.
|
||||
*/
|
||||
public int cBuffers;
|
||||
/**
|
||||
* Pointer to array of buffers.
|
||||
*/
|
||||
public SecBuffer.ByReference[] pBuffers;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "ulVersion", "cBuffers", "pBuffers" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with one SECBUFFER_EMPTY buffer.
|
||||
*/
|
||||
public SecBufferDesc() {
|
||||
ulVersion = SECBUFFER_VERSION;
|
||||
cBuffers = 1;
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference();
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with initial data.
|
||||
* @param type
|
||||
* Token type.
|
||||
* @param token
|
||||
* Initial token data.
|
||||
*/
|
||||
public SecBufferDesc(int type, byte[] token) {
|
||||
ulVersion = SECBUFFER_VERSION;
|
||||
cBuffers = 1;
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference(type, token);
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new SecBufferDesc with one SecBuffer of a given type and size.
|
||||
* @param type
|
||||
* @param tokenSize
|
||||
*/
|
||||
public SecBufferDesc(int type, int tokenSize) {
|
||||
ulVersion = SECBUFFER_VERSION;
|
||||
cBuffers = 1;
|
||||
SecBuffer.ByReference secBuffer = new SecBuffer.ByReference(type, tokenSize);
|
||||
pBuffers = (SecBuffer.ByReference[]) secBuffer.toArray(1);
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
if (pBuffers == null || cBuffers == 0) {
|
||||
throw new RuntimeException("pBuffers | cBuffers");
|
||||
}
|
||||
if (cBuffers == 1) {
|
||||
return pBuffers[0].getBytes();
|
||||
}
|
||||
throw new RuntimeException("cBuffers > 1");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A security integer.
|
||||
*/
|
||||
public static class SECURITY_INTEGER extends Structure {
|
||||
public int dwLower;
|
||||
public int dwUpper;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwLower", "dwUpper" });
|
||||
}
|
||||
|
||||
/**
|
||||
* An security integer of 0.
|
||||
*/
|
||||
public SECURITY_INTEGER() {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A timestamp.
|
||||
*/
|
||||
public static class TimeStamp extends SECURITY_INTEGER {
|
||||
}
|
||||
|
||||
/**
|
||||
* A pointer to an array of SecPkgInfo structures.
|
||||
*/
|
||||
public static class PSecPkgInfo extends Structure {
|
||||
|
||||
public static class ByReference extends PSecPkgInfo implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The first entry in an array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecPkgInfo.ByReference pPkgInfo;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "pPkgInfo" });
|
||||
}
|
||||
|
||||
public PSecPkgInfo() {
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of SecPkgInfo structures.
|
||||
*/
|
||||
public SecPkgInfo.ByReference[] toArray(int size) {
|
||||
return (SecPkgInfo.ByReference[]) pPkgInfo.toArray(size);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The SecPkgInfo structure provides general information about a security package,
|
||||
* such as its name and capabilities.
|
||||
*/
|
||||
public static class SecPkgInfo extends Structure {
|
||||
|
||||
/**
|
||||
* A reference pointer to a SecPkgInfo structure.
|
||||
*/
|
||||
public static class ByReference extends SecPkgInfo implements Structure.ByReference {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set of bit flags that describes the capabilities of the security package.
|
||||
*/
|
||||
public int fCapabilities;
|
||||
/**
|
||||
* Specifies the version of the package protocol. Must be 1.
|
||||
*/
|
||||
public short wVersion = 1;
|
||||
/**
|
||||
* Specifies a DCE RPC identifier, if appropriate. If the package does not implement one of
|
||||
* the DCE registered security systems, the reserved value SECPKG_ID_NONE is used.
|
||||
*/
|
||||
public short wRPCID;
|
||||
/**
|
||||
* Specifies the maximum size, in bytes, of the token.
|
||||
*/
|
||||
public int cbMaxToken;
|
||||
/**
|
||||
* Pointer to a null-terminated string that contains the name of the security package.
|
||||
*/
|
||||
public WString Name;
|
||||
/**
|
||||
* Pointer to a null-terminated string. This can be any additional string passed
|
||||
* back by the package.
|
||||
*/
|
||||
public WString Comment;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "fCapabilities", "wVersion", "wRPCID", "cbMaxToken", "Name", "Comment" });
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new package info.
|
||||
*/
|
||||
public SecPkgInfo() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,146 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Interface for the Tlhelp32.h header file.
|
||||
*/
|
||||
public interface Tlhelp32 extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Includes all heaps of the process specified in th32ProcessID in the snapshot. To enumerate the heaps, see
|
||||
* Heap32ListFirst.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPHEAPLIST = new WinDef.DWORD(0x00000001);
|
||||
|
||||
/**
|
||||
* Includes all processes in the system in the snapshot. To enumerate the processes, see Process32First.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPPROCESS = new WinDef.DWORD(0x00000002);
|
||||
|
||||
/**
|
||||
* Includes all threads in the system in the snapshot. To enumerate the threads, see Thread32First.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPTHREAD = new WinDef.DWORD(0x00000004);
|
||||
|
||||
/**
|
||||
* Includes all modules of the process specified in th32ProcessID in the snapshot. To enumerate the modules, see
|
||||
* Module32First. If the function fails with ERROR_BAD_LENGTH, retry the function until it succeeds.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPMODULE = new WinDef.DWORD(0x00000008);
|
||||
|
||||
/**
|
||||
* Includes all 32-bit modules of the process specified in th32ProcessID in the snapshot when called from a 64-bit
|
||||
* process. This flag can be combined with TH32CS_SNAPMODULE or TH32CS_SNAPALL. If the function fails with
|
||||
* ERROR_BAD_LENGTH, retry the function until it succeeds.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPMODULE32 = new WinDef.DWORD(0x00000010);
|
||||
|
||||
/**
|
||||
* Includes all processes and threads in the system, plus the heaps and modules of the process specified in th32ProcessID.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_SNAPALL = new WinDef.DWORD((TH32CS_SNAPHEAPLIST.intValue() |
|
||||
TH32CS_SNAPPROCESS.intValue() | TH32CS_SNAPTHREAD.intValue() | TH32CS_SNAPMODULE.intValue()));
|
||||
|
||||
/**
|
||||
* Indicates that the snapshot handle is to be inheritable.
|
||||
*/
|
||||
WinDef.DWORD TH32CS_INHERIT = new WinDef.DWORD(0x80000000);
|
||||
|
||||
/**
|
||||
* Describes an entry from a list of the processes residing in the system address space when a snapshot was taken.
|
||||
*/
|
||||
public static class PROCESSENTRY32 extends Structure {
|
||||
|
||||
public static class ByReference extends PROCESSENTRY32 implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public PROCESSENTRY32() {
|
||||
dwSize = new WinDef.DWORD(size());
|
||||
}
|
||||
|
||||
public PROCESSENTRY32(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The size of the structure, in bytes. Before calling the Process32First function, set this member to
|
||||
* sizeof(PROCESSENTRY32). If you do not initialize dwSize, Process32First fails.
|
||||
*/
|
||||
public WinDef.DWORD dwSize;
|
||||
|
||||
/**
|
||||
* This member is no longer used and is always set to zero.
|
||||
*/
|
||||
public WinDef.DWORD cntUsage;
|
||||
|
||||
/**
|
||||
* The process identifier.
|
||||
*/
|
||||
public WinDef.DWORD th32ProcessID;
|
||||
|
||||
/**
|
||||
* This member is no longer used and is always set to zero.
|
||||
*/
|
||||
public BaseTSD.ULONG_PTR th32DefaultHeapID;
|
||||
|
||||
/**
|
||||
* This member is no longer used and is always set to zero.
|
||||
*/
|
||||
public WinDef.DWORD th32ModuleID;
|
||||
|
||||
/**
|
||||
* The number of execution threads started by the process.
|
||||
*/
|
||||
public WinDef.DWORD cntThreads;
|
||||
|
||||
/**
|
||||
* The identifier of the process that created this process (its parent process).
|
||||
*/
|
||||
public WinDef.DWORD th32ParentProcessID;
|
||||
|
||||
/**
|
||||
* The base priority of any threads created by this process.
|
||||
*/
|
||||
public WinDef.LONG pcPriClassBase;
|
||||
|
||||
/**
|
||||
* This member is no longer used, and is always set to zero.
|
||||
*/
|
||||
public WinDef.DWORD dwFlags;
|
||||
|
||||
/**
|
||||
* The name of the executable file for the process. To retrieve the full path to the executable file, call the
|
||||
* Module32First function and check the szExePath member of the MODULEENTRY32 structure that is returned.
|
||||
* However, if the calling process is a 32-bit process, you must call the QueryFullProcessImageName function to
|
||||
* retrieve the full path of the executable file for a 64-bit process.
|
||||
*/
|
||||
public char[] szExeFile = new char[WinDef.MAX_PATH];
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwSize", "cntUsage", "th32ProcessID", "th32DefaultHeapID", "th32ModuleID", "cntThreads", "th32ParentProcessID", "pcPriClassBase", "dwFlags", "szExeFile" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,124 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Interface for the VerRsrc.h header file.
|
||||
*/
|
||||
public interface VerRsrc extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Contains version information for a file. This information is language and code page independent.
|
||||
*/
|
||||
public static class VS_FIXEDFILEINFO extends Structure {
|
||||
|
||||
public static class ByReference extends VS_FIXEDFILEINFO implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public VS_FIXEDFILEINFO() {
|
||||
}
|
||||
|
||||
public VS_FIXEDFILEINFO(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the value 0xFEEF04BD. This is used with the szKey member of the VS_VERSIONINFO structure when
|
||||
* searching a file for the VS_FIXEDFILEINFO structure.
|
||||
*/
|
||||
public WinDef.DWORD dwSignature;
|
||||
|
||||
/**
|
||||
* The binary version number of this structure. The high-order word of this member contains the major version
|
||||
* number, and the low-order word contains the minor version number.
|
||||
*/
|
||||
public WinDef.DWORD dwStrucVersion;
|
||||
|
||||
/**
|
||||
* The most significant 32 bits of the file's binary version number. This member is used with dwFileVersionLS to
|
||||
* form a 64-bit value used for numeric comparisons.
|
||||
*/
|
||||
public WinDef.DWORD dwFileVersionMS;
|
||||
|
||||
/**
|
||||
* The least significant 32 bits of the file's binary version number. This member is used with dwFileVersionMS
|
||||
* to form a 64-bit value used for numeric comparisons.
|
||||
*/
|
||||
public WinDef.DWORD dwFileVersionLS;
|
||||
|
||||
/**
|
||||
* The most significant 32 bits of the binary version number of the product with which this file was
|
||||
* distributed. This member is used with dwProductVersionLS to form a 64-bit value used for numeric comparisons.
|
||||
*/
|
||||
public WinDef.DWORD dwProductVersionMS;
|
||||
|
||||
/**
|
||||
* The least significant 32 bits of the binary version number of the product with which this file was
|
||||
* distributed. This member is used with dwProductVersionMS to form a 64-bit value used for numeric comparisons.
|
||||
*/
|
||||
public WinDef.DWORD dwProductVersionLS;
|
||||
|
||||
/**
|
||||
* Contains a bitmask that specifies the valid bits in dwFileFlags. A bit is valid only if it was defined when
|
||||
* the file was created.
|
||||
*/
|
||||
public WinDef.DWORD dwFileFlagsMask;
|
||||
|
||||
/**
|
||||
* Contains a bitmask that specifies the Boolean attributes of the file. This member can include one or more of
|
||||
* the following values.
|
||||
*/
|
||||
public WinDef.DWORD dwFileFlags;
|
||||
|
||||
/**
|
||||
* The operating system for which this file was designed.
|
||||
*/
|
||||
public WinDef.DWORD dwFileOS;
|
||||
|
||||
/**
|
||||
* The general type of file.
|
||||
*/
|
||||
public WinDef.DWORD dwFileType;
|
||||
|
||||
/**
|
||||
* The function of the file. The possible values depend on the value of dwFileType.
|
||||
*/
|
||||
public WinDef.DWORD dwFileSubtype;
|
||||
|
||||
/**
|
||||
* The most significant 32 bits of the file's 64-bit binary creation date and time stamp.
|
||||
*/
|
||||
public WinDef.DWORD dwFileDateMS;
|
||||
|
||||
/**
|
||||
* The least significant 32 bits of the file's 64-bit binary creation date and time stamp.
|
||||
*/
|
||||
public WinDef.DWORD dwFileDateLS;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwSignature", "dwStrucVersion", "dwFileVersionMS", "dwFileVersionLS", "dwProductVersionMS", "dwProductVersionLS", "dwFileFlagsMask", "dwFileFlags", "dwFileOS", "dwFileType", "dwFileSubtype", "dwFileDateMS", "dwFileDateLS" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Provides access to the w32 version library.
|
||||
*/
|
||||
public interface Version extends StdCallLibrary {
|
||||
|
||||
Version INSTANCE = (Version)
|
||||
Native.loadLibrary("version", Version.class, W32APIOptions.DEFAULT_OPTIONS);
|
||||
|
||||
/**
|
||||
* Determines whether the operating system can retrieve version information for a specified file. If version
|
||||
* information is available, GetFileVersionInfoSize returns the size, in bytes, of that information.
|
||||
*
|
||||
* @param lptstrFilename
|
||||
* The name of the file of interest. The function uses the search sequence specified by the LoadLibrary function.
|
||||
*
|
||||
* @param lpdwHandle
|
||||
* A pointer to a variable that the function sets to zero.
|
||||
*
|
||||
* @return
|
||||
* If the function succeeds, the return value is the size, in bytes, of the file's version information.
|
||||
*
|
||||
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
int GetFileVersionInfoSize(String lptstrFilename, IntByReference lpdwHandle);
|
||||
|
||||
/**
|
||||
* Retrieves version information for the specified file.
|
||||
*
|
||||
* @param lptstrFilename
|
||||
* The name of the file. If a full path is not specified, the function uses the search sequence specified by the
|
||||
* LoadLibrary function.
|
||||
*
|
||||
* @param dwHandle
|
||||
* This parameter is ignored.
|
||||
*
|
||||
* @param dwLen
|
||||
* The size, in bytes, of the buffer pointed to by the lpData parameter.
|
||||
*
|
||||
* Call the GetFileVersionInfoSize function first to determine the size, in bytes, of a file's version
|
||||
* information. The dwLen member should be equal to or greater than that value.
|
||||
*
|
||||
* If the buffer pointed to by lpData is not large enough, the function truncates the file's version information
|
||||
* to the size of the buffer.
|
||||
*
|
||||
* @param lpData
|
||||
* Pointer to a buffer that receives the file-version information.
|
||||
*
|
||||
* You can use this value in a subsequent call to the VerQueryValue function to retrieve data from the buffer.
|
||||
*
|
||||
* @return
|
||||
* If the function succeeds, the return value is nonzero.
|
||||
*
|
||||
* If the function fails, the return value is zero. To get extended error information, call GetLastError.
|
||||
*/
|
||||
boolean GetFileVersionInfo(String lptstrFilename, int dwHandle, int dwLen, Pointer lpData);
|
||||
|
||||
/**
|
||||
* Retrieves specified version information from the specified version-information resource. To retrieve the
|
||||
* appropriate resource, before you call VerQueryValue, you must first call the GetFileVersionInfoSize function, and
|
||||
* then the GetFileVersionInfo function.
|
||||
*
|
||||
* @param pBlock
|
||||
* The version-information resource returned by the GetFileVersionInfo function.
|
||||
*
|
||||
* @param lpSubBlock
|
||||
* The version-information value to be retrieved.
|
||||
*
|
||||
* @param lplpBuffer
|
||||
* When this method returns, contains the address of a pointer to the requested version information in the buffer
|
||||
* pointed to by pBlock. The memory pointed to by lplpBuffer is freed when the associated pBlock memory is freed.
|
||||
*
|
||||
* @param puLen
|
||||
* When this method returns, contains a pointer to the size of the requested data pointed to by lplpBuffer: for
|
||||
* version information values, the length in characters of the string stored at lplpBuffer; for translation array
|
||||
* values, the size in bytes of the array stored at lplpBuffer; and for root block, the size in bytes of the
|
||||
* structure.
|
||||
*
|
||||
* @return
|
||||
* If the specified version-information structure exists, and version information is available, the return value
|
||||
* is nonzero. If the address of the length buffer is zero, no value is available for the specified
|
||||
* version-information name.
|
||||
*
|
||||
* If the specified name does not exist or the specified resource is not valid, the return value is zero.
|
||||
*/
|
||||
boolean VerQueryValue(Pointer pBlock, String lpSubBlock, PointerByReference lplpBuffer, IntByReference puLen);
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
/* Copyright (c) 2010,2011 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Utility class for some common error functions.
|
||||
*/
|
||||
public abstract class W32Errors implements WinError {
|
||||
/**
|
||||
* Generic test for success on any status value (non-negative numbers
|
||||
* indicate success).
|
||||
*/
|
||||
public static final boolean SUCCEEDED(int hr) {
|
||||
return hr >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* and the inverse
|
||||
*/
|
||||
public static final boolean FAILED(int hr) {
|
||||
return hr < 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract error code from HRESULT
|
||||
*/
|
||||
public static final int HRESULT_CODE(int hr) {
|
||||
return hr & 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract error code from SCODE
|
||||
*/
|
||||
public static final int SCODE_CODE(int sc) {
|
||||
return sc & 0xFFFF;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the facility
|
||||
*/
|
||||
public static final int HRESULT_FACILITY(int hr) {
|
||||
return (hr >>= 16) & 0x1fff;
|
||||
}
|
||||
|
||||
public static final int SCODE_FACILITY(short sc) {
|
||||
return (sc >>= 16) & 0x1fff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the severity
|
||||
*/
|
||||
public static short HRESULT_SEVERITY(int hr) {
|
||||
return (short) ((hr >>= 31) & 0x1);
|
||||
}
|
||||
|
||||
public static short SCODE_SEVERITY(short sc) {
|
||||
return (short) ((sc >>= 31) & 0x1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an HRESULT value from component pieces
|
||||
*/
|
||||
public static int MAKE_HRESULT(short sev, short fac, short code) {
|
||||
return ((sev << 31) | (fac << 16) | code);
|
||||
}
|
||||
|
||||
public static final int MAKE_SCODE(short sev, short fac, short code) {
|
||||
return ((sev << 31) | (fac << 16) | code);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a WIN32 error value into a HRESULT
|
||||
* Note: This assumes that WIN32 errors fall in the range -32k to=32k.
|
||||
* @param x original w32 error code
|
||||
* @return the converted value
|
||||
*/
|
||||
public static final HRESULT HRESULT_FROM_WIN32(int x) {
|
||||
int f = FACILITY_WIN32;
|
||||
return new HRESULT(x <= 0 ? x : ((x) & 0x0000FFFF) | (f <<= 16) | 0x80000000);
|
||||
}
|
||||
|
||||
/**
|
||||
* FACILITY_USERMODE_FILTER_MANAGER
|
||||
*
|
||||
* Translation macro for converting:
|
||||
* NTSTATUS --> HRESULT
|
||||
*/
|
||||
public static final int FILTER_HRESULT_FROM_FLT_NTSTATUS(int x) {
|
||||
int f = FACILITY_USERMODE_FILTER_MANAGER;
|
||||
return (((x) & 0x8000FFFF) | (f <<= 16));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,258 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.jna.platform.FileMonitor;
|
||||
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTRByReference;
|
||||
import com.sun.jna.platform.win32.WinBase.OVERLAPPED;
|
||||
import com.sun.jna.platform.win32.WinNT.FILE_NOTIFY_INFORMATION;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
public class W32FileMonitor extends FileMonitor {
|
||||
|
||||
private static final int BUFFER_SIZE = 4096;
|
||||
|
||||
private class FileInfo {
|
||||
public final File file;
|
||||
public final HANDLE handle;
|
||||
public final int notifyMask;
|
||||
public final boolean recursive;
|
||||
public final FILE_NOTIFY_INFORMATION info = new FILE_NOTIFY_INFORMATION(BUFFER_SIZE);
|
||||
public final IntByReference infoLength = new IntByReference();
|
||||
public final OVERLAPPED overlapped = new OVERLAPPED();
|
||||
public FileInfo(File f, HANDLE h, int mask, boolean recurse) {
|
||||
this.file = f;
|
||||
this.handle = h;
|
||||
this.notifyMask = mask;
|
||||
this.recursive = recurse;
|
||||
}
|
||||
}
|
||||
private Thread watcher;
|
||||
private HANDLE port;
|
||||
private final Map<File, FileInfo> fileMap = new HashMap<File, FileInfo>();
|
||||
private final Map<HANDLE, FileInfo> handleMap = new HashMap<HANDLE, FileInfo>();
|
||||
private boolean disposing = false;
|
||||
|
||||
private void handleChanges(FileInfo finfo) throws IOException {
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
FILE_NOTIFY_INFORMATION fni = finfo.info;
|
||||
// Need an explicit read, since data was filled in asynchronously
|
||||
fni.read();
|
||||
do {
|
||||
FileEvent event = null;
|
||||
File file = new File(finfo.file, fni.getFilename());
|
||||
switch(fni.Action) {
|
||||
case 0:
|
||||
break;
|
||||
case WinNT.FILE_ACTION_MODIFIED:
|
||||
event = new FileEvent(file, FILE_MODIFIED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_ADDED:
|
||||
event = new FileEvent(file, FILE_CREATED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_REMOVED:
|
||||
event = new FileEvent(file, FILE_DELETED);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_RENAMED_OLD_NAME:
|
||||
event = new FileEvent(file, FILE_NAME_CHANGED_OLD);
|
||||
break;
|
||||
case WinNT.FILE_ACTION_RENAMED_NEW_NAME:
|
||||
event = new FileEvent(file, FILE_NAME_CHANGED_NEW);
|
||||
break;
|
||||
default:
|
||||
// TODO: other actions...
|
||||
System.err.println("Unrecognized file action '" + fni.Action + "'");
|
||||
}
|
||||
|
||||
if (event != null) {
|
||||
notify(event);
|
||||
}
|
||||
|
||||
fni = fni.next();
|
||||
} while (fni != null);
|
||||
|
||||
// trigger the next read
|
||||
if (!finfo.file.exists()) {
|
||||
unwatch(finfo.file);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!klib.ReadDirectoryChangesW(finfo.handle, finfo.info,
|
||||
finfo.info.size(), finfo.recursive, finfo.notifyMask,
|
||||
finfo.infoLength, finfo.overlapped, null)) {
|
||||
if (! disposing) {
|
||||
int err = klib.GetLastError();
|
||||
throw new IOException("ReadDirectoryChangesW failed on "
|
||||
+ finfo.file + ": '"
|
||||
+ Kernel32Util.formatMessageFromLastErrorCode(err)
|
||||
+ "' (" + err + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FileInfo waitForChange() {
|
||||
IntByReference rcount = new IntByReference();
|
||||
ULONG_PTRByReference rkey = new ULONG_PTRByReference();
|
||||
PointerByReference roverlap = new PointerByReference();
|
||||
if (! Kernel32.INSTANCE.GetQueuedCompletionStatus(port, rcount, rkey, roverlap, WinBase.INFINITE)) {
|
||||
return null;
|
||||
}
|
||||
synchronized (this) {
|
||||
return handleMap.get(new HANDLE(rkey.getValue().toPointer()));
|
||||
}
|
||||
}
|
||||
|
||||
private int convertMask(int mask) {
|
||||
int result = 0;
|
||||
if ((mask & FILE_CREATED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_CREATION;
|
||||
}
|
||||
if ((mask & FILE_DELETED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_NAME;
|
||||
}
|
||||
if ((mask & FILE_MODIFIED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_LAST_WRITE;
|
||||
}
|
||||
if ((mask & FILE_RENAMED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_NAME;
|
||||
}
|
||||
if ((mask & FILE_SIZE_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_SIZE;
|
||||
}
|
||||
if ((mask & FILE_ACCESSED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_LAST_ACCESS;
|
||||
}
|
||||
if ((mask & FILE_ATTRIBUTES_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_ATTRIBUTES;
|
||||
}
|
||||
if ((mask & FILE_SECURITY_CHANGED) != 0) {
|
||||
result |= WinNT.FILE_NOTIFY_CHANGE_SECURITY;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int watcherThreadID;
|
||||
|
||||
protected synchronized void watch(File file, int eventMask, boolean recursive) throws IOException {
|
||||
File dir = file;
|
||||
if (!dir.isDirectory()) {
|
||||
recursive = false;
|
||||
dir = file.getParentFile();
|
||||
}
|
||||
while (dir != null && !dir.exists()) {
|
||||
recursive = true;
|
||||
dir = dir.getParentFile();
|
||||
}
|
||||
if (dir == null) {
|
||||
throw new FileNotFoundException("No ancestor found for " + file);
|
||||
}
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
int mask = WinNT.FILE_SHARE_READ
|
||||
| WinNT.FILE_SHARE_WRITE | WinNT.FILE_SHARE_DELETE;
|
||||
int flags = WinNT.FILE_FLAG_BACKUP_SEMANTICS
|
||||
| WinNT.FILE_FLAG_OVERLAPPED;
|
||||
HANDLE handle = klib.CreateFile(file.getAbsolutePath(),
|
||||
WinNT.FILE_LIST_DIRECTORY,
|
||||
mask, null, WinNT.OPEN_EXISTING,
|
||||
flags, null);
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(handle)) {
|
||||
throw new IOException("Unable to open " + file + " ("
|
||||
+ klib.GetLastError() + ")");
|
||||
}
|
||||
int notifyMask = convertMask(eventMask);
|
||||
FileInfo finfo = new FileInfo(file, handle, notifyMask, recursive);
|
||||
fileMap.put(file, finfo);
|
||||
handleMap.put(handle, finfo);
|
||||
// Existing port is returned
|
||||
port = klib.CreateIoCompletionPort(handle, port, handle.getPointer(), 0);
|
||||
if (WinBase.INVALID_HANDLE_VALUE.equals(port)) {
|
||||
throw new IOException("Unable to create/use I/O Completion port "
|
||||
+ "for " + file + " ("
|
||||
+ klib.GetLastError() + ")");
|
||||
}
|
||||
// TODO: use FileIOCompletionRoutine callback method instead of a
|
||||
// dedicated thread
|
||||
if (!klib.ReadDirectoryChangesW(handle, finfo.info, finfo.info.size(),
|
||||
recursive, notifyMask, finfo.infoLength,
|
||||
finfo.overlapped, null)) {
|
||||
int err = klib.GetLastError();
|
||||
throw new IOException("ReadDirectoryChangesW failed on "
|
||||
+ finfo.file + ", handle " + handle
|
||||
+ ": '" + Kernel32Util.formatMessageFromLastErrorCode(err)
|
||||
+ "' (" + err + ")");
|
||||
}
|
||||
if (watcher == null) {
|
||||
watcher = new Thread("W32 File Monitor-" + (watcherThreadID++)) {
|
||||
public void run() {
|
||||
FileInfo finfo;
|
||||
while (true) {
|
||||
finfo = waitForChange();
|
||||
if (finfo == null) {
|
||||
synchronized(W32FileMonitor.this) {
|
||||
if (fileMap.isEmpty()) {
|
||||
watcher = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
handleChanges(finfo);
|
||||
}
|
||||
catch(IOException e) {
|
||||
// TODO: how is this best handled?
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
watcher.setDaemon(true);
|
||||
watcher.start();
|
||||
}
|
||||
}
|
||||
|
||||
protected synchronized void unwatch(File file) {
|
||||
FileInfo finfo = fileMap.remove(file);
|
||||
if (finfo != null) {
|
||||
handleMap.remove(finfo.handle);
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
// bug: the watcher may still be processing this file
|
||||
klib.CloseHandle(finfo.handle);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void dispose() {
|
||||
disposing = true;
|
||||
|
||||
// unwatch any remaining files in map, allows watcher thread to exit
|
||||
int i = 0;
|
||||
for (Object[] keys = fileMap.keySet().toArray(); !fileMap.isEmpty();) {
|
||||
unwatch((File)keys[i++]);
|
||||
}
|
||||
|
||||
Kernel32 klib = Kernel32.INSTANCE;
|
||||
klib.PostQueuedCompletionStatus(port, 0, null, null);
|
||||
klib.CloseHandle(port);
|
||||
port = null;
|
||||
watcher = null;
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.FileUtils;
|
||||
|
||||
public class W32FileUtils extends FileUtils {
|
||||
|
||||
public boolean hasTrash() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void moveToTrash(File[] files) throws IOException {
|
||||
Shell32 shell = Shell32.INSTANCE;
|
||||
ShellAPI.SHFILEOPSTRUCT fileop = new ShellAPI.SHFILEOPSTRUCT();
|
||||
fileop.wFunc = ShellAPI.FO_DELETE;
|
||||
String[] paths = new String[files.length];
|
||||
for (int i=0;i < paths.length;i++) {
|
||||
paths[i] = files[i].getAbsolutePath();
|
||||
}
|
||||
fileop.pFrom = new WString(fileop.encodePaths(paths));
|
||||
fileop.fFlags = ShellAPI.FOF_ALLOWUNDO|ShellAPI.FOF_NO_UI;
|
||||
int ret = shell.SHFileOperation(fileop);
|
||||
if (ret != 0) {
|
||||
throw new IOException("Move to trash failed: " + fileop.pFrom + ": " +
|
||||
Kernel32Util.formatMessageFromLastErrorCode(ret));
|
||||
}
|
||||
if (fileop.fAnyOperationsAborted) {
|
||||
throw new IOException("Move to trash aborted");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
/* Copyright (c) 2010 EugineLev, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.Winsvc.SC_HANDLE;
|
||||
import com.sun.jna.platform.win32.Winsvc.SC_STATUS_TYPE;
|
||||
import com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS_PROCESS;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Win32 Service wrapper
|
||||
* @author EugineLev
|
||||
*/
|
||||
public class W32Service {
|
||||
SC_HANDLE _handle = null;
|
||||
|
||||
/**
|
||||
* Win32 Service
|
||||
* @param handle
|
||||
* A handle to the service. This handle is returned by the CreateService or OpenService
|
||||
* function, and it must have the SERVICE_QUERY_STATUS access right.
|
||||
*/
|
||||
public W32Service(SC_HANDLE handle) {
|
||||
_handle = handle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close service.
|
||||
*/
|
||||
public void close() {
|
||||
if (_handle != null) {
|
||||
if (! Advapi32.INSTANCE.CloseServiceHandle(_handle)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
_handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the current status of the specified service based on the specified information level.
|
||||
* @return
|
||||
* Service status information
|
||||
*/
|
||||
public SERVICE_STATUS_PROCESS queryStatus() {
|
||||
IntByReference size = new IntByReference();
|
||||
|
||||
Advapi32.INSTANCE.QueryServiceStatusEx(_handle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO,
|
||||
null, 0, size);
|
||||
|
||||
SERVICE_STATUS_PROCESS status = new SERVICE_STATUS_PROCESS(size.getValue());
|
||||
if(! Advapi32.INSTANCE.QueryServiceStatusEx(_handle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO,
|
||||
status, status.size(), size)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
public void startService() {
|
||||
waitForNonPendingState();
|
||||
// If the service is already running - return
|
||||
if (queryStatus().dwCurrentState == Winsvc.SERVICE_RUNNING) {
|
||||
return;
|
||||
}
|
||||
if (! Advapi32.INSTANCE.StartService(_handle, 0, null)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
waitForNonPendingState();
|
||||
if (queryStatus().dwCurrentState != Winsvc.SERVICE_RUNNING) {
|
||||
throw new RuntimeException("Unable to start the service");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop service.
|
||||
*/
|
||||
public void stopService() {
|
||||
waitForNonPendingState();
|
||||
// If the service is already stopped - return
|
||||
if (queryStatus().dwCurrentState == Winsvc.SERVICE_STOPPED) {
|
||||
return;
|
||||
}
|
||||
if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_STOP,
|
||||
new Winsvc.SERVICE_STATUS())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
waitForNonPendingState();
|
||||
if (queryStatus().dwCurrentState != Winsvc.SERVICE_STOPPED) {
|
||||
throw new RuntimeException("Unable to stop the service");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Continue service.
|
||||
*/
|
||||
public void continueService() {
|
||||
waitForNonPendingState();
|
||||
// If the service is already stopped - return
|
||||
if (queryStatus().dwCurrentState == Winsvc.SERVICE_RUNNING) {
|
||||
return;
|
||||
}
|
||||
if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_CONTINUE,
|
||||
new Winsvc.SERVICE_STATUS())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
waitForNonPendingState();
|
||||
if (queryStatus().dwCurrentState != Winsvc.SERVICE_RUNNING) {
|
||||
throw new RuntimeException("Unable to continue the service");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause service.
|
||||
*/
|
||||
public void pauseService() {
|
||||
waitForNonPendingState();
|
||||
// If the service is already paused - return
|
||||
if (queryStatus().dwCurrentState == Winsvc.SERVICE_PAUSED) {
|
||||
return;
|
||||
}
|
||||
if (! Advapi32.INSTANCE.ControlService(_handle, Winsvc.SERVICE_CONTROL_PAUSE,
|
||||
new Winsvc.SERVICE_STATUS())) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
waitForNonPendingState();
|
||||
if (queryStatus().dwCurrentState != Winsvc.SERVICE_PAUSED) {
|
||||
throw new RuntimeException("Unable to pause the service");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the state to change to something other than a pending state.
|
||||
*/
|
||||
public void waitForNonPendingState() {
|
||||
|
||||
SERVICE_STATUS_PROCESS status = queryStatus();
|
||||
|
||||
int previousCheckPoint = status.dwCheckPoint;
|
||||
int checkpointStartTickCount = Kernel32.INSTANCE.GetTickCount();;
|
||||
|
||||
while (isPendingState(status.dwCurrentState)) {
|
||||
|
||||
// if the checkpoint advanced, start new tick count
|
||||
if (status.dwCheckPoint != previousCheckPoint) {
|
||||
previousCheckPoint = status.dwCheckPoint;
|
||||
checkpointStartTickCount = Kernel32.INSTANCE.GetTickCount();
|
||||
}
|
||||
|
||||
// if the time that passed is greater than the wait hint - throw timeout exception
|
||||
if (Kernel32.INSTANCE.GetTickCount() - checkpointStartTickCount > status.dwWaitHint) {
|
||||
throw new RuntimeException("Timeout waiting for service to change to a non-pending state.");
|
||||
}
|
||||
|
||||
// do not wait longer than the wait hint. A good interval is
|
||||
// one-tenth the wait hint, but no less than 1 second and no
|
||||
// more than 10 seconds.
|
||||
|
||||
int dwWaitTime = status.dwWaitHint / 10;
|
||||
|
||||
if (dwWaitTime < 1000)
|
||||
dwWaitTime = 1000;
|
||||
else if (dwWaitTime > 10000)
|
||||
dwWaitTime = 10000;
|
||||
|
||||
try {
|
||||
Thread.sleep( dwWaitTime );
|
||||
} catch (InterruptedException e){
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
status = queryStatus();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPendingState(int state) {
|
||||
switch (state) {
|
||||
case Winsvc.SERVICE_CONTINUE_PENDING:
|
||||
case Winsvc.SERVICE_STOP_PENDING:
|
||||
case Winsvc.SERVICE_PAUSE_PENDING:
|
||||
case Winsvc.SERVICE_START_PENDING:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the service handle.
|
||||
* @return
|
||||
* Returns the service handle.
|
||||
*/
|
||||
public SC_HANDLE getHandle() {
|
||||
return _handle;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/* Copyright (c) 2010 EugineLev, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.Winsvc.SC_HANDLE;
|
||||
|
||||
/**
|
||||
* Win32 Service Manager wrapper
|
||||
* @author EugineLev
|
||||
*/
|
||||
public class W32ServiceManager {
|
||||
SC_HANDLE _handle = null;
|
||||
String _machineName = null;
|
||||
String _databaseName = null;
|
||||
|
||||
public W32ServiceManager() {
|
||||
}
|
||||
|
||||
public W32ServiceManager(String machineName, String databaseName) {
|
||||
_machineName = machineName;
|
||||
_databaseName = databaseName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the Service Manager with the supplied permissions.
|
||||
* @param permissions
|
||||
* Permissions.
|
||||
*/
|
||||
public void open(int permissions) {
|
||||
close();
|
||||
|
||||
_handle = Advapi32.INSTANCE.OpenSCManager(
|
||||
_machineName, _databaseName, permissions);
|
||||
|
||||
if (_handle == null) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the previously opened Service Manager.
|
||||
*/
|
||||
public void close() {
|
||||
if (_handle != null) {
|
||||
if (! Advapi32.INSTANCE.CloseServiceHandle(_handle)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
_handle = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a Service.
|
||||
* @param serviceName
|
||||
* Service name.
|
||||
* @param permissions
|
||||
* Permissions.
|
||||
* @return
|
||||
* Returns an opened service.
|
||||
*/
|
||||
public W32Service openService(String serviceName, int permissions) {
|
||||
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(
|
||||
_handle, serviceName, permissions);
|
||||
|
||||
if (serviceHandle == null) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
return new W32Service(serviceHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the service manager handle.
|
||||
* @return
|
||||
* Returns the service manager handle.
|
||||
*/
|
||||
public SC_HANDLE getHandle() {
|
||||
return _handle;
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Digital Rapids Corp.
|
||||
*/
|
||||
|
||||
/* Copyright (c) 2010 Timothy Wall, All Rights Reserved
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
/**
|
||||
* Constant defined in WTypes.h
|
||||
* @author scott.palmer
|
||||
*/
|
||||
public interface WTypes {
|
||||
int CLSCTX_INPROC_SERVER = 0x1;
|
||||
int CLSCTX_INPROC_HANDLER = 0x2;
|
||||
int CLSCTX_LOCAL_SERVER = 0x4;
|
||||
int CLSCTX_INPROC_SERVER16 = 0x8;
|
||||
int CLSCTX_REMOTE_SERVER = 0x10;
|
||||
int CLSCTX_INPROC_HANDLER16 = 0x20;
|
||||
int CLSCTX_RESERVED1 = 0x40;
|
||||
int CLSCTX_RESERVED2 = 0x80;
|
||||
int CLSCTX_RESERVED3 = 0x100;
|
||||
int CLSCTX_RESERVED4 = 0x200;
|
||||
int CLSCTX_NO_CODE_DOWNLOAD = 0x400;
|
||||
int CLSCTX_RESERVED5 = 0x800;
|
||||
int CLSCTX_NO_CUSTOM_MARSHAL = 0x1000;
|
||||
int CLSCTX_ENABLE_CODE_DOWNLOAD = 0x2000;
|
||||
int CLSCTX_NO_FAILURE_LOG = 0x4000;
|
||||
int CLSCTX_DISABLE_AAA = 0x8000;
|
||||
int CLSCTX_ENABLE_AAA = 0x10000;
|
||||
int CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000;
|
||||
int CLSCTX_ACTIVATE_32_BIT_SERVER = 0x40000;
|
||||
int CLSCTX_ACTIVATE_64_BIT_SERVER = 0x80000;
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Wdm.h.
|
||||
* Microsoft Windows DDK.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Wdm extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The KEY_BASIC_INFORMATION structure defines a subset of
|
||||
* the full information that is available for a registry key.
|
||||
*/
|
||||
public static class KEY_BASIC_INFORMATION extends Structure {
|
||||
public KEY_BASIC_INFORMATION() {
|
||||
super();
|
||||
}
|
||||
|
||||
public KEY_BASIC_INFORMATION(int size) {
|
||||
NameLength = size - 16; // write time, title index and name length
|
||||
Name = new char[NameLength];
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public KEY_BASIC_INFORMATION(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The last time the key or any of its values changed.
|
||||
*/
|
||||
public long LastWriteTime;
|
||||
/**
|
||||
* Device and intermediate drivers should ignore this member.
|
||||
*/
|
||||
public int TitleIndex;
|
||||
/**
|
||||
* Specifies the size in bytes of the following name.
|
||||
*/
|
||||
public int NameLength;
|
||||
/**
|
||||
* A string of Unicode characters naming the key.
|
||||
* The string is not null-terminated.
|
||||
*/
|
||||
public char[] Name;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "LastWriteTime", "TitleIndex", "NameLength", "Name" });
|
||||
}
|
||||
/**
|
||||
* Name of the key.
|
||||
* @return String.
|
||||
*/
|
||||
public String getName() {
|
||||
return Native.toString(Name);
|
||||
}
|
||||
|
||||
public void read() {
|
||||
super.read();
|
||||
Name = new char[NameLength / 2];
|
||||
readField("Name");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The KEY_INFORMATION_CLASS enumeration type represents
|
||||
* the type of information to supply about a registry key.
|
||||
*/
|
||||
public abstract class KEY_INFORMATION_CLASS {
|
||||
public static final int KeyBasicInformation = 0;
|
||||
public static final int KeyNodeInformation = 1;
|
||||
public static final int KeyFullInformation = 2;
|
||||
public static final int KeyNameInformation = 3;
|
||||
public static final int KeyCachedInformation = 4;
|
||||
public static final int KeyVirtualizationInformation = 5;
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.WinNT.HRESULT;
|
||||
|
||||
/**
|
||||
* Win32 exception.
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Win32Exception extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private HRESULT _hr;
|
||||
|
||||
/**
|
||||
* Returns the error code of the error.
|
||||
* @return
|
||||
* Error code.
|
||||
*/
|
||||
public HRESULT getHR() {
|
||||
return _hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* New Win32 exception from HRESULT.
|
||||
* @param hr
|
||||
* HRESULT
|
||||
*/
|
||||
public Win32Exception(HRESULT hr) {
|
||||
super(Kernel32Util.formatMessageFromHR(hr));
|
||||
_hr = hr;
|
||||
}
|
||||
|
||||
/**
|
||||
* New Win32 exception from an error code, usually obtained from GetLastError.
|
||||
* @param code
|
||||
* Error code.
|
||||
*/
|
||||
public Win32Exception(int code) {
|
||||
this(W32Errors.HRESULT_FROM_WIN32(code));
|
||||
}
|
||||
}
|
||||
@@ -1,889 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Union;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.ByteByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Winbase.h (kernel32.dll/kernel services).
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinBase extends StdCallLibrary, WinDef, BaseTSD {
|
||||
|
||||
/** Constant value representing an invalid HANDLE. */
|
||||
HANDLE INVALID_HANDLE_VALUE =
|
||||
new HANDLE(Pointer.createConstant(Pointer.SIZE == 8
|
||||
? -1 : 0xFFFFFFFFL));
|
||||
|
||||
int WAIT_FAILED = 0xFFFFFFFF;
|
||||
int WAIT_OBJECT_0 = ((NTStatus.STATUS_WAIT_0 ) + 0 );
|
||||
int WAIT_ABANDONED = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );
|
||||
int WAIT_ABANDONED_0 = ((NTStatus.STATUS_ABANDONED_WAIT_0 ) + 0 );
|
||||
|
||||
/**
|
||||
* Maximum computer name length.
|
||||
* The value is 15 on Mac, 31 on everything else.
|
||||
*/
|
||||
int MAX_COMPUTERNAME_LENGTH = Platform.isMac() ? 15 : 31;
|
||||
|
||||
/**
|
||||
* This logon type is intended for users who will be interactively using the computer, such
|
||||
* as a user being logged on by a terminal server, remote shell, or similar process. This
|
||||
* logon type has the additional expense of caching logon information for disconnected operations;
|
||||
* therefore, it is inappropriate for some client/server applications, such as a mail server.
|
||||
*/
|
||||
int LOGON32_LOGON_INTERACTIVE = 2;
|
||||
/**
|
||||
* This logon type is intended for high performance servers to authenticate plaintext passwords.
|
||||
* The LogonUser function does not cache credentials for this logon type.
|
||||
*/
|
||||
int LOGON32_LOGON_NETWORK = 3;
|
||||
/**
|
||||
* This logon type is intended for batch servers, where processes may be executing on behalf
|
||||
* of a user without their direct intervention. This type is also for higher performance servers
|
||||
* that process many plaintext authentication attempts at a time, such as mail or Web servers.
|
||||
* The LogonUser function does not cache credentials for this logon type.
|
||||
*/
|
||||
int LOGON32_LOGON_BATCH = 4;
|
||||
/**
|
||||
* Indicates a service-type logon. The account provided must have the service privilege enabled.
|
||||
*/
|
||||
int LOGON32_LOGON_SERVICE = 5;
|
||||
/**
|
||||
* This logon type is for GINA DLLs that log on users who will be interactively using the computer.
|
||||
* This logon type can generate a unique audit record that shows when the workstation was unlocked.
|
||||
*/
|
||||
int LOGON32_LOGON_UNLOCK = 7;
|
||||
/**
|
||||
* This logon type preserves the name and password in the authentication package, which allows the
|
||||
* server to make connections to other network servers while impersonating the client. A server can
|
||||
* accept plaintext credentials from a client, call LogonUser, verify that the user can access the
|
||||
* system across the network, and still communicate with other servers.
|
||||
*/
|
||||
int LOGON32_LOGON_NETWORK_CLEARTEXT = 8;
|
||||
/**
|
||||
* This logon type allows the caller to clone its current token and specify new credentials for
|
||||
* outbound connections. The new logon session has the same local identifier but uses different
|
||||
* credentials for other network connections. This logon type is supported only by the
|
||||
* LOGON32_PROVIDER_WINNT50 logon provider.
|
||||
*/
|
||||
int LOGON32_LOGON_NEW_CREDENTIALS = 9;
|
||||
|
||||
/**
|
||||
* Use the standard logon provider for the system. The default security provider is negotiate,
|
||||
* unless you pass NULL for the domain name and the user name is not in UPN format. In this case,
|
||||
* the default provider is NTLM.
|
||||
*/
|
||||
int LOGON32_PROVIDER_DEFAULT = 0;
|
||||
|
||||
/**
|
||||
* Use the Windows NT 3.5 logon provider.
|
||||
*/
|
||||
int LOGON32_PROVIDER_WINNT35 = 1;
|
||||
/**
|
||||
* Use the NTLM logon provider.
|
||||
*/
|
||||
int LOGON32_PROVIDER_WINNT40 = 2;
|
||||
/**
|
||||
* Use the negotiate logon provider.
|
||||
*/
|
||||
int LOGON32_PROVIDER_WINNT50 = 3;
|
||||
|
||||
/**
|
||||
* If this flag is set, a child process created with the bInheritHandles parameter of
|
||||
* CreateProcess set to TRUE will inherit the object handle.
|
||||
*/
|
||||
int HANDLE_FLAG_INHERIT = 1;
|
||||
|
||||
/**
|
||||
* If this flag is set, calling the {@link Kernel32#CloseHandle} function will not
|
||||
* close the object handle.
|
||||
*/
|
||||
int HANDLE_FLAG_PROTECT_FROM_CLOSE = 2;
|
||||
|
||||
// STARTUPINFO flags
|
||||
int STARTF_USESHOWWINDOW = 0x001;
|
||||
int STARTF_USESIZE = 0x002;
|
||||
int STARTF_USEPOSITION = 0x004;
|
||||
int STARTF_USECOUNTCHARS = 0x008;
|
||||
int STARTF_USEFILLATTRIBUTE = 0x010;
|
||||
int STARTF_RUNFULLSCREEN = 0x020;
|
||||
int STARTF_FORCEONFEEDBACK = 0x040;
|
||||
int STARTF_FORCEOFFFEEDBACK = 0x080;
|
||||
int STARTF_USESTDHANDLES = 0x100;
|
||||
|
||||
// Process Creation flags
|
||||
int DEBUG_PROCESS = 0x00000001;
|
||||
int DEBUG_ONLY_THIS_PROCESS = 0x00000002;
|
||||
int CREATE_SUSPENDED = 0x00000004;
|
||||
int DETACHED_PROCESS = 0x00000008;
|
||||
int CREATE_NEW_CONSOLE = 0x00000010;
|
||||
int CREATE_NEW_PROCESS_GROUP = 0x00000200;
|
||||
int CREATE_UNICODE_ENVIRONMENT = 0x00000400;
|
||||
int CREATE_SEPARATE_WOW_VDM = 0x00000800;
|
||||
int CREATE_SHARED_WOW_VDM = 0x00001000;
|
||||
int CREATE_FORCEDOS = 0x00002000;
|
||||
int INHERIT_PARENT_AFFINITY = 0x00010000;
|
||||
int CREATE_PROTECTED_PROCESS = 0x00040000;
|
||||
int EXTENDED_STARTUPINFO_PRESENT = 0x00080000;
|
||||
int CREATE_BREAKAWAY_FROM_JOB = 0x01000000;
|
||||
int CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000;
|
||||
int CREATE_DEFAULT_ERROR_MODE = 0x04000000;
|
||||
int CREATE_NO_WINDOW = 0x08000000;
|
||||
|
||||
/* Invalid return values */
|
||||
int INVALID_FILE_SIZE = 0xFFFFFFFF;
|
||||
int INVALID_SET_FILE_POINTER = 0xFFFFFFFF;
|
||||
int INVALID_FILE_ATTRIBUTES = 0xFFFFFFFF;
|
||||
|
||||
/**
|
||||
* Return code for a process still active.
|
||||
*/
|
||||
int STILL_ACTIVE = WinNT.STATUS_PENDING;
|
||||
|
||||
|
||||
/**
|
||||
* The FILETIME structure is a 64-bit value representing the number of
|
||||
* 100-nanosecond intervals since January 1, 1601 (UTC).
|
||||
* Conversion code in this class Copyright 2002-2004 Apache Software Foundation.
|
||||
* @author Rainer Klute (klute@rainer-klute.de) for the Apache Software Foundation (org.apache.poi.hpsf)
|
||||
*/
|
||||
public static class FILETIME extends Structure {
|
||||
public int dwLowDateTime;
|
||||
public int dwHighDateTime;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwLowDateTime", "dwHighDateTime" });
|
||||
}
|
||||
|
||||
public static class ByReference extends FILETIME implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public FILETIME(Date date) {
|
||||
long rawValue = dateToFileTime(date);
|
||||
dwHighDateTime = (int)(rawValue >> 32 & 0xffffffffL);
|
||||
dwLowDateTime = (int)(rawValue & 0xffffffffL);
|
||||
}
|
||||
|
||||
public FILETIME() {
|
||||
}
|
||||
|
||||
public FILETIME(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>The difference between the Windows epoch (1601-01-01
|
||||
* 00:00:00) and the Unix epoch (1970-01-01 00:00:00) in
|
||||
* milliseconds: 11644473600000L. (Use your favorite spreadsheet
|
||||
* program to verify the correctness of this value. By the way,
|
||||
* did you notice that you can tell from the epochs which
|
||||
* operating system is the modern one? :-))</p>
|
||||
*/
|
||||
private static final long EPOCH_DIFF = 11644473600000L;
|
||||
|
||||
/**
|
||||
* <p>Converts a Windows FILETIME into a {@link Date}. The Windows
|
||||
* FILETIME structure holds a date and time associated with a
|
||||
* file. The structure identifies a 64-bit integer specifying the
|
||||
* number of 100-nanosecond intervals which have passed since
|
||||
* January 1, 1601. This 64-bit value is split into the two double
|
||||
* words stored in the structure.</p>
|
||||
*
|
||||
* @param high The higher double word of the FILETIME structure.
|
||||
* @param low The lower double word of the FILETIME structure.
|
||||
* @return The Windows FILETIME as a {@link Date}.
|
||||
*/
|
||||
public static Date filetimeToDate(final int high, final int low) {
|
||||
final long filetime = (long) high << 32 | low & 0xffffffffL;
|
||||
final long ms_since_16010101 = filetime / (1000 * 10);
|
||||
final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
|
||||
return new Date(ms_since_19700101);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Converts a {@link Date} into a filetime.</p>
|
||||
*
|
||||
* @param date The date to be converted
|
||||
* @return The filetime
|
||||
*
|
||||
* @see #filetimeToDate
|
||||
*/
|
||||
public static long dateToFileTime(final Date date) {
|
||||
final long ms_since_19700101 = date.getTime();
|
||||
final long ms_since_16010101 = ms_since_19700101 + EPOCH_DIFF;
|
||||
return ms_since_16010101 * 1000 * 10;
|
||||
}
|
||||
|
||||
public Date toDate() {
|
||||
return filetimeToDate(dwHighDateTime, dwLowDateTime);
|
||||
}
|
||||
|
||||
public long toLong() {
|
||||
return toDate().getTime();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return super.toString() + ": " + toDate().toString(); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
|
||||
/* Local Memory Flags */
|
||||
int LMEM_FIXED = 0x0000;
|
||||
int LMEM_MOVEABLE = 0x0002;
|
||||
int LMEM_NOCOMPACT = 0x0010;
|
||||
int LMEM_NODISCARD = 0x0020;
|
||||
int LMEM_ZEROINIT = 0x0040;
|
||||
int LMEM_MODIFY = 0x0080;
|
||||
int LMEM_DISCARDABLE = 0x0F00;
|
||||
int LMEM_VALID_FLAGS = 0x0F72;
|
||||
int LMEM_INVALID_HANDLE = 0x8000;
|
||||
|
||||
int LHND = (LMEM_MOVEABLE | LMEM_ZEROINIT);
|
||||
int LPTR = (LMEM_FIXED | LMEM_ZEROINIT);
|
||||
|
||||
/* Flags returned by LocalFlags (in addition to LMEM_DISCARDABLE) */
|
||||
int LMEM_DISCARDED = 0x4000;
|
||||
int LMEM_LOCKCOUNT = 0x00FF;
|
||||
|
||||
/**
|
||||
* Specifies a date and time, using individual members for the month,
|
||||
* day, year, weekday, hour, minute, second, and millisecond. The time
|
||||
* is either in coordinated universal time (UTC) or local time, depending
|
||||
* on the function that is being called.
|
||||
* http://msdn.microsoft.com/en-us/library/ms724950(VS.85).aspx
|
||||
*/
|
||||
public static class SYSTEMTIME extends Structure {
|
||||
// The year. The valid values for this member are 1601 through 30827.
|
||||
public short wYear;
|
||||
// The month. The valid values for this member are 1 through 12.
|
||||
public short wMonth;
|
||||
// The day of the week. The valid values for this member are 0 through 6.
|
||||
public short wDayOfWeek;
|
||||
// The day of the month. The valid values for this member are 1 through 31.
|
||||
public short wDay;
|
||||
// The hour. The valid values for this member are 0 through 23.
|
||||
public short wHour;
|
||||
// The minute. The valid values for this member are 0 through 59.
|
||||
public short wMinute;
|
||||
// The second. The valid values for this member are 0 through 59.
|
||||
public short wSecond;
|
||||
// The millisecond. The valid values for this member are 0 through 999.
|
||||
public short wMilliseconds;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "wYear", "wMonth", "wDayOfWeek", "wDay", "wHour", "wMinute", "wSecond", "wMilliseconds" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The lpBuffer parameter is a pointer to a PVOID pointer, and that the nSize
|
||||
* parameter specifies the minimum number of TCHARs to allocate for an output
|
||||
* message buffer. The function allocates a buffer large enough to hold the
|
||||
* formatted message, and places a pointer to the allocated buffer at the address
|
||||
* specified by lpBuffer. The caller should use the LocalFree function to free
|
||||
* the buffer when it is no longer needed.
|
||||
*/
|
||||
int FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100;
|
||||
/**
|
||||
* Insert sequences in the message definition are to be ignored and passed through
|
||||
* to the output buffer unchanged. This flag is useful for fetching a message for
|
||||
* later formatting. If this flag is set, the Arguments parameter is ignored.
|
||||
*/
|
||||
int FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200;
|
||||
/**
|
||||
* The lpSource parameter is a pointer to a null-terminated message definition.
|
||||
* The message definition may contain insert sequences, just as the message text
|
||||
* in a message table resource may. Cannot be used with FORMAT_MESSAGE_FROM_HMODULE
|
||||
* or FORMAT_MESSAGE_FROM_SYSTEM.
|
||||
*/
|
||||
int FORMAT_MESSAGE_FROM_STRING = 0x00000400;
|
||||
/**
|
||||
* The lpSource parameter is a module handle containing the message-table
|
||||
* resource(s) to search. If this lpSource handle is NULL, the current process's
|
||||
* application image file will be searched. Cannot be used with
|
||||
* FORMAT_MESSAGE_FROM_STRING.
|
||||
*/
|
||||
int FORMAT_MESSAGE_FROM_HMODULE = 0x00000800;
|
||||
/**
|
||||
* The function should search the system message-table resource(s) for the
|
||||
* requested message. If this flag is specified with FORMAT_MESSAGE_FROM_HMODULE,
|
||||
* the function searches the system message table if the message is not found in
|
||||
* the module specified by lpSource. Cannot be used with FORMAT_MESSAGE_FROM_STRING.
|
||||
* If this flag is specified, an application can pass the result of the
|
||||
* GetLastError function to retrieve the message text for a system-defined error.
|
||||
*/
|
||||
int FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000;
|
||||
/**
|
||||
* The Arguments parameter is not a va_list structure, but is a pointer to an array
|
||||
* of values that represent the arguments. This flag cannot be used with 64-bit
|
||||
* argument values. If you are using 64-bit values, you must use the va_list
|
||||
* structure.
|
||||
*/
|
||||
int FORMAT_MESSAGE_ARGUMENT_ARRAY = 0x00002000;
|
||||
|
||||
/**
|
||||
* The drive type cannot be determined.
|
||||
*/
|
||||
int DRIVE_UNKNOWN = 0;
|
||||
/**
|
||||
* The root path is invalid, for example, no volume is mounted at the path.
|
||||
*/
|
||||
int DRIVE_NO_ROOT_DIR = 1;
|
||||
/**
|
||||
* The drive is a type that has removable media, for example, a floppy drive
|
||||
* or removable hard disk.
|
||||
*/
|
||||
int DRIVE_REMOVABLE = 2;
|
||||
/**
|
||||
* The drive is a type that cannot be removed, for example, a fixed hard drive.
|
||||
*/
|
||||
int DRIVE_FIXED = 3;
|
||||
/**
|
||||
* The drive is a remote (network) drive.
|
||||
*/
|
||||
int DRIVE_REMOTE = 4;
|
||||
/**
|
||||
* The drive is a CD-ROM drive.
|
||||
*/
|
||||
int DRIVE_CDROM = 5;
|
||||
/**
|
||||
* The drive is a RAM disk.
|
||||
*/
|
||||
int DRIVE_RAMDISK = 6;
|
||||
|
||||
/**
|
||||
* The OVERLAPPED structure contains information used in
|
||||
* asynchronous (or overlapped) input and output (I/O).
|
||||
*/
|
||||
public static class OVERLAPPED extends Structure {
|
||||
public ULONG_PTR Internal;
|
||||
public ULONG_PTR InternalHigh;
|
||||
public int Offset;
|
||||
public int OffsetHigh;
|
||||
public HANDLE hEvent;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Internal", "InternalHigh", "Offset", "OffsetHigh", "hEvent" });
|
||||
}
|
||||
}
|
||||
|
||||
int INFINITE = 0xFFFFFFFF;
|
||||
|
||||
/**
|
||||
* Contains information about the current computer system. This includes the architecture and
|
||||
* type of the processor, the number of processors in the system, the page size, and other such
|
||||
* information.
|
||||
*/
|
||||
public static class SYSTEM_INFO extends Structure {
|
||||
|
||||
/** Unnamed inner structure. */
|
||||
public static class PI extends Structure {
|
||||
|
||||
public static class ByReference extends PI implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* System's processor architecture.
|
||||
* This value can be one of the following values:
|
||||
*
|
||||
* PROCESSOR_ARCHITECTURE_UNKNOWN
|
||||
* PROCESSOR_ARCHITECTURE_INTEL
|
||||
* PROCESSOR_ARCHITECTURE_IA64
|
||||
* PROCESSOR_ARCHITECTURE_AMD64
|
||||
*/
|
||||
public WORD wProcessorArchitecture;
|
||||
/**
|
||||
* Reserved for future use.
|
||||
*/
|
||||
public WORD wReserved;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "wProcessorArchitecture", "wReserved" });
|
||||
}
|
||||
}
|
||||
|
||||
/** Unnamed inner union. */
|
||||
public static class UNION extends Union {
|
||||
|
||||
public static class ByReference extends UNION implements Structure.ByReference {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* An obsolete member that is retained for compatibility with Windows NT 3.5 and earlier.
|
||||
* New applications should use the wProcessorArchitecture branch of the union.
|
||||
* Windows Me/98/95: The system always sets this member to zero, the value defined
|
||||
* for PROCESSOR_ARCHITECTURE_INTEL.
|
||||
*/
|
||||
public DWORD dwOemID;
|
||||
/**
|
||||
* Processor architecture (unnamed struct).
|
||||
*/
|
||||
public PI pi;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processor architecture (unnamed union).
|
||||
*/
|
||||
public UNION processorArchitecture;
|
||||
/**
|
||||
* Page size and the granularity of page protection and commitment.
|
||||
*/
|
||||
public DWORD dwPageSize;
|
||||
/**
|
||||
* Pointer to the lowest memory address accessible to applications and dynamic-link libraries (DLLs).
|
||||
*/
|
||||
public Pointer lpMinimumApplicationAddress;
|
||||
/**
|
||||
* Pointer to the highest memory address accessible to applications and DLLs.
|
||||
*/
|
||||
public Pointer lpMaximumApplicationAddress;
|
||||
/**
|
||||
* Mask representing the set of processors configured into the system. Bit 0 is processor 0; bit 31 is processor 31.
|
||||
*/
|
||||
public DWORD_PTR dwActiveProcessorMask;
|
||||
/**
|
||||
* Number of processors in the system.
|
||||
*/
|
||||
public DWORD dwNumberOfProcessors;
|
||||
/**
|
||||
* An obsolete member that is retained for compatibility with Windows NT 3.5 and Windows Me/98/95.
|
||||
* Use the wProcessorArchitecture, wProcessorLevel, and wProcessorRevision members to determine
|
||||
* the type of processor.
|
||||
* PROCESSOR_INTEL_386
|
||||
* PROCESSOR_INTEL_486
|
||||
* PROCESSOR_INTEL_PENTIUM
|
||||
*/
|
||||
public DWORD dwProcessorType;
|
||||
/**
|
||||
* Granularity for the starting address at which virtual memory can be allocated.
|
||||
*/
|
||||
public DWORD dwAllocationGranularity;
|
||||
/**
|
||||
* System's architecture-dependent processor level. It should be used only for display purposes.
|
||||
* To determine the feature set of a processor, use the IsProcessorFeaturePresent function.
|
||||
* If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_INTEL, wProcessorLevel is defined by the CPU vendor.
|
||||
* If wProcessorArchitecture is PROCESSOR_ARCHITECTURE_IA64, wProcessorLevel is set to 1.
|
||||
*/
|
||||
public WORD wProcessorLevel;
|
||||
/**
|
||||
* Architecture-dependent processor revision.
|
||||
*/
|
||||
public WORD wProcessorRevision;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "processorArchitecture", "dwPageSize", "lpMinimumApplicationAddress", "lpMaximumApplicationAddress", "dwActiveProcessorMask", "dwNumberOfProcessors", "dwProcessorType", "dwAllocationGranularity", "wProcessorLevel", "wProcessorRevision"});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information about the current state of both physical and virtual memory, including
|
||||
* extended memory. The GlobalMemoryStatusEx function stores information in this structure.
|
||||
*/
|
||||
public static class MEMORYSTATUSEX extends Structure {
|
||||
/**
|
||||
* The size of the structure, in bytes.
|
||||
*/
|
||||
public DWORD dwLength;
|
||||
/**
|
||||
* A number between 0 and 100 that specifies the approximate percentage of physical memory
|
||||
* that is in use (0 indicates no memory use and 100 indicates full memory use).
|
||||
*/
|
||||
public DWORD dwMemoryLoad;
|
||||
/**
|
||||
* The amount of actual physical memory, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalPhys;
|
||||
/**
|
||||
* The amount of physical memory currently available, in bytes. This is the amount of physical
|
||||
* memory that can be immediately reused without having to write its contents to disk first.
|
||||
* It is the sum of the size of the standby, free, and zero lists.
|
||||
*/
|
||||
public DWORDLONG ullAvailPhys;
|
||||
/**
|
||||
* The current committed memory limit for the system or the current process, whichever is smaller, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalPageFile;
|
||||
/**
|
||||
* The maximum amount of memory the current process can commit, in bytes. This value is equal to or smaller
|
||||
* than the system-wide available commit value.
|
||||
*/
|
||||
public DWORDLONG ullAvailPageFile;
|
||||
/**
|
||||
* The size of the user-mode portion of the virtual address space of the calling process, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullTotalVirtual;
|
||||
/**
|
||||
* The amount of unreserved and uncommitted memory currently in the user-mode portion of the
|
||||
* virtual address space of the calling process, in bytes.
|
||||
*/
|
||||
public DWORDLONG ullAvailVirtual;
|
||||
/**
|
||||
* Reserved. This value is always 0.
|
||||
*/
|
||||
public DWORDLONG ullAvailExtendedVirtual;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwLength", "dwMemoryLoad", "ullTotalPhys", "ullAvailPhys", "ullTotalPageFile", "ullAvailPageFile", "ullTotalVirtual", "ullAvailVirtual", "ullAvailExtendedVirtual" });
|
||||
}
|
||||
|
||||
public MEMORYSTATUSEX() {
|
||||
dwLength = new DWORD(size());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The SECURITY_ATTRIBUTES structure contains the security descriptor for an
|
||||
* object and specifies whether the handle retrieved by specifying this
|
||||
* structure is inheritable. This structure provides security settings for
|
||||
* objects created by various functions, such as {@link Kernel32#CreateFile},
|
||||
* {@link Kernel32#CreatePipe}, or {@link Advapi32#RegCreateKeyEx}.
|
||||
*/
|
||||
public static class SECURITY_ATTRIBUTES extends Structure {
|
||||
/**
|
||||
* The size of the structure, in bytes.
|
||||
*/
|
||||
public DWORD dwLength;
|
||||
|
||||
/**
|
||||
* A pointer to a SECURITY_DESCRIPTOR structure that controls access to the object.
|
||||
*/
|
||||
public Pointer lpSecurityDescriptor;
|
||||
|
||||
/**
|
||||
* A Boolean value that specifies whether the returned handle is inherited when
|
||||
* a new process is created
|
||||
*/
|
||||
public boolean bInheritHandle;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwLength", "lpSecurityDescriptor", "bInheritHandle" });
|
||||
}
|
||||
|
||||
public SECURITY_ATTRIBUTES() {
|
||||
dwLength = new DWORD(size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Specifies the window station, desktop, standard handles, and appearance of the main
|
||||
* window for a process at creation time.
|
||||
*/
|
||||
public static class STARTUPINFO extends Structure {
|
||||
/**
|
||||
* The size of the structure, in bytes.
|
||||
*/
|
||||
public DWORD cb;
|
||||
|
||||
/**
|
||||
* Reserved; must be NULL.
|
||||
*/
|
||||
public String lpReserved;
|
||||
|
||||
/**
|
||||
* The name of the desktop, or the name of both the desktop and window station for this process.
|
||||
* A backslash in the string indicates that the string includes both the desktop and window
|
||||
* station names. For more information, see Thread Connection to a Desktop.
|
||||
*/
|
||||
public String lpDesktop;
|
||||
|
||||
/**
|
||||
* For console processes, this is the title displayed in the title bar
|
||||
* if a new console window is created. If NULL, the name of the
|
||||
* executable file is used as the window title instead. This parameter
|
||||
* must be NULL for GUI or console processes that do not create a new
|
||||
* console window.
|
||||
*/
|
||||
public String lpTitle;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USEPOSITION, this member is the x offset
|
||||
* of the upper left corner of a window if a new window is created, in
|
||||
* pixels. Otherwise, this member is ignored.
|
||||
*
|
||||
* The offset is from the upper left corner of the screen. For GUI
|
||||
* processes, the specified position is used the first time the new
|
||||
* process calls CreateWindow to create an overlapped window if the x
|
||||
* parameter of CreateWindow is CW_USEDEFAULT.
|
||||
*/
|
||||
public DWORD dwX;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USEPOSITION, this member is the y offset
|
||||
* of the upper left corner of a window if a new window is created, in
|
||||
* pixels. Otherwise, this member is ignored.
|
||||
*
|
||||
* The offset is from the upper left corner of the screen. For GUI
|
||||
* processes, the specified position is used the first time the new
|
||||
* process calls CreateWindow to create an overlapped window if the y
|
||||
* parameter of CreateWindow is CW_USEDEFAULT.
|
||||
*/
|
||||
public DWORD dwY;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESIZE, this member is the width of the
|
||||
* window if a new window is created, in pixels. Otherwise, this member
|
||||
* is ignored.
|
||||
*
|
||||
* For GUI processes, this is used only the first time the new process
|
||||
* calls CreateWindow to create an overlapped window if the nWidth
|
||||
* parameter of CreateWindow is CW_USEDEFAULT.
|
||||
*/
|
||||
public DWORD dwXSize;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESIZE, this member is the height of the
|
||||
* window if a new window is created, in pixels. Otherwise, this member
|
||||
* is ignored.
|
||||
*
|
||||
* For GUI processes, this is used only the first time the new process
|
||||
* calls CreateWindow to create an overlapped window if the nHeight
|
||||
* parameter of CreateWindow is CW_USEDEFAULT.
|
||||
*/
|
||||
public DWORD dwYSize;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is
|
||||
* created in a console process, this member specifies the screen buffer
|
||||
* width, in character columns. Otherwise, this member is ignored.
|
||||
*/
|
||||
public DWORD dwXCountChars;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USECOUNTCHARS, if a new console window is
|
||||
* created in a console process, this member specifies the screen buffer
|
||||
* height, in character rows. Otherwise, this member is ignored.
|
||||
*/
|
||||
public DWORD dwYCountChars;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USEFILLATTRIBUTE, this member is the
|
||||
* initial text and background colors if a new console window is created
|
||||
* in a console application. Otherwise, this member is ignored.
|
||||
*
|
||||
* This value can be any combination of the following values:
|
||||
* FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED,
|
||||
* FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN,
|
||||
* BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following
|
||||
* combination of values produces red text on a white background:
|
||||
*
|
||||
* FOREGROUND_RED| BACKGROUND_RED| BACKGROUND_GREEN| BACKGROUND_BLUE
|
||||
*/
|
||||
public DWORD dwFillAttribute;
|
||||
|
||||
/**
|
||||
* A bit field that determines whether certain STARTUPINFO members are
|
||||
* used when the process creates a window.
|
||||
*/
|
||||
public int dwFlags;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESHOWWINDOW, this member can be any of
|
||||
* the values that can be specified in the nCmdShow parameter for the
|
||||
* ShowWindow function, except for SW_SHOWDEFAULT. Otherwise, this
|
||||
* member is ignored.
|
||||
*
|
||||
* For GUI processes, the first time ShowWindow is called, its nCmdShow
|
||||
* parameter is ignored wShowWindow specifies the default value. In
|
||||
* subsequent calls to ShowWindow, the wShowWindow member is used if the
|
||||
* nCmdShow parameter of ShowWindow is set to SW_SHOWDEFAULT.
|
||||
*/
|
||||
public WORD wShowWindow;
|
||||
|
||||
/**
|
||||
* Reserved for use by the C Run-time; must be zero.
|
||||
*/
|
||||
public WORD cbReserved2;
|
||||
|
||||
/**
|
||||
* Reserved for use by the C Run-time; must be NULL.
|
||||
*/
|
||||
public ByteByReference lpReserved2;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESTDHANDLES, this member is the
|
||||
* standard input handle for the process. If STARTF_USESTDHANDLES is not
|
||||
* specified, the default for standard input is the keyboard buffer.
|
||||
*
|
||||
* If dwFlags specifies STARTF_USEHOTKEY, this member specifies a hotkey
|
||||
* value that is sent as the wParam parameter of a WM_SETHOTKEY message
|
||||
* to the first eligible top-level window created by the application
|
||||
* that owns the process. If the window is created with the WS_POPUP
|
||||
* window style, it is not eligible unless the WS_EX_APPWINDOW extended
|
||||
* window style is also set. For more information, see CreateWindowEx.
|
||||
*
|
||||
* Otherwise, this member is ignored.
|
||||
*/
|
||||
public HANDLE hStdInput;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESTDHANDLES, this member is the
|
||||
* standard output handle for the process. Otherwise, this member is
|
||||
* ignored and the default for standard output is the console window's
|
||||
* buffer.
|
||||
*/
|
||||
public HANDLE hStdOutput;
|
||||
|
||||
/**
|
||||
* If dwFlags specifies STARTF_USESTDHANDLES, this member is the
|
||||
* standard error handle for the process. Otherwise, this member is
|
||||
* ignored and the default for standard error is the console window's
|
||||
* buffer.
|
||||
*/
|
||||
public HANDLE hStdError;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cb", "lpReserved", "lpDesktop", "lpTitle", "dwX", "dwY", "dwXSize", "dwYSize", "dwXCountChars", "dwYCountChars", "dwFillAttribute", "dwFlags", "wShowWindow", "cbReserved2", "lpReserved2", "hStdInput", "hStdOutput", "hStdError" });
|
||||
}
|
||||
|
||||
public STARTUPINFO() {
|
||||
cb = new DWORD(size());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information about a newly created process and its primary
|
||||
* thread. It is used with the CreateProcess, CreateProcessAsUser,
|
||||
* CreateProcessWithLogonW, or CreateProcessWithTokenW function.
|
||||
*/
|
||||
public static class PROCESS_INFORMATION extends Structure {
|
||||
|
||||
/**
|
||||
* A handle to the newly created process. The handle is used to specify
|
||||
* the process in all functions that perform operations on the process
|
||||
* object.
|
||||
*/
|
||||
public HANDLE hProcess;
|
||||
|
||||
/**
|
||||
* A handle to the primary thread of the newly created process. The
|
||||
* handle is used to specify the thread in all functions that perform
|
||||
* operations on the thread object.
|
||||
*/
|
||||
public HANDLE hThread;
|
||||
|
||||
/**
|
||||
* A value that can be used to identify a process. The value is valid
|
||||
* from the time the process is created until all handles to the process
|
||||
* are closed and the process object is freed; at this point, the
|
||||
* identifier may be reused.
|
||||
*/
|
||||
public DWORD dwProcessId;
|
||||
|
||||
/**
|
||||
* A value that can be used to identify a thread. The value is valid
|
||||
* from the time the thread is created until all handles to the thread
|
||||
* are closed and the thread object is freed; at this point, the
|
||||
* identifier may be reused.
|
||||
*/
|
||||
public DWORD dwThreadId;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "hProcess", "hThread", "dwProcessId", "dwThreadId" });
|
||||
}
|
||||
|
||||
public static class ByReference extends PROCESS_INFORMATION implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public PROCESS_INFORMATION() {
|
||||
}
|
||||
|
||||
public PROCESS_INFORMATION(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the file is to be moved to a different volume, the function simulates the move by using the CopyFile and DeleteFile functions.
|
||||
*
|
||||
* This value cannot be used with MOVEFILE_DELAY_UNTIL_REBOOT.
|
||||
*/
|
||||
int MOVEFILE_COPY_ALLOWED = 0x2;
|
||||
|
||||
/**
|
||||
* Reserved for future use.
|
||||
*/
|
||||
int MOVEFILE_CREATE_HARDLINK = 0x10;
|
||||
|
||||
/**
|
||||
* The system does not move the file until the operating system is restarted. The system moves the file immediately
|
||||
* after AUTOCHK is executed, but before creating any paging files. Consequently, this parameter enables the
|
||||
* function to delete paging files from previous startups.
|
||||
*
|
||||
* This value can be used only if the process is in the context of a user who belongs to the administrators group or
|
||||
* the LocalSystem account.
|
||||
*
|
||||
* This value cannot be used with MOVEFILE_COPY_ALLOWED.
|
||||
*
|
||||
* Windows Server 2003 and Windows XP: For information about special situations where this functionality can fail,
|
||||
* and a suggested workaround solution, see Files are not exchanged when Windows Server 2003 restarts if you use the
|
||||
* MoveFileEx function to schedule a replacement for some files in the Help and Support Knowledge Base.
|
||||
*
|
||||
* Windows 2000: If you specify the MOVEFILE_DELAY_UNTIL_REBOOT flag for dwFlags, you cannot also prepend the file
|
||||
* name that is specified by lpExistingFileName with "\\?".
|
||||
*/
|
||||
int MOVEFILE_DELAY_UNTIL_REBOOT = 0x4;
|
||||
|
||||
/**
|
||||
* The function fails if the source file is a link source, but the file cannot be tracked after the move. This
|
||||
* situation can occur if the destination is a volume formatted with the FAT file system.
|
||||
*/
|
||||
int MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20;
|
||||
|
||||
/**
|
||||
* If a file named lpNewFileName exists, the function replaces its contents with the contents of the
|
||||
* lpExistingFileName file, provided that security requirements regarding access control lists (ACLs) are met. For
|
||||
* more information, see the Remarks section of this topic.
|
||||
*
|
||||
* This value cannot be used if lpNewFileName or lpExistingFileName names a directory.
|
||||
*/
|
||||
int MOVEFILE_REPLACE_EXISTING = 0x1;
|
||||
|
||||
/**
|
||||
* The function does not return until the file is actually moved on the disk.
|
||||
*
|
||||
* Setting this value guarantees that a move performed as a copy and delete operation is flushed to disk before the
|
||||
* function returns. The flush occurs at the end of the copy operation.
|
||||
*
|
||||
* This value has no effect if MOVEFILE_DELAY_UNTIL_REBOOT is set.
|
||||
*/
|
||||
int MOVEFILE_WRITE_THROUGH = 0x8;
|
||||
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from WinCrypt.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinCrypt extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* The CryptoAPI CRYPTOAPI_BLOB structure is used for an arbitrary array of bytes.
|
||||
*/
|
||||
public static class DATA_BLOB extends Structure {
|
||||
public DATA_BLOB() {
|
||||
super();
|
||||
}
|
||||
|
||||
public DATA_BLOB(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public DATA_BLOB(byte [] data) {
|
||||
pbData = new Memory(data.length);
|
||||
pbData.write(0, data, 0, data.length);
|
||||
cbData = data.length;
|
||||
allocateMemory();
|
||||
}
|
||||
|
||||
public DATA_BLOB(String s) {
|
||||
this(Native.toByteArray(s));
|
||||
}
|
||||
|
||||
/**
|
||||
* The count of bytes in the buffer pointed to by pbData.
|
||||
*/
|
||||
public int cbData;
|
||||
/**
|
||||
* A pointer to a block of data bytes.
|
||||
*/
|
||||
public Pointer pbData;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbData", "pbData" });
|
||||
}
|
||||
/**
|
||||
* Get byte data.
|
||||
* @return
|
||||
* Byte data or null.
|
||||
*/
|
||||
public byte[] getData() {
|
||||
return pbData == null ? null : pbData.getByteArray(0, cbData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The CRYPTPROTECT_PROMPTSTRUCT structure provides the text of a prompt and
|
||||
* information about when and where that prompt is to be displayed when using
|
||||
* the CryptProtectData and CryptUnprotectData functions.
|
||||
*/
|
||||
public static class CRYPTPROTECT_PROMPTSTRUCT extends Structure {
|
||||
public CRYPTPROTECT_PROMPTSTRUCT() {
|
||||
super();
|
||||
}
|
||||
|
||||
public CRYPTPROTECT_PROMPTSTRUCT(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Size of this structure in bytes.
|
||||
*/
|
||||
public int cbSize;
|
||||
/**
|
||||
* DWORD flags that indicate when prompts to the user are to be displayed.
|
||||
*/
|
||||
public int dwPromptFlags;
|
||||
/**
|
||||
* Window handle to the parent window.
|
||||
*/
|
||||
public HWND hwndApp;
|
||||
/**
|
||||
* A string containing the text of a prompt to be displayed.
|
||||
*/
|
||||
public String szPrompt;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "dwPromptFlags", "hwndApp", "szPrompt" });
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// CryptProtect PromptStruct dwPromtFlags
|
||||
//
|
||||
|
||||
/**
|
||||
* Prompt on unprotect.
|
||||
*/
|
||||
int CRYPTPROTECT_PROMPT_ON_UNPROTECT = 0x1; // 1<<0
|
||||
/**
|
||||
* Prompt on protect.
|
||||
*/
|
||||
int CRYPTPROTECT_PROMPT_ON_PROTECT = 0x2; // 1<<1
|
||||
/**
|
||||
* Reserved, don't use.
|
||||
*/
|
||||
int CRYPTPROTECT_PROMPT_RESERVED = 0x04;
|
||||
/**
|
||||
* Default to strong variant UI protection (user supplied password currently).
|
||||
*/
|
||||
int CRYPTPROTECT_PROMPT_STRONG = 0x08; // 1<<3
|
||||
/**
|
||||
* Require strong variant UI protection (user supplied password currently).
|
||||
*/
|
||||
int CRYPTPROTECT_PROMPT_REQUIRE_STRONG = 0x10; // 1<<4
|
||||
|
||||
//
|
||||
// CryptProtectData and CryptUnprotectData dwFlags
|
||||
//
|
||||
/**
|
||||
* For remote-access situations where ui is not an option, if UI was specified
|
||||
* on protect or unprotect operation, the call will fail and GetLastError() will
|
||||
* indicate ERROR_PASSWORD_RESTRICTION.
|
||||
*/
|
||||
int CRYPTPROTECT_UI_FORBIDDEN = 0x1;
|
||||
/**
|
||||
* Per machine protected data -- any user on machine where CryptProtectData
|
||||
* took place may CryptUnprotectData.
|
||||
*/
|
||||
int CRYPTPROTECT_LOCAL_MACHINE = 0x4;
|
||||
/**
|
||||
* Force credential synchronize during CryptProtectData()
|
||||
* Synchronize is only operation that occurs during this operation.
|
||||
*/
|
||||
int CRYPTPROTECT_CRED_SYNC = 0x8;
|
||||
/**
|
||||
* Generate an Audit on protect and unprotect operations.
|
||||
*/
|
||||
int CRYPTPROTECT_AUDIT = 0x10;
|
||||
/**
|
||||
* Protect data with a non-recoverable key.
|
||||
*/
|
||||
int CRYPTPROTECT_NO_RECOVERY = 0x20;
|
||||
/**
|
||||
* Verify the protection of a protected blob.
|
||||
*/
|
||||
int CRYPTPROTECT_VERIFY_PROTECTION = 0x40;
|
||||
/**
|
||||
* Regenerate the local machine protection.
|
||||
*/
|
||||
int CRYPTPROTECT_CRED_REGENERATE = 0x80;
|
||||
}
|
||||
@@ -1,383 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.IntegerType;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.BaseTSD.LONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from Windef.h (various macros and types).
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public interface WinDef extends StdCallLibrary {
|
||||
|
||||
int MAX_PATH = 260;
|
||||
|
||||
/**
|
||||
* 16-bit unsigned integer.
|
||||
*/
|
||||
public static class WORD extends IntegerType {
|
||||
public WORD() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public WORD(long value) {
|
||||
super(2, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 32-bit unsigned integer.
|
||||
*/
|
||||
public static class DWORD extends IntegerType {
|
||||
public DWORD() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORD(long value) {
|
||||
super(4, value, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Low WORD.
|
||||
* @return
|
||||
* Low WORD.
|
||||
*/
|
||||
public WORD getLow() {
|
||||
return new WORD(longValue() & 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* High WORD.
|
||||
* @return
|
||||
* High WORD.
|
||||
*/
|
||||
public WORD getHigh() {
|
||||
return new WORD((longValue() >> 16) & 0xFFFF);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 32-bit signed integer.
|
||||
*/
|
||||
public static class LONG extends IntegerType {
|
||||
public LONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LONG(long value) {
|
||||
super(Native.LONG_SIZE, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a device context (DC).
|
||||
*/
|
||||
public static class HDC extends HANDLE {
|
||||
public HDC() {
|
||||
|
||||
}
|
||||
|
||||
public HDC(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to an icon.
|
||||
*/
|
||||
public static class HICON extends HANDLE {
|
||||
public HICON() {
|
||||
|
||||
}
|
||||
|
||||
public HICON(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a cursor.
|
||||
*/
|
||||
public static class HCURSOR extends HICON {
|
||||
public HCURSOR() {
|
||||
|
||||
}
|
||||
|
||||
public HCURSOR(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a cursor.
|
||||
*/
|
||||
public static class HMENU extends HANDLE {
|
||||
public HMENU() {
|
||||
|
||||
}
|
||||
|
||||
public HMENU(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a pen.
|
||||
*/
|
||||
public static class HPEN extends HANDLE {
|
||||
public HPEN() {
|
||||
|
||||
}
|
||||
|
||||
public HPEN(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a resource.
|
||||
*/
|
||||
public static class HRSRC extends HANDLE {
|
||||
public HRSRC() {
|
||||
|
||||
}
|
||||
|
||||
public HRSRC(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a palette.
|
||||
*/
|
||||
public static class HPALETTE extends HANDLE {
|
||||
public HPALETTE() {
|
||||
|
||||
}
|
||||
|
||||
public HPALETTE(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a bitmap.
|
||||
*/
|
||||
public static class HBITMAP extends HANDLE {
|
||||
public HBITMAP() {
|
||||
|
||||
}
|
||||
|
||||
public HBITMAP(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a region.
|
||||
*/
|
||||
public static class HRGN extends HANDLE {
|
||||
public HRGN() {
|
||||
|
||||
}
|
||||
|
||||
public HRGN(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a window.
|
||||
*/
|
||||
public static class HWND extends HANDLE {
|
||||
public HWND() {
|
||||
|
||||
}
|
||||
|
||||
public HWND(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to an instance.
|
||||
*/
|
||||
public static class HINSTANCE extends HANDLE {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a module. The value is the base address of the module.
|
||||
*/
|
||||
public static class HMODULE extends HINSTANCE {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle to a font.
|
||||
*/
|
||||
public static class HFONT extends HANDLE {
|
||||
public HFONT() {
|
||||
|
||||
}
|
||||
|
||||
public HFONT(Pointer p) {
|
||||
super(p);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message parameter.
|
||||
*/
|
||||
public static class LPARAM extends LONG_PTR {
|
||||
public LPARAM() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LPARAM(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Signed result of message processing.
|
||||
*/
|
||||
public static class LRESULT extends LONG_PTR {
|
||||
public LRESULT() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public LRESULT(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
/** Integer type big enough for a pointer. */
|
||||
public static class INT_PTR extends IntegerType {
|
||||
public INT_PTR() {
|
||||
super(Pointer.SIZE);
|
||||
}
|
||||
|
||||
public INT_PTR(long value) {
|
||||
super(Pointer.SIZE, value);
|
||||
}
|
||||
|
||||
public Pointer toPointer() {
|
||||
return Pointer.createConstant(longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsigned INT_PTR.
|
||||
*/
|
||||
public static class UINT_PTR extends IntegerType {
|
||||
public UINT_PTR() {
|
||||
super(Pointer.SIZE);
|
||||
}
|
||||
|
||||
public UINT_PTR(long value) {
|
||||
super(Pointer.SIZE, value, true);
|
||||
}
|
||||
|
||||
public Pointer toPointer() {
|
||||
return Pointer.createConstant(longValue());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Message parameter.
|
||||
*/
|
||||
public static class WPARAM extends UINT_PTR {
|
||||
public WPARAM() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public WPARAM(long value) {
|
||||
super(value);
|
||||
}
|
||||
}
|
||||
|
||||
public class RECT extends Structure {
|
||||
public int left;
|
||||
public int top;
|
||||
public int right;
|
||||
public int bottom;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "left", "top", "right", "bottom" });
|
||||
}
|
||||
|
||||
public Rectangle toRectangle() {
|
||||
return new Rectangle(left, top, right-left, bottom-top);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "[(" + left + "," + top + ")(" + right + "," + bottom + ")]";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 32-bit unsigned integer.
|
||||
*/
|
||||
public static class ULONG extends IntegerType {
|
||||
public ULONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ULONG(long value) {
|
||||
super(Native.LONG_SIZE, value, true);
|
||||
}
|
||||
|
||||
public static class ByReference implements Structure.ByReference {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 64-bit unsigned integer.
|
||||
*/
|
||||
public static class ULONGLONG extends IntegerType {
|
||||
public ULONGLONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public ULONGLONG(long value) {
|
||||
super(8, value, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 64-bit unsigned integer.
|
||||
*/
|
||||
public static class DWORDLONG extends IntegerType {
|
||||
public DWORDLONG() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
public DWORDLONG(long value) {
|
||||
super(8, value, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,118 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinDef.RECT;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from WinGDI.h.
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinGDI extends StdCallLibrary {
|
||||
public int RDH_RECTANGLES = 1;
|
||||
|
||||
public class RGNDATAHEADER extends Structure {
|
||||
public int dwSize = size();
|
||||
public int iType = RDH_RECTANGLES; // required
|
||||
public int nCount;
|
||||
public int nRgnSize;
|
||||
public RECT rcBound;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwSize", "iType", "nCount", "nRgnSize", "rcBound" });
|
||||
}
|
||||
}
|
||||
|
||||
public class RGNDATA extends Structure {
|
||||
public RGNDATAHEADER rdh;
|
||||
public byte[] Buffer;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "rdh", "Buffer" });
|
||||
}
|
||||
|
||||
public RGNDATA(int bufferSize) {
|
||||
Buffer = new byte[bufferSize];
|
||||
allocateMemory();
|
||||
}
|
||||
}
|
||||
|
||||
public int RGN_AND = 1;
|
||||
public int RGN_OR = 2;
|
||||
public int RGN_XOR = 3;
|
||||
public int RGN_DIFF = 4;
|
||||
public int RGN_COPY = 5;
|
||||
|
||||
public int ERROR = 0;
|
||||
public int NULLREGION = 1;
|
||||
public int SIMPLEREGION = 2;
|
||||
public int COMPLEXREGION = 3;
|
||||
|
||||
public int ALTERNATE = 1;
|
||||
public int WINDING = 2;
|
||||
|
||||
public int BI_RGB = 0;
|
||||
public int BI_RLE8 = 1;
|
||||
public int BI_RLE4 = 2;
|
||||
public int BI_BITFIELDS = 3;
|
||||
public int BI_JPEG = 4;
|
||||
public int BI_PNG = 5;
|
||||
|
||||
public class BITMAPINFOHEADER extends Structure {
|
||||
public int biSize = size();
|
||||
public int biWidth;
|
||||
public int biHeight;
|
||||
public short biPlanes;
|
||||
public short biBitCount;
|
||||
public int biCompression;
|
||||
public int biSizeImage;
|
||||
public int biXPelsPerMeter;
|
||||
public int biYPelsPerMeter;
|
||||
public int biClrUsed;
|
||||
public int biClrImportant;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "biSize", "biWidth", "biHeight", "biPlanes", "biBitCount", "biCompression", "biSizeImage", "biXPelsPerMeter", "biYPelsPerMeter", "biClrUsed", "biClrImportant" });
|
||||
}
|
||||
}
|
||||
|
||||
public class RGBQUAD extends Structure {
|
||||
public byte rgbBlue;
|
||||
public byte rgbGreen;
|
||||
public byte rgbRed;
|
||||
public byte rgbReserved = 0;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "rgbBlue", "rgbGreen", "rgbRed", "rgbReserved" });
|
||||
}
|
||||
}
|
||||
|
||||
public class BITMAPINFO extends Structure {
|
||||
public BITMAPINFOHEADER bmiHeader = new BITMAPINFOHEADER();
|
||||
public RGBQUAD[] bmiColors = new RGBQUAD[1];
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "bmiHeader", "bmiColors" });
|
||||
}
|
||||
public BITMAPINFO() { this(1); }
|
||||
public BITMAPINFO(int size) {
|
||||
bmiColors = new RGBQUAD[size];
|
||||
}
|
||||
}
|
||||
|
||||
public int DIB_RGB_COLORS = 0;
|
||||
public int DIB_PAL_COLORS = 1;
|
||||
}
|
||||
Diferenças do arquivo suprimidas por serem muito extensas
Carregar Diff
@@ -1,70 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.ptr.ByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* This module contains the function prototypes and constant, type and structure
|
||||
* definitions for the Windows 32-Bit Registry API.
|
||||
* Ported from WinReg.h
|
||||
* Microsoft Windows SDK 6.0A.
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinReg extends StdCallLibrary {
|
||||
|
||||
public static class HKEY extends HANDLE {
|
||||
public HKEY() { }
|
||||
public HKEY(Pointer p) { super(p); }
|
||||
public HKEY(int value) { super(new Pointer(value)); }
|
||||
}
|
||||
|
||||
public static class HKEYByReference extends ByReference {
|
||||
public HKEYByReference() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public HKEYByReference(HKEY h) {
|
||||
super(Pointer.SIZE);
|
||||
setValue(h);
|
||||
}
|
||||
|
||||
public void setValue(HKEY h) {
|
||||
getPointer().setPointer(0, h != null ? h.getPointer() : null);
|
||||
}
|
||||
|
||||
public HKEY getValue() {
|
||||
Pointer p = getPointer().getPointer(0);
|
||||
if (p == null)
|
||||
return null;
|
||||
if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p))
|
||||
return (HKEY) WinBase.INVALID_HANDLE_VALUE;
|
||||
HKEY h = new HKEY();
|
||||
h.setPointer(p);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
|
||||
HKEY HKEY_CLASSES_ROOT = new HKEY(0x80000000);
|
||||
HKEY HKEY_CURRENT_USER = new HKEY(0x80000001);
|
||||
HKEY HKEY_LOCAL_MACHINE = new HKEY(0x80000002);
|
||||
HKEY HKEY_USERS = new HKEY(0x80000003);
|
||||
HKEY HKEY_PERFORMANCE_DATA= new HKEY(0x80000004);
|
||||
HKEY HKEY_PERFORMANCE_TEXT= new HKEY(0x80000050);
|
||||
HKEY HKEY_PERFORMANCE_NLSTEXT = new HKEY(0x80000060);
|
||||
HKEY HKEY_CURRENT_CONFIG = new HKEY(0x80000005);
|
||||
HKEY HKEY_DYN_DATA = new HKEY(0x80000006);
|
||||
}
|
||||
@@ -1,694 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.Union;
|
||||
import com.sun.jna.platform.win32.BaseTSD.ULONG_PTR;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Ported from WinUser.h Microsoft Windows SDK 6.0A.
|
||||
*
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface WinUser extends StdCallLibrary, WinDef {
|
||||
HWND HWND_BROADCAST = new HWND(Pointer.createConstant(0xFFFF));
|
||||
|
||||
int FLASHW_STOP = 0;
|
||||
int FLASHW_CAPTION = 1;
|
||||
int FLASHW_TRAY = 2;
|
||||
int FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY);
|
||||
int FLASHW_TIMER = 4;
|
||||
int FLASHW_TIMERNOFG = 12;
|
||||
|
||||
int IMAGE_BITMAP = 0;
|
||||
int IMAGE_ICON = 1;
|
||||
int IMAGE_CURSOR = 2;
|
||||
int IMAGE_ENHMETAFILE = 3;
|
||||
|
||||
int LR_DEFAULTCOLOR = 0x0000;
|
||||
int LR_MONOCHROME = 0x0001;
|
||||
int LR_COLOR = 0x0002;
|
||||
int LR_COPYRETURNORG = 0x0004;
|
||||
int LR_COPYDELETEORG = 0x0008;
|
||||
int LR_LOADFROMFILE = 0x0010;
|
||||
int LR_LOADTRANSPARENT = 0x0020;
|
||||
int LR_DEFAULTSIZE = 0x0040;
|
||||
int LR_VGACOLOR = 0x0080;
|
||||
int LR_LOADMAP3DCOLORS = 0x1000;
|
||||
int LR_CREATEDIBSECTION = 0x2000;
|
||||
int LR_COPYFROMRESOURCE = 0x4000;
|
||||
int LR_SHARED = 0x8000;
|
||||
|
||||
public class GUITHREADINFO extends Structure {
|
||||
public int cbSize = size();
|
||||
public int flags;
|
||||
public HWND hwndActive;
|
||||
public HWND hwndFocus;
|
||||
public HWND hwndCapture;
|
||||
public HWND hwndMenuOwner;
|
||||
public HWND hwndMoveSize;
|
||||
public HWND hwndCaret;
|
||||
public RECT rcCaret;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "flags", "hwndActive", "hwndFocus", "hwndCapture", "hwndMenuOwner", "hwndMoveSize", "hwndCaret", "rcCaret" });
|
||||
}
|
||||
}
|
||||
|
||||
public class WINDOWINFO extends Structure {
|
||||
public int cbSize = size();
|
||||
public RECT rcWindow;
|
||||
public RECT rcClient;
|
||||
public int dwStyle;
|
||||
public int dwExStyle;
|
||||
public int dwWindowStatus;
|
||||
public int cxWindowBorders;
|
||||
public int cyWindowBorders;
|
||||
public short atomWindowType;
|
||||
public short wCreatorVersion;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "rcWindow", "rcClient", "dwStyle", "dwExStyle", "dwWindowStatus", "cxWindowBorders", "cyWindowBorders", "atomWindowType", "wCreatorVersion" });
|
||||
}
|
||||
}
|
||||
|
||||
int GWL_EXSTYLE = -20;
|
||||
int GWL_STYLE = -16;
|
||||
int GWL_WNDPROC = -4;
|
||||
int GWL_HINSTANCE = -6;
|
||||
int GWL_ID = -12;
|
||||
int GWL_USERDATA = -21;
|
||||
int DWL_DLGPROC = 4;
|
||||
|
||||
int DWL_MSGRESULT = 0;
|
||||
int DWL_USER = 8;
|
||||
|
||||
int WS_MAXIMIZE = 0x01000000;
|
||||
int WS_VISIBLE = 0x10000000;
|
||||
int WS_MINIMIZE = 0x20000000;
|
||||
int WS_CHILD = 0x40000000;
|
||||
int WS_POPUP = 0x80000000;
|
||||
int WS_EX_COMPOSITED = 0x20000000;
|
||||
int WS_EX_LAYERED = 0x80000;
|
||||
int WS_EX_TRANSPARENT = 32;
|
||||
|
||||
int LWA_COLORKEY = 1;
|
||||
int LWA_ALPHA = 2;
|
||||
int ULW_COLORKEY = 1;
|
||||
int ULW_ALPHA = 2;
|
||||
int ULW_OPAQUE = 4;
|
||||
|
||||
/** Defines the x- and y-coordinates of a point. */
|
||||
public class POINT extends Structure {
|
||||
public int x, y;
|
||||
public POINT() { }
|
||||
public POINT(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "x", "y" });
|
||||
}
|
||||
}
|
||||
|
||||
public class MSG extends Structure {
|
||||
public HWND hWnd;
|
||||
public int message;
|
||||
public WPARAM wParam;
|
||||
public LPARAM lParam;
|
||||
public int time;
|
||||
public POINT pt;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "hWnd", "message", "wParam", "lParam", "time", "pt" });
|
||||
}
|
||||
}
|
||||
|
||||
public class FLASHWINFO extends Structure {
|
||||
public int cbSize;
|
||||
public HANDLE hWnd;
|
||||
public int dwFlags;
|
||||
public int uCount;
|
||||
public int dwTimeout;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "hWnd", "dwFlags", "uCount", "dwTimeout" });
|
||||
}
|
||||
}
|
||||
|
||||
public interface WNDENUMPROC extends StdCallCallback {
|
||||
/** Return whether to continue enumeration. */
|
||||
boolean callback(HWND hWnd, Pointer data);
|
||||
}
|
||||
|
||||
public interface LowLevelKeyboardProc extends HOOKPROC {
|
||||
LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT lParam);
|
||||
}
|
||||
|
||||
/** Specifies the width and height of a rectangle. */
|
||||
public class SIZE extends Structure {
|
||||
public int cx, cy;
|
||||
public SIZE() { }
|
||||
public SIZE(int w, int h) {
|
||||
this.cx = w;
|
||||
this.cy = h;
|
||||
}
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cx", "cy" });
|
||||
}
|
||||
}
|
||||
|
||||
int AC_SRC_OVER = 0x00;
|
||||
int AC_SRC_ALPHA = 0x01;
|
||||
int AC_SRC_NO_PREMULT_ALPHA = 0x01;
|
||||
int AC_SRC_NO_ALPHA = 0x02;
|
||||
|
||||
public class BLENDFUNCTION extends Structure {
|
||||
public byte BlendOp = AC_SRC_OVER; // only valid value
|
||||
public byte BlendFlags = 0; // only valid value
|
||||
public byte SourceConstantAlpha;
|
||||
public byte AlphaFormat;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "BlendOp", "BlendFlags", "SourceConstantAlpha", "AlphaFormat"});
|
||||
}
|
||||
}
|
||||
|
||||
int VK_SHIFT = 16;
|
||||
int VK_LSHIFT = 0xA0;
|
||||
int VK_RSHIFT = 0xA1;
|
||||
int VK_CONTROL = 17;
|
||||
int VK_LCONTROL = 0xA2;
|
||||
int VK_RCONTROL = 0xA3;
|
||||
int VK_MENU = 18;
|
||||
int VK_LMENU = 0xA4;
|
||||
int VK_RMENU = 0xA5;
|
||||
|
||||
int MOD_ALT = 0x0001;
|
||||
int MOD_CONTROL = 0x0002;
|
||||
int MOD_NOREPEAT = 0x4000;
|
||||
int MOD_SHIFT = 0x0004;
|
||||
int MOD_WIN = 0x0008;
|
||||
|
||||
int WH_KEYBOARD = 2;
|
||||
int WH_MOUSE = 7;
|
||||
int WH_KEYBOARD_LL = 13;
|
||||
int WH_MOUSE_LL = 14;
|
||||
|
||||
public class HHOOK extends HANDLE {
|
||||
|
||||
}
|
||||
|
||||
public interface HOOKPROC extends StdCallCallback {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The WM_PAINT message is sent when the system or another application makes a request to paint a portion of an \
|
||||
* application's window.
|
||||
*/
|
||||
int WM_PAINT = 0x000F;
|
||||
|
||||
/**
|
||||
* Sent as a signal that a window or an application should terminate.
|
||||
*/
|
||||
int WM_CLOSE = 0x0010;
|
||||
|
||||
/**
|
||||
* Indicates a request to terminate an application, and is generated when the application calls the PostQuitMessage
|
||||
* function.
|
||||
*/
|
||||
int WM_QUIT = 0x0012;
|
||||
|
||||
/**
|
||||
* Sent to a window when the window is about to be hidden or shown.
|
||||
*/
|
||||
int WM_SHOWWINDOW = 0x0018;
|
||||
|
||||
/**
|
||||
* Sent to the parent window of an owner-drawn button, combo box, list box, or menu when a visual aspect of the
|
||||
* button, combo box, list box, or menu has changed.
|
||||
*/
|
||||
int WM_DRAWITEM = 0x002B;
|
||||
|
||||
/**
|
||||
* Posted to the window with the keyboard focus when a nonsystem key is pressed. A nonsystem key is a key that is
|
||||
* pressed when the ALT key is not pressed.
|
||||
*/
|
||||
int WM_KEYDOWN = 0x0100;
|
||||
|
||||
/**
|
||||
* Posted to the window with the keyboard focus when a WM_KEYDOWN message is translated by the TranslateMessage
|
||||
* function. The WM_CHAR message contains the character code of the key that was pressed.
|
||||
*/
|
||||
int WM_CHAR = 0x0102;
|
||||
|
||||
/**
|
||||
* A window receives this message when the user chooses a command from the Window menu (formerly known as the system
|
||||
* or control menu) or when the user chooses the maximize button, minimize button, restore button, or close button.
|
||||
*/
|
||||
int WM_SYSCOMMAND = 0x0112;
|
||||
|
||||
/**
|
||||
* An application sends the WM_MDIMAXIMIZE message to a multiple-document interface (MDI) client window to maximize
|
||||
* an MDI child window.
|
||||
*/
|
||||
int WM_MDIMAXIMIZE = 0x0225;
|
||||
|
||||
/**
|
||||
* Posted when the user presses a hot key registered by the RegisterHotKey function.
|
||||
* The message is placed at the top of the message queue associated with the thread that registered the hot key.
|
||||
*/
|
||||
int WM_HOTKEY = 0x0312;
|
||||
|
||||
int WM_KEYUP = 257;
|
||||
int WM_SYSKEYDOWN = 260;
|
||||
int WM_SYSKEYUP = 261;
|
||||
|
||||
public class KBDLLHOOKSTRUCT extends Structure {
|
||||
public int vkCode;
|
||||
public int scanCode;
|
||||
public int flags;
|
||||
public int time;
|
||||
public ULONG_PTR dwExtraInfo;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "vkCode", "scanCode", "flags", "time", "dwExtraInfo" });
|
||||
}
|
||||
}
|
||||
|
||||
int SM_CXSCREEN = 0;
|
||||
int SM_CYSCREEN = 1;
|
||||
int SM_CXVSCROLL = 2;
|
||||
int SM_CYHSCROLL = 3;
|
||||
int SM_CYCAPTION = 4;
|
||||
int SM_CXBORDER = 5;
|
||||
int SM_CYBORDER = 6;
|
||||
int SM_CXDLGFRAME = 7;
|
||||
int SM_CYDLGFRAME = 8;
|
||||
int SM_CYVTHUMB = 9;
|
||||
int SM_CXHTHUMB = 10;
|
||||
int SM_CXICON = 11;
|
||||
int SM_CYICON = 12;
|
||||
int SM_CXCURSOR = 13;
|
||||
int SM_CYCURSOR = 14;
|
||||
int SM_CYMENU = 15;
|
||||
int SM_CXFULLSCREEN = 16;
|
||||
int SM_CYFULLSCREEN = 17;
|
||||
int SM_CYKANJIWINDOW = 18;
|
||||
int SM_MOUSEPRESENT = 19;
|
||||
int SM_CYVSCROLL = 20;
|
||||
int SM_CXHSCROLL = 21;
|
||||
int SM_DEBUG = 22;
|
||||
int SM_SWAPBUTTON = 23;
|
||||
int SM_RESERVED1 = 24;
|
||||
int SM_RESERVED2 = 25;
|
||||
int SM_RESERVED3 = 26;
|
||||
int SM_RESERVED4 = 27;
|
||||
int SM_CXMIN = 28;
|
||||
int SM_CYMIN = 29;
|
||||
int SM_CXSIZE = 30;
|
||||
int SM_CYSIZE = 31;
|
||||
int SM_CXFRAME = 32;
|
||||
int SM_CYFRAME = 33;
|
||||
int SM_CXMINTRACK = 34;
|
||||
int SM_CYMINTRACK = 35;
|
||||
int SM_CXDOUBLECLK = 36;
|
||||
int SM_CYDOUBLECLK = 37;
|
||||
int SM_CXICONSPACING = 38;
|
||||
int SM_CYICONSPACING = 39;
|
||||
int SM_MENUDROPALIGNMENT = 40;
|
||||
int SM_PENWINDOWS = 41;
|
||||
int SM_DBCSENABLED = 42;
|
||||
int SM_CMOUSEBUTTONS = 43;
|
||||
|
||||
int SM_CXFIXEDFRAME = SM_CXDLGFRAME; /* ;win40 name change */
|
||||
int SM_CYFIXEDFRAME = SM_CYDLGFRAME; /* ;win40 name change */
|
||||
int SM_CXSIZEFRAME = SM_CXFRAME; /* ;win40 name change */
|
||||
int SM_CYSIZEFRAME = SM_CYFRAME; /* ;win40 name change */
|
||||
|
||||
int SM_SECURE = 44;
|
||||
int SM_CXEDGE = 45;
|
||||
int SM_CYEDGE = 46;
|
||||
int SM_CXMINSPACING = 47;
|
||||
int SM_CYMINSPACING = 48;
|
||||
int SM_CXSMICON = 49;
|
||||
int SM_CYSMICON = 50;
|
||||
int SM_CYSMCAPTION = 51;
|
||||
int SM_CXSMSIZE = 52;
|
||||
int SM_CYSMSIZE = 53;
|
||||
int SM_CXMENUSIZE = 54;
|
||||
int SM_CYMENUSIZE = 55;
|
||||
int SM_ARRANGE = 56;
|
||||
int SM_CXMINIMIZED = 57;
|
||||
int SM_CYMINIMIZED = 58;
|
||||
int SM_CXMAXTRACK = 59;
|
||||
int SM_CYMAXTRACK = 60;
|
||||
int SM_CXMAXIMIZED = 61;
|
||||
int SM_CYMAXIMIZED = 62;
|
||||
int SM_NETWORK = 63;
|
||||
int SM_CLEANBOOT = 67;
|
||||
int SM_CXDRAG = 68;
|
||||
int SM_CYDRAG = 69;
|
||||
int SM_SHOWSOUNDS = 70;
|
||||
int SM_CXMENUCHECK = 71;
|
||||
int SM_CYMENUCHECK = 72;
|
||||
int SM_SLOWMACHINE = 73;
|
||||
int SM_MIDEASTENABLED = 74;
|
||||
int SM_MOUSEWHEELPRESENT = 75;
|
||||
int SM_XVIRTUALSCREEN = 76;
|
||||
int SM_YVIRTUALSCREEN = 77;
|
||||
int SM_CXVIRTUALSCREEN = 78;
|
||||
int SM_CYVIRTUALSCREEN = 79;
|
||||
int SM_CMONITORS = 80;
|
||||
int SM_SAMEDISPLAYFORMAT = 81;
|
||||
int SM_IMMENABLED = 82;
|
||||
int SM_CXFOCUSBORDER = 83;
|
||||
int SM_CYFOCUSBORDER = 84;
|
||||
int SM_TABLETPC = 86;
|
||||
int SM_MEDIACENTER = 87;
|
||||
int SM_STARTER = 88;
|
||||
int SM_SERVERR2 = 89;
|
||||
int SM_MOUSEHORIZONTALWHEELPRESENT = 91;
|
||||
int SM_CXPADDEDBORDER = 92;
|
||||
int SM_REMOTESESSION = 0x1000;
|
||||
int SM_SHUTTINGDOWN = 0x2000;
|
||||
int SM_REMOTECONTROL = 0x2001;
|
||||
int SM_CARETBLINKINGENABLED = 0x2002;
|
||||
|
||||
int SW_HIDE = 0;
|
||||
int SW_SHOWNORMAL = 1;
|
||||
int SW_NORMAL = 1;
|
||||
int SW_SHOWMINIMIZED = 2;
|
||||
int SW_SHOWMAXIMIZED = 3;
|
||||
int SW_MAXIMIZE = 3;
|
||||
int SW_SHOWNOACTIVATE = 4;
|
||||
int SW_SHOW = 5;
|
||||
int SW_MINIMIZE = 6;
|
||||
int SW_SHOWMINNOACTIVE = 7;
|
||||
int SW_SHOWNA = 8;
|
||||
int SW_RESTORE = 9;
|
||||
int SW_SHOWDEFAULT = 10;
|
||||
int SW_FORCEMINIMIZE = 11;
|
||||
int SW_MAX = 11;
|
||||
|
||||
int RDW_INVALIDATE = 0x0001;
|
||||
int RDW_INTERNALPAINT = 0x0002;
|
||||
int RDW_ERASE = 0x0004;
|
||||
int RDW_VALIDATE = 0x0008;
|
||||
int RDW_NOINTERNALPAINT = 0x0010;
|
||||
int RDW_NOERASE = 0x0020;
|
||||
int RDW_NOCHILDREN = 0x0040;
|
||||
int RDW_ALLCHILDREN = 0x0080;
|
||||
int RDW_UPDATENOW = 0x0100;
|
||||
int RDW_ERASENOW = 0x0200;
|
||||
int RDW_FRAME = 0x0400;
|
||||
int RDW_NOFRAME = 0x0800;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the window of the same type that is highest in the Z order.
|
||||
*
|
||||
* If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a
|
||||
* top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle
|
||||
* identifies a sibling window.
|
||||
*/
|
||||
int GW_HWNDFIRST = 0;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the window of the same type that is lowest in the Z order.
|
||||
*
|
||||
* If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a
|
||||
* top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle
|
||||
* identifies a sibling window.
|
||||
*/
|
||||
int GW_HWNDLAST = 1;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the window below the specified window in the Z order.
|
||||
*
|
||||
* If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a
|
||||
* top-level window, the handle identifies a top-level window. If the specified window is a child window, the handle
|
||||
* identifies a sibling window.
|
||||
*/
|
||||
int GW_HWNDNEXT = 2;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the window above the specified window in the Z order.
|
||||
*
|
||||
* If the specified window is a topmost window, the handle identifies a topmost window. If the specified window is a
|
||||
* top-level window, the handle identifies a top-level window. If the specified window is a child window, the
|
||||
* handle identifies a sibling window.
|
||||
*/
|
||||
int GW_HWNDPREV = 3;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the specified window's owner window, if any. For more information, see Owned
|
||||
* Windows.
|
||||
*/
|
||||
int GW_OWNER = 4;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the child window at the top of the Z order, if the specified window is a parent
|
||||
* window; otherwise, the retrieved handle is NULL. The function examines only child windows of the specified
|
||||
* window. It does not examine descendant windows.
|
||||
*/
|
||||
int GW_CHILD = 5;
|
||||
|
||||
/**
|
||||
* The retrieved handle identifies the enabled popup window owned by the specified window (the search uses the first
|
||||
* such window found using GW_HWNDNEXT); otherwise, if there are no enabled popup windows, the retrieved handle is
|
||||
* that of the specified window.
|
||||
*/
|
||||
int GW_ENABLEDPOPUP = 6;
|
||||
|
||||
/**
|
||||
* Retains the current Z order (ignores the hWndInsertAfter parameter).
|
||||
*/
|
||||
int SWP_NOZORDER = 0x0004;
|
||||
|
||||
/**
|
||||
* Minimizes the window.
|
||||
*/
|
||||
int SC_MINIMIZE = 0xF020;
|
||||
|
||||
/**
|
||||
* Maximizes the window.
|
||||
*/
|
||||
int SC_MAXIMIZE = 0xF030;
|
||||
|
||||
/**
|
||||
* Contains information about a simulated message generated by an input device other than a keyboard or mouse.
|
||||
*/
|
||||
public static class HARDWAREINPUT extends Structure {
|
||||
|
||||
public static class ByReference extends HARDWAREINPUT implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public HARDWAREINPUT() {
|
||||
}
|
||||
|
||||
public HARDWAREINPUT(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WinDef.DWORD uMsg;
|
||||
public WinDef.WORD wParamL;
|
||||
public WinDef.WORD wParamH;
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "uMsg", "wParamL", "wParamH" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by SendInput to store information for synthesizing input events such as keystrokes, mouse movement, and mouse
|
||||
* clicks.
|
||||
*/
|
||||
public static class INPUT extends Structure {
|
||||
|
||||
public static final int INPUT_MOUSE = 0;
|
||||
public static final int INPUT_KEYBOARD = 1;
|
||||
public static final int INPUT_HARDWARE = 2;
|
||||
|
||||
public static class ByReference extends INPUT implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public INPUT() {
|
||||
}
|
||||
|
||||
public INPUT(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WinDef.DWORD type;
|
||||
public INPUT_UNION input = new INPUT_UNION();
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "type", "input" });
|
||||
}
|
||||
|
||||
public static class INPUT_UNION extends Union {
|
||||
|
||||
public INPUT_UNION() {
|
||||
}
|
||||
|
||||
public INPUT_UNION(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public MOUSEINPUT mi;
|
||||
public KEYBDINPUT ki;
|
||||
public HARDWAREINPUT hi;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information about a simulated keyboard event.
|
||||
*/
|
||||
public static class KEYBDINPUT extends Structure {
|
||||
|
||||
/**
|
||||
* If specified, the scan code was preceded by a prefix byte that has the value 0xE0 (224).
|
||||
*/
|
||||
public static final int KEYEVENTF_EXTENDEDKEY = 0x0001;
|
||||
|
||||
/**
|
||||
* If specified, the key is being released. If not specified, the key is being pressed.
|
||||
*/
|
||||
public static final int KEYEVENTF_KEYUP = 0x0002;
|
||||
|
||||
/**
|
||||
* If specified, the system synthesizes a VK_PACKET keystroke. The wVk parameter must be zero. This flag can only be
|
||||
* combined with the KEYEVENTF_KEYUP flag. For more information, see the Remarks section.
|
||||
*/
|
||||
public static final int KEYEVENTF_UNICODE = 0x0004;
|
||||
|
||||
/**
|
||||
* If specified, wScan identifies the key and wVk is ignored.
|
||||
*/
|
||||
public static final int KEYEVENTF_SCANCODE = 0x0008;
|
||||
|
||||
public static class ByReference extends KEYBDINPUT implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public KEYBDINPUT() {
|
||||
}
|
||||
|
||||
public KEYBDINPUT(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* A virtual-key code. The code must be a value in the range 1 to 254. If the dwFlags member specifies
|
||||
* KEYEVENTF_UNICODE, wVk must be 0.
|
||||
*/
|
||||
public WinDef.WORD wVk;
|
||||
|
||||
/**
|
||||
* A hardware scan code for the key. If dwFlags specifies KEYEVENTF_UNICODE, wScan specifies a Unicode character
|
||||
* which is to be sent to the foreground application.
|
||||
*/
|
||||
public WinDef.WORD wScan;
|
||||
|
||||
/**
|
||||
* Specifies various aspects of a keystroke. This member can be certain combinations of the following values.
|
||||
*/
|
||||
public WinDef.DWORD dwFlags;
|
||||
|
||||
/**
|
||||
* The time stamp for the event, in milliseconds. If this parameter is zero, the system will provide its own time
|
||||
* stamp.
|
||||
*/
|
||||
public WinDef.DWORD time;
|
||||
|
||||
/**
|
||||
* An additional value associated with the keystroke. Use the GetMessageExtraInfo function to obtain this
|
||||
* information.
|
||||
*/
|
||||
public BaseTSD.ULONG_PTR dwExtraInfo;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "wVk", "wScan", "dwFlags", "time", "dwExtraInfo" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains information about a simulated mouse event.
|
||||
*/
|
||||
public static class MOUSEINPUT extends Structure {
|
||||
|
||||
public static class ByReference extends MOUSEINPUT implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public MOUSEINPUT() {
|
||||
}
|
||||
|
||||
public MOUSEINPUT(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
public WinDef.LONG dx;
|
||||
public WinDef.LONG dy;
|
||||
public WinDef.DWORD mouseData;
|
||||
public WinDef.DWORD dwFlags;
|
||||
public WinDef.DWORD time;
|
||||
public BaseTSD.ULONG_PTR dwExtraInfo;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dx", "dy", "mouseData", "dwFlags", "time", "dwExtraInfo" });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains the time of the last input.
|
||||
*/
|
||||
public static class LASTINPUTINFO extends Structure {
|
||||
public int cbSize = size();
|
||||
|
||||
// Tick count of when the last input event was received.
|
||||
public int dwTime;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "cbSize", "dwTime" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* Interface for the Winioctl.h header file.
|
||||
*/
|
||||
public interface Winioctl extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Retrieves the device type, device number, and, for a partitionable device, the partition number of a device.
|
||||
*/
|
||||
int IOCTL_STORAGE_GET_DEVICE_NUMBER = 0x2D1080;
|
||||
|
||||
/**
|
||||
* Contains information about a device. This structure is used by the IOCTL_STORAGE_GET_DEVICE_NUMBER control code.
|
||||
*/
|
||||
public static class STORAGE_DEVICE_NUMBER extends Structure {
|
||||
|
||||
public static class ByReference extends STORAGE_DEVICE_NUMBER implements Structure.ByReference {
|
||||
public ByReference() {
|
||||
}
|
||||
|
||||
public ByReference(Pointer memory) {
|
||||
super(memory);
|
||||
}
|
||||
}
|
||||
|
||||
public STORAGE_DEVICE_NUMBER() {
|
||||
}
|
||||
|
||||
public STORAGE_DEVICE_NUMBER(Pointer memory) {
|
||||
super(memory);
|
||||
read();
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of device. Values from 0 through 32,767 are reserved for use by Microsoft. Values from 32,768
|
||||
* through 65,535 are reserved for use by other vendors.
|
||||
*/
|
||||
public int DeviceType;
|
||||
|
||||
/**
|
||||
* The number of this device.
|
||||
*/
|
||||
public int DeviceNumber;
|
||||
|
||||
/**
|
||||
* The partition number of the device, if the device can be partitioned. Otherwise, this member is -1.
|
||||
*/
|
||||
public int PartitionNumber;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "DeviceType", "DeviceNumber", "PartitionNumber" });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/**
|
||||
* Ported from Winspool.h.
|
||||
* Windows SDK 6.0a
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public interface Winspool extends StdCallLibrary {
|
||||
|
||||
Winspool INSTANCE = (Winspool) Native.loadLibrary("Winspool.drv", Winspool.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
/**
|
||||
* The EnumPrinters function enumerates available printers, print servers, domains, or print providers.
|
||||
* @param Flags
|
||||
* The types of print objects that the function should enumerate.
|
||||
* @param Name
|
||||
* If Level is 1, Flags contains PRINTER_ENUM_NAME, and Name is non-NULL, then Name is a pointer
|
||||
* to a null-terminated string that specifies the name of the object to enumerate. This string can
|
||||
* be the name of a server, a domain, or a print provider.
|
||||
* If Level is 1, Flags contains PRINTER_ENUM_NAME, and Name is NULL, then the function enumerates
|
||||
* the available print providers.
|
||||
* If Level is 1, Flags contains PRINTER_ENUM_REMOTE, and Name is NULL, then the function enumerates
|
||||
* the printers in the user's domain.
|
||||
* If Level is 2 or 5,Name is a pointer to a null-terminated string that specifies the name of a
|
||||
* server whose printers are to be enumerated. If this string is NULL, then the function enumerates
|
||||
* the printers installed on the local computer.
|
||||
* If Level is 4, Name should be NULL. The function always queries on the local computer.
|
||||
* When Name is NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS enumerates
|
||||
* printers that are installed on the local machine. These printers include those that are physically
|
||||
* attached to the local machine as well as remote printers to which it has a network connection.
|
||||
* When Name is not NULL, setting Flags to PRINTER_ENUM_LOCAL | PRINTER_ENUM_NAME enumerates the
|
||||
* local printers that are installed on the server Name.
|
||||
* @param Level
|
||||
* The type of data structures pointed to by pPrinterEnum. Valid values are 1, 2, 4, and 5, which
|
||||
* correspond to the PRINTER_INFO_1, PRINTER_INFO_2 , PRINTER_INFO_4, and PRINTER_INFO_5 data
|
||||
* structures.
|
||||
* @param pPrinterEnum
|
||||
* A pointer to a buffer that receives an array of PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_4,
|
||||
* or PRINTER_INFO_5 structures. Each structure contains data that describes an available print
|
||||
* object.
|
||||
* If Level is 1, the array contains PRINTER_INFO_1 structures. If Level is 2, the array contains
|
||||
* PRINTER_INFO_2 structures. If Level is 4, the array contains PRINTER_INFO_4 structures. If Level
|
||||
* is 5, the array contains PRINTER_INFO_5 structures.
|
||||
* The buffer must be large enough to receive the array of data structures and any strings or other
|
||||
* data to which the structure members point. If the buffer is too small, the pcbNeeded parameter
|
||||
* returns the required buffer size.
|
||||
* @param cbBuf
|
||||
* The size, in bytes, of the buffer pointed to by pPrinterEnum.
|
||||
* @param pcbNeeded
|
||||
* A pointer to a value that receives the number of bytes copied if the function succeeds or the
|
||||
* number of bytes required if cbBuf is too small.
|
||||
* @param pcReturned
|
||||
* A pointer to a value that receives the number of PRINTER_INFO_1, PRINTER_INFO_2 , PRINTER_INFO_4,
|
||||
* or PRINTER_INFO_5 structures that the function returns in the array to which pPrinterEnum points.
|
||||
* @return
|
||||
* If the function succeeds, the return value is a nonzero value.
|
||||
* If the function fails, the return value is zero.
|
||||
*/
|
||||
boolean EnumPrinters(int Flags, String Name, int Level, Pointer pPrinterEnum,
|
||||
int cbBuf, IntByReference pcbNeeded, IntByReference pcReturned);
|
||||
|
||||
public static class PRINTER_INFO_1 extends Structure {
|
||||
public int Flags;
|
||||
public String pDescription;
|
||||
public String pName;
|
||||
public String pComment;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "Flags", "pDescription", "pName", "pComment" });
|
||||
}
|
||||
|
||||
public PRINTER_INFO_1() {
|
||||
}
|
||||
|
||||
public PRINTER_INFO_1(int size) {
|
||||
super(new Memory(size));
|
||||
}
|
||||
}
|
||||
|
||||
public static class PRINTER_INFO_4 extends Structure {
|
||||
public String pPrinterName;
|
||||
public String pServerName;
|
||||
public DWORD Attributes;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "pPrinterName", "pServerName", "Attributes" });
|
||||
}
|
||||
|
||||
public PRINTER_INFO_4() {
|
||||
}
|
||||
|
||||
public PRINTER_INFO_4(int size) {
|
||||
super(new Memory(size));
|
||||
}
|
||||
}
|
||||
|
||||
int PRINTER_ENUM_DEFAULT = 0x00000001;
|
||||
int PRINTER_ENUM_LOCAL = 0x00000002;
|
||||
int PRINTER_ENUM_CONNECTIONS = 0x00000004;
|
||||
int PRINTER_ENUM_FAVORITE = 0x00000004;
|
||||
int PRINTER_ENUM_NAME = 0x00000008;
|
||||
int PRINTER_ENUM_REMOTE = 0x00000010;
|
||||
int PRINTER_ENUM_SHARED = 0x00000020;
|
||||
int PRINTER_ENUM_NETWORK = 0x00000040;
|
||||
|
||||
int PRINTER_ENUM_EXPAND = 0x00004000;
|
||||
int PRINTER_ENUM_CONTAINER = 0x00008000;
|
||||
|
||||
int PRINTER_ENUM_ICONMASK = 0x00ff0000;
|
||||
int PRINTER_ENUM_ICON1 = 0x00010000;
|
||||
int PRINTER_ENUM_ICON2 = 0x00020000;
|
||||
int PRINTER_ENUM_ICON3 = 0x00040000;
|
||||
int PRINTER_ENUM_ICON4 = 0x00080000;
|
||||
int PRINTER_ENUM_ICON5 = 0x00100000;
|
||||
int PRINTER_ENUM_ICON6 = 0x00200000;
|
||||
int PRINTER_ENUM_ICON7 = 0x00400000;
|
||||
int PRINTER_ENUM_ICON8 = 0x00800000;
|
||||
int PRINTER_ENUM_HIDE = 0x01000000;
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_1;
|
||||
import com.sun.jna.platform.win32.Winspool.PRINTER_INFO_4;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
/**
|
||||
* Winspool Utility API.
|
||||
*
|
||||
* @author dblock[at]dblock.org
|
||||
*/
|
||||
public abstract class WinspoolUtil {
|
||||
|
||||
public static PRINTER_INFO_1[] getPrinterInfo1() {
|
||||
IntByReference pcbNeeded = new IntByReference();
|
||||
IntByReference pcReturned = new IntByReference();
|
||||
Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
|
||||
null, 1, null, 0, pcbNeeded, pcReturned);
|
||||
if (pcbNeeded.getValue() <= 0) {
|
||||
return new PRINTER_INFO_1[0];
|
||||
}
|
||||
|
||||
PRINTER_INFO_1 pPrinterEnum = new PRINTER_INFO_1(pcbNeeded.getValue());
|
||||
if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
|
||||
null, 1, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
pPrinterEnum.read();
|
||||
|
||||
return (PRINTER_INFO_1[]) pPrinterEnum.toArray(pcReturned.getValue());
|
||||
}
|
||||
|
||||
public static PRINTER_INFO_4[] getPrinterInfo4() {
|
||||
IntByReference pcbNeeded = new IntByReference();
|
||||
IntByReference pcReturned = new IntByReference();
|
||||
Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
|
||||
null, 4, null, 0, pcbNeeded, pcReturned);
|
||||
if (pcbNeeded.getValue() <= 0) {
|
||||
return new PRINTER_INFO_4[0];
|
||||
}
|
||||
|
||||
PRINTER_INFO_4 pPrinterEnum = new PRINTER_INFO_4(pcbNeeded.getValue());
|
||||
if (!Winspool.INSTANCE.EnumPrinters(Winspool.PRINTER_ENUM_LOCAL,
|
||||
null, 4, pPrinterEnum.getPointer(), pcbNeeded.getValue(), pcbNeeded, pcReturned)) {
|
||||
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
pPrinterEnum.read();
|
||||
|
||||
return (PRINTER_INFO_4[]) pPrinterEnum.toArray(pcReturned.getValue());
|
||||
}
|
||||
}
|
||||
@@ -1,300 +0,0 @@
|
||||
/* Copyright (c) 2010 EugineLev, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Structure;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.win32.StdCallLibrary;
|
||||
|
||||
/**
|
||||
* This module defines the 32-Bit Windows types and constants that are defined
|
||||
* by NT, but exposed through the Win32 API.
|
||||
* Ported from Winsvc.h.
|
||||
* Microsoft Windows SDK 7.0A.
|
||||
* @author EugineLev
|
||||
*/
|
||||
public interface Winsvc extends StdCallLibrary {
|
||||
|
||||
/**
|
||||
* Contains status information for a service. The ControlService, EnumDependentServices,
|
||||
* EnumServicesStatus, and QueryServiceStatus functions use this structure. A service
|
||||
* uses this structure in the SetServiceStatus function to report its current status
|
||||
* to the service control manager.
|
||||
*/
|
||||
public static class SERVICE_STATUS extends Structure {
|
||||
|
||||
/**
|
||||
* dwServiceType - the type of service. This member can be one
|
||||
* of the following values:
|
||||
* SERVICE_KERNEL_DRIVER, SERVICE_FILE_SYSTEM_DRIVER,
|
||||
* SERVICE_WIN32_OWN_PROCESS, SERVICE_WIN32_SHARE_PROCESS,
|
||||
|
||||
* If the service type is either SERVICE_WIN32_OWN_PROCESS or
|
||||
* SERVICE_WIN32_SHARE_PROCESS, and the service is running in the
|
||||
* context of the LocalSystem account, the following type may also
|
||||
* be specified:
|
||||
* SERVICE_INTERACTIVE_PROCESS
|
||||
*
|
||||
* These values can be found in WinNT.h
|
||||
*/
|
||||
public int dwServiceType;
|
||||
|
||||
/**
|
||||
* dwCurrentState - The current state of the service.
|
||||
* This member can be one of the following values:
|
||||
* SERVICE_STOPPED, SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING,
|
||||
* SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, SERVICE_PAUSED
|
||||
*/
|
||||
public int dwCurrentState;
|
||||
|
||||
/**
|
||||
* dwControlsAccepted - The control codes the service accepts and processes
|
||||
* in its handler function:
|
||||
* SERVICE_ACCEPT_STOP, SERVICE_ACCEPT_PAUSE_CONTINUE, SERVICE_ACCEPT_SHUTDOWN,
|
||||
* SERVICE_ACCEPT_PARAMCHANGE, SERVICE_ACCEPT_NETBINDCHANGE, SERVICE_ACCEPT_HARDWAREPROFILECHANGE,
|
||||
* SERVICE_ACCEPT_POWEREVENT, SERVICE_ACCEPT_SESSIONCHANGE, SERVICE_ACCEPT_PRESHUTDOWN,
|
||||
* SERVICE_ACCEPT_TIMECHANGE, SERVICE_ACCEPT_TRIGGEREVENT
|
||||
*/
|
||||
public int dwControlsAccepted;
|
||||
|
||||
/**
|
||||
* dwWin32ExitCode - The error code the service uses to report an error that occurs
|
||||
* when it is starting or stopping. To return an error code specific to the service,
|
||||
* the service must set this value to ERROR_SERVICE_SPECIFIC_ERROR to indicate that
|
||||
* the dwServiceSpecificExitCode member contains the error code. The service should
|
||||
* set this value to NO_ERROR when it is running and on normal termination.
|
||||
*/
|
||||
public int dwWin32ExitCode;
|
||||
|
||||
/**
|
||||
* dwServiceSpecificExitCode - A service-specific error code that the service returns
|
||||
* when an error occurs while the service is starting or stopping. This value is
|
||||
* ignored unless the dwWin32ExitCode member is set to ERROR_SERVICE_SPECIFIC_ERROR.
|
||||
*/
|
||||
public int dwServiceSpecificExitCode;
|
||||
|
||||
/**
|
||||
* dwCheckPoint - The check-point value the service increments periodically to report
|
||||
* its progress during a lengthy start, stop, pause, or continue operation.
|
||||
*/
|
||||
public int dwCheckPoint;
|
||||
|
||||
/**
|
||||
* dwWaitHint - The estimated time required for a pending start, stop, pause, or continue
|
||||
* operation, in milliseconds.
|
||||
*/
|
||||
public int dwWaitHint;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint" });
|
||||
}
|
||||
|
||||
public SERVICE_STATUS() {
|
||||
super();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains process status information for a service. The ControlServiceEx,
|
||||
* EnumServicesStatusEx, NotifyServiceStatusChange, and QueryServiceStatusEx
|
||||
* functions use this structure.
|
||||
*/
|
||||
public class SERVICE_STATUS_PROCESS extends Structure {
|
||||
/**
|
||||
* dwServiceType - the type of service. This member can be one
|
||||
* of the following values:
|
||||
* SERVICE_KERNEL_DRIVER, SERVICE_FILE_SYSTEM_DRIVER,
|
||||
* SERVICE_WIN32_OWN_PROCESS, SERVICE_WIN32_SHARE_PROCESS,
|
||||
|
||||
* If the service type is either SERVICE_WIN32_OWN_PROCESS or
|
||||
* SERVICE_WIN32_SHARE_PROCESS, and the service is running in the
|
||||
* context of the LocalSystem account, the following type may also
|
||||
* be specified:
|
||||
* SERVICE_INTERACTIVE_PROCESS
|
||||
*
|
||||
* These values can be found in WinNT.h
|
||||
*/
|
||||
public int dwServiceType;
|
||||
|
||||
/**
|
||||
* dwCurrentState - The current state of the service.
|
||||
* This member can be one of the following values:
|
||||
* SERVICE_STOPPED, SERVICE_START_PENDING, SERVICE_STOP_PENDING, SERVICE_RUNNING,
|
||||
* SERVICE_CONTINUE_PENDING, SERVICE_PAUSE_PENDING, SERVICE_PAUSED
|
||||
*/
|
||||
public int dwCurrentState;
|
||||
|
||||
/**
|
||||
* dwControlsAccepted - The control codes the service accepts and processes
|
||||
* in its handler function:
|
||||
* SERVICE_ACCEPT_STOP, SERVICE_ACCEPT_PAUSE_CONTINUE, SERVICE_ACCEPT_SHUTDOWN,
|
||||
* SERVICE_ACCEPT_PARAMCHANGE, SERVICE_ACCEPT_NETBINDCHANGE, SERVICE_ACCEPT_HARDWAREPROFILECHANGE,
|
||||
* SERVICE_ACCEPT_POWEREVENT, SERVICE_ACCEPT_SESSIONCHANGE, SERVICE_ACCEPT_PRESHUTDOWN,
|
||||
* SERVICE_ACCEPT_TIMECHANGE, SERVICE_ACCEPT_TRIGGEREVENT
|
||||
*/
|
||||
public int dwControlsAccepted;
|
||||
|
||||
/**
|
||||
* dwWin32ExitCode - The error code the service uses to report an error that occurs
|
||||
* when it is starting or stopping. To return an error code specific to the service,
|
||||
* the service must set this value to ERROR_SERVICE_SPECIFIC_ERROR to indicate that
|
||||
* the dwServiceSpecificExitCode member contains the error code. The service should
|
||||
* set this value to NO_ERROR when it is running and on normal termination.
|
||||
*/
|
||||
public int dwWin32ExitCode;
|
||||
|
||||
/**
|
||||
* dwServiceSpecificExitCode - A service-specific error code that the service returns
|
||||
* when an error occurs while the service is starting or stopping. This value is
|
||||
* ignored unless the dwWin32ExitCode member is set to ERROR_SERVICE_SPECIFIC_ERROR.
|
||||
*/
|
||||
public int dwServiceSpecificExitCode;
|
||||
|
||||
/**
|
||||
* dwCheckPoint - The check-point value the service increments periodically to report
|
||||
* its progress during a lengthy start, stop, pause, or continue operation.
|
||||
*/
|
||||
public int dwCheckPoint;
|
||||
|
||||
/**
|
||||
* dwWaitHint - The estimated time required for a pending start, stop, pause, or continue
|
||||
* operation, in milliseconds.
|
||||
*/
|
||||
public int dwWaitHint;
|
||||
|
||||
/**
|
||||
* dwProcessId - The process identifier of the service.
|
||||
*/
|
||||
public int dwProcessId;
|
||||
|
||||
/**
|
||||
* This member can be one of the following values: 0, or SERVICE_RUNS_IN_SYSTEM_PROCESS
|
||||
*/
|
||||
public int dwServiceFlags;
|
||||
|
||||
protected List getFieldOrder() {
|
||||
return Arrays.asList(new String[] { "dwServiceType", "dwCurrentState", "dwControlsAccepted", "dwWin32ExitCode", "dwServiceSpecificExitCode", "dwCheckPoint", "dwWaitHint", "dwProcessId", "dwServiceFlags" });
|
||||
}
|
||||
|
||||
public SERVICE_STATUS_PROCESS() {
|
||||
}
|
||||
|
||||
public SERVICE_STATUS_PROCESS(int size) {
|
||||
super(new Memory(size));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Service flags for QueryServiceStatusEx
|
||||
//
|
||||
int SERVICE_RUNS_IN_SYSTEM_PROCESS = 0x00000001;
|
||||
|
||||
public static class SC_HANDLE extends HANDLE { }
|
||||
|
||||
//
|
||||
// Service Control Manager object specific access types
|
||||
//
|
||||
int SC_MANAGER_CONNECT = 0x0001;
|
||||
int SC_MANAGER_CREATE_SERVICE = 0x0002;
|
||||
int SC_MANAGER_ENUMERATE_SERVICE = 0x0004;
|
||||
int SC_MANAGER_LOCK = 0x0008;
|
||||
int SC_MANAGER_QUERY_LOCK_STATUS = 0x0010;
|
||||
int SC_MANAGER_MODIFY_BOOT_CONFIG = 0x0020;
|
||||
|
||||
int SC_MANAGER_ALL_ACCESS =
|
||||
WinNT.STANDARD_RIGHTS_REQUIRED | SC_MANAGER_CONNECT
|
||||
| SC_MANAGER_CREATE_SERVICE | SC_MANAGER_ENUMERATE_SERVICE
|
||||
| SC_MANAGER_LOCK | SC_MANAGER_QUERY_LOCK_STATUS
|
||||
| SC_MANAGER_MODIFY_BOOT_CONFIG;
|
||||
|
||||
//
|
||||
// Service object specific access type
|
||||
//
|
||||
int SERVICE_QUERY_CONFIG = 0x0001;
|
||||
int SERVICE_CHANGE_CONFIG = 0x0002;
|
||||
int SERVICE_QUERY_STATUS = 0x0004;
|
||||
int SERVICE_ENUMERATE_DEPENDENTS = 0x0008;
|
||||
int SERVICE_START = 0x0010;
|
||||
int SERVICE_STOP = 0x0020;
|
||||
int SERVICE_PAUSE_CONTINUE = 0x0040;
|
||||
int SERVICE_INTERROGATE = 0x0080;
|
||||
int SERVICE_USER_DEFINED_CONTROL = 0x0100;
|
||||
|
||||
int SERVICE_ALL_ACCESS =
|
||||
WinNT.STANDARD_RIGHTS_REQUIRED | SERVICE_QUERY_CONFIG
|
||||
| SERVICE_CHANGE_CONFIG | SERVICE_QUERY_STATUS
|
||||
| SERVICE_ENUMERATE_DEPENDENTS | SERVICE_START | SERVICE_STOP
|
||||
| SERVICE_PAUSE_CONTINUE | SERVICE_INTERROGATE
|
||||
| SERVICE_USER_DEFINED_CONTROL;
|
||||
|
||||
//
|
||||
// Controls
|
||||
//
|
||||
int SERVICE_CONTROL_STOP = 0x00000001;
|
||||
int SERVICE_CONTROL_PAUSE = 0x00000002;
|
||||
int SERVICE_CONTROL_CONTINUE = 0x00000003;
|
||||
int SERVICE_CONTROL_INTERROGATE = 0x00000004;
|
||||
// int SERVICE_CONTROL_SHUTDOWN = 0x00000005;
|
||||
int SERVICE_CONTROL_PARAMCHANGE = 0x00000006;
|
||||
int SERVICE_CONTROL_NETBINDADD = 0x00000007;
|
||||
int SERVICE_CONTROL_NETBINDREMOVE = 0x00000008;
|
||||
int SERVICE_CONTROL_NETBINDENABLE = 0x00000009;
|
||||
int SERVICE_CONTROL_NETBINDDISABLE = 0x0000000A;
|
||||
// int SERVICE_CONTROL_DEVICEEVENT = 0x0000000B;
|
||||
// int SERVICE_CONTROL_HARDWAREPROFILECHANGE = 0x0000000C;
|
||||
// int SERVICE_CONTROL_POWEREVENT = 0x0000000D;
|
||||
// int SERVICE_CONTROL_SESSIONCHANGE = 0x0000000E;
|
||||
// int SERVICE_CONTROL_PRESHUTDOWN = 0x0000000F;
|
||||
// int SERVICE_CONTROL_TIMECHANGE = 0x00000010;
|
||||
// int SERVICE_CONTROL_TRIGGEREVENT = 0x00000020;
|
||||
|
||||
//
|
||||
// Service State -- for CurrentState
|
||||
//
|
||||
int SERVICE_STOPPED = 0x00000001;
|
||||
int SERVICE_START_PENDING = 0x00000002;
|
||||
int SERVICE_STOP_PENDING = 0x00000003;
|
||||
int SERVICE_RUNNING = 0x00000004;
|
||||
int SERVICE_CONTINUE_PENDING = 0x00000005;
|
||||
int SERVICE_PAUSE_PENDING = 0x00000006;
|
||||
int SERVICE_PAUSED = 0x00000007;
|
||||
|
||||
//
|
||||
// Controls Accepted (Bit Mask)
|
||||
//
|
||||
int SERVICE_ACCEPT_STOP = 0x00000001;
|
||||
int SERVICE_ACCEPT_PAUSE_CONTINUE = 0x00000002;
|
||||
int SERVICE_ACCEPT_SHUTDOWN = 0x00000004;
|
||||
int SERVICE_ACCEPT_PARAMCHANGE = 0x00000008;
|
||||
int SERVICE_ACCEPT_NETBINDCHANGE = 0x00000010;
|
||||
int SERVICE_ACCEPT_HARDWAREPROFILECHANGE = 0x00000020;
|
||||
int SERVICE_ACCEPT_POWEREVENT = 0x00000040;
|
||||
int SERVICE_ACCEPT_SESSIONCHANGE = 0x00000080;
|
||||
int SERVICE_ACCEPT_PRESHUTDOWN = 0x00000100;
|
||||
int SERVICE_ACCEPT_TIMECHANGE = 0x00000200;
|
||||
int SERVICE_ACCEPT_TRIGGEREVENT = 0x00000400;
|
||||
|
||||
/**
|
||||
* The SC_STATUS_TYPE enumeration type contains values
|
||||
*/
|
||||
public abstract class SC_STATUS_TYPE {
|
||||
public static final int SC_STATUS_PROCESS_INFO = 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/* Copyright (c) 2011 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
* <p/>
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.wince;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.platform.win32.WinNT;
|
||||
import com.sun.jna.win32.W32APIOptions;
|
||||
|
||||
/** Definition <code>coredll.dll</code>.
|
||||
Add other win32 interface mappings as needed.
|
||||
*/
|
||||
public interface CoreDLL extends WinNT {
|
||||
|
||||
CoreDLL INSTANCE = (CoreDLL)
|
||||
Native.loadLibrary("coredll", CoreDLL.class,
|
||||
W32APIOptions.UNICODE_OPTIONS);
|
||||
|
||||
}
|
||||
@@ -1,817 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.LMAccess.USER_INFO_1;
|
||||
import com.sun.jna.platform.win32.WinBase.FILETIME;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinNT.EVENTLOGRECORD;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.PSIDByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.SECURITY_IMPERSONATION_LEVEL;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_AND_ATTRIBUTES;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_NAME_USE;
|
||||
import com.sun.jna.platform.win32.WinNT.TOKEN_PRIVILEGES;
|
||||
import com.sun.jna.platform.win32.WinNT.TOKEN_TYPE;
|
||||
import com.sun.jna.platform.win32.WinNT.WELL_KNOWN_SID_TYPE;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
import com.sun.jna.platform.win32.Winsvc.SC_HANDLE;
|
||||
import com.sun.jna.platform.win32.Winsvc.SC_STATUS_TYPE;
|
||||
import com.sun.jna.platform.win32.Winsvc.SERVICE_STATUS_PROCESS;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Advapi32Test extends TestCase {
|
||||
|
||||
private static final String EVERYONE = "S-1-1-0";
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Advapi32Test.class);
|
||||
}
|
||||
|
||||
public void testGetUserName() {
|
||||
IntByReference len = new IntByReference();
|
||||
assertFalse(Advapi32.INSTANCE.GetUserNameW(null, len));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
char[] buffer = new char[len.getValue()];
|
||||
assertTrue(Advapi32.INSTANCE.GetUserNameW(buffer, len));
|
||||
String username = Native.toString(buffer);
|
||||
assertTrue(username.length() > 0);
|
||||
}
|
||||
|
||||
public void testLookupAccountName() {
|
||||
IntByReference pSid = new IntByReference(0);
|
||||
IntByReference pDomain = new IntByReference(0);
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
String accountName = "Administrator";
|
||||
assertFalse(Advapi32.INSTANCE.LookupAccountName(
|
||||
null, accountName, null, pSid, null, pDomain, peUse));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
assertTrue(pSid.getValue() > 0);
|
||||
Memory sidMemory = new Memory(pSid.getValue());
|
||||
PSID pSidMemory = new PSID(sidMemory);
|
||||
char[] referencedDomainName = new char[pDomain.getValue() + 1];
|
||||
assertTrue(Advapi32.INSTANCE.LookupAccountName(
|
||||
null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
|
||||
assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
|
||||
assertTrue(Native.toString(referencedDomainName).length() > 0);
|
||||
}
|
||||
|
||||
public void testIsValidSid() {
|
||||
String sidString = EVERYONE;
|
||||
PSIDByReference sid = new PSIDByReference();
|
||||
assertTrue("SID conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
|
||||
assertTrue("Converted SID not valid: " + sid.getValue(), Advapi32.INSTANCE.IsValidSid(sid.getValue()));
|
||||
int sidLength = Advapi32.INSTANCE.GetLengthSid(sid.getValue());
|
||||
assertTrue(sidLength > 0);
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(sid.getValue()));
|
||||
}
|
||||
|
||||
public void testGetSidLength() {
|
||||
String sidString = EVERYONE;
|
||||
PSIDByReference sid = new PSIDByReference();
|
||||
assertTrue("SID conversion failed", Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
|
||||
assertEquals("Wrong SID lenght", 12, Advapi32.INSTANCE.GetLengthSid(sid.getValue()));
|
||||
}
|
||||
|
||||
public void testLookupAccountSid() {
|
||||
// get SID bytes
|
||||
String sidString = EVERYONE;
|
||||
PSIDByReference sid = new PSIDByReference();
|
||||
assertTrue(Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
|
||||
int sidLength = Advapi32.INSTANCE.GetLengthSid(sid.getValue());
|
||||
assertTrue(sidLength > 0);
|
||||
// lookup account
|
||||
IntByReference cchName = new IntByReference();
|
||||
IntByReference cchReferencedDomainName = new IntByReference();
|
||||
PointerByReference peUse = new PointerByReference();
|
||||
assertFalse(Advapi32.INSTANCE.LookupAccountSid(null, sid.getValue(),
|
||||
null, cchName, null, cchReferencedDomainName, peUse));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
assertTrue(cchName.getValue() > 0);
|
||||
assertTrue(cchReferencedDomainName.getValue() > 0);
|
||||
char[] referencedDomainName = new char[cchReferencedDomainName.getValue()];
|
||||
char[] name = new char[cchName.getValue()];
|
||||
assertTrue(Advapi32.INSTANCE.LookupAccountSid(null, sid.getValue(),
|
||||
name, cchName, referencedDomainName, cchReferencedDomainName, peUse));
|
||||
assertEquals(5, peUse.getPointer().getInt(0)); // SidTypeWellKnownGroup
|
||||
String nameString = Native.toString(name);
|
||||
String referencedDomainNameString = Native.toString(referencedDomainName);
|
||||
assertTrue(nameString.length() > 0);
|
||||
assertEquals("Everyone", nameString);
|
||||
assertTrue(referencedDomainNameString.length() == 0);
|
||||
assertEquals(null, Kernel32.INSTANCE.LocalFree(sid.getValue().getPointer()));
|
||||
}
|
||||
|
||||
public void testConvertSid() {
|
||||
String sidString = EVERYONE;
|
||||
PSIDByReference sid = new PSIDByReference();
|
||||
assertTrue(Advapi32.INSTANCE.ConvertStringSidToSid(
|
||||
sidString, sid));
|
||||
PointerByReference convertedSidStringPtr = new PointerByReference();
|
||||
assertTrue(Advapi32.INSTANCE.ConvertSidToStringSid(
|
||||
sid.getValue(), convertedSidStringPtr));
|
||||
String convertedSidString = convertedSidStringPtr.getValue().getString(0, true);
|
||||
assertEquals(convertedSidString, sidString);
|
||||
assertEquals(null, Kernel32.INSTANCE.LocalFree(convertedSidStringPtr.getValue()));
|
||||
assertEquals(null, Kernel32.INSTANCE.LocalFree(sid.getValue().getPointer()));
|
||||
}
|
||||
|
||||
public void testLogonUser() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
assertFalse(Advapi32.INSTANCE.LogonUser("AccountDoesntExist", ".", "passwordIsInvalid",
|
||||
WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phToken));
|
||||
assertTrue(W32Errors.ERROR_SUCCESS != Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testOpenThreadTokenNoToken() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
|
||||
assertNotNull(threadHandle);
|
||||
assertFalse(Advapi32.INSTANCE.OpenThreadToken(threadHandle,
|
||||
WinNT.TOKEN_READ, false, phToken));
|
||||
assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testOpenProcessToken() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testOpenThreadOrProcessToken() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE threadHandle = Kernel32.INSTANCE.GetCurrentThread();
|
||||
if (! Advapi32.INSTANCE.OpenThreadToken(threadHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, true, phToken)) {
|
||||
assertEquals(W32Errors.ERROR_NO_TOKEN, Kernel32.INSTANCE.GetLastError());
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
}
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testDuplicateToken() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLEByReference phTokenDup = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
assertTrue(Advapi32.INSTANCE.DuplicateToken(phToken.getValue(),
|
||||
WinNT.SECURITY_IMPERSONATION_LEVEL.SecurityImpersonation, phTokenDup));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phTokenDup.getValue()));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testDuplicateTokenEx() {
|
||||
HANDLEByReference hExistingToken = new HANDLEByReference();
|
||||
HANDLEByReference phNewToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, hExistingToken));
|
||||
assertTrue(Advapi32.INSTANCE.DuplicateTokenEx(hExistingToken.getValue(),
|
||||
WinNT.GENERIC_READ, null, SECURITY_IMPERSONATION_LEVEL.SecurityAnonymous,
|
||||
TOKEN_TYPE.TokenPrimary, phNewToken));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phNewToken.getValue()));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hExistingToken.getValue()));
|
||||
}
|
||||
|
||||
public void testGetTokenOwnerInformation() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
assertFalse(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenOwner, null, 0, tokenInformationLength));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
WinNT.TOKEN_OWNER owner = new WinNT.TOKEN_OWNER(tokenInformationLength.getValue());
|
||||
assertTrue(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenOwner, owner,
|
||||
tokenInformationLength.getValue(), tokenInformationLength));
|
||||
assertTrue(tokenInformationLength.getValue() > 0);
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(owner.Owner));
|
||||
int sidLength = Advapi32.INSTANCE.GetLengthSid(owner.Owner);
|
||||
assertTrue(sidLength < tokenInformationLength.getValue());
|
||||
assertTrue(sidLength > 0);
|
||||
// System.out.println(Advapi32Util.convertSidToStringSid(owner.Owner));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testGetTokenUserInformation() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
assertFalse(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, null, 0, tokenInformationLength));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
WinNT.TOKEN_USER user = new WinNT.TOKEN_USER(tokenInformationLength.getValue());
|
||||
assertTrue(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenUser, user,
|
||||
tokenInformationLength.getValue(), tokenInformationLength));
|
||||
assertTrue(tokenInformationLength.getValue() > 0);
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(user.User.Sid));
|
||||
int sidLength = Advapi32.INSTANCE.GetLengthSid(user.User.Sid);
|
||||
assertTrue(sidLength > 0);
|
||||
assertTrue(sidLength < tokenInformationLength.getValue());
|
||||
// System.out.println(Advapi32Util.convertSidToStringSid(user.User.Sid));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testGetTokenGroupsInformation() {
|
||||
HANDLEByReference phToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, phToken));
|
||||
IntByReference tokenInformationLength = new IntByReference();
|
||||
assertFalse(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, null, 0, tokenInformationLength));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
WinNT.TOKEN_GROUPS groups = new WinNT.TOKEN_GROUPS(tokenInformationLength.getValue());
|
||||
assertTrue(Advapi32.INSTANCE.GetTokenInformation(phToken.getValue(),
|
||||
WinNT.TOKEN_INFORMATION_CLASS.TokenGroups, groups,
|
||||
tokenInformationLength.getValue(), tokenInformationLength));
|
||||
assertTrue(tokenInformationLength.getValue() > 0);
|
||||
assertTrue(groups.GroupCount > 0);
|
||||
for (SID_AND_ATTRIBUTES sidAndAttribute : groups.getGroups()) {
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(sidAndAttribute.Sid));
|
||||
// System.out.println(Advapi32Util.convertSidToStringSid(sidAndAttribute.Sid));
|
||||
}
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(phToken.getValue()));
|
||||
}
|
||||
|
||||
public void testImpersonateLoggedOnUser() {
|
||||
USER_INFO_1 userInfo = new USER_INFO_1();
|
||||
userInfo.usri1_name = new WString("JNAAdvapi32TestImp");
|
||||
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
|
||||
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
|
||||
try {
|
||||
HANDLEByReference phUser = new HANDLEByReference();
|
||||
try {
|
||||
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(),
|
||||
null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK,
|
||||
WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
|
||||
assertTrue(Advapi32.INSTANCE.ImpersonateLoggedOnUser(phUser.getValue()));
|
||||
assertTrue(Advapi32.INSTANCE.RevertToSelf());
|
||||
} finally {
|
||||
if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
|
||||
Kernel32.INSTANCE.CloseHandle(phUser.getValue());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(
|
||||
null, userInfo.usri1_name.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegOpenKeyEx() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft", 0, WinNT.KEY_READ, phKey));
|
||||
assertTrue(WinBase.INVALID_HANDLE_VALUE != phKey.getValue());
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegQueryValueEx() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", 0, WinNT.KEY_READ, phKey));
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
IntByReference lpType = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phKey.getValue(), "User Agent", 0, lpType, (char[]) null, lpcbData));
|
||||
assertEquals(WinNT.REG_SZ, lpType.getValue());
|
||||
assertTrue(lpcbData.getValue() > 0);
|
||||
char[] buffer = new char[lpcbData.getValue()];
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phKey.getValue(), "User Agent", 0, lpType, buffer, lpcbData));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegDeleteValue() {
|
||||
assertEquals(W32Errors.ERROR_FILE_NOT_FOUND, Advapi32.INSTANCE.RegDeleteValue(
|
||||
WinReg.HKEY_CURRENT_USER, "JNAAdvapi32TestDoesntExist"));
|
||||
}
|
||||
|
||||
public void testRegSetValueEx_REG_SZ() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
// create parent key
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
|
||||
HKEYByReference phkTest = new HKEYByReference();
|
||||
IntByReference lpdwDisposition = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
|
||||
phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
|
||||
null, phkTest, lpdwDisposition));
|
||||
// write a REG_SZ value
|
||||
char[] lpData = Native.toCharArray("Test");
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(
|
||||
phkTest.getValue(), "REG_SZ", 0, WinNT.REG_SZ, lpData, lpData.length * 2));
|
||||
// re-read the REG_SZ value
|
||||
IntByReference lpType = new IntByReference();
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkTest.getValue(), "REG_SZ", 0, lpType, (char[]) null, lpcbData));
|
||||
assertEquals(WinNT.REG_SZ, lpType.getValue());
|
||||
assertTrue(lpcbData.getValue() > 0);
|
||||
char[] buffer = new char[lpcbData.getValue()];
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkTest.getValue(), "REG_SZ", 0, lpType, buffer, lpcbData));
|
||||
assertEquals("Test", Native.toString(buffer));
|
||||
// delete the test key
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(
|
||||
phkTest.getValue()));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
|
||||
phKey.getValue(), "JNAAdvapi32Test"));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegSetValueEx_DWORD() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
// create parent key
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
|
||||
HKEYByReference phkTest = new HKEYByReference();
|
||||
IntByReference lpdwDisposition = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
|
||||
phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
|
||||
null, phkTest, lpdwDisposition));
|
||||
// write a REG_DWORD value
|
||||
int value = 42145;
|
||||
byte[] data = new byte[4];
|
||||
data[0] = (byte)(value & 0xff);
|
||||
data[1] = (byte)((value >> 8) & 0xff);
|
||||
data[2] = (byte)((value >> 16) & 0xff);
|
||||
data[3] = (byte)((value >> 24) & 0xff);
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegSetValueEx(
|
||||
phkTest.getValue(), "DWORD", 0, WinNT.REG_DWORD, data, 4));
|
||||
// re-read the REG_DWORD value
|
||||
IntByReference lpType = new IntByReference();
|
||||
IntByReference lpcbData = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkTest.getValue(), "DWORD", 0, lpType, (char[]) null, lpcbData));
|
||||
assertEquals(WinNT.REG_DWORD, lpType.getValue());
|
||||
assertEquals(4, lpcbData.getValue());
|
||||
IntByReference valueRead = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryValueEx(
|
||||
phkTest.getValue(), "DWORD", 0, lpType, valueRead, lpcbData));
|
||||
assertEquals(value, valueRead.getValue());
|
||||
// delete the test key
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(
|
||||
phkTest.getValue()));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
|
||||
phKey.getValue(), "JNAAdvapi32Test"));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegCreateKeyEx() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software", 0, WinNT.KEY_WRITE | WinNT.KEY_READ, phKey));
|
||||
HKEYByReference phkResult = new HKEYByReference();
|
||||
IntByReference lpdwDisposition = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCreateKeyEx(
|
||||
phKey.getValue(), "JNAAdvapi32Test", 0, null, 0, WinNT.KEY_ALL_ACCESS,
|
||||
null, phkResult, lpdwDisposition));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phkResult.getValue()));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegDeleteKey(
|
||||
phKey.getValue(), "JNAAdvapi32Test"));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegDeleteKey() {
|
||||
assertEquals(W32Errors.ERROR_FILE_NOT_FOUND, Advapi32.INSTANCE.RegDeleteKey(
|
||||
WinReg.HKEY_CURRENT_USER, "JNAAdvapi32TestDoesntExist"));
|
||||
}
|
||||
|
||||
public void testRegEnumKeyEx() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
|
||||
0, WinNT.KEY_READ, phKey));
|
||||
IntByReference lpcSubKeys = new IntByReference();
|
||||
IntByReference lpcMaxSubKeyLen = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(
|
||||
phKey.getValue(), null, null, null, lpcSubKeys, lpcMaxSubKeyLen, null, null,
|
||||
null, null, null, null));
|
||||
char[] name = new char[lpcMaxSubKeyLen.getValue() + 1];
|
||||
for (int i = 0; i < lpcSubKeys.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1);
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumKeyEx(
|
||||
phKey.getValue(), i, name, lpcchValueName, null, null, null, null));
|
||||
assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
|
||||
}
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegEnumValue() {
|
||||
HKEYByReference phKey = new HKEYByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegOpenKeyEx(
|
||||
WinReg.HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
|
||||
0, WinNT.KEY_READ, phKey));
|
||||
IntByReference lpcValues = new IntByReference();
|
||||
IntByReference lpcMaxValueNameLen = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(
|
||||
phKey.getValue(), null, null, null, null, null, null, lpcValues,
|
||||
lpcMaxValueNameLen, null, null, null));
|
||||
char[] name = new char[lpcMaxValueNameLen.getValue() + 1];
|
||||
for (int i = 0; i < lpcValues.getValue(); i++) {
|
||||
IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1);
|
||||
IntByReference lpType = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegEnumValue(
|
||||
phKey.getValue(), i, name, lpcchValueName, null,
|
||||
lpType, null, null));
|
||||
assertEquals(Native.toString(name).length(), lpcchValueName.getValue());
|
||||
}
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegCloseKey(phKey.getValue()));
|
||||
}
|
||||
|
||||
public void testRegQueryInfoKey() {
|
||||
IntByReference lpcClass = new IntByReference();
|
||||
IntByReference lpcSubKeys = new IntByReference();
|
||||
IntByReference lpcMaxSubKeyLen = new IntByReference();
|
||||
IntByReference lpcValues = new IntByReference();
|
||||
IntByReference lpcMaxClassLen = new IntByReference();
|
||||
IntByReference lpcMaxValueNameLen = new IntByReference();
|
||||
IntByReference lpcMaxValueLen = new IntByReference();
|
||||
IntByReference lpcbSecurityDescriptor = new IntByReference();
|
||||
FILETIME lpftLastWriteTime = new FILETIME();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Advapi32.INSTANCE.RegQueryInfoKey(
|
||||
WinReg.HKEY_LOCAL_MACHINE, null, lpcClass, null,
|
||||
lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues,
|
||||
lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor,
|
||||
lpftLastWriteTime));
|
||||
assertTrue(lpcSubKeys.getValue() > 0);
|
||||
}
|
||||
|
||||
public void testIsWellKnownSid() {
|
||||
String sidString = EVERYONE;
|
||||
PSIDByReference sid = new PSIDByReference();
|
||||
assertTrue(Advapi32.INSTANCE.ConvertStringSidToSid(sidString, sid));
|
||||
assertTrue(Advapi32.INSTANCE.IsWellKnownSid(sid.getValue(),
|
||||
WELL_KNOWN_SID_TYPE.WinWorldSid));
|
||||
assertFalse(Advapi32.INSTANCE.IsWellKnownSid(sid.getValue(),
|
||||
WELL_KNOWN_SID_TYPE.WinAccountAdministratorSid));
|
||||
}
|
||||
|
||||
public void testCreateWellKnownSid() {
|
||||
PSID pSid = new PSID(WinNT.SECURITY_MAX_SID_SIZE);
|
||||
IntByReference cbSid = new IntByReference(WinNT.SECURITY_MAX_SID_SIZE);
|
||||
assertTrue(Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinWorldSid,
|
||||
null, pSid, cbSid));
|
||||
assertTrue(Advapi32.INSTANCE.IsWellKnownSid(pSid,
|
||||
WELL_KNOWN_SID_TYPE.WinWorldSid));
|
||||
assertTrue(cbSid.getValue() <= WinNT.SECURITY_MAX_SID_SIZE);
|
||||
PointerByReference convertedSidStringPtr = new PointerByReference();
|
||||
assertTrue(Advapi32.INSTANCE.ConvertSidToStringSid(
|
||||
pSid, convertedSidStringPtr));
|
||||
String convertedSidString = convertedSidStringPtr.getValue().getString(0, true);
|
||||
assertEquals(EVERYONE, convertedSidString);
|
||||
}
|
||||
|
||||
public void testOpenEventLog() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
assertNotNull(h);
|
||||
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
|
||||
public void testRegisterEventSource() {
|
||||
// the Security event log is reserved
|
||||
HANDLE h = Advapi32.INSTANCE.RegisterEventSource(null, "Security");
|
||||
assertNull(h);
|
||||
assertEquals(W32Errors.ERROR_ACCESS_DENIED, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testReportEvent() {
|
||||
String applicationEventLog = "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application";
|
||||
String jnaEventSource = "JNADevEventSource";
|
||||
String jnaEventSourceRegistryPath = applicationEventLog + "\\" + jnaEventSource;
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_LOCAL_MACHINE, jnaEventSourceRegistryPath);
|
||||
HANDLE h = Advapi32.INSTANCE.RegisterEventSource(null, jnaEventSource);
|
||||
IntByReference before = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
|
||||
assertNotNull(h);
|
||||
String s[] = { "JNA", "Event" };
|
||||
Memory m = new Memory(4);
|
||||
m.setByte(0, (byte) 1);
|
||||
m.setByte(1, (byte) 2);
|
||||
m.setByte(2, (byte) 3);
|
||||
m.setByte(3, (byte) 4);
|
||||
assertTrue(Advapi32.INSTANCE.ReportEvent(h, WinNT.EVENTLOG_ERROR_TYPE, 0, 0, null, 2, 4, s, m));
|
||||
IntByReference after = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
|
||||
assertTrue(before.getValue() < after.getValue());
|
||||
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
|
||||
assertTrue(Advapi32.INSTANCE.DeregisterEventSource(h));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_LOCAL_MACHINE, jnaEventSourceRegistryPath);
|
||||
}
|
||||
|
||||
public void testGetNumberOfEventLogRecords() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
|
||||
IntByReference n = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, n));
|
||||
assertTrue(n.getValue() >= 0);
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
|
||||
/*
|
||||
public void testClearEventLog() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
assertFalse(h.equals(WinBase.INVALID_HANDLE_VALUE));
|
||||
IntByReference before = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, before));
|
||||
assertTrue(before.getValue() >= 0);
|
||||
assertTrue(Advapi32.INSTANCE.ClearEventLog(h, null));
|
||||
IntByReference after = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(h, after));
|
||||
assertTrue(after.getValue() < before.getValue() || before.getValue() == 0);
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
*/
|
||||
|
||||
public void testBackupEventLog() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
assertNotNull(h);
|
||||
String backupFileName = Kernel32Util.getTempPath() + "\\JNADevEventLog.bak";
|
||||
File f = new File(backupFileName);
|
||||
if (f.exists()) {
|
||||
f.delete();
|
||||
}
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.BackupEventLog(h, backupFileName));
|
||||
HANDLE hBackup = Advapi32.INSTANCE.OpenBackupEventLog(null, backupFileName);
|
||||
assertNotNull(hBackup);
|
||||
|
||||
IntByReference n = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetNumberOfEventLogRecords(hBackup, n));
|
||||
assertTrue(n.getValue() >= 0);
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(hBackup));
|
||||
}
|
||||
|
||||
public void testReadEventLog() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
IntByReference pnBytesRead = new IntByReference();
|
||||
IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
|
||||
Memory buffer = new Memory(1);
|
||||
assertFalse(Advapi32.INSTANCE.ReadEventLog(h,
|
||||
WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_BACKWARDS_READ,
|
||||
0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
assertTrue(pnMinNumberOfBytesNeeded.getValue() > 0);
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
|
||||
public void testReadEventLogEntries() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
IntByReference pnBytesRead = new IntByReference();
|
||||
IntByReference pnMinNumberOfBytesNeeded = new IntByReference();
|
||||
Memory buffer = new Memory(1024 * 64);
|
||||
// shorten test, avoid iterating through all events
|
||||
int maxReads = 3;
|
||||
int rc = 0;
|
||||
while(true) {
|
||||
if (maxReads-- <= 0)
|
||||
break;
|
||||
if (! Advapi32.INSTANCE.ReadEventLog(h,
|
||||
WinNT.EVENTLOG_SEQUENTIAL_READ | WinNT.EVENTLOG_FORWARDS_READ,
|
||||
0, buffer, (int) buffer.size(), pnBytesRead, pnMinNumberOfBytesNeeded)) {
|
||||
rc = Kernel32.INSTANCE.GetLastError();
|
||||
if (rc == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
|
||||
buffer = new Memory(pnMinNumberOfBytesNeeded.getValue());
|
||||
rc = 0;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
int dwRead = pnBytesRead.getValue();
|
||||
Pointer pevlr = buffer;
|
||||
int maxRecords = 3;
|
||||
while (dwRead > 0 && maxRecords-- > 0) {
|
||||
EVENTLOGRECORD record = new EVENTLOGRECORD(pevlr);
|
||||
/*
|
||||
System.out.println(record.RecordNumber.intValue()
|
||||
+ " Event ID: " + record.EventID.intValue()
|
||||
+ " Event Type: " + record.EventType.intValue()
|
||||
+ " Event Source: " + pevlr.getString(record.size(), true));
|
||||
*/
|
||||
dwRead -= record.Length.intValue();
|
||||
pevlr = pevlr.share(record.Length.intValue());
|
||||
}
|
||||
}
|
||||
assertTrue("Unexpected error after reading event log: "
|
||||
+ new Win32Exception(rc),
|
||||
rc == W32Errors.ERROR_HANDLE_EOF || rc == 0);
|
||||
assertTrue("Error closing event log",
|
||||
Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
|
||||
public void testGetOldestEventLogRecord() {
|
||||
HANDLE h = Advapi32.INSTANCE.OpenEventLog(null, "Application");
|
||||
IntByReference oldestRecord = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetOldestEventLogRecord(h, oldestRecord));
|
||||
assertTrue(oldestRecord.getValue() >= 0);
|
||||
assertTrue(Advapi32.INSTANCE.CloseEventLog(h));
|
||||
}
|
||||
|
||||
public void testQueryServiceStatusEx() {
|
||||
|
||||
SC_HANDLE scmHandle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(scmHandle);
|
||||
|
||||
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(scmHandle, "eventlog", Winsvc.SERVICE_QUERY_STATUS);
|
||||
assertNotNull(serviceHandle);
|
||||
|
||||
IntByReference pcbBytesNeeded = new IntByReference();
|
||||
|
||||
assertFalse(Advapi32.INSTANCE.QueryServiceStatusEx(serviceHandle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO,
|
||||
null, 0, pcbBytesNeeded));
|
||||
assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
assertTrue(pcbBytesNeeded.getValue() > 0);
|
||||
|
||||
SERVICE_STATUS_PROCESS status = new SERVICE_STATUS_PROCESS(pcbBytesNeeded.getValue());
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.QueryServiceStatusEx(serviceHandle, SC_STATUS_TYPE.SC_STATUS_PROCESS_INFO,
|
||||
status, status.size(), pcbBytesNeeded));
|
||||
|
||||
assertTrue(status.dwCurrentState == Winsvc.SERVICE_STOPPED ||
|
||||
status.dwCurrentState == Winsvc.SERVICE_RUNNING);
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(serviceHandle));
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(scmHandle));
|
||||
}
|
||||
|
||||
|
||||
public void testControlService() {
|
||||
SC_HANDLE scmHandle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(scmHandle);
|
||||
|
||||
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(scmHandle, "eventlog", Winsvc.SERVICE_QUERY_CONFIG);
|
||||
assertNotNull(serviceHandle);
|
||||
|
||||
Winsvc.SERVICE_STATUS serverStatus = new Winsvc.SERVICE_STATUS();
|
||||
|
||||
assertNotNull(serviceHandle);
|
||||
assertFalse(Advapi32.INSTANCE.ControlService(serviceHandle, Winsvc.SERVICE_CONTROL_STOP, serverStatus));
|
||||
assertEquals(W32Errors.ERROR_ACCESS_DENIED, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(serviceHandle));
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(scmHandle));
|
||||
}
|
||||
|
||||
public void testStartService() {
|
||||
SC_HANDLE scmHandle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(scmHandle);
|
||||
|
||||
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(scmHandle, "eventlog", Winsvc.SERVICE_QUERY_CONFIG);
|
||||
assertNotNull(serviceHandle);
|
||||
|
||||
assertFalse(Advapi32.INSTANCE.StartService(serviceHandle, 0, null));
|
||||
assertEquals(W32Errors.ERROR_ACCESS_DENIED, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(serviceHandle));
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(scmHandle));
|
||||
}
|
||||
|
||||
public void testOpenService() {
|
||||
assertNull(Advapi32.INSTANCE.OpenService(null, "eventlog", Winsvc.SERVICE_QUERY_CONFIG ));
|
||||
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
SC_HANDLE scmHandle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(scmHandle);
|
||||
|
||||
SC_HANDLE serviceHandle = Advapi32.INSTANCE.OpenService(scmHandle, "eventlog", Winsvc.SERVICE_QUERY_CONFIG );
|
||||
assertNotNull(serviceHandle);
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(serviceHandle));
|
||||
|
||||
assertNull(Advapi32.INSTANCE.OpenService(scmHandle, "slashesArentValidChars/", Winsvc.SERVICE_QUERY_CONFIG ));
|
||||
assertEquals(W32Errors.ERROR_INVALID_NAME, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
assertNull(Advapi32.INSTANCE.OpenService(scmHandle, "serviceDoesNotExist", Winsvc.SERVICE_QUERY_CONFIG ));
|
||||
assertEquals(W32Errors.ERROR_SERVICE_DOES_NOT_EXIST, Kernel32.INSTANCE.GetLastError());
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(scmHandle));
|
||||
}
|
||||
|
||||
public void testOpenSCManager() {
|
||||
SC_HANDLE handle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(handle);
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(handle));
|
||||
|
||||
assertNull(Advapi32.INSTANCE.OpenSCManager("invalidMachineName", null, Winsvc.SC_MANAGER_CONNECT));
|
||||
int err = Kernel32.INSTANCE.GetLastError();
|
||||
assertTrue("Unexpected error in OpenSCManager: " + err,
|
||||
err == W32Errors.RPC_S_SERVER_UNAVAILABLE
|
||||
|| err == W32Errors.RPC_S_INVALID_NET_ADDR);
|
||||
|
||||
assertNull(Advapi32.INSTANCE.OpenSCManager(null, "invalidDatabase", Winsvc.SC_MANAGER_CONNECT));
|
||||
assertEquals(W32Errors.ERROR_INVALID_NAME, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testCloseServiceHandle() throws Exception {
|
||||
SC_HANDLE handle = Advapi32.INSTANCE.OpenSCManager(null, null, Winsvc.SC_MANAGER_CONNECT);
|
||||
assertNotNull(handle);
|
||||
assertTrue(Advapi32.INSTANCE.CloseServiceHandle(handle));
|
||||
|
||||
assertFalse(Advapi32.INSTANCE.CloseServiceHandle(null));
|
||||
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testCreateProcessAsUser() {
|
||||
HANDLEByReference hToken = new HANDLEByReference();
|
||||
HANDLE processHandle = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(processHandle,
|
||||
WinNT.TOKEN_DUPLICATE | WinNT.TOKEN_QUERY, hToken));
|
||||
|
||||
assertFalse(Advapi32.INSTANCE.CreateProcessAsUser(hToken.getValue(), null, "InvalidCmdLine.jna",
|
||||
null, null, false, 0, null, null, new WinBase.STARTUPINFO(),
|
||||
new WinBase.PROCESS_INFORMATION()));
|
||||
assertEquals(W32Errors.ERROR_FILE_NOT_FOUND, Kernel32.INSTANCE.GetLastError());
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hToken.getValue()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests both {@link Advapi32#LookupPrivilegeValue} and {@link Advapi32#LookupPrivilegeName}
|
||||
*/
|
||||
public void testLookupPrivilegeValueAndLookupPrivilegeName() {
|
||||
WinNT.LUID luid = new WinNT.LUID();
|
||||
|
||||
assertFalse(Advapi32.INSTANCE.LookupPrivilegeValue(null, "InvalidName", luid));
|
||||
assertEquals(Kernel32.INSTANCE.GetLastError(), W32Errors.ERROR_NO_SUCH_PRIVILEGE);
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.LookupPrivilegeValue(null, WinNT.SE_BACKUP_NAME, luid));
|
||||
assertTrue(luid.LowPart > 0 || luid.HighPart > 0);
|
||||
|
||||
char[] lpName = new char[256];
|
||||
IntByReference cchName = new IntByReference(lpName.length);
|
||||
assertTrue(Advapi32.INSTANCE.LookupPrivilegeName(null, luid, lpName, cchName));
|
||||
assertEquals(WinNT.SE_BACKUP_NAME.length(), cchName.getValue());
|
||||
assertEquals(WinNT.SE_BACKUP_NAME, Native.toString(lpName));
|
||||
}
|
||||
|
||||
public void testAdjustTokenPrivileges() {
|
||||
HANDLEByReference hToken = new HANDLEByReference();
|
||||
assertTrue(Advapi32.INSTANCE.OpenProcessToken(Kernel32.INSTANCE.GetCurrentProcess(),
|
||||
WinNT.TOKEN_ADJUST_PRIVILEGES | WinNT.TOKEN_QUERY, hToken));
|
||||
|
||||
// Find an already enabled privilege
|
||||
TOKEN_PRIVILEGES tp = new TOKEN_PRIVILEGES(1024);
|
||||
IntByReference returnLength = new IntByReference();
|
||||
assertTrue(Advapi32.INSTANCE.GetTokenInformation(hToken.getValue(), WinNT.TOKEN_INFORMATION_CLASS.TokenPrivileges,
|
||||
tp, tp.size(), returnLength));
|
||||
assertTrue(tp.PrivilegeCount.intValue() > 0);
|
||||
|
||||
WinNT.LUID luid = null;
|
||||
for (int i=0; i<tp.PrivilegeCount.intValue(); i++) {
|
||||
if ((tp.Privileges[i].Attributes.intValue() & WinNT.SE_PRIVILEGE_ENABLED) > 0) {
|
||||
luid = tp.Privileges[i].Luid;
|
||||
}
|
||||
}
|
||||
assertTrue(luid != null);
|
||||
|
||||
// Re-enable it. That should succeed.
|
||||
tp = new WinNT.TOKEN_PRIVILEGES(1);
|
||||
tp.Privileges[0] = new WinNT.LUID_AND_ATTRIBUTES(luid, new DWORD(WinNT.SE_PRIVILEGE_ENABLED));
|
||||
|
||||
assertTrue(Advapi32.INSTANCE.AdjustTokenPrivileges(hToken.getValue(), false, tp, 0, null, null));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hToken.getValue()));
|
||||
}
|
||||
|
||||
public void testImpersonateSelf() {
|
||||
assertTrue(Advapi32.INSTANCE.ImpersonateSelf(WinNT.SECURITY_IMPERSONATION_LEVEL.SecurityAnonymous));
|
||||
assertTrue(Advapi32.INSTANCE.RevertToSelf());
|
||||
}
|
||||
}
|
||||
@@ -1,452 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.Advapi32Util.Account;
|
||||
import com.sun.jna.platform.win32.Advapi32Util.EventLogIterator;
|
||||
import com.sun.jna.platform.win32.Advapi32Util.EventLogRecord;
|
||||
import com.sun.jna.platform.win32.LMAccess.USER_INFO_1;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.PSID;
|
||||
import com.sun.jna.platform.win32.WinNT.SID_NAME_USE;
|
||||
import com.sun.jna.platform.win32.WinNT.WELL_KNOWN_SID_TYPE;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEY;
|
||||
import com.sun.jna.platform.win32.WinReg.HKEYByReference;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Advapi32UtilTest extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Advapi32UtilTest.class);
|
||||
String currentUserName = Advapi32Util.getUserName();
|
||||
System.out.println("GetUserName: " + currentUserName);
|
||||
|
||||
for(Account group : Advapi32Util.getCurrentUserGroups()) {
|
||||
System.out.println(" " + group.fqn + " [" + group.sidString + "]");
|
||||
}
|
||||
|
||||
Account accountByName = Advapi32Util.getAccountByName(currentUserName);
|
||||
System.out.println("AccountByName: " + currentUserName);
|
||||
System.out.println(" Fqn: " + accountByName.fqn);
|
||||
System.out.println(" Domain: " + accountByName.domain);
|
||||
System.out.println(" Sid: " + accountByName.sidString);
|
||||
|
||||
Account accountBySid = Advapi32Util.getAccountBySid(new PSID(accountByName.sid));
|
||||
System.out.println("AccountBySid: " + accountByName.sidString);
|
||||
System.out.println(" Fqn: " + accountBySid.fqn);
|
||||
System.out.println(" Name: " + accountBySid.name);
|
||||
System.out.println(" Domain: " + accountBySid.domain);
|
||||
}
|
||||
|
||||
public void testGetUsername() {
|
||||
String username = Advapi32Util.getUserName();
|
||||
assertTrue(username.length() > 0);
|
||||
}
|
||||
|
||||
public void testGetAccountBySid() {
|
||||
String accountName = Advapi32Util.getUserName();
|
||||
Account currentUser = Advapi32Util.getAccountByName(accountName);
|
||||
Account account = Advapi32Util.getAccountBySid(new PSID(currentUser.sid));
|
||||
assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
|
||||
assertEquals(currentUser.fqn.toLowerCase(), account.fqn.toLowerCase());
|
||||
assertEquals(currentUser.name.toLowerCase(), account.name.toLowerCase());
|
||||
assertEquals(currentUser.domain.toLowerCase(), account.domain.toLowerCase());
|
||||
assertEquals(currentUser.sidString, account.sidString);
|
||||
}
|
||||
|
||||
public void testGetAccountByName() {
|
||||
String accountName = Advapi32Util.getUserName();
|
||||
Account account = Advapi32Util.getAccountByName(accountName);
|
||||
assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
|
||||
}
|
||||
|
||||
public void testGetAccountNameFromSid() {
|
||||
assertEquals("Everyone", Advapi32Util.getAccountBySid("S-1-1-0").name);
|
||||
}
|
||||
|
||||
public void testGetAccountSidFromName() {
|
||||
assertEquals("S-1-1-0", Advapi32Util.getAccountByName("Everyone").sidString);
|
||||
}
|
||||
|
||||
public void testConvertSid() {
|
||||
String sidString = "S-1-1-0"; // Everyone
|
||||
byte[] sidBytes = Advapi32Util.convertStringSidToSid(sidString);
|
||||
assertTrue(sidBytes.length > 0);
|
||||
String convertedSidString = Advapi32Util.convertSidToStringSid(new PSID(sidBytes));
|
||||
assertEquals(convertedSidString, sidString);
|
||||
}
|
||||
|
||||
public void testGetCurrentUserGroups() {
|
||||
Account[] groups = Advapi32Util.getCurrentUserGroups();
|
||||
assertTrue(groups.length > 0);
|
||||
for(Account group : groups) {
|
||||
assertTrue(group.name.length() > 0);
|
||||
assertTrue(group.sidString.length() > 0);
|
||||
assertTrue(group.sid.length > 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetUserGroups() {
|
||||
USER_INFO_1 userInfo = new USER_INFO_1();
|
||||
userInfo.usri1_name = new WString("JNANetapi32TestUser");
|
||||
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
|
||||
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
|
||||
try {
|
||||
assertEquals("Error in NetUserAdd",
|
||||
LMErr.NERR_Success,
|
||||
Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null));
|
||||
HANDLEByReference phUser = new HANDLEByReference();
|
||||
try {
|
||||
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(),
|
||||
null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK,
|
||||
WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
|
||||
Account[] groups = Advapi32Util.getTokenGroups(phUser.getValue());
|
||||
assertTrue(groups.length > 0);
|
||||
for(Account group : groups) {
|
||||
assertTrue(group.name.length() > 0);
|
||||
assertTrue(group.sidString.length() > 0);
|
||||
assertTrue(group.sid.length > 0);
|
||||
}
|
||||
} finally {
|
||||
if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
|
||||
Kernel32.INSTANCE.CloseHandle(phUser.getValue());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
assertEquals("Error in NetUserDel",
|
||||
LMErr.NERR_Success,
|
||||
Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetUserAccount() {
|
||||
USER_INFO_1 userInfo = new USER_INFO_1();
|
||||
userInfo.usri1_name = new WString("JNANetapi32TestUser");
|
||||
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
|
||||
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
|
||||
try {
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
|
||||
null, 1, userInfo, null));
|
||||
HANDLEByReference phUser = new HANDLEByReference();
|
||||
try {
|
||||
assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(),
|
||||
null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK,
|
||||
WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
|
||||
Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
|
||||
assertTrue(account.name.length() > 0);
|
||||
assertEquals(userInfo.usri1_name.toString(), account.name);
|
||||
} finally {
|
||||
if (phUser.getValue() != WinBase.INVALID_HANDLE_VALUE) {
|
||||
Kernel32.INSTANCE.CloseHandle(phUser.getValue());
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(
|
||||
null, userInfo.usri1_name.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testRegistryKeyExists() {
|
||||
assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
""));
|
||||
assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
"Software\\Microsoft"));
|
||||
assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
"KeyDoesNotExist\\SubKeyDoesNotExist"));
|
||||
}
|
||||
|
||||
public void testRegistryValueExists() {
|
||||
assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
"Software\\Microsoft", ""));
|
||||
assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
"Software\\Microsoft", "KeyDoesNotExist"));
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE,
|
||||
"SYSTEM\\CurrentControlSet\\Control", "SystemBootDevice"));
|
||||
}
|
||||
|
||||
public void testRegistryCreateDeleteKey() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
assertFalse(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA"));
|
||||
}
|
||||
|
||||
public void testRegistryCreateKeyDisposition() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
assertTrue(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"));
|
||||
assertFalse(Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA"));
|
||||
assertTrue(Advapi32Util.registryKeyExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistryDeleteValue() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42);
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"));
|
||||
Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue");
|
||||
assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetIntValue() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue", 42);
|
||||
assertEquals(42, Advapi32Util.registryGetIntValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\JNA", "IntValue"));
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "IntValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetLongValue() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetLongValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue", 1234L);
|
||||
assertEquals(1234L, Advapi32Util.registryGetLongValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\JNA", "LongValue"));
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "LongValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetStringValue() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Hello World");
|
||||
assertEquals("Hello World", Advapi32Util.registryGetStringValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\JNA", "StringValue"));
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetExpandableStringValue() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue", "Temp is %TEMP%");
|
||||
assertEquals("Temp is %TEMP%", Advapi32Util.registryGetExpandableStringValue(WinReg.HKEY_CURRENT_USER,
|
||||
"Software\\JNA", "StringValue"));
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetStringArray() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
String[] dataWritten = { "Hello", "World" };
|
||||
Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue", dataWritten);
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue"));
|
||||
String[] dataRead = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "MultiStringValue");
|
||||
assertEquals(dataWritten.length, dataRead.length);
|
||||
for(int i = 0; i < dataRead.length; i++) {
|
||||
assertEquals(dataWritten[i], dataRead[i]);
|
||||
}
|
||||
dataWritten = new String[0];
|
||||
Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString", dataWritten);
|
||||
dataRead = Advapi32Util.registryGetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyMultiString");
|
||||
assertEquals(0, dataRead.length);
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistrySetGetBinaryValue() {
|
||||
byte[] data = { 0x00, 0x01, 0x02 };
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue", data);
|
||||
byte[] read = Advapi32Util.registryGetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue");
|
||||
assertEquals(data.length, read.length);
|
||||
for(int i = 0; i < data.length; i++) {
|
||||
assertEquals(data[i], read[i]);
|
||||
}
|
||||
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "BinaryValue"));
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistryGetKeys() {
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
|
||||
String[] subKeys = Advapi32Util.registryGetKeys(WinReg.HKEY_CURRENT_USER, "Software\\JNA");
|
||||
assertEquals(2, subKeys.length);
|
||||
assertEquals(subKeys[0], "Key1");
|
||||
assertEquals(subKeys[1], "Key2");
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key1");
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "Key2");
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistryGetValues() {
|
||||
String uu = new String("A" + "\\u00ea" + "\\u00f1" + "\\u00fc" + "C");
|
||||
Advapi32Util.registryCreateKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
Advapi32Util.registrySetIntValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "FourtyTwo" + uu, 42);
|
||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "42" + uu, "FourtyTwo" + uu);
|
||||
Advapi32Util.registrySetExpandableStringValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "ExpandableString", "%TEMP%");
|
||||
byte[] dataWritten = { 0xD, 0xE, 0xA, 0xD, 0xB, 0xE, 0xE, 0xF };
|
||||
Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "DeadBeef", dataWritten);
|
||||
String[] stringsWritten = { "Hello", "World", "Hello World", uu };
|
||||
Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "StringArray", stringsWritten);
|
||||
String[] emptyArray = new String[0];
|
||||
Advapi32Util.registrySetStringArray(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyStringArray", emptyArray);
|
||||
Advapi32Util.registrySetBinaryValue(WinReg.HKEY_CURRENT_USER, "Software\\JNA", "EmptyBinary", new byte[0]);
|
||||
TreeMap<String, Object> values = Advapi32Util.registryGetValues(WinReg.HKEY_CURRENT_USER, "Software\\JNA");
|
||||
assertEquals(7, values.keySet().size());
|
||||
assertEquals("FourtyTwo" + uu, values.get("42" + uu));
|
||||
assertEquals(42, values.get("FourtyTwo" + uu));
|
||||
assertEquals("%TEMP%", values.get("ExpandableString"));
|
||||
byte[] dataRead = (byte[]) values.get("DeadBeef");
|
||||
assertEquals(dataWritten.length, dataRead.length);
|
||||
for(int i = 0; i < dataWritten.length; i++) {
|
||||
assertEquals(dataWritten[i], dataRead[i]);
|
||||
}
|
||||
String[] stringsRead = (String[]) values.get("StringArray");
|
||||
assertEquals(stringsWritten.length, stringsRead.length);
|
||||
for(int i = 0; i < stringsWritten.length; i++) {
|
||||
assertEquals(stringsWritten[i], stringsRead[i]);
|
||||
}
|
||||
stringsRead = (String[]) values.get("EmptyStringArray");
|
||||
assertEquals(0, stringsRead.length);
|
||||
Advapi32Util.registryDeleteKey(WinReg.HKEY_CURRENT_USER, "Software", "JNA");
|
||||
}
|
||||
|
||||
public void testRegistryGetEmptyValues() {
|
||||
HKEY root = WinReg.HKEY_CURRENT_USER;
|
||||
String keyPath = "Software\\JNA";
|
||||
Advapi32Util.registryCreateKey(root, "Software", "JNA");
|
||||
doTestRegistryGetEmptyValues(root, keyPath, WinNT.REG_BINARY);
|
||||
doTestRegistryGetEmptyValues(root, keyPath, WinNT.REG_EXPAND_SZ);
|
||||
doTestRegistryGetEmptyValues(root, keyPath, WinNT.REG_MULTI_SZ);
|
||||
doTestRegistryGetEmptyValues(root, keyPath, WinNT.REG_NONE);
|
||||
doTestRegistryGetEmptyValues(root, keyPath, WinNT.REG_SZ);
|
||||
Advapi32Util.registryDeleteKey(root, "Software", "JNA");
|
||||
}
|
||||
|
||||
private void doTestRegistryGetEmptyValues(HKEY root, String keyPath, int valueType) {
|
||||
String valueName = "EmptyValue";
|
||||
registrySetEmptyValue(root, keyPath, valueName, valueType);
|
||||
Map<String, Object> values = Advapi32Util.registryGetValues(root, keyPath);
|
||||
assertEquals(1, values.size());
|
||||
assertTrue(values.containsKey(valueName));
|
||||
}
|
||||
|
||||
private static void registrySetEmptyValue(HKEY root, String keyPath, String name, final int valueType) {
|
||||
HKEYByReference phkKey = new HKEYByReference();
|
||||
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE, phkKey);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
try {
|
||||
char[] data = new char[0];
|
||||
rc = Advapi32.INSTANCE.RegSetValueEx(phkKey.getValue(), name, 0, valueType, data, 0);
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
} finally {
|
||||
rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue());
|
||||
if (rc != W32Errors.ERROR_SUCCESS) {
|
||||
throw new Win32Exception(rc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsWellKnownSid() {
|
||||
String everyoneString = "S-1-1-0";
|
||||
assertTrue(Advapi32Util.isWellKnownSid(everyoneString, WELL_KNOWN_SID_TYPE.WinWorldSid));
|
||||
assertFalse(Advapi32Util.isWellKnownSid(everyoneString, WELL_KNOWN_SID_TYPE.WinAccountAdministratorSid));
|
||||
byte[] everyoneBytes = Advapi32Util.convertStringSidToSid(everyoneString);
|
||||
assertTrue(Advapi32Util.isWellKnownSid(everyoneBytes, WELL_KNOWN_SID_TYPE.WinWorldSid));
|
||||
assertFalse(Advapi32Util.isWellKnownSid(everyoneBytes, WELL_KNOWN_SID_TYPE.WinAccountAdministratorSid));
|
||||
}
|
||||
|
||||
public void testEventLogIteratorForwards() {
|
||||
EventLogIterator iter = new EventLogIterator("Application");
|
||||
try {
|
||||
int max = 100;
|
||||
int lastId = 0;
|
||||
while(iter.hasNext()) {
|
||||
EventLogRecord record = iter.next();
|
||||
assertTrue(record.getRecordNumber() > lastId);
|
||||
lastId = record.getRecordNumber();
|
||||
assertNotNull(record.getType().name());
|
||||
assertNotNull(record.getSource());
|
||||
if (record.getRecord().DataLength.intValue() > 0) {
|
||||
assertEquals(record.getData().length,
|
||||
record.getRecord().DataLength.intValue());
|
||||
} else {
|
||||
assertNull(record.getData());
|
||||
}
|
||||
if (record.getRecord().NumStrings.intValue() > 0) {
|
||||
assertEquals(record.getStrings().length,
|
||||
record.getRecord().NumStrings.intValue());
|
||||
} else {
|
||||
assertNull(record.getStrings());
|
||||
}
|
||||
|
||||
if (max-- <= 0) {
|
||||
break; // shorten test
|
||||
}
|
||||
/*
|
||||
System.out.println(record.getRecordNumber()
|
||||
+ ": Event ID: " + record.getEventId()
|
||||
+ ", Event Type: " + record.getType()
|
||||
+ ", Event Source: " + record.getSource());
|
||||
*/
|
||||
}
|
||||
} finally {
|
||||
iter.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testEventLogIteratorBackwards() {
|
||||
EventLogIterator iter = new EventLogIterator(null,
|
||||
"Application", WinNT.EVENTLOG_BACKWARDS_READ);
|
||||
try {
|
||||
int max = 100;
|
||||
int lastId = -1;
|
||||
while(iter.hasNext()) {
|
||||
EventLogRecord record = iter.next();
|
||||
/*
|
||||
System.out.println(record.getRecordNumber()
|
||||
+ ": Event ID: " + record.getEventId()
|
||||
+ ", Event Type: " + record.getType()
|
||||
+ ", Event Source: " + record.getSource());
|
||||
*/
|
||||
assertTrue(record.getRecordNumber() < lastId || lastId == -1);
|
||||
lastId = record.getRecordNumber();
|
||||
if (max-- <= 0) {
|
||||
break; // shorten test
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
iter.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetEnvironmentBlock() {
|
||||
String expected = "KEY=value\0"
|
||||
+ "KEY_EMPTY=\0"
|
||||
+ "KEY_NUMBER=2\0"
|
||||
+ "\0";
|
||||
|
||||
// Order is important to kept checking result simple
|
||||
Map<String, String> mockEnvironment = new TreeMap<String, String>();
|
||||
mockEnvironment.put("KEY", "value");
|
||||
mockEnvironment.put("KEY_EMPTY", "");
|
||||
mockEnvironment.put("KEY_NUMBER", "2");
|
||||
mockEnvironment.put("KEY_NULL", null);
|
||||
|
||||
String block = Advapi32Util.getEnvironmentBlock(mockEnvironment);
|
||||
assertEquals("Environment block must comprise key=value pairs separated by NUL characters", expected, block);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.platform.win32.WinCrypt.DATA_BLOB;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Crypt32Test extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Crypt32Test.class);
|
||||
}
|
||||
|
||||
public void testCryptProtectUnprotectData() {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB("hello world");
|
||||
DATA_BLOB pDataEncrypted = new DATA_BLOB();
|
||||
assertTrue(Crypt32.INSTANCE.CryptProtectData(pDataIn, "description",
|
||||
null, null, null, 0, pDataEncrypted));
|
||||
PointerByReference pDescription = new PointerByReference();
|
||||
DATA_BLOB pDataDecrypted = new DATA_BLOB();
|
||||
assertTrue(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
|
||||
null, null, null, 0, pDataDecrypted));
|
||||
assertEquals("description", pDescription.getValue().getString(0, true));
|
||||
assertEquals("hello world", pDataDecrypted.pbData.getString(0));
|
||||
Kernel32.INSTANCE.LocalFree(pDataEncrypted.pbData);
|
||||
Kernel32.INSTANCE.LocalFree(pDataDecrypted.pbData);
|
||||
Kernel32.INSTANCE.LocalFree(pDescription.getValue());
|
||||
}
|
||||
|
||||
public void testCryptProtectUnprotectDataWithEntropy() {
|
||||
DATA_BLOB pDataIn = new DATA_BLOB("hello world");
|
||||
DATA_BLOB pDataEncrypted = new DATA_BLOB();
|
||||
DATA_BLOB pEntropy = new DATA_BLOB("entropy");
|
||||
assertTrue(Crypt32.INSTANCE.CryptProtectData(pDataIn, "description",
|
||||
pEntropy, null, null, 0, pDataEncrypted));
|
||||
PointerByReference pDescription = new PointerByReference();
|
||||
DATA_BLOB pDataDecrypted = new DATA_BLOB();
|
||||
// can't decrypt without entropy
|
||||
assertFalse(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
|
||||
null, null, null, 0, pDataDecrypted));
|
||||
// decrypt with entropy
|
||||
assertTrue(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
|
||||
pEntropy, null, null, 0, pDataDecrypted));
|
||||
assertEquals("description", pDescription.getValue().getString(0, true));
|
||||
assertEquals("hello world", pDataDecrypted.pbData.getString(0));
|
||||
Kernel32.INSTANCE.LocalFree(pDataEncrypted.pbData);
|
||||
Kernel32.INSTANCE.LocalFree(pDataDecrypted.pbData);
|
||||
Kernel32.INSTANCE.LocalFree(pDescription.getValue());
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/* Copyright (c) Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Crypt32UtilTest extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Crypt32UtilTest.class);
|
||||
}
|
||||
|
||||
public void testCryptProtectUnprotectData() {
|
||||
byte[] data = new byte[2];
|
||||
data[0] = 42;
|
||||
data[1] = 12;
|
||||
byte[] protectedData = Crypt32Util.cryptProtectData(data);
|
||||
byte[] unprotectedData = Crypt32Util.cryptUnprotectData(protectedData);
|
||||
assertEquals(data.length, unprotectedData.length);
|
||||
assertEquals(data[0], unprotectedData[0]);
|
||||
assertEquals(data[1], unprotectedData[1]);
|
||||
}
|
||||
|
||||
public void testCryptProtectUnprotectMachineKey() {
|
||||
String s = "Hello World";
|
||||
byte[] data = Native.toByteArray(s);
|
||||
byte[] protectedData = Crypt32Util.cryptProtectData(data,
|
||||
WinCrypt.CRYPTPROTECT_LOCAL_MACHINE | WinCrypt.CRYPTPROTECT_UI_FORBIDDEN);
|
||||
byte[] unprotectedData = Crypt32Util.cryptUnprotectData(protectedData,
|
||||
WinCrypt.CRYPTPROTECT_LOCAL_MACHINE);
|
||||
String unprotectedString = Native.toString(unprotectedData);
|
||||
assertEquals(s, unprotectedString);
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/* Copyright (c) 2010 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.platform.win32.WinGDI.BITMAPINFO;
|
||||
|
||||
/**
|
||||
* @author twalljava[at]dev[dot]java[dot]net
|
||||
*/
|
||||
public class GDI32Test extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(GDI32Test.class);
|
||||
}
|
||||
|
||||
public void testBITMAPINFO() {
|
||||
BITMAPINFO info = new BITMAPINFO();
|
||||
assertEquals("Wrong size for BITMAPINFO()", 44, info.size());
|
||||
|
||||
info = new BITMAPINFO(2);
|
||||
assertEquals("Wrong size for BITMAPINFO(2)", 48, info.size());
|
||||
|
||||
info = new BITMAPINFO(16);
|
||||
assertEquals("Wrong size for BITMAPINFO(16)", 104, info.size());
|
||||
}
|
||||
}
|
||||
@@ -1,478 +0,0 @@
|
||||
/* Copyright (c) 2007 Timothy Wall, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.Native;
|
||||
import com.sun.jna.NativeMappedConverter;
|
||||
import com.sun.jna.Platform;
|
||||
import com.sun.jna.Pointer;
|
||||
import com.sun.jna.Memory;
|
||||
import com.sun.jna.platform.win32.WinBase.MEMORYSTATUSEX;
|
||||
import com.sun.jna.platform.win32.WinBase.SYSTEM_INFO;
|
||||
import com.sun.jna.platform.win32.WinDef.DWORD;
|
||||
import com.sun.jna.platform.win32.WinDef.HWND;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLE;
|
||||
import com.sun.jna.platform.win32.WinNT.HANDLEByReference;
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
import com.sun.jna.platform.win32.WinNT.OSVERSIONINFO;
|
||||
import com.sun.jna.platform.win32.WinNT.OSVERSIONINFOEX;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
|
||||
public class Kernel32Test extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
OSVERSIONINFO lpVersionInfo = new OSVERSIONINFO();
|
||||
assertTrue(Kernel32.INSTANCE.GetVersionEx(lpVersionInfo));
|
||||
System.out.println("Operating system: "
|
||||
+ lpVersionInfo.dwMajorVersion.longValue() + "." + lpVersionInfo.dwMinorVersion.longValue()
|
||||
+ " (" + lpVersionInfo.dwBuildNumber + ")"
|
||||
+ " [" + Native.toString(lpVersionInfo.szCSDVersion) + "]");
|
||||
junit.textui.TestRunner.run(Kernel32Test.class);
|
||||
}
|
||||
|
||||
public void testGetDriveType() {
|
||||
if (!Platform.isWindows()) return;
|
||||
|
||||
Kernel32 kernel = Kernel32.INSTANCE;
|
||||
assertEquals("Wrong drive type.", WinBase.DRIVE_FIXED, kernel.GetDriveType("c:"));
|
||||
}
|
||||
|
||||
public void testStructureOutArgument() {
|
||||
Kernel32 kernel = Kernel32.INSTANCE;
|
||||
WinBase.SYSTEMTIME time = new WinBase.SYSTEMTIME();
|
||||
kernel.GetSystemTime(time);
|
||||
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||
assertEquals("Hour not properly set",
|
||||
cal.get(Calendar.HOUR_OF_DAY), time.wHour);
|
||||
assertEquals("Day not properly set",
|
||||
cal.get(Calendar.DAY_OF_WEEK)-1,
|
||||
time.wDayOfWeek);
|
||||
assertEquals("Year not properly set",
|
||||
cal.get(Calendar.YEAR), time.wYear);
|
||||
}
|
||||
|
||||
public void testGetLastError() {
|
||||
Kernel32 kernel = Kernel32.INSTANCE;
|
||||
int ERRCODE = 8;
|
||||
|
||||
kernel.SetLastError(ERRCODE);
|
||||
int code = kernel.GetLastError();
|
||||
assertEquals("Wrong error value after SetLastError", ERRCODE, code);
|
||||
|
||||
if (kernel.GetProcessVersion(-1) == 0) {
|
||||
final int INVALID_PARAMETER = 87;
|
||||
code = kernel.GetLastError();
|
||||
assertEquals("Wrong error value after failed syscall", INVALID_PARAMETER, code);
|
||||
}
|
||||
else {
|
||||
fail("GetProcessId(NULL) should fail");
|
||||
}
|
||||
}
|
||||
|
||||
public void testConvertHWND_BROADCAST() {
|
||||
HWND hwnd = WinUser.HWND_BROADCAST;
|
||||
NativeMappedConverter.getInstance(hwnd.getClass()).toNative(hwnd, null);
|
||||
}
|
||||
|
||||
public void testGetComputerName() {
|
||||
IntByReference lpnSize = new IntByReference(0);
|
||||
assertFalse(Kernel32.INSTANCE.GetComputerName(null, lpnSize));
|
||||
assertEquals(W32Errors.ERROR_BUFFER_OVERFLOW, Kernel32.INSTANCE.GetLastError());
|
||||
char buffer[] = new char[WinBase.MAX_COMPUTERNAME_LENGTH + 1];
|
||||
lpnSize.setValue(buffer.length);
|
||||
assertTrue(Kernel32.INSTANCE.GetComputerName(buffer, lpnSize));
|
||||
}
|
||||
|
||||
public void testWaitForSingleObject() {
|
||||
HANDLE handle = Kernel32.INSTANCE.CreateEvent(null, false, false, null);
|
||||
|
||||
// handle runs into timeout since it is not triggered
|
||||
// WAIT_TIMEOUT = 0x00000102
|
||||
assertEquals(W32Errors.WAIT_TIMEOUT, Kernel32.INSTANCE.WaitForSingleObject(
|
||||
handle, 1000));
|
||||
|
||||
Kernel32.INSTANCE.CloseHandle(handle);
|
||||
}
|
||||
|
||||
public void testWaitForMultipleObjects(){
|
||||
HANDLE[] handles = new HANDLE[2];
|
||||
|
||||
handles[0] = Kernel32.INSTANCE.CreateEvent(null, false, false, null);
|
||||
handles[1] = Kernel32.INSTANCE.CreateEvent(null, false, false, null);
|
||||
|
||||
// handle runs into timeout since it is not triggered
|
||||
// WAIT_TIMEOUT = 0x00000102
|
||||
assertEquals(W32Errors.WAIT_TIMEOUT, Kernel32.INSTANCE.WaitForMultipleObjects(
|
||||
handles.length, handles, false, 1000));
|
||||
|
||||
Kernel32.INSTANCE.CloseHandle(handles[0]);
|
||||
Kernel32.INSTANCE.CloseHandle(handles[1]);
|
||||
|
||||
// invalid Handle
|
||||
handles[0] = WinBase.INVALID_HANDLE_VALUE;
|
||||
handles[1] = Kernel32.INSTANCE.CreateEvent(null, false, false, null);
|
||||
|
||||
// returns WAIT_FAILED since handle is invalid
|
||||
assertEquals(WinBase.WAIT_FAILED, Kernel32.INSTANCE.WaitForMultipleObjects(
|
||||
handles.length, handles, false, 5000));
|
||||
|
||||
Kernel32.INSTANCE.CloseHandle(handles[1]);
|
||||
}
|
||||
|
||||
public void testGetCurrentThreadId() {
|
||||
assertTrue(Kernel32.INSTANCE.GetCurrentThreadId() > 0);
|
||||
}
|
||||
|
||||
public void testGetCurrentThread() {
|
||||
HANDLE h = Kernel32.INSTANCE.GetCurrentThread();
|
||||
assertNotNull(h);
|
||||
assertFalse(h.equals(0));
|
||||
// CloseHandle does not need to be called for a thread handle
|
||||
assertFalse(Kernel32.INSTANCE.CloseHandle(h));
|
||||
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testOpenThread() {
|
||||
HANDLE h = Kernel32.INSTANCE.OpenThread(WinNT.THREAD_ALL_ACCESS, false,
|
||||
Kernel32.INSTANCE.GetCurrentThreadId());
|
||||
assertNotNull(h);
|
||||
assertFalse(h.equals(0));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(h));
|
||||
}
|
||||
|
||||
public void testGetCurrentProcessId() {
|
||||
assertTrue(Kernel32.INSTANCE.GetCurrentProcessId() > 0);
|
||||
}
|
||||
|
||||
public void testGetCurrentProcess() {
|
||||
HANDLE h = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertNotNull(h);
|
||||
assertFalse(h.equals(0));
|
||||
// CloseHandle does not need to be called for a process handle
|
||||
assertFalse(Kernel32.INSTANCE.CloseHandle(h));
|
||||
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testOpenProcess() {
|
||||
HANDLE h = Kernel32.INSTANCE.OpenProcess(0, false,
|
||||
Kernel32.INSTANCE.GetCurrentProcessId());
|
||||
assertNull(h);
|
||||
// opening your own process fails with access denied
|
||||
assertEquals(W32Errors.ERROR_ACCESS_DENIED, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testGetTempPath() {
|
||||
char[] buffer = new char[WinDef.MAX_PATH];
|
||||
assertTrue(Kernel32.INSTANCE.GetTempPath(new DWORD(WinDef.MAX_PATH), buffer).intValue() > 0);
|
||||
}
|
||||
|
||||
public void testGetTickCount() throws InterruptedException {
|
||||
// Tick count rolls over every 49.7 days, so to safeguard from
|
||||
// roll-over, we will get two time spans. At least one should
|
||||
// yield a positive.
|
||||
int tick1 = Kernel32.INSTANCE.GetTickCount();
|
||||
Thread.sleep(10);
|
||||
int tick2 = Kernel32.INSTANCE.GetTickCount();
|
||||
Thread.sleep(10);
|
||||
int tick3 = Kernel32.INSTANCE.GetTickCount();
|
||||
|
||||
assertTrue(tick2 > tick1 || tick3 > tick2);
|
||||
}
|
||||
|
||||
public void testGetVersion() {
|
||||
DWORD version = Kernel32.INSTANCE.GetVersion();
|
||||
assertTrue("Version high should be non-zero: 0x" + Integer.toHexString(version.getHigh().intValue()), version.getHigh().intValue() != 0);
|
||||
assertTrue("Version low should be >= 0: 0x" + Integer.toHexString(version.getLow().intValue()), version.getLow().intValue() >= 0);
|
||||
}
|
||||
|
||||
public void testGetVersionEx_OSVERSIONINFO() {
|
||||
OSVERSIONINFO lpVersionInfo = new OSVERSIONINFO();
|
||||
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
|
||||
assertTrue(Kernel32.INSTANCE.GetVersionEx(lpVersionInfo));
|
||||
assertTrue(lpVersionInfo.dwMajorVersion.longValue() > 0);
|
||||
assertTrue(lpVersionInfo.dwMinorVersion.longValue() >= 0);
|
||||
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
|
||||
assertTrue(lpVersionInfo.dwPlatformId.longValue() > 0);
|
||||
assertTrue(lpVersionInfo.dwBuildNumber.longValue() > 0);
|
||||
assertTrue(Native.toString(lpVersionInfo.szCSDVersion).length() >= 0);
|
||||
}
|
||||
|
||||
public void testGetVersionEx_OSVERSIONINFOEX() {
|
||||
OSVERSIONINFOEX lpVersionInfo = new OSVERSIONINFOEX();
|
||||
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
|
||||
assertTrue(Kernel32.INSTANCE.GetVersionEx(lpVersionInfo));
|
||||
assertTrue(lpVersionInfo.dwMajorVersion.longValue() > 0);
|
||||
assertTrue(lpVersionInfo.dwMinorVersion.longValue() >= 0);
|
||||
assertEquals(lpVersionInfo.size(), lpVersionInfo.dwOSVersionInfoSize.longValue());
|
||||
assertTrue(lpVersionInfo.dwPlatformId.longValue() > 0);
|
||||
assertTrue(lpVersionInfo.dwBuildNumber.longValue() > 0);
|
||||
assertTrue(Native.toString(lpVersionInfo.szCSDVersion).length() >= 0);
|
||||
assertTrue(lpVersionInfo.wProductType >= 0);
|
||||
}
|
||||
|
||||
public void testGetSystemInfo() {
|
||||
SYSTEM_INFO lpSystemInfo = new SYSTEM_INFO();
|
||||
Kernel32.INSTANCE.GetSystemInfo(lpSystemInfo);
|
||||
assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0);
|
||||
}
|
||||
|
||||
public void testIsWow64Process() {
|
||||
try {
|
||||
IntByReference isWow64 = new IntByReference(42);
|
||||
HANDLE hProcess = Kernel32.INSTANCE.GetCurrentProcess();
|
||||
assertTrue(Kernel32.INSTANCE.IsWow64Process(hProcess, isWow64));
|
||||
assertTrue(0 == isWow64.getValue() || 1 == isWow64.getValue());
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// IsWow64Process is not available on this OS
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetNativeSystemInfo() {
|
||||
try {
|
||||
SYSTEM_INFO lpSystemInfo = new SYSTEM_INFO();
|
||||
Kernel32.INSTANCE.GetNativeSystemInfo(lpSystemInfo);
|
||||
assertTrue(lpSystemInfo.dwNumberOfProcessors.intValue() > 0);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
// only available under WOW64
|
||||
}
|
||||
}
|
||||
|
||||
public void testGlobalMemoryStatusEx() {
|
||||
MEMORYSTATUSEX lpBuffer = new MEMORYSTATUSEX();
|
||||
assertTrue(Kernel32.INSTANCE.GlobalMemoryStatusEx(lpBuffer));
|
||||
assertTrue(lpBuffer.ullTotalPhys.longValue() > 0);
|
||||
assertTrue(lpBuffer.dwMemoryLoad.intValue() >= 0 && lpBuffer.dwMemoryLoad.intValue() <= 100);
|
||||
assertEquals(0, lpBuffer.ullAvailExtendedVirtual.intValue());
|
||||
}
|
||||
|
||||
public void testGetLogicalDriveStrings() {
|
||||
DWORD dwSize = Kernel32.INSTANCE.GetLogicalDriveStrings(new DWORD(0), null);
|
||||
assertTrue(dwSize.intValue() > 0);
|
||||
char buf[] = new char[dwSize.intValue()];
|
||||
assertTrue(Kernel32.INSTANCE.GetLogicalDriveStrings(dwSize, buf).intValue() > 0);
|
||||
}
|
||||
|
||||
public void testGetDiskFreeSpaceEx() {
|
||||
LARGE_INTEGER.ByReference lpFreeBytesAvailable = new LARGE_INTEGER.ByReference();
|
||||
LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new LARGE_INTEGER.ByReference();
|
||||
LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new LARGE_INTEGER.ByReference();
|
||||
assertTrue(Kernel32.INSTANCE.GetDiskFreeSpaceEx(null,
|
||||
lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes));
|
||||
assertTrue(lpTotalNumberOfFreeBytes.getValue() > 0);
|
||||
assertTrue(lpTotalNumberOfFreeBytes.getValue() < lpTotalNumberOfBytes.getValue());
|
||||
}
|
||||
|
||||
public void testDeleteFile() {
|
||||
String filename = Kernel32Util.getTempPath() + "\\FileDoesNotExist.jna";
|
||||
assertFalse(Kernel32.INSTANCE.DeleteFile(filename));
|
||||
assertEquals(W32Errors.ERROR_FILE_NOT_FOUND, Kernel32.INSTANCE.GetLastError());
|
||||
}
|
||||
|
||||
public void testReadFile() throws IOException {
|
||||
String expected = "jna - testReadFile";
|
||||
File tmp = File.createTempFile("testReadFile", "jna");
|
||||
tmp.deleteOnExit();
|
||||
|
||||
FileWriter fw = new FileWriter(tmp);
|
||||
fw.append(expected);
|
||||
fw.close();
|
||||
|
||||
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
|
||||
new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
|
||||
assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);
|
||||
|
||||
Memory m = new Memory(2048);
|
||||
IntByReference lpNumberOfBytesRead = new IntByReference(0);
|
||||
assertTrue(Kernel32.INSTANCE.ReadFile(hFile, m, (int) m.size(), lpNumberOfBytesRead, null));
|
||||
int read = lpNumberOfBytesRead.getValue();
|
||||
assertEquals(expected.length(), read);
|
||||
assertEquals(expected, new String(m.getByteArray(0, read)));
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
|
||||
}
|
||||
|
||||
public void testSetHandleInformation() throws IOException {
|
||||
File tmp = File.createTempFile("testSetHandleInformation", "jna");
|
||||
tmp.deleteOnExit();
|
||||
|
||||
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
|
||||
new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
|
||||
assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.SetHandleInformation(hFile, WinBase.HANDLE_FLAG_PROTECT_FROM_CLOSE, 0));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
|
||||
}
|
||||
|
||||
public void testCreatePipe() {
|
||||
HANDLEByReference hReadPipe = new HANDLEByReference();
|
||||
HANDLEByReference hWritePipe = new HANDLEByReference();
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.CreatePipe(hReadPipe, hWritePipe, null, 0));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hReadPipe.getValue()));
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hWritePipe.getValue()));
|
||||
}
|
||||
|
||||
public void testGetExitCodeProcess() {
|
||||
IntByReference lpExitCode = new IntByReference(0);
|
||||
assertTrue(Kernel32.INSTANCE.GetExitCodeProcess(Kernel32.INSTANCE.GetCurrentProcess(), lpExitCode));
|
||||
assertEquals(WinBase.STILL_ACTIVE, lpExitCode.getValue());
|
||||
}
|
||||
|
||||
public void testTerminateProcess() throws IOException {
|
||||
File tmp = File.createTempFile("testTerminateProcess", "jna");
|
||||
tmp.deleteOnExit();
|
||||
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_READ, WinNT.FILE_SHARE_READ,
|
||||
new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
|
||||
|
||||
assertFalse(Kernel32.INSTANCE.TerminateProcess(hFile, 1));
|
||||
assertEquals(W32Errors.ERROR_INVALID_HANDLE, Kernel32.INSTANCE.GetLastError());
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
|
||||
}
|
||||
|
||||
public void testGetFileAttributes() {
|
||||
assertTrue(WinBase.INVALID_FILE_ATTRIBUTES != Kernel32.INSTANCE.GetFileAttributes("."));
|
||||
}
|
||||
|
||||
public void testCopyFile() throws IOException {
|
||||
File source = File.createTempFile("testCopyFile", "jna");
|
||||
source.deleteOnExit();
|
||||
File destination = new File(source.getParent(), source.getName() + "-destination");
|
||||
destination.deleteOnExit();
|
||||
|
||||
Kernel32.INSTANCE.CopyFile(source.getCanonicalPath(), destination.getCanonicalPath(), true);
|
||||
assertTrue(destination.exists());
|
||||
}
|
||||
|
||||
public void testMoveFile() throws IOException {
|
||||
File source = File.createTempFile("testMoveFile", "jna");
|
||||
source.deleteOnExit();
|
||||
File destination = new File(source.getParent(), source.getName() + "-destination");
|
||||
destination.deleteOnExit();
|
||||
|
||||
Kernel32.INSTANCE.MoveFile(source.getCanonicalPath(), destination.getCanonicalPath());
|
||||
assertTrue(destination.exists());
|
||||
assertFalse(source.exists());
|
||||
}
|
||||
|
||||
public void testMoveFileEx() throws IOException {
|
||||
File source = File.createTempFile("testMoveFileEx", "jna");
|
||||
source.deleteOnExit();
|
||||
File destination = File.createTempFile("testCopyFile", "jna");
|
||||
destination.deleteOnExit();
|
||||
|
||||
Kernel32.INSTANCE.MoveFileEx(source.getCanonicalPath(), destination.getCanonicalPath(), new DWORD(WinBase.MOVEFILE_REPLACE_EXISTING));
|
||||
assertTrue(destination.exists());
|
||||
assertFalse(source.exists());
|
||||
}
|
||||
|
||||
public void testCreateProcess() {
|
||||
WinBase.STARTUPINFO startupInfo = new WinBase.STARTUPINFO();
|
||||
WinBase.PROCESS_INFORMATION.ByReference processInformation = new WinBase.PROCESS_INFORMATION.ByReference();
|
||||
|
||||
boolean status = Kernel32.INSTANCE.CreateProcess(
|
||||
null,
|
||||
"cmd.exe /c echo hi",
|
||||
null,
|
||||
null,
|
||||
true,
|
||||
new WinDef.DWORD(0),
|
||||
Pointer.NULL,
|
||||
System.getProperty("java.io.tmpdir"),
|
||||
startupInfo,
|
||||
processInformation);
|
||||
|
||||
assertTrue(status);
|
||||
assertTrue(processInformation.dwProcessId.longValue() > 0);
|
||||
}
|
||||
|
||||
public void testGetEnvironmentVariable() {
|
||||
assertTrue(Kernel32.INSTANCE.SetEnvironmentVariable("jna-getenvironment-test", "42"));
|
||||
int size = Kernel32.INSTANCE.GetEnvironmentVariable("jna-getenvironment-test", null, 0);
|
||||
assertTrue(size == 3);
|
||||
char[] data = new char[size];
|
||||
assertEquals(size - 1, Kernel32.INSTANCE.GetEnvironmentVariable("jna-getenvironment-test", data, size));
|
||||
assertEquals(size - 1, Native.toString(data).length());
|
||||
}
|
||||
|
||||
public void testSetEnvironmentVariable() {
|
||||
int value = new Random().nextInt();
|
||||
Kernel32.INSTANCE.SetEnvironmentVariable("jna-setenvironment-test", Integer.toString(value));
|
||||
assertEquals(Integer.toString(value), Kernel32Util.getEnvironmentVariable("jna-setenvironment-test"));
|
||||
}
|
||||
|
||||
public void testGetSetFileTime() throws IOException {
|
||||
File tmp = File.createTempFile("testGetSetFileTime", "jna");
|
||||
tmp.deleteOnExit();
|
||||
|
||||
HANDLE hFile = Kernel32.INSTANCE.CreateFile(tmp.getAbsolutePath(), WinNT.GENERIC_WRITE, WinNT.FILE_SHARE_WRITE,
|
||||
new WinBase.SECURITY_ATTRIBUTES(), WinNT.OPEN_EXISTING, WinNT.FILE_ATTRIBUTE_NORMAL, null);
|
||||
assertFalse(hFile == WinBase.INVALID_HANDLE_VALUE);
|
||||
|
||||
WinBase.FILETIME.ByReference creationTime = new WinBase.FILETIME.ByReference();
|
||||
WinBase.FILETIME.ByReference accessTime = new WinBase.FILETIME.ByReference();
|
||||
WinBase.FILETIME.ByReference modifiedTime = new WinBase.FILETIME.ByReference();
|
||||
Kernel32.INSTANCE.GetFileTime(hFile, creationTime, accessTime, modifiedTime);
|
||||
|
||||
assertEquals(creationTime.toDate().getYear(), new Date().getYear());
|
||||
assertEquals(accessTime.toDate().getYear(), new Date().getYear());
|
||||
assertEquals(modifiedTime.toDate().getYear(), new Date().getYear());
|
||||
|
||||
Kernel32.INSTANCE.SetFileTime(hFile, null, null, new WinBase.FILETIME(new Date(2010, 1, 1)));
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(hFile));
|
||||
|
||||
assertEquals(2010, new Date(tmp.lastModified()).getYear());
|
||||
}
|
||||
|
||||
public void testSetFileAttributes() throws IOException {
|
||||
File tmp = File.createTempFile("testSetFileAttributes", "jna");
|
||||
tmp.deleteOnExit();
|
||||
|
||||
Kernel32.INSTANCE.SetFileAttributes(tmp.getCanonicalPath(), new DWORD(WinNT.FILE_ATTRIBUTE_HIDDEN));
|
||||
int attributes = Kernel32.INSTANCE.GetFileAttributes(tmp.getCanonicalPath());
|
||||
|
||||
assertTrue((attributes & WinNT.FILE_ATTRIBUTE_HIDDEN) != 0);
|
||||
}
|
||||
|
||||
public void testGetProcessList() throws IOException {
|
||||
WinNT.HANDLE processEnumHandle = Kernel32.INSTANCE.CreateToolhelp32Snapshot(Tlhelp32.TH32CS_SNAPALL, new WinDef.DWORD(0));
|
||||
assertFalse(WinBase.INVALID_HANDLE_VALUE.equals(processEnumHandle));
|
||||
|
||||
Tlhelp32.PROCESSENTRY32.ByReference processEntry = new Tlhelp32.PROCESSENTRY32.ByReference();
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.Process32First(processEnumHandle, processEntry));
|
||||
|
||||
List<Long> processIdList = new ArrayList<Long>();
|
||||
processIdList.add(processEntry.th32ProcessID.longValue());
|
||||
|
||||
while (Kernel32.INSTANCE.Process32Next(processEnumHandle, processEntry))
|
||||
{
|
||||
processIdList.add(processEntry.th32ProcessID.longValue());
|
||||
}
|
||||
|
||||
assertTrue(Kernel32.INSTANCE.CloseHandle(processEnumHandle));
|
||||
assertTrue(processIdList.size() > 4);
|
||||
}
|
||||
}
|
||||
@@ -1,132 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.sun.jna.platform.win32.WinNT.LARGE_INTEGER;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Kernel32UtilTest extends TestCase {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.out.println("Computer name: " + Kernel32Util.getComputerName());
|
||||
System.out.println("Temp path: " + Kernel32Util.getTempPath());
|
||||
// logical drives
|
||||
System.out.println("Logical drives: ");
|
||||
String[] logicalDrives = Kernel32Util.getLogicalDriveStrings();
|
||||
for(String logicalDrive : logicalDrives) {
|
||||
// drive type
|
||||
System.out.println(" " + logicalDrive + " ("
|
||||
+ Kernel32.INSTANCE.GetDriveType(logicalDrive) + ")");
|
||||
// free space
|
||||
LARGE_INTEGER.ByReference lpFreeBytesAvailable = new LARGE_INTEGER.ByReference();
|
||||
LARGE_INTEGER.ByReference lpTotalNumberOfBytes = new LARGE_INTEGER.ByReference();
|
||||
LARGE_INTEGER.ByReference lpTotalNumberOfFreeBytes = new LARGE_INTEGER.ByReference();
|
||||
if (Kernel32.INSTANCE.GetDiskFreeSpaceEx(logicalDrive, lpFreeBytesAvailable, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes)) {
|
||||
System.out.println(" Total: " + formatBytes(lpTotalNumberOfBytes.getValue()));
|
||||
System.out.println(" Free: " + formatBytes(lpTotalNumberOfFreeBytes.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
junit.textui.TestRunner.run(Kernel32UtilTest.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format bytes.
|
||||
* @param bytes
|
||||
* Bytes.
|
||||
* @return
|
||||
* Rounded string representation of the byte size.
|
||||
*/
|
||||
private static String formatBytes(long bytes) {
|
||||
if (bytes == 1) { // bytes
|
||||
return String.format("%d byte", bytes);
|
||||
} else if (bytes < 1024) { // bytes
|
||||
return String.format("%d bytes", bytes);
|
||||
} else if (bytes < 1048576 && bytes % 1024 == 0) { // Kb
|
||||
return String.format("%.0f KB", (double) bytes / 1024);
|
||||
} else if (bytes < 1048576) { // Kb
|
||||
return String.format("%.1f KB", (double) bytes / 1024);
|
||||
} else if (bytes % 1048576 == 0 && bytes < 1073741824) { // Mb
|
||||
return String.format("%.0f MB", (double) bytes / 1048576);
|
||||
} else if (bytes < 1073741824) { // Mb
|
||||
return String.format("%.1f MB", (double) bytes / 1048576);
|
||||
} else if (bytes % 1073741824 == 0 && bytes < 1099511627776L) { // GB
|
||||
return String.format("%.0f GB", (double) bytes / 1073741824);
|
||||
} else if (bytes < 1099511627776L ) {
|
||||
return String.format("%.1f GB", (double) bytes / 1073741824);
|
||||
} else if (bytes % 1099511627776L == 0 && bytes < 1125899906842624L) { // TB
|
||||
return String.format("%.0f TB", (double) bytes / 1099511627776L);
|
||||
} else if (bytes < 1125899906842624L ) {
|
||||
return String.format("%.1f TB", (double) bytes / 1099511627776L);
|
||||
} else {
|
||||
return String.format("%d bytes", bytes);
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetComputerName() {
|
||||
assertTrue(Kernel32Util.getComputerName().length() > 0);
|
||||
}
|
||||
|
||||
public void testFormatMessageFromLastErrorCode() {
|
||||
assertEquals("The remote server has been paused or is in the process of being started.",
|
||||
Kernel32Util.formatMessageFromLastErrorCode(W32Errors.ERROR_SHARING_PAUSED));
|
||||
}
|
||||
|
||||
public void testFormatMessageFromHR() {
|
||||
assertEquals("The operation completed successfully.",
|
||||
Kernel32Util.formatMessageFromHR(W32Errors.S_OK));
|
||||
}
|
||||
|
||||
public void testGetTempPath() {
|
||||
assertTrue(Kernel32Util.getTempPath().length() > 0);
|
||||
}
|
||||
|
||||
public void testGetLogicalDriveStrings() {
|
||||
String[] logicalDrives = Kernel32Util.getLogicalDriveStrings();
|
||||
assertTrue(logicalDrives.length > 0);
|
||||
for(String logicalDrive : logicalDrives) {
|
||||
assertTrue(logicalDrive.length() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void testDeleteFile() throws IOException {
|
||||
String filename = Kernel32Util.getTempPath() + "\\FileDoesNotExist.jna";
|
||||
File f = new File(filename);
|
||||
f.createNewFile();
|
||||
Kernel32Util.deleteFile(filename);
|
||||
}
|
||||
|
||||
public void testGetFileAttributes() throws IOException {
|
||||
String filename = Kernel32Util.getTempPath();
|
||||
int fileAttributes = Kernel32Util.getFileAttributes(filename);
|
||||
assertEquals(WinNT.FILE_ATTRIBUTE_DIRECTORY, fileAttributes & WinNT.FILE_ATTRIBUTE_DIRECTORY);
|
||||
File tempFile = File.createTempFile("jna", "tmp");
|
||||
tempFile.deleteOnExit();
|
||||
int fileAttributes2 = Kernel32Util.getFileAttributes(tempFile.getAbsolutePath());
|
||||
tempFile.delete();
|
||||
assertEquals(0, fileAttributes2 & WinNT.FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
public void testGetEnvironmentVariable() {
|
||||
assertEquals(null, Kernel32Util.getEnvironmentVariable("jna-getenvironment-test"));
|
||||
Kernel32.INSTANCE.SetEnvironmentVariable("jna-getenvironment-test", "42");
|
||||
assertEquals("42", Kernel32Util.getEnvironmentVariable("jna-getenvironment-test"));
|
||||
}
|
||||
}
|
||||
@@ -1,72 +0,0 @@
|
||||
/* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MsiTest extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(MsiTest.class);
|
||||
}
|
||||
|
||||
public void testMsiEnumComponents() {
|
||||
char[] componentBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
|
||||
String component = new String(componentBuffer).trim();
|
||||
assertTrue(component.length() > 0);
|
||||
}
|
||||
|
||||
public void testMsiGetProductCodeW() {
|
||||
char[] componentBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
|
||||
String component = new String(componentBuffer).trim();
|
||||
|
||||
char[] productBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiGetProductCode(component, productBuffer));
|
||||
|
||||
String product = new String(productBuffer).trim();
|
||||
assertTrue(product.length() > 0);
|
||||
}
|
||||
|
||||
public void testMsiLocateComponentW() {
|
||||
char[] componentBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
|
||||
String component = new String(componentBuffer).trim();
|
||||
|
||||
char[] pathBuffer = new char[WinDef.MAX_PATH];
|
||||
IntByReference pathBufferSize = new IntByReference(pathBuffer.length);
|
||||
Msi.INSTANCE.MsiLocateComponent(component, pathBuffer, pathBufferSize);
|
||||
|
||||
String path = new String(pathBuffer, 0, pathBufferSize.getValue()).trim();
|
||||
assertTrue(path.length() > 0);
|
||||
}
|
||||
|
||||
public void testMsiGetComponentPathW() {
|
||||
char[] componentBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiEnumComponents(new WinDef.DWORD(0), componentBuffer));
|
||||
String component = new String(componentBuffer).trim();
|
||||
|
||||
char[] productBuffer = new char[40];
|
||||
assertTrue(W32Errors.ERROR_SUCCESS == Msi.INSTANCE.MsiGetProductCode(component, productBuffer));
|
||||
|
||||
String product = new String(productBuffer).trim();
|
||||
assertTrue(product.length() > 0);
|
||||
|
||||
char[] pathBuffer = new char[WinDef.MAX_PATH];
|
||||
IntByReference pathBufferSize = new IntByReference(pathBuffer.length);
|
||||
Msi.INSTANCE.MsiGetComponentPath(product, component, pathBuffer, pathBufferSize);
|
||||
|
||||
String path = new String(pathBuffer, 0, pathBufferSize.getValue()).trim();
|
||||
assertTrue(path.length() > 0);
|
||||
}
|
||||
}
|
||||
@@ -1,256 +0,0 @@
|
||||
/* Copyright (c) 2010 Daniel Doubrovkine, All Rights Reserved
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
package com.sun.jna.platform.win32;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.sun.jna.WString;
|
||||
import com.sun.jna.platform.win32.DsGetDC.DS_DOMAIN_TRUSTS;
|
||||
import com.sun.jna.platform.win32.DsGetDC.PDOMAIN_CONTROLLER_INFO;
|
||||
import com.sun.jna.platform.win32.LMAccess.GROUP_INFO_2;
|
||||
import com.sun.jna.platform.win32.LMAccess.GROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.LMAccess.LOCALGROUP_USERS_INFO_0;
|
||||
import com.sun.jna.platform.win32.LMAccess.USER_INFO_1;
|
||||
import com.sun.jna.platform.win32.NTSecApi.LSA_FOREST_TRUST_RECORD;
|
||||
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_INFORMATION;
|
||||
import com.sun.jna.platform.win32.NTSecApi.PLSA_FOREST_TRUST_RECORD;
|
||||
import com.sun.jna.platform.win32.Netapi32Util.User;
|
||||
import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT;
|
||||
import com.sun.jna.ptr.IntByReference;
|
||||
import com.sun.jna.ptr.PointerByReference;
|
||||
|
||||
/**
|
||||
* @author dblock[at]dblock[dot]org
|
||||
*/
|
||||
public class Netapi32Test extends TestCase {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(Netapi32Test.class);
|
||||
}
|
||||
|
||||
public void testNetGetJoinInformation() {
|
||||
IntByReference bufferType = new IntByReference();
|
||||
assertEquals(W32Errors.ERROR_INVALID_PARAMETER, Netapi32.INSTANCE.NetGetJoinInformation(
|
||||
null, null, bufferType));
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetGetJoinInformation(
|
||||
null, lpNameBuffer, bufferType));
|
||||
assertTrue(lpNameBuffer.getValue().getString(0).length() > 0);
|
||||
assertTrue(bufferType.getValue() > 0);
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
|
||||
lpNameBuffer.getValue()));
|
||||
}
|
||||
|
||||
public void testNetGetLocalGroups() {
|
||||
for(int i = 0; i < 2; i++) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesRead = new IntByReference();
|
||||
IntByReference totalEntries = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetLocalGroupEnum(null, i, bufptr,
|
||||
LMCons.MAX_PREFERRED_LENGTH,
|
||||
entriesRead,
|
||||
totalEntries,
|
||||
null));
|
||||
assertTrue(entriesRead.getValue() > 0);
|
||||
assertEquals(totalEntries.getValue(), entriesRead.getValue());
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
|
||||
bufptr.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testNetGetDCName() {
|
||||
PointerByReference lpNameBuffer = new PointerByReference();
|
||||
IntByReference BufferType = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGetJoinInformation(null, lpNameBuffer, BufferType));
|
||||
if (BufferType.getValue() == LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName) {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGetDCName(null, null, bufptr));
|
||||
String dc = bufptr.getValue().getString(0);
|
||||
assertTrue(dc.length() > 0);
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
|
||||
}
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(lpNameBuffer.getValue()));
|
||||
}
|
||||
|
||||
public void testNetUserGetGroups() {
|
||||
User[] users = Netapi32Util.getUsers();
|
||||
assertTrue(users.length >= 1);
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserGetGroups(
|
||||
null, users[0].name, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH,
|
||||
entriesread, totalentries));
|
||||
GROUP_USERS_INFO_0 lgroup = new GROUP_USERS_INFO_0(bufptr.getValue());
|
||||
GROUP_USERS_INFO_0[] lgroups = (GROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
for (GROUP_USERS_INFO_0 localGroupInfo : lgroups) {
|
||||
assertTrue(localGroupInfo.grui0_name.length() > 0);
|
||||
}
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
|
||||
}
|
||||
|
||||
public void testNetUserGetLocalGroups() {
|
||||
String currentUser = Secur32Util.getUserNameEx(
|
||||
EXTENDED_NAME_FORMAT.NameSamCompatible);
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserGetLocalGroups(
|
||||
null, currentUser, 0, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH,
|
||||
entriesread, totalentries));
|
||||
LOCALGROUP_USERS_INFO_0 lgroup = new LOCALGROUP_USERS_INFO_0(bufptr.getValue());
|
||||
LOCALGROUP_USERS_INFO_0[] lgroups = (LOCALGROUP_USERS_INFO_0[]) lgroup.toArray(entriesread.getValue());
|
||||
for (LOCALGROUP_USERS_INFO_0 localGroupInfo : lgroups) {
|
||||
assertTrue(localGroupInfo.lgrui0_name.length() > 0);
|
||||
}
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
|
||||
}
|
||||
|
||||
public void testNetGroupEnum() {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetGroupEnum(
|
||||
null, 2, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
|
||||
GROUP_INFO_2 group = new GROUP_INFO_2(bufptr.getValue());
|
||||
GROUP_INFO_2[] groups = (GROUP_INFO_2[]) group.toArray(entriesread.getValue());
|
||||
for (GROUP_INFO_2 grpi : groups) {
|
||||
assertTrue(grpi.grpi2_name.length() > 0);
|
||||
}
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
|
||||
}
|
||||
|
||||
public void testNetUserEnum() {
|
||||
PointerByReference bufptr = new PointerByReference();
|
||||
IntByReference entriesread = new IntByReference();
|
||||
IntByReference totalentries = new IntByReference();
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserEnum(
|
||||
null, 1, 0, bufptr, LMCons.MAX_PREFERRED_LENGTH, entriesread, totalentries, null));
|
||||
USER_INFO_1 userinfo = new USER_INFO_1(bufptr.getValue());
|
||||
USER_INFO_1[] userinfos = (USER_INFO_1[]) userinfo.toArray(entriesread.getValue());
|
||||
for (USER_INFO_1 ui : userinfos) {
|
||||
assertTrue(ui.usri1_name.length() > 0);
|
||||
}
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetApiBufferFree(bufptr.getValue()));
|
||||
}
|
||||
|
||||
public void testNetUserAdd() {
|
||||
USER_INFO_1 userInfo = new USER_INFO_1();
|
||||
userInfo.usri1_name = new WString("JNANetapi32TestUser");
|
||||
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
|
||||
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
|
||||
Kernel32Util.getComputerName(), 1, userInfo, null));
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(
|
||||
Kernel32Util.getComputerName(), userInfo.usri1_name.toString()));
|
||||
}
|
||||
|
||||
public void testNetUserChangePassword() {
|
||||
USER_INFO_1 userInfo = new USER_INFO_1();
|
||||
userInfo.usri1_name = new WString("JNANetapi32TestUser");
|
||||
userInfo.usri1_password = new WString("!JNAP$$Wrd0");
|
||||
userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserAdd(
|
||||
Kernel32Util.getComputerName(), 1, userInfo, null));
|
||||
try {
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserChangePassword(
|
||||
Kernel32Util.getComputerName(), userInfo.usri1_name.toString(), userInfo.usri1_password.toString(),
|
||||
"!JNAP%%Wrd1"));
|
||||
} finally {
|
||||
assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(
|
||||
Kernel32Util.getComputerName(), userInfo.usri1_name.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void testNetUserDel() {
|
||||
assertEquals(LMErr.NERR_UserNotFound, Netapi32.INSTANCE.NetUserDel(
|
||||
Kernel32Util.getComputerName(), "JNANetapi32TestUserDoesntExist"));
|
||||
}
|
||||
|
||||
public void testDsGetDcName() {
|
||||
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
|
||||
return;
|
||||
|
||||
PDOMAIN_CONTROLLER_INFO.ByReference pdci = new PDOMAIN_CONTROLLER_INFO.ByReference();
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.DsGetDcName(
|
||||
null, null, null, null, 0, pdci));
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
|
||||
pdci.getPointer()));
|
||||
}
|
||||
|
||||
public void testDsGetForestTrustInformation() {
|
||||
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
|
||||
return;
|
||||
|
||||
String domainController = Netapi32Util.getDCName();
|
||||
PLSA_FOREST_TRUST_INFORMATION.ByReference pfti = new PLSA_FOREST_TRUST_INFORMATION.ByReference();
|
||||
assertEquals(W32Errors.NO_ERROR, Netapi32.INSTANCE.DsGetForestTrustInformation(
|
||||
domainController, null, 0, pfti));
|
||||
|
||||
assertTrue(pfti.fti.RecordCount >= 0);
|
||||
|
||||
for (PLSA_FOREST_TRUST_RECORD precord : pfti.fti.getEntries()) {
|
||||
LSA_FOREST_TRUST_RECORD.UNION data = precord.tr.u;
|
||||
switch(precord.tr.ForestTrustType) {
|
||||
case NTSecApi.ForestTrustTopLevelName:
|
||||
case NTSecApi.ForestTrustTopLevelNameEx:
|
||||
assertTrue(data.TopLevelName.Length > 0);
|
||||
assertTrue(data.TopLevelName.MaximumLength > 0);
|
||||
assertTrue(data.TopLevelName.MaximumLength >= data.TopLevelName.Length);
|
||||
assertTrue(data.TopLevelName.getString().length() > 0);
|
||||
break;
|
||||
case NTSecApi.ForestTrustDomainInfo:
|
||||
assertTrue(data.DomainInfo.DnsName.Length > 0);
|
||||
assertTrue(data.DomainInfo.DnsName.MaximumLength > 0);
|
||||
assertTrue(data.DomainInfo.DnsName.MaximumLength >= data.DomainInfo.DnsName.Length);
|
||||
assertTrue(data.DomainInfo.DnsName.getString().length() > 0);
|
||||
assertTrue(data.DomainInfo.NetbiosName.Length > 0);
|
||||
assertTrue(data.DomainInfo.NetbiosName.MaximumLength > 0);
|
||||
assertTrue(data.DomainInfo.NetbiosName.MaximumLength >= data.DomainInfo.NetbiosName.Length);
|
||||
assertTrue(data.DomainInfo.NetbiosName.getString().length() > 0);
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(data.DomainInfo.Sid));
|
||||
assertTrue(Advapi32Util.convertSidToStringSid(data.DomainInfo.Sid).startsWith("S-"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
|
||||
pfti.getPointer()));
|
||||
}
|
||||
|
||||
|
||||
public void testDsEnumerateDomainTrusts() {
|
||||
if (Netapi32Util.getJoinStatus() != LMJoin.NETSETUP_JOIN_STATUS.NetSetupDomainName)
|
||||
return;
|
||||
|
||||
IntByReference domainTrustCount = new IntByReference();
|
||||
PointerByReference domainsPointerRef = new PointerByReference();
|
||||
assertEquals(W32Errors.NO_ERROR, Netapi32.INSTANCE.DsEnumerateDomainTrusts(null,
|
||||
DsGetDC.DS_DOMAIN_VALID_FLAGS, domainsPointerRef, domainTrustCount));
|
||||
assertTrue(domainTrustCount.getValue() >= 0);
|
||||
|
||||
DS_DOMAIN_TRUSTS domainTrustRefs = new DS_DOMAIN_TRUSTS(domainsPointerRef.getValue());
|
||||
DS_DOMAIN_TRUSTS[] domainTrusts = (DS_DOMAIN_TRUSTS[]) domainTrustRefs.toArray(new DS_DOMAIN_TRUSTS[domainTrustCount.getValue()]);
|
||||
|
||||
for(DS_DOMAIN_TRUSTS trust : domainTrusts) {
|
||||
assertTrue(trust.DnsDomainName.length() > 0);
|
||||
assertTrue(Advapi32.INSTANCE.IsValidSid(trust.DomainSid));
|
||||
assertTrue(Advapi32Util.convertSidToStringSid(trust.DomainSid).startsWith("S-"));
|
||||
assertTrue(Ole32Util.getStringFromGUID(trust.DomainGuid).startsWith("{"));
|
||||
}
|
||||
|
||||
|
||||
assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(domainTrustRefs.getPointer()));
|
||||
}
|
||||
|
||||
}
|
||||
Alguns arquivos não foram exibidos porque demasiados arquivos foram alterados neste diff Mostrar Mais
Referência em uma Nova Issue
Bloquear um usuário