From a412e515678fe27726cd0c0ccea3d5fc6b767de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sat, 24 May 2025 04:40:41 +0200 Subject: [PATCH] JNA packages refactoring --- .../flash}/jna/platform/win32/Advapi32.java | 10 +- .../jna/platform/win32/Advapi32Util.java | 6 +- .../flash}/jna/platform/win32/W32Errors.java | 3 +- .../jna/platform/win32/Win32Exception.java | 2 +- .../flash/jna/platform/win32/WinBase.java | 1037 ++++++++ .../flash/jna/platform/win32/WinNT.java | 2112 +++++++++++++++++ .../flash}/jna/platform/win32/WinReg.java | 4 +- .../jna/platform/win32/package-info.java | 2 +- .../com/jpexs/video/SimpleMediaPlayer.java | 4 +- .../console/CommandLineArgumentParser.java | 2 +- .../flash/console/ContextMenuTools.java | 14 +- src/com/jpexs/decompiler/flash/gui/Main.java | 7 +- .../gui/jna/platform/win32/Advapi32.java | 977 ++++++++ .../gui/jna/platform/win32/Advapi32Util.java | 1059 +++++++++ .../flash/gui}/jna/platform/win32/BITMAP.java | 8 +- .../gui}/jna/platform/win32/BaseTSD.java | 2 +- .../flash/gui}/jna/platform/win32/Gdi32.java | 18 +- .../gui}/jna/platform/win32/ICONINFO.java | 6 +- .../gui}/jna/platform/win32/Kernel32.java | 3 +- .../win32/MEMORY_BASIC_INFORMATION.java | 4 +- .../jna/platform/win32/PROCESSENTRY32.java | 2 +- .../flash/gui}/jna/platform/win32/Psapi.java | 4 +- .../jna/platform/win32/SHELLEXECUTEINFO.java | 10 +- .../gui}/jna/platform/win32/SHFILEINFO.java | 4 +- .../gui}/jna/platform/win32/Shell32.java | 6 +- .../flash/gui}/jna/platform/win32/User32.java | 6 +- .../gui/jna/platform/win32/W32Errors.java | 186 ++ .../jna/platform/win32/Win32Exception.java | 75 + .../gui}/jna/platform/win32/WinBase.java | 4 +- .../flash/gui}/jna/platform/win32/WinDef.java | 6 +- .../gui}/jna/platform/win32/WinError.java | 2 +- .../flash/gui}/jna/platform/win32/WinGDI.java | 2 +- .../flash/gui}/jna/platform/win32/WinNT.java | 2 +- .../flash/gui/jna/platform/win32/WinReg.java | 94 + .../gui}/jna/platform/win32/WinUser.java | 2 +- .../gui/jna/platform/win32/package-info.java | 4 + .../flash/gui/pipes/FirstInstance.java | 4 +- .../flash/gui/pipes/PipeInputStream.java | 4 +- .../flash/gui/pipes/PipeOutputStream.java | 4 +- src/com/jpexs/process/win32/Win32Process.java | 2 +- .../process/win32/Win32ProcessTools.java | 32 +- 41 files changed, 5640 insertions(+), 95 deletions(-) rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/Advapi32.java (99%) rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/Advapi32Util.java (99%) rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/W32Errors.java (97%) rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/Win32Exception.java (97%) create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinBase.java create mode 100644 libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinNT.java rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/WinReg.java (95%) rename libsrc/ffdec_lib/src/com/{sun => jpexs/decompiler/flash}/jna/platform/win32/package-info.java (55%) create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32.java create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32Util.java rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/BITMAP.java (81%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/BaseTSD.java (98%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/Gdi32.java (95%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/ICONINFO.java (84%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/Kernel32.java (99%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/MEMORY_BASIC_INFORMATION.java (91%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/PROCESSENTRY32.java (98%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/Psapi.java (89%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/SHELLEXECUTEINFO.java (82%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/SHFILEINFO.java (90%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/Shell32.java (88%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/User32.java (99%) create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/W32Errors.java create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Win32Exception.java rename {libsrc/ffdec_lib/src/com/sun => src/com/jpexs/decompiler/flash/gui}/jna/platform/win32/WinBase.java (99%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/WinDef.java (99%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/WinError.java (99%) rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/WinGDI.java (98%) rename {libsrc/ffdec_lib/src/com/sun => src/com/jpexs/decompiler/flash/gui}/jna/platform/win32/WinNT.java (99%) create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinReg.java rename src/com/{sun => jpexs/decompiler/flash/gui}/jna/platform/win32/WinUser.java (99%) create mode 100644 src/com/jpexs/decompiler/flash/gui/jna/platform/win32/package-info.java diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32.java similarity index 99% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32.java index 83cc8f93d..9a200e4ed 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; /** * @author JPEXS @@ -35,10 +35,10 @@ import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES; -import com.sun.jna.platform.win32.WinNT.HANDLE; -import com.sun.jna.platform.win32.WinNT.HANDLEByReference; -import com.sun.jna.platform.win32.WinReg.HKEY; -import com.sun.jna.platform.win32.WinReg.HKEYByReference; +import com.jpexs.decompiler.flash.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.jna.platform.win32.WinNT.HANDLEByReference; +import com.jpexs.decompiler.flash.jna.platform.win32.WinReg.HKEY; +import com.jpexs.decompiler.flash.jna.platform.win32.WinReg.HKEYByReference; import com.sun.jna.ptr.IntByReference; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32Util.java similarity index 99% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32Util.java index 904443b97..fbe816222 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Advapi32Util.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Advapi32Util.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; /** * @author JPEXS @@ -23,8 +23,8 @@ import com.sun.jna.Memory; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.platform.win32.WinNT.EVENTLOGRECORD; -import com.sun.jna.platform.win32.WinReg.HKEY; -import com.sun.jna.platform.win32.WinReg.HKEYByReference; +import com.jpexs.decompiler.flash.jna.platform.win32.WinReg.HKEY; +import com.jpexs.decompiler.flash.jna.platform.win32.WinReg.HKEYByReference; import com.sun.jna.ptr.IntByReference; import java.util.ArrayList; import java.util.Map; diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/W32Errors.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/W32Errors.java similarity index 97% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/W32Errors.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/W32Errors.java index 38599dc6e..7d05aca71 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/W32Errors.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/W32Errors.java @@ -14,8 +14,9 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; +import com.sun.jna.platform.win32.WinError; import com.sun.jna.platform.win32.WinNT.HRESULT; // TODO: Auto-generated Javadoc diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Win32Exception.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Win32Exception.java similarity index 97% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Win32Exception.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Win32Exception.java index b46308872..fb5aa9333 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/Win32Exception.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/Win32Exception.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; /** * @author JPEXS diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinBase.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinBase.java new file mode 100644 index 000000000..71a3a038f --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinBase.java @@ -0,0 +1,1037 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.jna.platform.win32; + +import com.sun.jna.Native; +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.BaseTSD; +import com.sun.jna.platform.win32.WinDef; +import com.jpexs.decompiler.flash.jna.platform.win32.WinNT.HANDLE; +import com.sun.jna.ptr.ByteByReference; +import com.sun.jna.win32.StdCallLibrary; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +/** + * 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(Native.POINTER_SIZE == 8 + ? -1 : 0xFFFFFFFFL)); + + /** + * 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; + + @Override + 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(); + } + + /** + *

+ * 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? + * :-))

+ */ + private static final long EPOCH_DIFF = 11644473600000L; + + /** + *

+ * 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.

+ * + * @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); + } + + /** + *

+ * Converts a {@link Date} into a filetime.

+ * + * @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(); + } + + @Override + 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; + + @Override + 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; + + @Override + 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; + + @Override + 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; + + @Override + 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; + + @Override + 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 Kernel32#CreateFile, + * Kernel32#CreatePipe, or 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; + + @Override + 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; + + @Override + 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; + + @Override + 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; +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinNT.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinNT.java new file mode 100644 index 000000000..2180b30cc --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinNT.java @@ -0,0 +1,2112 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.jna.platform.win32; + +import com.sun.jna.FromNativeContext; +import com.sun.jna.Memory; +import com.sun.jna.Native; +import com.sun.jna.NativeLong; +import com.sun.jna.Pointer; +import com.sun.jna.PointerType; +import com.sun.jna.Structure; +import com.sun.jna.Union; +import com.sun.jna.platform.win32.BaseTSD; +import com.sun.jna.platform.win32.WinDef; +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.ptr.ByReference; +import java.util.Arrays; +import java.util.List; + +/** + * This module defines the 32-Bit Windows types and constants that are defined + * by NT, but exposed through the Win32 API. Ported from WinNT.h Microsoft + * Windows SDK 6.0A. Avoid including any NIO Buffer mappings here; put them in a + * DLL-derived interface (e.g. kernel32, user32, etc) instead. + * + * @author dblock[at]dblock.org + */ +@SuppressWarnings("serial") +public interface WinNT extends WinError, WinDef, WinBase, BaseTSD { + + // + // The following are masks for the predefined standard access types + // + int DELETE = 0x00010000; + + int READ_CONTROL = 0x00020000; + + int WRITE_DAC = 0x00040000; + + int WRITE_OWNER = 0x00080000; + + int SYNCHRONIZE = 0x00100000; + + int STANDARD_RIGHTS_REQUIRED = 0x000F0000; + + int STANDARD_RIGHTS_READ = READ_CONTROL; + + int STANDARD_RIGHTS_WRITE = READ_CONTROL; + + int STANDARD_RIGHTS_EXECUTE = READ_CONTROL; + + int STANDARD_RIGHTS_ALL = 0x001F0000; + + int SPECIFIC_RIGHTS_ALL = 0x0000FFFF; + + // + // Token Specific Access Rights. + // + /** + * Required to attach a primary token to a process. The + * SE_ASSIGNPRIMARYTOKEN_NAME privilege is also required to accomplish this + * task. + */ + int TOKEN_ASSIGN_PRIMARY = 0x0001; + + /** + * Required to duplicate an access token. + */ + int TOKEN_DUPLICATE = 0x0002; + + /** + * Required to attach an impersonation access token to a process. + */ + int TOKEN_IMPERSONATE = 0x0004; + + /** + * Required to query an access token. + */ + int TOKEN_QUERY = 0x0008; + + /** + * Required to query the source of an access token. + */ + int TOKEN_QUERY_SOURCE = 0x0010; + + /** + * Required to enable or disable the privileges in an access token. + */ + int TOKEN_ADJUST_PRIVILEGES = 0x0020; + + /** + * Required to adjust the attributes of the groups in an access token. + */ + int TOKEN_ADJUST_GROUPS = 0x0040; + + /** + * Required to change the default owner, primary group, or DACL of an access + * token. + */ + int TOKEN_ADJUST_DEFAULT = 0x0080; + + /** + * Required to adjust the session ID of an access token. The SE_TCB_NAME + * privilege is required. + */ + int TOKEN_ADJUST_SESSIONID = 0x0100; + + int TOKEN_ALL_ACCESS_P = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY + | TOKEN_DUPLICATE | TOKEN_IMPERSONATE | TOKEN_QUERY + | TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES + | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT; + + /** + * Combines all possible access rights for a token. + */ + int TOKEN_ALL_ACCESS = TOKEN_ALL_ACCESS_P | TOKEN_ADJUST_SESSIONID; + + /** + * Combines STANDARD_RIGHTS_READ and TOKEN_QUERY. + */ + int TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY; + + /** + * Combines STANDARD_RIGHTS_WRITE, TOKEN_ADJUST_PRIVILEGES, + * TOKEN_ADJUST_GROUPS, and TOKEN_ADJUST_DEFAULT. + */ + int TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES + | TOKEN_ADJUST_GROUPS | TOKEN_ADJUST_DEFAULT; + + /** + * Combines STANDARD_RIGHTS_EXECUTE and TOKEN_IMPERSONATE. + */ + int TOKEN_EXECUTE = STANDARD_RIGHTS_EXECUTE; + + int THREAD_TERMINATE = 0x0001; + + int THREAD_SUSPEND_RESUME = 0x0002; + + int THREAD_GET_CONTEXT = 0x0008; + + int THREAD_SET_CONTEXT = 0x0010; + + int THREAD_QUERY_INFORMATION = 0x0040; + + int THREAD_SET_INFORMATION = 0x0020; + + int THREAD_SET_THREAD_TOKEN = 0x0080; + + int THREAD_IMPERSONATE = 0x0100; + + int THREAD_DIRECT_IMPERSONATION = 0x0200; + + int THREAD_SET_LIMITED_INFORMATION = 0x0400; + + int THREAD_QUERY_LIMITED_INFORMATION = 0x0800; + + int THREAD_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x3FF; + + /** + * The SECURITY_IMPERSONATION_LEVEL enumeration type contains values that + * specify security impersonation levels. Security impersonation levels + * govern the degree to which a server process can act on behalf of a client + * process. + */ + public abstract class SECURITY_IMPERSONATION_LEVEL { + + /** + * The server process cannot obtain identification information about the + * client, and it cannot impersonate the client. It is defined with no + * value given, and thus, by ANSI C rules, defaults to a value of zero. + */ + public static final int SecurityAnonymous = 0; + + /** + * The server process can obtain information about the client, such as + * security identifiers and privileges, but it cannot impersonate the + * client. This is useful for servers that export their own objects, for + * example, database products that export tables and views. Using the + * retrieved client-security information, the server can make + * access-validation decisions without being able to use other services + * that are using the client's security context. + */ + public static final int SecurityIdentification = 1; + + /** + * The server process can impersonate the client's security context on + * its local system. The server cannot impersonate the client on remote + * systems. + */ + public static final int SecurityImpersonation = 2; + + /** + * The server process can impersonate the client's security context on + * remote systems. + */ + public static final int SecurityDelegation = 3; + } + + /** + * The TOKEN_INFORMATION_CLASS enumeration type contains values that specify + * the type of information being assigned to or retrieved from an access + * token. + */ + public abstract class TOKEN_INFORMATION_CLASS { + + public static final int TokenUser = 1; + + public static final int TokenGroups = 2; + + public static final int TokenPrivileges = 3; + + public static final int TokenOwner = 4; + + public static final int TokenPrimaryGroup = 5; + + public static final int TokenDefaultDacl = 6; + + public static final int TokenSource = 7; + + public static final int TokenType = 8; + + public static final int TokenImpersonationLevel = 9; + + public static final int TokenStatistics = 10; + + public static final int TokenRestrictedSids = 11; + + public static final int TokenSessionId = 12; + + public static final int TokenGroupsAndPrivileges = 13; + + public static final int TokenSessionReference = 14; + + public static final int TokenSandBoxInert = 15; + + public static final int TokenAuditPolicy = 16; + + public static final int TokenOrigin = 17; + + public static final int TokenElevationType = 18; + + public static final int TokenLinkedToken = 19; + + public static final int TokenElevation = 20; + + public static final int TokenHasRestrictions = 21; + + public static final int TokenAccessInformation = 22; + + public static final int TokenVirtualizationAllowed = 23; + + public static final int TokenVirtualizationEnabled = 24; + + public static final int TokenIntegrityLevel = 25; + + public static final int TokenUIAccess = 26; + + public static final int TokenMandatoryPolicy = 27; + + public static final int TokenLogonSid = 28; + } + + /** + * The TOKEN_TYPE enumeration type contains values that differentiate + * between a primary token and an impersonation token. + */ + public abstract class TOKEN_TYPE { + + public static final int TokenPrimary = 1; + + public static final int TokenImpersonation = 2; + } + + /** + * The LUID_AND_ATTRIBUTES structure represents a locally unique identifier + * (LUID) and its attributes. + */ + public static class LUID_AND_ATTRIBUTES extends Structure { + + /** + * Specifies an LUID value. + */ + public LUID Luid; + + /** + * Specifies attributes of the LUID. This value contains up to 32 + * one-bit flags. Its meaning is dependent on the definition and use of + * the LUID. + */ + public DWORD Attributes; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"Luid", "Attributes"}); + } + + public LUID_AND_ATTRIBUTES() { + } + + public LUID_AND_ATTRIBUTES(LUID luid, DWORD attributes) { + this.Luid = luid; + this.Attributes = attributes; + } + } + + /** + * The TOKEN_PRIVILEGES structure contains information about a set of + * privileges for an access token. + */ + public static class TOKEN_PRIVILEGES extends Structure { + + /** + * This must be set to the number of entries in the Privileges array. + */ + public DWORD PrivilegeCount; + + /** + * Specifies an array of LUID_AND_ATTRIBUTES structures. Each structure + * contains the LUID and attributes of a privilege. + */ + public LUID_AND_ATTRIBUTES[] Privileges; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"PrivilegeCount", "Privileges"}); + } + + /** + * Creates an empty instance with no privileges. + */ + public TOKEN_PRIVILEGES() { + this(0); + } + + /** + * @param nbOfPrivileges Desired size of the Privileges array + */ + public TOKEN_PRIVILEGES(int nbOfPrivileges) { + PrivilegeCount = new DWORD(nbOfPrivileges); + Privileges = new LUID_AND_ATTRIBUTES[nbOfPrivileges]; + } + + /** + * Initialize a TOKEN_PRIVILEGES instance from initialized memory. + * + * @param p p + */ + public TOKEN_PRIVILEGES(Pointer p) { + super(p); + int count = p.getInt(0); + PrivilegeCount = new DWORD(count); + Privileges = new LUID_AND_ATTRIBUTES[count]; + read(); + } + } + + /** + * The SID_NAME_USE enumeration type contains values that specify the type + * of a security identifier (SID). + */ + public abstract class SID_NAME_USE { + + /** + * Indicates a user SID. + */ + public static final int SidTypeUser = 1; + + /** + * Indicates a group SID. + */ + public static final int SidTypeGroup = 2; + + /** + * Indicates a domain SID. + */ + public static final int SidTypeDomain = 3; + + /** + * Indicates an alias SID. + */ + public static final int SidTypeAlias = 4; + + /** + * Indicates a SID for a well-known group. + */ + public static final int SidTypeWellKnownGroup = 5; + + /** + * Indicates a SID for a deleted account. + */ + public static final int SidTypeDeletedAccount = 6; + + /** + * Indicates an invalid SID. + */ + public static final int SidTypeInvalid = 7; + + /** + * Indicates an unknown SID type. + */ + public static final int SidTypeUnknown = 8; + + /** + * Indicates a SID for a computer. + */ + public static final int SidTypeComputer = 9; + + /** + * ? + */ + public static final int SidTypeLabel = 10; + } + + /* File access rights */ + int FILE_READ_DATA = 0x00000001; + + int FILE_LIST_DIRECTORY = 0x00000001; + + int FILE_WRITE_DATA = 0x00000002; + + int FILE_ADD_FILE = 0x00000002; + + int FILE_APPEND_DATA = 0x00000004; + + int FILE_ADD_SUBDIRECTORY = 0x00000004; + + int FILE_CREATE_PIPE_INSTANCE = 0x00000004; + + int FILE_READ_EA = 0x00000008; + + int FILE_WRITE_EA = 0x00000010; + + int FILE_EXECUTE = 0x00000020; + + int FILE_TRAVERSE = 0x00000020; + + int FILE_DELETE_CHILD = 0x00000040; + + int FILE_READ_ATTRIBUTES = 0x00000080; + + int FILE_WRITE_ATTRIBUTES = 0x00000100; + + int FILE_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0x000001FF; + + int FILE_GENERIC_READ = STANDARD_RIGHTS_READ | SYNCHRONIZE | FILE_READ_DATA + | FILE_READ_ATTRIBUTES | FILE_READ_EA; + + int FILE_GENERIC_WRITE = STANDARD_RIGHTS_WRITE | SYNCHRONIZE + | FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA + | FILE_APPEND_DATA; + + int FILE_GENERIC_EXECUTE = STANDARD_RIGHTS_EXECUTE | SYNCHRONIZE + | FILE_READ_ATTRIBUTES | FILE_EXECUTE; + + int CREATE_NEW = 1; + + int CREATE_ALWAYS = 2; + + int OPEN_EXISTING = 3; + + int OPEN_ALWAYS = 4; + + int TRUNCATE_EXISTING = 5; + + int FILE_FLAG_WRITE_THROUGH = 0x80000000; + + int FILE_FLAG_OVERLAPPED = 0x40000000; + + int FILE_FLAG_NO_BUFFERING = 0x20000000; + + int FILE_FLAG_RANDOM_ACCESS = 0x10000000; + + int FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000; + + int FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; + + int FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; + + int FILE_FLAG_POSIX_SEMANTICS = 0x01000000; + + int FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000; + + int FILE_FLAG_OPEN_NO_RECALL = 0x00100000; + + // + // These are the generic rights. + // + int GENERIC_READ = 0x80000000; + + int GENERIC_WRITE = 0x40000000; + + int GENERIC_EXECUTE = 0x20000000; + + int GENERIC_ALL = 0x10000000; + + // + // AccessSystemAcl access type + // + int ACCESS_SYSTEM_SECURITY = 0x01000000; + + int PAGE_NOACCESS = 0x01; + + int PAGE_READONLY = 0x02; + + int PAGE_READWRITE = 0x04; + + int PAGE_WRITECOPY = 0x08; + + int PAGE_EXECUTE = 0x10; + + int PAGE_EXECUTE_READ = 0x20; + + int PAGE_EXECUTE_READWRITE = 0x40; + + int PAGE_GUARD = 0x100; + + int SECTION_QUERY = 0x0001; + + int SECTION_MAP_WRITE = 0x0002; + + int SECTION_MAP_READ = 0x0004; + + int SECTION_MAP_EXECUTE = 0x0008; + + int SECTION_EXTEND_SIZE = 0x0010; + + int FILE_SHARE_READ = 0x00000001; + + int FILE_SHARE_WRITE = 0x00000002; + + int FILE_SHARE_DELETE = 0x00000004; + + int FILE_TYPE_CHAR = 0x0002; + + int FILE_TYPE_DISK = 0x0001; + + int FILE_TYPE_PIPE = 0x0003; + + int FILE_TYPE_REMOTE = 0x8000; + + int FILE_TYPE_UNKNOWN = 0x0000; + + int FILE_ATTRIBUTE_READONLY = 0x00000001; + + int FILE_ATTRIBUTE_HIDDEN = 0x00000002; + + int FILE_ATTRIBUTE_SYSTEM = 0x00000004; + + int FILE_ATTRIBUTE_DIRECTORY = 0x00000010; + + int FILE_ATTRIBUTE_ARCHIVE = 0x00000020; + + int FILE_ATTRIBUTE_DEVICE = 0x00000040; + + int FILE_ATTRIBUTE_NORMAL = 0x00000080; + + int FILE_ATTRIBUTE_TEMPORARY = 0x00000100; + + int FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200; + + int FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400; + + int FILE_ATTRIBUTE_COMPRESSED = 0x00000800; + + int FILE_ATTRIBUTE_OFFLINE = 0x00001000; + + int FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000; + + int FILE_ATTRIBUTE_ENCRYPTED = 0x00004000; + + int FILE_ATTRIBUTE_VIRTUAL = 0x00010000; + + int FILE_NOTIFY_CHANGE_FILE_NAME = 0x00000001; + + int FILE_NOTIFY_CHANGE_DIR_NAME = 0x00000002; + + int FILE_NOTIFY_CHANGE_NAME = 0x00000003; + + int FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x00000004; + + int FILE_NOTIFY_CHANGE_SIZE = 0x00000008; + + int FILE_NOTIFY_CHANGE_LAST_WRITE = 0x00000010; + + int FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x00000020; + + int FILE_NOTIFY_CHANGE_CREATION = 0x00000040; + + int FILE_NOTIFY_CHANGE_SECURITY = 0x00000100; + + int FILE_ACTION_ADDED = 0x00000001; + + int FILE_ACTION_REMOVED = 0x00000002; + + int FILE_ACTION_MODIFIED = 0x00000003; + + int FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; + + int FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; + + int FILE_CASE_SENSITIVE_SEARCH = 0x00000001; + + int FILE_CASE_PRESERVED_NAMES = 0x00000002; + + int FILE_UNICODE_ON_DISK = 0x00000004; + + int FILE_PERSISTENT_ACLS = 0x00000008; + + int FILE_FILE_COMPRESSION = 0x00000010; + + int FILE_VOLUME_QUOTAS = 0x00000020; + + int FILE_SUPPORTS_SPARSE_FILES = 0x00000040; + + int FILE_SUPPORTS_REPARSE_POINTS = 0x00000080; + + int FILE_SUPPORTS_REMOTE_STORAGE = 0x00000100; + + int FILE_VOLUME_IS_COMPRESSED = 0x00008000; + + int FILE_SUPPORTS_OBJECT_IDS = 0x00010000; + + int FILE_SUPPORTS_ENCRYPTION = 0x00020000; + + int FILE_NAMED_STREAMS = 0x00040000; + + int FILE_READ_ONLY_VOLUME = 0x00080000; + + int FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000; + + int FILE_SUPPORTS_TRANSACTIONS = 0x00200000; + + /** + * The FILE_NOTIFY_INFORMATION structure describes the changes found by the + * ReadDirectoryChangesW function. + *

+ * This structure is non-trivial since it is a pattern stamped into a large + * block of result memory rather than something that stands alone or is used + * for input. + */ + public static class FILE_NOTIFY_INFORMATION extends Structure { + + public int NextEntryOffset; + + public int Action; + + public int FileNameLength; + + // filename is not nul-terminated, so we can't use a String/WString + public char[] FileName = new char[1]; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"NextEntryOffset", "Action", "FileNameLength", "FileName"}); + } + + private FILE_NOTIFY_INFORMATION() { + } + + public FILE_NOTIFY_INFORMATION(int size) { + if (size < size()) { + throw new IllegalArgumentException("Size must greater than " + + size() + ", requested " + size); + } + allocateMemory(size); + } + + /** + * WARNING: this filename may be either the short or long form of the + * filename. + * + * @return result + */ + public String getFilename() { + return new String(FileName, 0, FileNameLength / 2); + } + + @Override + public void read() { + // avoid reading filename until we know how long it is + FileName = new char[0]; + super.read(); + FileName = getPointer().getCharArray(12, FileNameLength / 2); + } + + public FILE_NOTIFY_INFORMATION next() { + if (NextEntryOffset == 0) { + return null; + } + FILE_NOTIFY_INFORMATION next = new FILE_NOTIFY_INFORMATION(); + next.useMemory(getPointer(), NextEntryOffset); + next.read(); + return next; + } + } + + /** + * Registry options. + */ + int KEY_QUERY_VALUE = 0x0001; + + int KEY_SET_VALUE = 0x0002; + + int KEY_CREATE_SUB_KEY = 0x0004; + + int KEY_ENUMERATE_SUB_KEYS = 0x0008; + + int KEY_NOTIFY = 0x0010; + + int KEY_CREATE_LINK = 0x0020; + + int KEY_WOW64_32KEY = 0x0200; + + int KEY_WOW64_64KEY = 0x0100; + + int KEY_WOW64_RES = 0x0300; + + int KEY_READ = STANDARD_RIGHTS_READ | KEY_QUERY_VALUE + | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY & (~SYNCHRONIZE); + + int KEY_WRITE = STANDARD_RIGHTS_WRITE | KEY_SET_VALUE | KEY_CREATE_SUB_KEY + & (~SYNCHRONIZE); + + int KEY_EXECUTE = KEY_READ & (~SYNCHRONIZE); + + int KEY_ALL_ACCESS = STANDARD_RIGHTS_ALL | KEY_QUERY_VALUE | KEY_SET_VALUE + | KEY_CREATE_SUB_KEY | KEY_ENUMERATE_SUB_KEYS | KEY_NOTIFY + | KEY_CREATE_LINK & (~SYNCHRONIZE); + + // + // Open/Create Options + // + /** + * Parameter is reserved. + */ + int REG_OPTION_RESERVED = 0x00000000; + + /** + * Key is preserved when system is rebooted. + */ + int REG_OPTION_NON_VOLATILE = 0x00000000; + + /** + * Key is not preserved when system is rebooted. + */ + int REG_OPTION_VOLATILE = 0x00000001; + + /** + * Created key is a symbolic link. + */ + int REG_OPTION_CREATE_LINK = 0x00000002; + + /** + * Open for backup or restore special access rules privilege required. + */ + int REG_OPTION_BACKUP_RESTORE = 0x00000004; + + /** + * Open symbolic link. + */ + int REG_OPTION_OPEN_LINK = 0x00000008; + + int REG_LEGAL_OPTION = REG_OPTION_RESERVED | REG_OPTION_NON_VOLATILE + | REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK + | REG_OPTION_BACKUP_RESTORE | REG_OPTION_OPEN_LINK; + + // + // Key creation/open disposition + // + /** + * New Registry Key created. + */ + int REG_CREATED_NEW_KEY = 0x00000001; + + /** + * Existing Key opened. + */ + int REG_OPENED_EXISTING_KEY = 0x00000002; + + int REG_STANDARD_FORMAT = 1; + + int REG_LATEST_FORMAT = 2; + + int REG_NO_COMPRESSION = 4; + + // + // Key restore & hive load flags + // + /** + * Restore whole hive volatile. + */ + int REG_WHOLE_HIVE_VOLATILE = 0x00000001; + + /** + * Unwind changes to last flush. + */ + int REG_REFRESH_HIVE = 0x00000002; + + /** + * Never lazy flush this hive. + */ + int REG_NO_LAZY_FLUSH = 0x00000004; + + /** + * Force the restore process even when we have open handles on subkeys. + */ + int REG_FORCE_RESTORE = 0x00000008; + + /** + * Loads the hive visible to the calling process. + */ + int REG_APP_HIVE = 0x00000010; + + /** + * Hive cannot be mounted by any other process while in use. + */ + int REG_PROCESS_PRIVATE = 0x00000020; + + /** + * Starts Hive Journal. + */ + int REG_START_JOURNAL = 0x00000040; + + /** + * Grow hive file in exact 4k increments. + */ + int REG_HIVE_EXACT_FILE_GROWTH = 0x00000080; + + /** + * No RM is started for this hive = no transactions. + */ + int REG_HIVE_NO_RM = 0x00000100; + + /** + * Legacy single logging is used for this hive. + */ + int REG_HIVE_SINGLE_LOG = 0x00000200; + + // + // Unload Flags + // + int REG_FORCE_UNLOAD = 1; + + // + // Notify filter values + // + int REG_NOTIFY_CHANGE_NAME = 0x00000001; + + int REG_NOTIFY_CHANGE_ATTRIBUTES = 0x00000002; + + int REG_NOTIFY_CHANGE_LAST_SET = 0x00000004; + + int REG_NOTIFY_CHANGE_SECURITY = 0x00000008; + + int REG_LEGAL_CHANGE_FILTER = REG_NOTIFY_CHANGE_NAME + | REG_NOTIFY_CHANGE_ATTRIBUTES | REG_NOTIFY_CHANGE_LAST_SET + | REG_NOTIFY_CHANGE_SECURITY; + + // + // Predefined Value Types. + // + /** + * No value type. + */ + int REG_NONE = 0; + + /** + * Unicode null-terminated string. + */ + int REG_SZ = 1; + + /** + * Unicode null-terminated string with environment variable references. + */ + int REG_EXPAND_SZ = 2; + + /** + * Free-formed binary. + */ + int REG_BINARY = 3; + + /** + * 32-bit number. + */ + int REG_DWORD = 4; + + /** + * 32-bit number, same as REG_DWORD. + */ + int REG_DWORD_LITTLE_ENDIAN = 4; + + /** + * 32-bit number. + */ + int REG_DWORD_BIG_ENDIAN = 5; + + /** + * Symbolic link (unicode). + */ + int REG_LINK = 6; + + /** + * Multiple unicode strings. + */ + int REG_MULTI_SZ = 7; + + /** + * Resource list in the resource map. + */ + int REG_RESOURCE_LIST = 8; + + /** + * Resource list in the hardware description. + */ + int REG_FULL_RESOURCE_DESCRIPTOR = 9; + + /** + * + */ + int REG_RESOURCE_REQUIREMENTS_LIST = 10; + + /** + * 64-bit number. + */ + int REG_QWORD = 11; + + /** + * 64-bit number, same as REG_QWORD. + */ + int REG_QWORD_LITTLE_ENDIAN = 11; + + /** + * A 64-bit value that is guaranteed to be unique on the operating system + * that generated it until the system is restarted. + */ + public static class LUID extends Structure { + + public int LowPart; + + public int HighPart; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"LowPart", "HighPart"}); + } + } + + /** + * A 64-bit integer; + */ + public static class LARGE_INTEGER extends Structure { + + public static class ByReference extends LARGE_INTEGER implements + Structure.ByReference { + } + + public static class LowHigh extends Structure { + + public DWORD LowPart; + + public DWORD HighPart; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"LowPart", "HighPart"}); + } + } + + public static class UNION extends Union { + + public LowHigh lh; + + public long value; + } + + public UNION u; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"u"}); + } + + /** + * Low DWORD. + * + * @return DWORD. + */ + public DWORD getLow() { + return u.lh.LowPart; + } + + /** + * High DWORD. + * + * @return DWORD. + */ + public DWORD getHigh() { + return u.lh.HighPart; + } + + /** + * 64-bit value. + * + * @return 64-bit value. + */ + public long getValue() { + return u.value; + } + } + + /** + * Handle to an object. + */ + public static class HANDLE extends PointerType { + + private boolean immutable; + + public HANDLE() { + } + + public HANDLE(Pointer p) { + super(); + setPointer(p); + immutable = true; + } + + /** + * Override to the appropriate object for INVALID_HANDLE_VALUE. + * + * @param nativeValue nativeValue + * @param context context + * @return result + */ + @Override + public Object fromNative(Object nativeValue, FromNativeContext context) { + Object o = super.fromNative(nativeValue, context); + if (WinBase.INVALID_HANDLE_VALUE.equals(o)) { + return WinBase.INVALID_HANDLE_VALUE; + } + return o; + } + + @Override + public final void setPointer(Pointer p) { + if (immutable) { + throw new UnsupportedOperationException("immutable reference"); + } + + super.setPointer(p); + } + } + + /** + * LPHANDLE + */ + public static final class HANDLEByReference extends ByReference { + + public HANDLEByReference() { + this(null); + } + + public HANDLEByReference(HANDLE h) { + super(Native.POINTER_SIZE); + setValue(h); + } + + public void setValue(HANDLE h) { + getPointer().setPointer(0, h != null ? h.getPointer() : null); + } + + public HANDLE getValue() { + Pointer p = getPointer().getPointer(0); + if (p == null) { + return null; + } + if (WinBase.INVALID_HANDLE_VALUE.getPointer().equals(p)) { + return WinBase.INVALID_HANDLE_VALUE; + } + HANDLE h = new HANDLE(); + h.setPointer(p); + return h; + } + } + + /** + * Return code used by interfaces. It is zero upon success and nonzero to + * represent an error code or status information. + */ + class HRESULT extends NativeLong { + + public HRESULT() { + } + + public HRESULT(int value) { + super(value); + } + } + + /** + * The WELL_KNOWN_SID_TYPE enumeration type is a list of commonly used + * security identifiers (SIDs). Programs can pass these values to the + * CreateWellKnownSid function to create a SID from this list. + */ + public abstract class WELL_KNOWN_SID_TYPE { + + /** + * Indicates a null SID. + */ + public static final int WinNullSid = 0; + + /** + * Indicates a SID that matches everyone. + */ + public static final int WinWorldSid = 1; + + /** + * Indicates a local SID. + */ + public static final int WinLocalSid = 2; + + /** + * Indicates a SID that matches the owner or creator of an object. + */ + public static final int WinCreatorOwnerSid = 3; + + /** + * Indicates a SID that matches the creator group of an object. + */ + public static final int WinCreatorGroupSid = 4; + + /** + * Indicates a creator owner server SID. + */ + public static final int WinCreatorOwnerServerSid = 5; + + /** + * Indicates a creator group server SID. + */ + public static final int WinCreatorGroupServerSid = 6; + + /** + * Indicates a SID for the Windows NT authority. + */ + public static final int WinNtAuthoritySid = 7; + + /** + * Indicates a SID for a dial-up account. + */ + public static final int WinDialupSid = 8; + + /** + * Indicates a SID for a network account. This SID is added to the + * process of a token when it logs on across a network. The + * corresponding logon type is LOGON32_LOGON_NETWORK. + */ + public static final int WinNetworkSid = 9; + + /** + * Indicates a SID for a batch process. This SID is added to the process + * of a token when it logs on as a batch job. The corresponding logon + * type is LOGON32_LOGON_BATCH. + */ + public static final int WinBatchSid = 10; + + /** + * Indicates a SID for an interactive account. This SID is added to the + * process of a token when it logs on interactively. The corresponding + * logon type is LOGON32_LOGON_INTERACTIVE. + */ + public static final int WinInteractiveSid = 11; + + /** + * Indicates a SID for a service. This SID is added to the process of a + * token when it logs on as a service. The corresponding logon type is + * LOGON32_LOGON_bSERVICE. + */ + public static final int WinServiceSid = 12; + + /** + * Indicates a SID for the anonymous account. + */ + public static final int WinAnonymousSid = 13; + + /** + * Indicates a proxy SID. + */ + public static final int WinProxySid = 14; + + /** + * Indicates a SID for an enterprise controller. + */ + public static final int WinEnterpriseControllersSid = 15; + + /** + * Indicates a SID for self. + */ + public static final int WinSelfSid = 16; + + /** + * Indicates a SID that matches any authenticated user. + */ + public static final int WinAuthenticatedUserSid = 17; + + /** + * Indicates a SID for restricted code. + */ + public static final int WinRestrictedCodeSid = 18; + + /** + * Indicates a SID that matches a terminal server account. + */ + public static final int WinTerminalServerSid = 19; + + /** + * Indicates a SID that matches remote logons. + */ + public static final int WinRemoteLogonIdSid = 20; + + /** + * Indicates a SID that matches logon IDs. + */ + public static final int WinLogonIdsSid = 21; + + /** + * Indicates a SID that matches the local system. + */ + public static final int WinLocalSystemSid = 22; + + /** + * Indicates a SID that matches a local service. + */ + public static final int WinLocalServiceSid = 23; + + /** + * Indicates a SID that matches a network service. + */ + public static final int WinNetworkServiceSid = 24; + + /** + * Indicates a SID that matches the domain account. + */ + public static final int WinBuiltinDomainSid = 25; + + /** + * Indicates a SID that matches the administrator account. + */ + public static final int WinBuiltinAdministratorsSid = 26; + + /** + * Indicates a SID that matches built-in user accounts. + */ + public static final int WinBuiltinUsersSid = 27; + + /** + * Indicates a SID that matches the guest account. + */ + public static final int WinBuiltinGuestsSid = 28; + + /** + * Indicates a SID that matches the power users group. + */ + public static final int WinBuiltinPowerUsersSid = 29; + + /** + * Indicates a SID that matches the account operators account. + */ + public static final int WinBuiltinAccountOperatorsSid = 30; + + /** + * Indicates a SID that matches the system operators group. + */ + public static final int WinBuiltinSystemOperatorsSid = 31; + + /** + * Indicates a SID that matches the print operators group. + */ + public static final int WinBuiltinPrintOperatorsSid = 32; + + /** + * Indicates a SID that matches the backup operators group. + */ + public static final int WinBuiltinBackupOperatorsSid = 33; + + /** + * Indicates a SID that matches the replicator account. + */ + public static final int WinBuiltinReplicatorSid = 34; + + /** + * Indicates a SID that matches pre-Windows 2000 compatible accounts. + */ + public static final int WinBuiltinPreWindows2000CompatibleAccessSid = 35; + + /** + * Indicates a SID that matches remote desktop users. + */ + public static final int WinBuiltinRemoteDesktopUsersSid = 36; + + /** + * Indicates a SID that matches the network operators group. + */ + public static final int WinBuiltinNetworkConfigurationOperatorsSid = 37; + + /** + * Indicates a SID that matches the account administrators group. + */ + public static final int WinAccountAdministratorSid = 38; + + /** + * Indicates a SID that matches the account guest group. + */ + public static final int WinAccountGuestSid = 39; + + /** + * Indicates a SID that matches account Kerberos target group. + */ + public static final int WinAccountKrbtgtSid = 40; + + /** + * Indicates a SID that matches the account domain administrator group. + */ + public static final int WinAccountDomainAdminsSid = 41; + + /** + * Indicates a SID that matches the account domain users group. + */ + public static final int WinAccountDomainUsersSid = 42; + + /** + * Indicates a SID that matches the account domain guests group. + */ + public static final int WinAccountDomainGuestsSid = 43; + + /** + * Indicates a SID that matches the account computer group. + */ + public static final int WinAccountComputersSid = 44; + + /** + * Indicates a SID that matches the account controller group. + */ + public static final int WinAccountControllersSid = 45; + + /** + * Indicates a SID that matches the certificate administrators group. + */ + public static final int WinAccountCertAdminsSid = 46; + + /** + * Indicates a SID that matches the schema administrators group. + */ + public static final int WinAccountSchemaAdminsSid = 47; + + /** + * Indicates a SID that matches the enterprise administrators group. + */ + public static final int WinAccountEnterpriseAdminsSid = 48; + + /** + * Indicates a SID that matches the policy administrators group. + */ + public static final int WinAccountPolicyAdminsSid = 49; + + /** + * Indicates a SID that matches the RAS and IAS server account. + */ + public static final int WinAccountRasAndIasServersSid = 50; + + /** + * Indicates a SID present when the Microsoft NTLM authentication + * package authenticated the client. + */ + public static final int WinNTLMAuthenticationSid = 51; + + /** + * Indicates a SID present when the Microsoft Digest authentication + * package authenticated the client. + */ + public static final int WinDigestAuthenticationSid = 52; + + /** + * Indicates a SID present when the Secure Channel (SSL/TLS) + * authentication package authenticated the client. + */ + public static final int WinSChannelAuthenticationSid = 53; + + /** + * Indicates a SID present when the user authenticated from within the + * forest or across a trust that does not have the selective + * authentication option enabled. If this SID is present, then + * WinOtherOrganizationSid cannot be present. + */ + public static final int WinThisOrganizationSid = 54; + + /** + * Indicates a SID present when the user authenticated across a forest + * with the selective authentication option enabled. If this SID is + * present, then WinThisOrganizationSid cannot be present. + */ + public static final int WinOtherOrganizationSid = 55; + + /** + * Indicates a SID that allows a user to create incoming forest trusts. + * It is added to the token of users who are a member of the Incoming + * Forest Trust Builders built-in group in the root domain of the + * forest. + */ + public static final int WinBuiltinIncomingForestTrustBuildersSid = 56; + + /** + * Indicates a SID that matches the performance monitor user group. + */ + public static final int WinBuiltinPerfMonitoringUsersSid = 57; + + /** + * Indicates a SID that matches the performance log user group. + */ + public static final int WinBuiltinPerfLoggingUsersSid = 58; + + /** + * Indicates a SID that matches the Windows Authorization Access group. + */ + public static final int WinBuiltinAuthorizationAccessSid = 59; + + /** + * Indicates a SID is present in a server that can issue Terminal Server + * licenses. + */ + public static final int WinBuiltinTerminalServerLicenseServersSid = 60; + + /** + * + */ + public static final int WinBuiltinDCOMUsersSid = 61; + + /** + * + */ + public static final int WinBuiltinIUsersSid = 62; + + /** + * + */ + public static final int WinIUserSid = 63; + + /** + * + */ + public static final int WinBuiltinCryptoOperatorsSid = 64; + + /** + * + */ + public static final int WinUntrustedLabelSid = 65; + + /** + * + */ + public static final int WinLowLabelSid = 66; + + /** + * + */ + public static final int WinMediumLabelSid = 67; + + /** + * + */ + public static final int WinHighLabelSid = 68; + + /** + * + */ + public static final int WinSystemLabelSid = 69; + + /** + * + */ + public static final int WinWriteRestrictedCodeSid = 70; + + /** + * + */ + public static final int WinCreatorOwnerRightsSid = 71; + + /** + * + */ + public static final int WinCacheablePrincipalsGroupSid = 72; + + /** + * + */ + public static final int WinNonCacheablePrincipalsGroupSid = 73; + + /** + * + */ + public static final int WinEnterpriseReadonlyControllersSid = 74; + + /** + * Indicates a SID that matches a read-only enterprise domain + * controller. + */ + public static final int WinAccountReadonlyControllersSid = 75; + + /** + * Indicates a SID that matches the built-in DCOM certification services + * access group. + */ + public static final int WinBuiltinEventLogReadersGroup = 76; + } + + /** + * Current SID revision level. + */ + int SID_REVISION = 1; + + int SID_MAX_SUB_AUTHORITIES = 15; + + int SID_RECOMMENDED_SUB_AUTHORITIES = 1; + + /** + * Maximum bytes used by a SID. (sizeof(SID) - sizeof(DWORD) + + * (SID_MAX_SUB_AUTHORITIES * sizeof(DWORD))) + */ + int SECURITY_MAX_SID_SIZE = 68; + + /** + * The OSVERSIONINFO data structure contains operating system version + * information. The information includes major and minor version numbers, a + * build number, a platform identifier, and descriptive text about the + * operating system. This structure is used with the GetVersionEx function. + */ + public static class OSVERSIONINFO extends Structure { + + /** + * Size of this data structure, in bytes. Set this member to + * sizeof(OSVERSIONINFO) before calling the GetVersionEx function. + */ + public DWORD dwOSVersionInfoSize; + + /** + * Major version number of the operating system. + */ + public DWORD dwMajorVersion; + + /** + * Minor version number of the operating system. + */ + public DWORD dwMinorVersion; + + /** + * Build number of the operating system. + */ + public DWORD dwBuildNumber; + + /** + * Operating system platform. + */ + public DWORD dwPlatformId; + + /** + * Pointer to a null-terminated string, such as "Service Pack 3", that + * indicates the latest Service Pack installed on the system. + */ + public char[] szCSDVersion; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion"}); + } + + public OSVERSIONINFO() { + szCSDVersion = new char[128]; + dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFO) + } + + public OSVERSIONINFO(Pointer memory) { + super(memory); + read(); + } + } + + /** + * Contains operating system version information. The information includes + * major and minor version numbers, a build number, a platform identifier, + * and information about product suites and the latest Service Pack + * installed on the system. + */ + public static class OSVERSIONINFOEX extends Structure { + + /** + * The size of this data structure, in bytes. + */ + public DWORD dwOSVersionInfoSize; + + /** + * The major version number of the operating system. + */ + public DWORD dwMajorVersion; + + /** + * The minor version number of the operating system. + */ + public DWORD dwMinorVersion; + + /** + * The build number of the operating system. + */ + public DWORD dwBuildNumber; + + /** + * The operating system platform. This member can be + * VER_PLATFORM_WIN32_NT. + */ + public DWORD dwPlatformId; + + /** + * A null-terminated string, such as "Service Pack 3", that indicates + * the latest Service Pack installed on the system. If no Service Pack + * has been installed, the string is empty. + */ + public char[] szCSDVersion; + + /** + * The major version number of the latest Service Pack installed on the + * system. For example, for Service Pack 3, the major version number is + * 3. If no Service Pack has been installed, the value is zero. + */ + public WORD wServicePackMajor; + + /** + * The minor version number of the latest Service Pack installed on the + * system. For example, for Service Pack 3, the minor version number is + * 0. + */ + public WORD wServicePackMinor; + + /** + * A bit mask that identifies the product suites available on the + * system. + */ + public WORD wSuiteMask; + + /** + * Any additional information about the system. + */ + public byte wProductType; + + /** + * Reserved for future use. + */ + public byte wReserved; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"dwOSVersionInfoSize", "dwMajorVersion", "dwMinorVersion", "dwBuildNumber", "dwPlatformId", "szCSDVersion", "wServicePackMajor", "wServicePackMinor", "wSuiteMask", "wProductType", "wReserved"}); + } + + public OSVERSIONINFOEX() { + szCSDVersion = new char[128]; + dwOSVersionInfoSize = new DWORD(size()); // sizeof(OSVERSIONINFOEX) + } + + public OSVERSIONINFOEX(Pointer memory) { + super(memory); + read(); + } + } + + int VER_EQUAL = 1; + + int VER_GREATER = 2; + + int VER_GREATER_EQUAL = 3; + + int VER_LESS = 4; + + int VER_LESS_EQUAL = 5; + + int VER_AND = 6; + + int VER_OR = 7; + + int VER_CONDITION_MASK = 7; + + int VER_NUM_BITS_PER_CONDITION_MASK = 3; + + int VER_MINORVERSION = 0x0000001; + + int VER_MAJORVERSION = 0x0000002; + + int VER_BUILDNUMBER = 0x0000004; + + int VER_PLATFORMID = 0x0000008; + + int VER_SERVICEPACKMINOR = 0x0000010; + + int VER_SERVICEPACKMAJOR = 0x0000020; + + int VER_SUITENAME = 0x0000040; + + int VER_PRODUCT_TYPE = 0x0000080; + + int VER_NT_WORKSTATION = 0x0000001; + + int VER_NT_DOMAIN_CONTROLLER = 0x0000002; + + int VER_NT_SERVER = 0x0000003; + + int VER_PLATFORM_WIN32s = 0; + + int VER_PLATFORM_WIN32_WINDOWS = 1; + + int VER_PLATFORM_WIN32_NT = 2; + + /** + * Read the records sequentially. If this is the first read operation, the + * EVENTLOG_FORWARDS_READ EVENTLOG_BACKWARDS_READ flags determines which + * record is read first. + */ + int EVENTLOG_SEQUENTIAL_READ = 0x0001; + + /** + * Begin reading from the record specified in the dwRecordOffset parameter. + * This option may not work with large log files if the function cannot + * determine the log file's size. For details, see Knowledge Base article, + * 177199. + */ + int EVENTLOG_SEEK_READ = 0x0002; + + /** + * The log is read in chronological order (oldest to newest). The default. + */ + int EVENTLOG_FORWARDS_READ = 0x0004; + + /** + * The log is read in reverse chronological order (newest to oldest). + */ + int EVENTLOG_BACKWARDS_READ = 0x0008; + + /** + * Information event + */ + int EVENTLOG_SUCCESS = 0x0000; + + /** + * Error event + */ + int EVENTLOG_ERROR_TYPE = 0x0001; + + /** + * Warning event + */ + int EVENTLOG_WARNING_TYPE = 0x0002; + + /** + * Information event + */ + int EVENTLOG_INFORMATION_TYPE = 0x0004; + + /** + * Success Audit event + */ + int EVENTLOG_AUDIT_SUCCESS = 0x0008; + + /** + * Failure Audit event + */ + int EVENTLOG_AUDIT_FAILURE = 0x0010; + + /** + * The EVENTLOGRECORD structure contains information about an event record + * returned by the ReadEventLog function. + */ + public static class EVENTLOGRECORD extends Structure { + + /** + * Size of this event record, in bytes. Note that this value is stored + * at both ends of the entry to ease moving forward or backward through + * the log. The length includes any pad bytes inserted at the end of the + * record for DWORD alignment. + */ + public DWORD Length; + + /** + * Reserved. + */ + public DWORD Reserved; + + /** + * Record number of the record. This value can be used with the + * EVENTLOG_SEEK_READ flag in the ReadEventLog function to begin reading + * at a specified record. + */ + public DWORD RecordNumber; + + /** + * Time at which this entry was submitted. This time is measured in the + * number of seconds elapsed since 00:00:00 January 1, 1970, Universal + * Coordinated Time. + */ + public DWORD TimeGenerated; + + /** + * Time at which this entry was received by the service to be written to + * the log. This time is measured in the number of seconds elapsed since + * 00:00:00 January 1, 1970, Universal Coordinated Time. + */ + public DWORD TimeWritten; + + /** + * Event identifier. The value is specific to the event source for the + * event, and is used with source name to locate a description string in + * the message file for the event source. + */ + public DWORD EventID; + + /** + * Type of event. + */ + public WORD EventType; + + /** + * Number of strings present in the log (at the position indicated by + * StringOffset). These strings are merged into the message before it is + * displayed to the user. + */ + public WORD NumStrings; + + /** + * Category for this event. The meaning of this value depends on the + * event source. + */ + public WORD EventCategory; + + /** + * Reserved. + */ + public WORD ReservedFlags; + + /** + * Reserved. + */ + public DWORD ClosingRecordNumber; + + /** + * Offset of the description strings within this event log record. + */ + public DWORD StringOffset; + + /** + * Size of the UserSid member, in bytes. This value can be zero if no + * security identifier was provided. + */ + public DWORD UserSidLength; + + /** + * Offset of the security identifier (SID) within this event log record. + * To obtain the user name for this SID, use the LookupAccountSid + * function. + */ + public DWORD UserSidOffset; + + /** + * Size of the event-specific data (at the position indicated by + * DataOffset), in bytes. + */ + public DWORD DataLength; + + /** + * Offset of the event-specific information within this event log + * record, in bytes. This information could be something specific (a + * disk driver might log the number of retries, for example), followed + * by binary information specific to the event being logged and to the + * source that generated the entry. + */ + public DWORD DataOffset; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"Length", "Reserved", "RecordNumber", "TimeGenerated", "TimeWritten", "EventID", "EventType", "NumStrings", "EventCategory", "ReservedFlags", "ClosingRecordNumber", "StringOffset", "UserSidLength", "UserSidOffset", "DataLength", "DataOffset"}); + } + + public EVENTLOGRECORD() { + } + + public EVENTLOGRECORD(Pointer p) { + super(p); + read(); + } + } + + // + // Service Types (Bit Mask) + // + int SERVICE_KERNEL_DRIVER = 0x00000001; + + int SERVICE_FILE_SYSTEM_DRIVER = 0x00000002; + + int SERVICE_ADAPTER = 0x00000004; + + int SERVICE_RECOGNIZER_DRIVER = 0x00000008; + + int SERVICE_DRIVER = SERVICE_KERNEL_DRIVER | SERVICE_FILE_SYSTEM_DRIVER + | SERVICE_RECOGNIZER_DRIVER; + + int SERVICE_WIN32_OWN_PROCESS = 0x00000010; + + int SERVICE_WIN32_SHARE_PROCESS = 0x00000020; + + int SERVICE_WIN32 = SERVICE_WIN32_OWN_PROCESS | SERVICE_WIN32_SHARE_PROCESS; + + int SERVICE_INTERACTIVE_PROCESS = 0x00000100; + + int SERVICE_TYPE_ALL = SERVICE_WIN32 | SERVICE_ADAPTER | SERVICE_DRIVER + | SERVICE_INTERACTIVE_PROCESS; + + int STATUS_PENDING = 0x00000103; + + // Privilege Constants + String SE_CREATE_TOKEN_NAME = "SeCreateTokenPrivilege"; + + String SE_ASSIGNPRIMARYTOKEN_NAME = "SeAssignPrimaryTokenPrivilege"; + + String SE_LOCK_MEMORY_NAME = "SeLockMemoryPrivilege"; + + String SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege"; + + String SE_UNSOLICITED_INPUT_NAME = "SeUnsolicitedInputPrivilege"; + + String SE_MACHINE_ACCOUNT_NAME = "SeMachineAccountPrivilege"; + + String SE_TCB_NAME = "SeTcbPrivilege"; + + String SE_SECURITY_NAME = "SeSecurityPrivilege"; + + String SE_TAKE_OWNERSHIP_NAME = "SeTakeOwnershipPrivilege"; + + String SE_LOAD_DRIVER_NAME = "SeLoadDriverPrivilege"; + + String SE_SYSTEM_PROFILE_NAME = "SeSystemProfilePrivilege"; + + String SE_SYSTEMTIME_NAME = "SeSystemtimePrivilege"; + + String SE_PROF_SINGLE_PROCESS_NAME = "SeProfileSingleProcessPrivilege"; + + String SE_INC_BASE_PRIORITY_NAME = "SeIncreaseBasePriorityPrivilege"; + + String SE_CREATE_PAGEFILE_NAME = "SeCreatePagefilePrivilege"; + + String SE_CREATE_PERMANENT_NAME = "SeCreatePermanentPrivilege"; + + String SE_BACKUP_NAME = "SeBackupPrivilege"; + + String SE_RESTORE_NAME = "SeRestorePrivilege"; + + String SE_SHUTDOWN_NAME = "SeShutdownPrivilege"; + + String SE_DEBUG_NAME = "SeDebugPrivilege"; + + String SE_AUDIT_NAME = "SeAuditPrivilege"; + + String SE_SYSTEM_ENVIRONMENT_NAME = "SeSystemEnvironmentPrivilege"; + + String SE_CHANGE_NOTIFY_NAME = "SeChangeNotifyPrivilege"; + + String SE_REMOTE_SHUTDOWN_NAME = "SeRemoteShutdownPrivilege"; + + String SE_UNDOCK_NAME = "SeUndockPrivilege"; + + String SE_SYNC_AGENT_NAME = "SeSyncAgentPrivilege"; + + String SE_ENABLE_DELEGATION_NAME = "SeEnableDelegationPrivilege"; + + String SE_MANAGE_VOLUME_NAME = "SeManageVolumePrivilege"; + + String SE_IMPERSONATE_NAME = "SeImpersonatePrivilege"; + + String SE_CREATE_GLOBAL_NAME = "SeCreateGlobalPrivilege"; + + int SE_PRIVILEGE_ENABLED_BY_DEFAULT = 0x00000001; + + int SE_PRIVILEGE_ENABLED = 0x00000002; + + int SE_PRIVILEGE_REMOVED = 0X00000004; + + int SE_PRIVILEGE_USED_FOR_ACCESS = 0x80000000; + + int PROCESS_TERMINATE = 0x00000001; + + int PROCESS_SYNCHRONIZE = 0x00100000; + + /* Security information types */ + int OWNER_SECURITY_INFORMATION = 0x00000001; + + int GROUP_SECURITY_INFORMATION = 0x00000002; + + int DACL_SECURITY_INFORMATION = 0x00000004; + + int SACL_SECURITY_INFORMATION = 0x00000008; + + int LABEL_SECURITY_INFORMATION = 0x00000010; + + int PROTECTED_DACL_SECURITY_INFORMATION = 0x80000000; + + int PROTECTED_SACL_SECURITY_INFORMATION = 0x40000000; + + int UNPROTECTED_DACL_SECURITY_INFORMATION = 0x20000000; + + int UNPROTECTED_SACL_SECURITY_INFORMATION = 0x10000000; + + public static class SECURITY_DESCRIPTOR extends Structure { + + public static class ByReference extends SECURITY_DESCRIPTOR implements + Structure.ByReference { + } + + public SECURITY_DESCRIPTOR() { + } + + public SECURITY_DESCRIPTOR(byte[] data) { + super(); + this.data = data; + useMemory(new Memory(data.length)); + } + + public SECURITY_DESCRIPTOR(Pointer memory) { + super(memory); + read(); + } + + public byte[] data; + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[]{"data"}); + } + } + /* ACE types */ + + byte ACCESS_ALLOWED_ACE_TYPE = 0x00; + + byte ACCESS_DENIED_ACE_TYPE = 0x01; + + byte SYSTEM_AUDIT_ACE_TYPE = 0x02; + + byte SYSTEM_ALARM_ACE_TYPE = 0x03; + + byte ACCESS_ALLOWED_COMPOUND_ACE_TYPE = 0x04; + + byte ACCESS_ALLOWED_OBJECT_ACE_TYPE = 0x05; + + byte ACCESS_DENIED_OBJECT_ACE_TYPE = 0x06; + + byte SYSTEM_AUDIT_OBJECT_ACE_TYPE = 0x07; + + byte SYSTEM_ALARM_OBJECT_ACE_TYPE = 0x08; + + byte ACCESS_ALLOWED_CALLBACK_ACE_TYPE = 0x09; + + byte ACCESS_DENIED_CALLBACK_ACE_TYPE = 0x0A; + + byte ACCESS_ALLOWED_CALLBACK_OBJECT_ACE_TYPE = 0x0B; + + byte ACCESS_DENIED_CALLBACK_OBJECT_ACE_TYPE = 0x0C; + + byte SYSTEM_AUDIT_CALLBACK_ACE_TYPE = 0x0D; + + byte SYSTEM_ALARM_CALLBACK_ACE_TYPE = 0x0E; + + byte SYSTEM_AUDIT_CALLBACK_OBJECT_ACE_TYPE = 0x0F; + + byte SYSTEM_ALARM_CALLBACK_OBJECT_ACE_TYPE = 0x10; + + byte SYSTEM_MANDATORY_LABEL_ACE_TYPE = 0x11; + + /* ACE inherit flags */ + byte OBJECT_INHERIT_ACE = 0x01; + + byte CONTAINER_INHERIT_ACE = 0x02; + + byte NO_PROPAGATE_INHERIT_ACE = 0x04; + + byte INHERIT_ONLY_ACE = 0x08; + + byte INHERITED_ACE = 0x10; + + byte VALID_INHERIT_FLAGS = 0x1F; + + // TODO: figure out how OVERLAPPED is used and apply an appropriate mapping + interface OVERLAPPED_COMPLETION_ROUTINE extends StdCallCallback { + + void callback(int errorCode, int nBytesTransferred, + WinBase.OVERLAPPED overlapped); + } +} diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinReg.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinReg.java similarity index 95% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinReg.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinReg.java index 7ef2d99ff..cdc308257 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinReg.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/WinReg.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; import com.sun.jna.Native; import com.sun.jna.Pointer; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.ByReference; import com.sun.jna.win32.StdCallLibrary; diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/package-info.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/package-info.java similarity index 55% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/package-info.java rename to libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/package-info.java index 420819858..4a8335777 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/package-info.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/jna/platform/win32/package-info.java @@ -1,4 +1,4 @@ /** * Windows API functions and structures accessible via JNA. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.jna.platform.win32; diff --git a/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java b/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java index 319132b1d..453f9e134 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java +++ b/libsrc/ffdec_lib/src/com/jpexs/video/SimpleMediaPlayer.java @@ -19,8 +19,8 @@ package com.jpexs.video; import com.jpexs.helpers.Helper; import com.sun.jna.NativeLibrary; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Advapi32Util; -import com.sun.jna.platform.win32.WinReg; +import com.jpexs.decompiler.flash.jna.platform.win32.Advapi32Util; +import com.jpexs.decompiler.flash.jna.platform.win32.WinReg; import java.awt.image.BufferedImage; import java.nio.ByteBuffer; import java.util.ArrayList; diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index 56c15c282..2f4d6516d 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -190,7 +190,7 @@ import com.jpexs.helpers.utf8.Utf8Helper; import com.jpexs.process.Process; import com.jpexs.process.ProcessTools; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Kernel32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; import gnu.jpdf.PDFGraphics; import gnu.jpdf.PDFJob; import java.awt.Font; diff --git a/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java b/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java index 463030f83..661821d0b 100644 --- a/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java +++ b/src/com/jpexs/decompiler/flash/console/ContextMenuTools.java @@ -19,13 +19,13 @@ package com.jpexs.decompiler.flash.console; import com.jpexs.helpers.utf8.Utf8Helper; import com.sun.jna.Platform; import com.sun.jna.WString; -import com.sun.jna.platform.win32.Advapi32Util; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.SHELLEXECUTEINFO; -import com.sun.jna.platform.win32.Shell32; -import com.sun.jna.platform.win32.Win32Exception; -import com.sun.jna.platform.win32.WinReg; -import com.sun.jna.platform.win32.WinUser; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Advapi32Util; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.SHELLEXECUTEINFO; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Shell32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Win32Exception; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinUser; import java.io.File; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index da7e32516..fec40e1c9 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -49,12 +49,12 @@ import com.jpexs.decompiler.flash.gfx.GfxConvertor; import com.jpexs.decompiler.flash.gui.debugger.DebugAdapter; import com.jpexs.decompiler.flash.gui.debugger.DebugLoaderDataModified; import com.jpexs.decompiler.flash.gui.debugger.DebuggerTools; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Advapi32Util; import com.jpexs.decompiler.flash.gui.pipes.FirstInstance; import com.jpexs.decompiler.flash.gui.soleditor.CookiesChangedListener; import com.jpexs.decompiler.flash.gui.soleditor.SharedObjectsStorage; import com.jpexs.decompiler.flash.gui.soleditor.SolEditorFrame; import com.jpexs.decompiler.flash.gui.taglistview.TagListTreeModel; -import com.jpexs.decompiler.flash.gui.tagtree.AbstractTagTreeModel; import com.jpexs.decompiler.flash.gui.tagtree.TagTreeModel; import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin; import com.jpexs.decompiler.flash.tags.DefineBinaryDataTag; @@ -82,9 +82,8 @@ import com.jpexs.helpers.Stopwatch; import com.jpexs.helpers.streams.SeekableInputStream; import com.jpexs.helpers.utf8.Utf8Helper; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Advapi32Util; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.WinReg; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg; import java.awt.Component; import java.awt.GraphicsConfiguration; import java.awt.GraphicsEnvironment; diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32.java new file mode 100644 index 000000000..61df9e942 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32.java @@ -0,0 +1,977 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; + +/** + * @author JPEXS + */ +/* 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. + */ +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.sun.jna.Structure; +import com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLEByReference; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg.HKEY; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg.HKEYByReference; +import com.sun.jna.ptr.IntByReference; +import com.sun.jna.win32.StdCallLibrary; +import com.sun.jna.win32.W32APIOptions; + +/** + * Advapi32.dll Interface. + * + * @author dblock[at]dblock.org + */ +public interface Advapi32 extends StdCallLibrary { + + /** + * Advapi32 instance. + */ + Advapi32 INSTANCE = (Advapi32) Native.loadLibrary("Advapi32", + Advapi32.class, W32APIOptions.UNICODE_OPTIONS); + + /** + * Retrieves the name of the user associated with the current thread. + * http://msdn.microsoft.com/en-us/library/ms724432(VS.85).aspx + * + * @param buffer Buffer to receive the user's logon name. + * @param len On input, the size of the buffer, on output the number of + * characters copied into the buffer, including the terminating null + * character. + * @return True if succeeded. + */ + public boolean GetUserNameW(char[] buffer, IntByReference len); + + /** + * The LogonUser function attempts to log a user on to the local computer. + * The local computer is the computer from which LogonUser was called. You + * cannot use LogonUser to log on to a remote computer. You specify the user + * with a user name and domain, and authenticate the user with a plaintext + * password. If the function succeeds, you receive a handle to a token that + * represents the logged-on user. You can then use this token handle to + * impersonate the specified user or, in most cases, to create a process + * that runs in the context of the specified user. + * + * @param lpszUsername A pointer to a null-terminated string that specifies + * the name of the user. This is the name of the user account to log on to. + * If you use the user principal name (UPN) format, user@DNS_domain_name, + * the lpszDomain parameter must be NULL. + * @param lpszDomain A pointer to a null-terminated string that specifies + * the name of the domain or server whose account database contains the + * lpszUsername account. If this parameter is NULL, the user name must be + * specified in UPN format. If this parameter is ".", the function validates + * the account using only the local account database. + * @param lpszPassword A pointer to a null-terminated string that specifies + * the plaintext password for the user account specified by lpszUsername. + * @param logonType The type of logon operation to perform. + * @param logonProvider Specifies the logon provider. + * @param phToken A pointer to a handle variable that receives a handle to a + * token that represents the specified user. + * @return If the function succeeds, the function returns nonzero. If the + * function fails, it returns zero. To get extended error information, call + * GetLastError. + */ + public boolean LogonUser( + String lpszUsername, + String lpszDomain, + String lpszPassword, + int logonType, + int logonProvider, + HANDLEByReference phToken); + + /** + * The OpenThreadToken function opens the access token associated with a + * thread. + * + * @param ThreadHandle Handle to the thread whose access token is opened. + * @param DesiredAccess Specifies an access mask that specifies the + * requested types of access to the access token. These requested access + * types are reconciled against the token's discretionary access control + * list (DACL) to determine which accesses are granted or denied. + * @param OpenAsSelf Indicates whether the access check is to be made + * against the security context of the thread calling the OpenThreadToken + * function or against the security context of the process for the calling + * thread. + * @param TokenHandle Pointer to a variable that receives the handle to the + * newly opened access token. + * @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. + */ + public boolean OpenThreadToken( + HANDLE ThreadHandle, + int DesiredAccess, + boolean OpenAsSelf, + HANDLEByReference TokenHandle); + + /** + * The OpenProcessToken function opens the access token associated with a + * process. + * + * @param ProcessHandle Handle to the process whose access token is opened. + * The process must have the PROCESS_QUERY_INFORMATION access permission. + * @param DesiredAccess Specifies an access mask that specifies the + * requested types of access to the access token. These requested access + * types are compared with the discretionary access control list (DACL) of + * the token to determine which accesses are granted or denied. + * @param TokenHandle Pointer to a handle that identifies the newly opened + * access token when the function returns. + * @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. + */ + public boolean OpenProcessToken( + HANDLE ProcessHandle, + int DesiredAccess, + HANDLEByReference TokenHandle); + + /** + * The DuplicateToken function creates a new access token that duplicates + * one already in existence. + * + * @param ExistingTokenHandle Handle to an access token opened with + * TOKEN_DUPLICATE access. + * @param ImpersonationLevel Specifies a SECURITY_IMPERSONATION_LEVEL + * enumerated type that supplies the impersonation level of the new token. + * @param DuplicateTokenHandle Pointer to a variable that receives a handle + * to the duplicate token. This handle has TOKEN_IMPERSONATE and TOKEN_QUERY + * access to the new token. + * @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. + */ + public boolean DuplicateToken( + HANDLE ExistingTokenHandle, + int ImpersonationLevel, + HANDLEByReference DuplicateTokenHandle); + + /** + * The DuplicateTokenEx function creates a new access token that duplicates + * an existing token. This function can create either a primary token or an + * impersonation token. + * + * @param hExistingToken A handle to an access token opened with + * TOKEN_DUPLICATE access. + * @param dwDesiredAccess Specifies the requested access rights for the new + * token. + * @param lpTokenAttributes A pointer to a SECURITY_ATTRIBUTES structure + * that specifies a security descriptor for the new token and determines + * whether child processes can inherit the token. + * @param ImpersonationLevel Specifies a value from the + * SECURITY_IMPERSONATION_LEVEL enumeration that indicates the impersonation + * level of the new token. + * @param TokenType Specifies one of the following values from the + * TOKEN_TYPE enumeration. + * @param phNewToken A pointer to a HANDLE variable that receives the new + * token. + * @return If the function succeeds, the function returns a nonzero value. + * If the function fails, it returns zero. To get extended error + * information, call GetLastError. + */ + public boolean DuplicateTokenEx( + HANDLE hExistingToken, + int dwDesiredAccess, + WinBase.SECURITY_ATTRIBUTES lpTokenAttributes, + int ImpersonationLevel, + int TokenType, + HANDLEByReference phNewToken); + + /** + * Retrieves a specified type of information about an access token. The + * calling process must have appropriate access rights to obtain the + * information. + * + * @param tokenHandle Handle to an access token from which information is + * retrieved. If TokenInformationClass specifies TokenSource, the handle + * must have TOKEN_QUERY_SOURCE access. For all other TokenInformationClass + * values, the handle must have TOKEN_QUERY access. + * @param tokenInformationClass Specifies a value from the + * TOKEN_INFORMATION_CLASS enumerated type to identify the type of + * information the function retrieves. + * @param tokenInformation Pointer to a buffer the function fills with the + * requested information. The structure put into this buffer depends upon + * the type of information specified by the TokenInformationClass parameter. + * @param tokenInformationLength Specifies the size, in bytes, of the buffer + * pointed to by the TokenInformation parameter. If TokenInformation is + * NULL, this parameter must be zero. + * @param returnLength Pointer to a variable that receives the number of + * bytes needed for the buffer pointed to by the TokenInformation parameter. + * If this value is larger than the value specified in the + * TokenInformationLength parameter, the function fails and stores no data + * in 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. + */ + public boolean GetTokenInformation( + HANDLE tokenHandle, + int tokenInformationClass, + Structure tokenInformation, + int tokenInformationLength, + IntByReference returnLength); + + /** + * The ImpersonateLoggedOnUser function lets the calling thread impersonate + * the security context of a logged-on user. The user is represented by a + * token handle. + * + * @param hToken Handle to a primary or impersonation access token that + * represents a logged-on user. This can be a token handle returned by a + * call to LogonUser, CreateRestrictedToken, DuplicateToken, + * DuplicateTokenEx, OpenProcessToken, or OpenThreadToken functions. If + * hToken is a primary token, it must have TOKEN_QUERY and TOKEN_DUPLICATE + * access. If hToken is an impersonation token, it must have TOKEN_QUERY and + * TOKEN_IMPERSONATE access. + * @return If the function succeeds, the return value is nonzero. + */ + public boolean ImpersonateLoggedOnUser(HANDLE hToken); + + /** + * The ImpersonateSelf function obtains an access token that impersonates + * the security context of the calling process. The token is assigned to the + * calling thread. + * + * @param ImpersonationLevel Specifies a SECURITY_IMPERSONATION_LEVEL + * enumerated type that supplies the impersonation level of the new token. + * @return If the function succeeds, the return value is nonzero. + */ + public boolean ImpersonateSelf(int ImpersonationLevel); + + /** + * The RevertToSelf function terminates the impersonation of a client + * application. + * + * @return If the function succeeds, the return value is nonzero. + */ + public boolean RevertToSelf(); + + /** + * The RegOpenKeyEx function opens the specified registry key. Note that key + * names are not case-sensitive. + * + * @param hKey Handle to an open key. + * @param lpSubKey Pointer to a null-terminated string containing the name + * of the subkey to open. + * @param ulOptions Reserved; must be zero. + * @param samDesired Access mask that specifies the desired access rights to + * the key. The function fails if the security descriptor of the key does + * not permit the requested access for the calling process. + * @param phkResult Pointer to a variable that receives a handle to the + * opened key. If the key is not one of the predefined registry keys, call + * the RegCloseKey function after you have finished using the handle. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegOpenKeyEx(HKEY hKey, String lpSubKey, int ulOptions, int samDesired, + HKEYByReference phkResult); + + /** + * The RegQueryValueEx function retrieves the type and data for a specified + * value name associated with an open registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_QUERY_VALUE access right. + * @param lpValueName Pointer to a null-terminated string containing the + * name of the value to query. If lpValueName is NULL or an empty string, + * "", the function retrieves the type and data for the key's unnamed or + * default value, if any. + * @param lpReserved Reserved; must be NULL. + * @param lpType Pointer to a variable that receives a code indicating the + * type of data stored in the specified value. + * @param lpData Pointer to a buffer that receives the value's data. This + * parameter can be NULL if the data is not required. If the data is a + * string, the function checks for a terminating null character. If one is + * not found, the string is stored with a null terminator if the buffer is + * large enough to accommodate the extra character. Otherwise, the string is + * stored as is. + * @param lpcbData Pointer to a variable that specifies the size of the + * buffer pointed to by the lpData parameter, in bytes. When the function + * returns, this variable contains the size of the data copied to lpData. + * The lpcbData parameter can be NULL only if lpData is NULL. If the data + * has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes + * any terminating null character or characters. If the buffer specified by + * lpData parameter is not large enough to hold the data, the function + * returns ERROR_MORE_DATA and stores the required buffer size in the + * variable pointed to by lpcbData. In this case, the contents of the lpData + * buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the + * function returns ERROR_SUCCESS and stores the size of the data, in bytes, + * in the variable pointed to by lpcbData. This enables an application to + * determine the best way to allocate a buffer for the value's data. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved, + IntByReference lpType, char[] lpData, IntByReference lpcbData); + + /** + * The RegQueryValueEx function retrieves the type and data for a specified + * value name associated with an open registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_QUERY_VALUE access right. + * @param lpValueName Pointer to a null-terminated string containing the + * name of the value to query. If lpValueName is NULL or an empty string, + * "", the function retrieves the type and data for the key's unnamed or + * default value, if any. + * @param lpReserved Reserved; must be NULL. + * @param lpType Pointer to a variable that receives a code indicating the + * type of data stored in the specified value. + * @param lpData Pointer to a buffer that receives the value's data. This + * parameter can be NULL if the data is not required. If the data is a + * string, the function checks for a terminating null character. If one is + * not found, the string is stored with a null terminator if the buffer is + * large enough to accommodate the extra character. Otherwise, the string is + * stored as is. + * @param lpcbData Pointer to a variable that specifies the size of the + * buffer pointed to by the lpData parameter, in bytes. When the function + * returns, this variable contains the size of the data copied to lpData. + * The lpcbData parameter can be NULL only if lpData is NULL. If the data + * has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes + * any terminating null character or characters. If the buffer specified by + * lpData parameter is not large enough to hold the data, the function + * returns ERROR_MORE_DATA and stores the required buffer size in the + * variable pointed to by lpcbData. In this case, the contents of the lpData + * buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the + * function returns ERROR_SUCCESS and stores the size of the data, in bytes, + * in the variable pointed to by lpcbData. This enables an application to + * determine the best way to allocate a buffer for the value's data. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved, + IntByReference lpType, byte[] lpData, IntByReference lpcbData); + + /** + * The RegQueryValueEx function retrieves the type and data for a specified + * value name associated with an open registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_QUERY_VALUE access right. + * @param lpValueName Pointer to a null-terminated string containing the + * name of the value to query. If lpValueName is NULL or an empty string, + * "", the function retrieves the type and data for the key's unnamed or + * default value, if any. + * @param lpReserved Reserved; must be NULL. + * @param lpType Pointer to a variable that receives a code indicating the + * type of data stored in the specified value. + * @param lpData Pointer to a buffer that receives the value's data. This + * parameter can be NULL if the data is not required. If the data is a + * string, the function checks for a terminating null character. If one is + * not found, the string is stored with a null terminator if the buffer is + * large enough to accommodate the extra character. Otherwise, the string is + * stored as is. + * @param lpcbData Pointer to a variable that specifies the size of the + * buffer pointed to by the lpData parameter, in bytes. When the function + * returns, this variable contains the size of the data copied to lpData. + * The lpcbData parameter can be NULL only if lpData is NULL. If the data + * has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes + * any terminating null character or characters. If the buffer specified by + * lpData parameter is not large enough to hold the data, the function + * returns ERROR_MORE_DATA and stores the required buffer size in the + * variable pointed to by lpcbData. In this case, the contents of the lpData + * buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the + * function returns ERROR_SUCCESS and stores the size of the data, in bytes, + * in the variable pointed to by lpcbData. This enables an application to + * determine the best way to allocate a buffer for the value's data. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved, + IntByReference lpType, IntByReference lpData, IntByReference lpcbData); + + /** + * The RegQueryValueEx function retrieves the type and data for a specified + * value name associated with an open registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_QUERY_VALUE access right. + * @param lpValueName Pointer to a null-terminated string containing the + * name of the value to query. If lpValueName is NULL or an empty string, + * "", the function retrieves the type and data for the key's unnamed or + * default value, if any. + * @param lpReserved Reserved; must be NULL. + * @param lpType Pointer to a variable that receives a code indicating the + * type of data stored in the specified value. + * @param lpData Pointer to a buffer that receives the value's data. This + * parameter can be NULL if the data is not required. If the data is a + * string, the function checks for a terminating null character. If one is + * not found, the string is stored with a null terminator if the buffer is + * large enough to accommodate the extra character. Otherwise, the string is + * stored as is. + * @param lpcbData Pointer to a variable that specifies the size of the + * buffer pointed to by the lpData parameter, in bytes. When the function + * returns, this variable contains the size of the data copied to lpData. + * The lpcbData parameter can be NULL only if lpData is NULL. If the data + * has the REG_SZ, REG_MULTI_SZ or REG_EXPAND_SZ type, this size includes + * any terminating null character or characters. If the buffer specified by + * lpData parameter is not large enough to hold the data, the function + * returns ERROR_MORE_DATA and stores the required buffer size in the + * variable pointed to by lpcbData. In this case, the contents of the lpData + * buffer are undefined. If lpData is NULL, and lpcbData is non-NULL, the + * function returns ERROR_SUCCESS and stores the size of the data, in bytes, + * in the variable pointed to by lpcbData. This enables an application to + * determine the best way to allocate a buffer for the value's data. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegQueryValueEx(HKEY hKey, String lpValueName, int lpReserved, + IntByReference lpType, Pointer lpData, IntByReference lpcbData); + + /** + * The RegCloseKey function releases a handle to the specified registry key. + * + * @param hKey Handle to the open key to be closed. The handle must have + * been opened by the RegCreateKeyEx, RegOpenKeyEx, or RegConnectRegistry + * function. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegCloseKey(HKEY hKey); + + /** + * The RegDeleteValue function removes a named value from the specified + * registry key. Note that value names are not case-sensitive. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_SET_VALUE access right. + * @param lpValueName Pointer to a null-terminated string that names the + * value to remove. If this parameter is NULL or an empty string, the value + * set by the RegSetValue function is removed. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegDeleteValue(HKEY hKey, String lpValueName); + + /** + * The RegSetValueEx function sets the data and type of a specified value + * under a registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_SET_VALUE access right. + * @param lpValueName Pointer to a string containing the name of the value + * to set. If a value with this name is not already present in the key, the + * function adds it to the key. If lpValueName is NULL or an empty string, + * "", the function sets the type and data for the key's unnamed or default + * value. + * @param Reserved Reserved; must be zero. + * @param dwType Type of data pointed to by the lpData parameter. + * @param lpData Pointer to a buffer containing the data to be stored with + * the specified value name. + * @param cbData Size of the information pointed to by the lpData parameter, + * in bytes. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, + * cbData must include the size of the terminating null character or + * characters. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType, + char[] lpData, int cbData); + + /** + * The RegSetValueEx function sets the data and type of a specified value + * under a registry key. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_SET_VALUE access right. + * @param lpValueName Pointer to a string containing the name of the value + * to set. If a value with this name is not already present in the key, the + * function adds it to the key. If lpValueName is NULL or an empty string, + * "", the function sets the type and data for the key's unnamed or default + * value. + * @param Reserved Reserved; must be zero. + * @param dwType Type of data pointed to by the lpData parameter. + * @param lpData Pointer to a buffer containing the data to be stored with + * the specified value name. + * @param cbData Size of the information pointed to by the lpData parameter, + * in bytes. If the data is of type REG_SZ, REG_EXPAND_SZ, or REG_MULTI_SZ, + * cbData must include the size of the terminating null character or + * characters. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegSetValueEx(HKEY hKey, String lpValueName, int Reserved, int dwType, + byte[] lpData, int cbData); + + /** + * Creates the specified registry key. + * @param hKey hKey + * @param lpSubKey lpSubKey + * @param Reserved Reserved + * @param lpClass lpClass + * @param dwOptions dwOptions + * @param samDesired samDesired + * @param lpSecurityAttributes lpSecurityAttributes + * @param phkResult phkResult + * @param lpdwDisposition lpdwDisposition + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegCreateKeyEx(HKEY hKey, String lpSubKey, int Reserved, String lpClass, + int dwOptions, int samDesired, SECURITY_ATTRIBUTES lpSecurityAttributes, + HKEYByReference phkResult, IntByReference lpdwDisposition); + + /** + * Removes the specified registry key. + * @param hKey hKey + * @param name name + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegDeleteKey(HKEY hKey, String name); + + /** + * The RegEnumKeyEx function enumerates subkeys of the specified open + * registry key. The function retrieves information about one subkey each + * time it is called. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_ENUMERATE_SUB_KEYS access right. + * @param dwIndex Index of the subkey to retrieve. This parameter should be + * zero for the first call to the RegEnumKeyEx function and then incremented + * for subsequent calls. Because subkeys are not ordered, any new subkey + * will have an arbitrary index. This means that the function may return + * subkeys in any order. + * @param lpName Pointer to a buffer that receives the name of the subkey, + * including the terminating null character. The function copies only the + * name of the subkey, not the full key hierarchy, to the buffer. + * @param lpcName Pointer to a variable that specifies the size of the + * buffer specified by the lpName parameter, in TCHARs. This size should + * include the terminating null character. When the function returns, the + * variable pointed to by lpcName contains the number of characters stored + * in the buffer. The count returned does not include the terminating null + * character. + * @param reserved Reserved; must be NULL. + * @param lpClass Pointer to a buffer that receives the null-terminated + * class string of the enumerated subkey. This parameter can be NULL. + * @param lpcClass Pointer to a variable that specifies the size of the + * buffer specified by the lpClass parameter, in TCHARs. The size should + * include the terminating null character. When the function returns, + * lpcClass contains the number of characters stored in the buffer. The + * count returned does not include the terminating null character. This + * parameter can be NULL only if lpClass is NULL. + * @param lpftLastWriteTime Pointer to a variable that receives the time at + * which the enumerated subkey was last written. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegEnumKeyEx(HKEY hKey, int dwIndex, char[] lpName, IntByReference lpcName, + IntByReference reserved, char[] lpClass, IntByReference lpcClass, + WinBase.FILETIME lpftLastWriteTime); + + /** + * The RegEnumValue function enumerates the values for the specified open + * registry key. The function copies one indexed value name and data block + * for the key each time it is called. + * + * @param hKey Handle to an open key. The key must have been opened with the + * KEY_QUERY_VALUE access right. + * @param dwIndex Index of the value to be retrieved. This parameter should + * be zero for the first call to the RegEnumValue function and then be + * incremented for subsequent calls. Because values are not ordered, any new + * value will have an arbitrary index. This means that the function may + * return values in any order. + * @param lpValueName Pointer to a buffer that receives the name of the + * value, including the terminating null character. + * @param lpcchValueName Pointer to a variable that specifies the size of + * the buffer pointed to by the lpValueName parameter, in TCHARs. This size + * should include the terminating null character. When the function returns, + * the variable pointed to by lpcValueName contains the number of characters + * stored in the buffer. The count returned does not include the terminating + * null character. + * @param reserved Reserved; must be NULL. + * @param lpType Pointer to a variable that receives a code indicating the + * type of data stored in the specified value. + * @param lpData Pointer to a buffer that receives the data for the value + * entry. This parameter can be NULL if the data is not required. + * @param lpcbData Pointer to a variable that specifies the size of the + * buffer pointed to by the lpData parameter, in bytes. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegEnumValue(HKEY hKey, int dwIndex, char[] lpValueName, + IntByReference lpcchValueName, IntByReference reserved, + IntByReference lpType, byte[] lpData, IntByReference lpcbData); + + /** + * The RegQueryInfoKey function retrieves information about the specified + * registry key. + * + * @param hKey A handle to an open key. The key must have been opened with + * the KEY_QUERY_VALUE access right. + * @param lpClass A pointer to a buffer that receives the null-terminated + * class string of the key. This parameter can be ignored. This parameter + * can be NULL. + * @param lpcClass A pointer to a variable that specifies the size of the + * buffer pointed to by the lpClass parameter, in characters. + * @param lpReserved Reserved; must be NULL. + * @param lpcSubKeys A pointer to a variable that receives the number of + * subkeys that are contained by the specified key. This parameter can be + * NULL. + * @param lpcMaxSubKeyLen A pointer to a variable that receives the size of + * the key's subkey with the longest name, in characters, not including the + * terminating null character. This parameter can be NULL. + * @param lpcMaxClassLen A pointer to a variable that receives the size of + * the longest string that specifies a subkey class, in characters. The + * count returned does not include the terminating null character. This + * parameter can be NULL. + * @param lpcValues A pointer to a variable that receives the number of + * values that are associated with the key. This parameter can be NULL. + * @param lpcMaxValueNameLen A pointer to a variable that receives the size + * of the key's longest value name, in characters. The size does not include + * the terminating null character. This parameter can be NULL. + * @param lpcMaxValueLen A pointer to a variable that receives the size of + * the longest data component among the key's values, in bytes. This + * parameter can be NULL. + * @param lpcbSecurityDescriptor A pointer to a variable that receives the + * size of the key's security descriptor, in bytes. This parameter can be + * NULL. + * @param lpftLastWriteTime A pointer to a FILETIME structure that receives + * the last write time. This parameter can be NULL. + * @return If the function succeeds, the return value is ERROR_SUCCESS. If + * the function fails, the return value is a nonzero error code defined in + * Winerror.h. + */ + public int RegQueryInfoKey(HKEY hKey, char[] lpClass, + IntByReference lpcClass, IntByReference lpReserved, + IntByReference lpcSubKeys, IntByReference lpcMaxSubKeyLen, + IntByReference lpcMaxClassLen, IntByReference lpcValues, + IntByReference lpcMaxValueNameLen, IntByReference lpcMaxValueLen, + IntByReference lpcbSecurityDescriptor, + WinBase.FILETIME lpftLastWriteTime); + + /** + * Retrieves a registered handle to the specified event log. + * + * @param lpUNCServerName The Universal Naming Convention (UNC) name of the + * remote server on which this operation is to be performed. If this + * parameter is NULL, the local computer is used. + * @param lpSourceName The name of the event source whose handle is to be + * retrieved. The source name must be a subkey of a log under the Eventlog + * registry key. However, the Security log is for system use only. + * @return If the function succeeds, the return value is a handle to the + * event log. If the function fails, the return value is NULL. To get + * extended error information, call GetLastError. The function returns + * ERROR_ACCESS_DENIED if lpSourceName specifies the Security event log. + */ + public HANDLE RegisterEventSource(String lpUNCServerName, String lpSourceName); + + /** + * Closes the specified event log. + * + * @param hEventLog A handle to the event log. The RegisterEventSource + * function returns this handle. + * @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. + */ + public boolean DeregisterEventSource(HANDLE hEventLog); + + /** + * Opens a handle to the specified event log. + * + * @param lpUNCServerName The Universal Naming Convention (UNC) name of the + * remote server on which the event log is to be opened. If this parameter + * is NULL, the local computer is used. + * @param lpSourceName The name of the log. If you specify a custom log and + * it cannot be found, the event logging service opens the Application log; + * however, there will be no associated message or category string file. + * @return If the function succeeds, the return value is the handle to an + * event log. If the function fails, the return value is NULL. To get + * extended error information, call GetLastError. + */ + public HANDLE OpenEventLog(String lpUNCServerName, String lpSourceName); + + /** + * Closes the specified event log. + * + * @param hEventLog A handle to the event log to be closed. The OpenEventLog + * or OpenBackupEventLog function returns this handle. + * @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. + */ + public boolean CloseEventLog(HANDLE hEventLog); + + /** + * Retrieves the number of records in the specified event log. + * + * @param hEventLog A handle to the open event log. The OpenEventLog or + * OpenBackupEventLog function returns this handle. + * @param NumberOfRecords A pointer to a variable that receives the number + * of records in the specified event log. + * @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. + */ + public boolean GetNumberOfEventLogRecords(HANDLE hEventLog, IntByReference NumberOfRecords); + + /** + * Clears the specified event log, and optionally saves the current copy of + * the log to a backup file. + * + * @param hEventLog A handle to the event log to be cleared. The + * OpenEventLog function returns this handle. + * @param lpBackupFileName The absolute or relative path of the backup file. + * If this file already exists, the function fails. If the lpBackupFileName + * parameter is NULL, the event log is not backed up. + * @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. The ClearEventLog function can fail if + * the event log is empty or the backup file already exists. + */ + public boolean ClearEventLog(HANDLE hEventLog, String lpBackupFileName); + + /** + * Saves the specified event log to a backup file. The function does not + * clear the event log. + * + * @param hEventLog A handle to the open event log. The OpenEventLog + * function returns this handle. + * @param lpBackupFileName The absolute or relative path of the backup file. + * @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. + */ + public boolean BackupEventLog(HANDLE hEventLog, String lpBackupFileName); + + /** + * Opens a handle to a backup event log created by the BackupEventLog + * function. + * + * @param lpUNCServerName The Universal Naming Convention (UNC) name of the + * remote server on which this operation is to be performed. If this + * parameter is NULL, the local computer is used. + * @param lpFileName The full path of the backup file. + * @return If the function succeeds, the return value is a handle to the + * backup event log. If the function fails, the return value is NULL. To get + * extended error information, call GetLastError. + */ + public HANDLE OpenBackupEventLog(String lpUNCServerName, String lpFileName); + + /** + * Reads the specified number of entries from the specified event log. The + * function can be used to read log entries in chronological or reverse + * chronological order. + * + * @param hEventLog A handle to the event log to be read. The OpenEventLog + * function returns this handle. + * @param dwReadFlags Use the following flag values to indicate how to read + * the log file. + * @param dwRecordOffset The record number of the log-entry at which the + * read operation should start. This parameter is ignored unless dwReadFlags + * includes the EVENTLOG_SEEK_READ flag. + * @param lpBuffer An application-allocated buffer that will receive one or + * more EVENTLOGRECORD structures. This parameter cannot be NULL, even if + * the nNumberOfBytesToRead parameter is zero. The maximum size of this + * buffer is 0x7ffff bytes. + * @param nNumberOfBytesToRead The size of the lpBuffer buffer, in bytes. + * This function will read as many log entries as will fit in the buffer; + * the function will not return partial entries. + * @param pnBytesRead A pointer to a variable that receives the number of + * bytes read by the function. + * @param pnMinNumberOfBytesNeeded A pointer to a variable that receives the + * required size of the lpBuffer buffer. This value is valid only this + * function returns zero and GetLastError returns ERROR_INSUFFICIENT_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. + */ + public boolean ReadEventLog(HANDLE hEventLog, int dwReadFlags, int dwRecordOffset, + Pointer lpBuffer, int nNumberOfBytesToRead, IntByReference pnBytesRead, + IntByReference pnMinNumberOfBytesNeeded); + + /** + * The GetOldestEventLogRecord function retrieves the absolute record number + * of the oldest record in the specified event log. + * + * @param hEventLog Handle to the open event log. This handle is returned by + * the OpenEventLog or OpenBackupEventLog function. + * @param OldestRecord Pointer to a variable that receives the absolute + * record number of the oldest record in the specified event log. + * @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. + */ + public boolean GetOldestEventLogRecord(HANDLE hEventLog, IntByReference OldestRecord); + + /** + * Creates a new process and its primary thread. The new process runs in the + * security context of the user represented by the specified token. + *

+ * Typically, the process that calls the CreateProcessAsUser function must + * have the SE_INCREASE_QUOTA_NAME privilege and may require the + * SE_ASSIGNPRIMARYTOKEN_NAME privilege if the token is not assignable. If + * this function fails with ERROR_PRIVILEGE_NOT_HELD (1314), use the + * CreateProcessWithLogonW function instead. CreateProcessWithLogonW + * requires no special privileges, but the specified user account must be + * allowed to log on interactively. Generally, it is best to use + * CreateProcessWithLogonW to create a process with alternate credentials. + * + * @param hToken A handle to the primary token that represents a user. + * @param lpApplicationName The name of the module to be executed. + * @param lpCommandLine The command line to be executed. + * @param lpProcessAttributes A pointer to a SECURITY_ATTRIBUTES structure + * that specifies a security descriptor for the new process object and + * determines whether child processes can inherit the returned handle to the + * process. + * @param lpThreadAttributes A pointer to a SECURITY_ATTRIBUTES structure + * that specifies a security descriptor for the new thread object and + * determines whether child processes can inherit the returned handle to the + * thread. + * @param bInheritHandles If this parameter is TRUE, each inheritable handle + * in the calling process is inherited by the new process. If the parameter + * is FALSE, the handles are not inherited. Note that inherited handles have + * the same value and access rights as the original handles. + * @param dwCreationFlags The flags that control the priority class and the + * creation of the process. For a list of values, see Process Creation + * Flags. + * @param lpEnvironment A pointer to an environment block for the new + * process. If this parameter is NULL, the new process uses the environment + * of the calling process. + *

+ * An environment block consists of a null-terminated block of + * null-terminated strings. Each string is in the following form: + * name=value\0 + * @param lpCurrentDirectory The full path to the current directory for the + * process. The string can also specify a UNC path. + * @param lpStartupInfo A pointer to a STARTUPINFO or STARTUPINFOEX + * structure. + * @param lpProcessInformation A pointer to a PROCESS_INFORMATION structure + * that receives identification information about the new process. + * @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. + */ + public boolean CreateProcessAsUser( + HANDLE hToken, + String lpApplicationName, + String lpCommandLine, + SECURITY_ATTRIBUTES lpProcessAttributes, + SECURITY_ATTRIBUTES lpThreadAttributes, + boolean bInheritHandles, + int dwCreationFlags, + String lpEnvironment, + String lpCurrentDirectory, + WinBase.STARTUPINFO lpStartupInfo, + WinBase.PROCESS_INFORMATION lpProcessInformation); + + /** + * The AdjustTokenPrivileges function enables or disables privileges in the + * specified access token. Enabling or disabling privileges in an access + * token requires TOKEN_ADJUST_PRIVILEGES access. + * + * @param TokenHandle A handle to the access token that contains the + * privileges to be modified. + * @param DisableAllPrivileges Specifies whether the function disables all + * of the token's privileges. + * @param NewState A pointer to a TOKEN_PRIVILEGES structure that specifies + * an array of privileges and their attributes. + * @param BufferLength Specifies the size, in bytes, of the buffer pointed + * to by the PreviousState parameter. This parameter can be zero if the + * PreviousState parameter is NULL. + * @param PreviousState A pointer to a buffer that the function fills with a + * TOKEN_PRIVILEGES structure that contains the previous state of any + * privileges that the function modifies. + * @param ReturnLength A pointer to a variable that receives the required + * size, in bytes, of the buffer pointed to by the PreviousState parameter. + * @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. + */ + public boolean AdjustTokenPrivileges( + HANDLE TokenHandle, + boolean DisableAllPrivileges, + WinNT.TOKEN_PRIVILEGES NewState, + int BufferLength, + WinNT.TOKEN_PRIVILEGES PreviousState, + IntByReference ReturnLength); + + /** + * The LookupPrivilegeName function retrieves the name that corresponds to + * the privilege represented on a specific system by a specified locally + * unique identifier (LUID). + * + * @param lpSystemName A pointer to a null-terminated string that specifies + * the name of the system on which the privilege name is retrieved. If a + * null string is specified, the function attempts to find the privilege + * name on the local system. + * @param lpLuid A pointer to the LUID by which the privilege is known on + * the target system. + * @param lpName A pointer to a buffer that receives a null-terminated + * string that represents the privilege name. For example, this string could + * be "SeSecurityPrivilege". + * @param cchName A pointer to a variable that specifies the size, in a + * TCHAR value, of the lpName 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. + */ + public boolean LookupPrivilegeName( + String lpSystemName, + WinNT.LUID lpLuid, + char[] lpName, + IntByReference cchName); + + /** + * The LookupPrivilegeValue function retrieves the locally unique identifier + * (LUID) used on a specified system to locally represent the specified + * privilege name. + * + * @param lpSystemName A pointer to a null-terminated string that specifies + * the name of the system on which the privilege name is retrieved. If a + * null string is specified, the function attempts to find the privilege + * name on the local system. + * @param lpName A pointer to a null-terminated string that specifies the + * name of the privilege, as defined in the Winnt.h header file. For + * example, this parameter could specify the constant, SE_SECURITY_NAME, or + * its corresponding string, "SeSecurityPrivilege". + * @param lpLuid A pointer to a variable that receives the LUID by which the + * privilege is known on the system specified by the lpSystemName parameter. + * @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. + */ + public boolean LookupPrivilegeValue( + String lpSystemName, + String lpName, + WinNT.LUID lpLuid); +} diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32Util.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32Util.java new file mode 100644 index 000000000..cb470dd81 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Advapi32Util.java @@ -0,0 +1,1059 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; + +/** + * @author JPEXS + */ +import com.sun.jna.Memory; +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.EVENTLOGRECORD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg.HKEY; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg.HKEYByReference; +import com.sun.jna.ptr.IntByReference; +import java.util.ArrayList; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +/** + * Advapi32 utility API. + * + * @author dblock[at]dblock.org + */ +public abstract class Advapi32Util { + + /** + * Constructor. + */ + private Advapi32Util() { + + } + + /** + * An account. + */ + public static class Account { + + /** + * Account name. + */ + public String name; + + /** + * Account domain. + */ + public String domain; + + /** + * Account SID. + */ + public byte[] sid; + + /** + * String representation of the account SID. + */ + public String sidString; + + /** + * Account type, one of SID_NAME_USE. + */ + public int accountType; + + /** + * Fully qualified account name. + */ + public String fqn; + + /** + * Constructor. + */ + public Account() { + + } + } + + /** + * Checks whether a registry key exists. + * @param root HKEY_LOCAL_MACHINE, etc. + * @param key Path to the registry key. + * @return True if the key exists. + */ + public static boolean registryKeyExists(HKEY root, String key) { + return registryKeyExists(root, key, false); + } + + /** + * Checks whether a registry key exists. + * + * @param root HKEY_LOCAL_MACHINE, etc. + * @param key Path to the registry key. + * @param use64BitKey True if the key is 64-bit. + * @return True if the key exists. + */ + public static boolean registryKeyExists(HKEY root, String key, boolean use64BitKey) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64BitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); + switch (rc) { + case W32Errors.ERROR_SUCCESS: + Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + return true; + case W32Errors.ERROR_FILE_NOT_FOUND: + return false; + default: + throw new Win32Exception(rc); + } + } + + /** + * Checks whether a registry key exists. + * + * @param root HKEY_LOCAL_MACHINE, etc. + * @param key Path to the registry key. + * @param value Value + * @return True if the key exists. + */ + public static boolean registryValueExists(HKEY root, String key, String value) { + return registryValueExists(root, key, value, false); + } + + /** + * Checks whether a registry value exists. + * + * @param root HKEY_LOCAL_MACHINE, etc. + * @param key Registry key path. + * @param value Value name. + * @param use64bitKey Use 64 bit key + * @return True if the value exists. + */ + public static boolean registryValueExists(HKEY root, String key, String value, boolean use64bitKey) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64bitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); + try { + switch (rc) { + case W32Errors.ERROR_SUCCESS: + break; + case W32Errors.ERROR_FILE_NOT_FOUND: + return false; + default: + throw new Win32Exception(rc); + } + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + switch (rc) { + case W32Errors.ERROR_SUCCESS: + case W32Errors.ERROR_INSUFFICIENT_BUFFER: + return true; + case W32Errors.ERROR_FILE_NOT_FOUND: + return false; + default: + throw new Win32Exception(rc); + } + } finally { + if (phkKey.getValue() != null && phkKey.getValue() != WinBase.INVALID_HANDLE_VALUE) { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + } + + /** + * Get a registry REG_SZ value. + * + * @param root Root key. + * @param key Registry path. + * @param value Name of the value to retrieve. + * @return String value. + */ + public static String registryGetStringValue(HKEY root, String key, String value) { + return registryGetStringValue(root, key, value, false); + } + + /** + * Get a registry REG_SZ value. + * + * @param root Root key. + * @param key Registry path. + * @param value Name of the value to retrieve. + * @param use64bitKey Use 64 bit key + * @return String value. + */ + public static String registryGetStringValue(HKEY root, String key, String value, boolean use64bitKey) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | (use64bitKey ? 0 : WinNT.KEY_WOW64_32KEY), phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + if (lpType.getValue() != WinNT.REG_SZ) { + throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ"); + } + char[] data = new char[lpcbData.getValue()]; + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + return Native.toString(data); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get a registry REG_EXPAND_SZ value. + * + * @param root Root key. + * @param key Registry path. + * @param value Name of the value to retrieve. + * @return String value. + */ + public static String registryGetExpandableStringValue(HKEY root, String key, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + if (lpType.getValue() != WinNT.REG_EXPAND_SZ) { + throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ"); + } + char[] data = new char[lpcbData.getValue()]; + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + return Native.toString(data); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get a registry REG_MULTI_SZ value. + * + * @param root Root key. + * @param key Registry path. + * @param value Name of the value to retrieve. + * @return String value. + */ + public static String[] registryGetStringArray(HKEY root, String key, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + if (lpType.getValue() != WinNT.REG_MULTI_SZ) { + throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ"); + } + Memory data = new Memory(lpcbData.getValue()); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + ArrayList result = new ArrayList<>(); + int offset = 0; + while (offset < data.size()) { + String s = data.getString(offset); //FIXME, true); + offset += s.length() * Native.WCHAR_SIZE; + offset += Native.WCHAR_SIZE; + result.add(s); + } + return result.toArray(new String[result.size()]); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get a registry REG_BINARY value. + * + * @param root Root key. + * @param key Registry path. + * @param value Name of the value to retrieve. + * @return String value. + */ + public static byte[] registryGetBinaryValue(HKEY root, String key, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + if (lpType.getValue() != WinNT.REG_BINARY) { + throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_BINARY"); + } + byte[] data = new byte[lpcbData.getValue()]; + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + return data; + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get a registry DWORD value. + * + * @param root Root key. + * @param key Registry key path. + * @param value Name of the value to retrieve. + * @return Integer value. + */ + public static int registryGetIntValue(HKEY root, String key, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + IntByReference lpcbData = new IntByReference(); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, (char[]) null, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + if (lpType.getValue() != WinNT.REG_DWORD) { + throw new RuntimeException("Unexpected registry type " + lpType.getValue() + ", expected REG_SZ"); + } + IntByReference data = new IntByReference(); + rc = Advapi32.INSTANCE.RegQueryValueEx( + phkKey.getValue(), value, 0, lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS && rc != W32Errors.ERROR_INSUFFICIENT_BUFFER) { + throw new Win32Exception(rc); + } + return data.getValue(); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Create a registry key. + * + * @param hKey Parent key. + * @param keyName Key name. + * @return True if the key was created, false otherwise. + */ + public static boolean registryCreateKey(HKEY hKey, String keyName) { + HKEYByReference phkResult = new HKEYByReference(); + IntByReference lpdwDisposition = new IntByReference(); + int rc = Advapi32.INSTANCE.RegCreateKeyEx(hKey, keyName, 0, null, WinNT.REG_OPTION_NON_VOLATILE, + WinNT.KEY_READ, null, phkResult, lpdwDisposition); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + rc = Advapi32.INSTANCE.RegCloseKey(phkResult.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + return WinNT.REG_CREATED_NEW_KEY == lpdwDisposition.getValue(); + } + + /** + * Create a registry key. + * + * @param root Root key. + * @param parentPath Path to an existing registry key. + * @param keyName Key name. + * @return True if the key was created, false otherwise. + */ + public static boolean registryCreateKey(HKEY root, String parentPath, String keyName) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, parentPath, 0, WinNT.KEY_CREATE_SUB_KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + return registryCreateKey(phkKey.getValue(), keyName); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Set an integer value in registry. + * + * @param hKey Parent key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetIntValue(HKEY hKey, String name, int value) { + 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); + int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_DWORD, data, 4); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Set an integer value in registry. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetIntValue(HKEY root, String keyPath, String name, int value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registrySetIntValue(phkKey.getValue(), name, value); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Set a string value in registry. + * + * @param hKey Parent key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetStringValue(HKEY hKey, String name, String value) { + char[] data = Native.toCharArray(value); + int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_SZ, + data, data.length * Native.WCHAR_SIZE); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Set a string value in registry. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetStringValue(HKEY root, String keyPath, String name, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registrySetStringValue(phkKey.getValue(), name, value); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Set an expandable string value in registry. + * + * @param hKey Parent key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetExpandableStringValue(HKEY hKey, String name, String value) { + char[] data = Native.toCharArray(value); + int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_EXPAND_SZ, + data, data.length * Native.WCHAR_SIZE); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Set a string value in registry. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param name Value name. + * @param value Value to write to registry. + */ + public static void registrySetExpandableStringValue(HKEY root, String keyPath, String name, String value) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registrySetExpandableStringValue(phkKey.getValue(), name, value); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Set a string array value in registry. + * + * @param hKey Parent key. + * @param name Name. + * @param arr Array of strings to write to registry. + */ + public static void registrySetStringArray(HKEY hKey, String name, String[] arr) { + int size = 0; + for (String s : arr) { + size += s.length() * Native.WCHAR_SIZE; + size += Native.WCHAR_SIZE; + } + + int offset = 0; + Memory data = new Memory(size); + for (String s : arr) { + data.setString(offset, s);//FIXME, true); + offset += s.length() * Native.WCHAR_SIZE; + offset += Native.WCHAR_SIZE; + } + + int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_MULTI_SZ, + data.getByteArray(0, size), size); + + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Set a string array value in registry. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param name Value name. + * @param arr Array of strings to write to registry. + */ + public static void registrySetStringArray(HKEY root, String keyPath, String name, String[] arr) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registrySetStringArray(phkKey.getValue(), name, arr); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Set a binary value in registry. + * + * @param hKey Parent key. + * @param name Value name. + * @param data Data to write to registry. + */ + public static void registrySetBinaryValue(HKEY hKey, String name, byte[] data) { + int rc = Advapi32.INSTANCE.RegSetValueEx(hKey, name, 0, WinNT.REG_BINARY, data, data.length); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Set a binary value in registry. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param name Value name. + * @param data Data to write to registry. + */ + public static void registrySetBinaryValue(HKEY root, String keyPath, String name, byte[] data) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registrySetBinaryValue(phkKey.getValue(), name, data); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Delete a registry key. + * + * @param hKey Parent key. + * @param keyName Name of the key to delete. + */ + public static void registryDeleteKey(HKEY hKey, String keyName) { + int rc = Advapi32.INSTANCE.RegDeleteKey(hKey, keyName); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Delete a registry key. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param keyName Name of the key to delete. + */ + public static void registryDeleteKey(HKEY root, String keyPath, String keyName) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registryDeleteKey(phkKey.getValue(), keyName); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Delete a registry value. + * + * @param hKey Parent key. + * @param valueName Name of the value to delete. + */ + public static void registryDeleteValue(HKEY hKey, String valueName) { + int rc = Advapi32.INSTANCE.RegDeleteValue(hKey, valueName); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + + /** + * Delete a registry value. + * + * @param root Root key. + * @param keyPath Path to an existing registry key. + * @param valueName Name of the value to delete. + */ + public static void registryDeleteValue(HKEY root, String keyPath, String valueName) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WRITE | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + registryDeleteValue(phkKey.getValue(), valueName); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get names of the registry key's sub-keys. + * + * @param hKey Registry key. + * @return Array of registry key names. + */ + public static String[] registryGetKeys(HKEY hKey) { + IntByReference lpcSubKeys = new IntByReference(); + IntByReference lpcMaxSubKeyLen = new IntByReference(); + int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null, + lpcSubKeys, lpcMaxSubKeyLen, null, null, null, null, null, null); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + ArrayList keys = new ArrayList<>(lpcSubKeys.getValue()); + char[] name = new char[lpcMaxSubKeyLen.getValue() + 1]; + for (int i = 0; i < lpcSubKeys.getValue(); i++) { + IntByReference lpcchValueName = new IntByReference(lpcMaxSubKeyLen.getValue() + 1); + rc = Advapi32.INSTANCE.RegEnumKeyEx(hKey, i, name, lpcchValueName, + null, null, null, null); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + keys.add(Native.toString(name)); + } + return keys.toArray(new String[keys.size()]); + } + + /** + * Get names of the registry key's sub-keys. + * + * @param root Root key. + * @param keyPath Path to a registry key. + * @return Array of registry key names. + */ + public static String[] registryGetKeys(HKEY root, String keyPath) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + return registryGetKeys(phkKey.getValue()); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Get a table of registry values. + * + * @param hKey Registry key. + * @return Table of values. + */ + public static TreeMap registryGetValues(HKEY hKey) { + IntByReference lpcValues = new IntByReference(); + IntByReference lpcMaxValueNameLen = new IntByReference(); + IntByReference lpcMaxValueLen = new IntByReference(); + int rc = Advapi32.INSTANCE.RegQueryInfoKey(hKey, null, null, null, null, + null, null, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, null, null); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + TreeMap keyValues = new TreeMap<>(); + char[] name = new char[lpcMaxValueNameLen.getValue() + 1]; + byte[] data = new byte[lpcMaxValueLen.getValue()]; + for (int i = 0; i < lpcValues.getValue(); i++) { + IntByReference lpcchValueName = new IntByReference(lpcMaxValueNameLen.getValue() + 1); + IntByReference lpcbData = new IntByReference(lpcMaxValueLen.getValue()); + IntByReference lpType = new IntByReference(); + rc = Advapi32.INSTANCE.RegEnumValue(hKey, i, name, lpcchValueName, null, + lpType, data, lpcbData); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + + String nameString = Native.toString(name); + + Memory byteData = new Memory(lpcbData.getValue()); + byteData.write(0, data, 0, lpcbData.getValue()); + + switch (lpType.getValue()) { + case WinNT.REG_DWORD: { + keyValues.put(nameString, byteData.getInt(0)); + break; + } + case WinNT.REG_SZ: + case WinNT.REG_EXPAND_SZ: { + keyValues.put(nameString, byteData.getString(0)); //FIXME, true); + break; + } + case WinNT.REG_BINARY: { + keyValues.put(nameString, byteData.getByteArray(0, lpcbData.getValue())); + break; + } + case WinNT.REG_MULTI_SZ: { + Memory stringData = new Memory(lpcbData.getValue()); + stringData.write(0, data, 0, lpcbData.getValue()); + ArrayList result = new ArrayList<>(); + int offset = 0; + while (offset < stringData.size()) { + String s = stringData.getString(offset); //FIXME, true); + offset += s.length() * Native.WCHAR_SIZE; + offset += Native.WCHAR_SIZE; + result.add(s); + } + keyValues.put(nameString, result.toArray(new String[result.size()])); + break; + } + default: + throw new RuntimeException("Unsupported type: " + lpType.getValue()); + } + } + return keyValues; + } + + /** + * Get a table of registry values. + * + * @param root Registry root. + * @param keyPath Registry key path. + * @return Table of values. + */ + public static TreeMap registryGetValues(HKEY root, String keyPath) { + HKEYByReference phkKey = new HKEYByReference(); + int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, keyPath, 0, WinNT.KEY_READ | WinNT.KEY_WOW64_32KEY, phkKey); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + try { + return registryGetValues(phkKey.getValue()); + } finally { + rc = Advapi32.INSTANCE.RegCloseKey(phkKey.getValue()); + if (rc != W32Errors.ERROR_SUCCESS) { + throw new Win32Exception(rc); + } + } + } + + /** + * Converts a map of environment variables to an environment block suitable + * for {@link Advapi32#CreateProcessAsUser}. This environment block consists + * of null-terminated blocks of null-terminated strings. Each string is in + * the following form: name=value\0 + * + * @param environment Environment variables + * @return A environment block + */ + public static String getEnvironmentBlock(Map environment) { + StringBuilder out = new StringBuilder(); + for (Entry entry : environment.entrySet()) { + if (entry.getValue() != null) { + out.append(entry.getKey()).append("=").append(entry.getValue()).append("\0"); + } + } + return out.toString() + "\0"; + } + + /** + * Event log types. + */ + public static enum EventLogType { + + /** + * Error event. + */ + Error, + /** + * Warning event. + */ + Warning, + /** + * Informational event. + */ + Informational, + /** + * Audit success event. + */ + AuditSuccess, + /** + * Audit failure event. + */ + AuditFailure + } + + /** + * An event log record. + */ + public static class EventLogRecord { + + private EVENTLOGRECORD _record = null; + + private final String _source; + + private byte[] _data; + + private String[] _strings; + + /** + * Raw record data. + * + * @return EVENTLOGRECORD. + */ + public EVENTLOGRECORD getRecord() { + return _record; + } + + /** + * Event Id. + * + * @return Integer. + */ + public int getEventId() { + return _record.EventID.intValue(); + } + + /** + * Event source. + * + * @return String. + */ + public String getSource() { + return _source; + } + + /** + * Status code for the facility, part of the Event ID. + * + * @return Status code. + */ + public int getStatusCode() { + return _record.EventID.intValue() & 0xFFFF; + } + + /** + * Record number of the record. This value can be used with the + * EVENTLOG_SEEK_READ flag in the ReadEventLog function to begin reading + * at a specified record. + * + * @return Integer. + */ + public int getRecordNumber() { + return _record.RecordNumber.intValue(); + } + + /** + * Record length, with data. + * + * @return Number of bytes in the record including data. + */ + public int getLength() { + return _record.Length.intValue(); + } + + /** + * Strings associated with this event. + * + * @return Array of strings or null. + */ + public String[] getStrings() { + return _strings; + } + + /** + * Event log type. + * + * @return Event log type. + */ + public EventLogType getType() { + switch (_record.EventType.intValue()) { + case WinNT.EVENTLOG_SUCCESS: + case WinNT.EVENTLOG_INFORMATION_TYPE: + return EventLogType.Informational; + case WinNT.EVENTLOG_AUDIT_FAILURE: + return EventLogType.AuditFailure; + case WinNT.EVENTLOG_AUDIT_SUCCESS: + return EventLogType.AuditSuccess; + case WinNT.EVENTLOG_ERROR_TYPE: + return EventLogType.Error; + case WinNT.EVENTLOG_WARNING_TYPE: + return EventLogType.Warning; + default: + throw new RuntimeException("Invalid type: " + _record.EventType.intValue()); + } + } + + /** + * Raw data associated with the record. + * + * @return Array of bytes or null. + */ + public byte[] getData() { + return _data; + } + + /** + * Constructor. + * @param pevlr Pointer to the EVENTLOGRECORD structure + */ + public EventLogRecord(Pointer pevlr) { + _record = new EVENTLOGRECORD(pevlr); + _source = pevlr.getString(_record.size()); //, true); FIXME + // data + if (_record.DataLength.intValue() > 0) { + _data = pevlr.getByteArray(_record.DataOffset.intValue(), + _record.DataLength.intValue()); + } + // strings + if (_record.NumStrings.intValue() > 0) { + ArrayList strings = new ArrayList<>(); + int count = _record.NumStrings.intValue(); + long offset = _record.StringOffset.intValue(); + while (count > 0) { + String s = pevlr.getString(offset); //FIXME, true); + strings.add(s); + offset += s.length() * Native.WCHAR_SIZE; + offset += Native.WCHAR_SIZE; + count--; + } + _strings = strings.toArray(new String[strings.size()]); + } + } + } +} diff --git a/src/com/sun/jna/platform/win32/BITMAP.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BITMAP.java similarity index 81% rename from src/com/sun/jna/platform/win32/BITMAP.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BITMAP.java index 93aa8c1ea..462d07552 100644 --- a/src/com/sun/jna/platform/win32/BITMAP.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BITMAP.java @@ -14,12 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Structure; -import com.sun.jna.platform.win32.WinDef.LONG; -import com.sun.jna.platform.win32.WinDef.LPVOID; -import com.sun.jna.platform.win32.WinDef.WORD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.LONG; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.LPVOID; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.WORD; import java.util.Arrays; import java.util.List; diff --git a/src/com/sun/jna/platform/win32/BaseTSD.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BaseTSD.java similarity index 98% rename from src/com/sun/jna/platform/win32/BaseTSD.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BaseTSD.java index 6ac5efab0..061916d67 100644 --- a/src/com/sun/jna/platform/win32/BaseTSD.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/BaseTSD.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.IntegerType; import com.sun.jna.Native; diff --git a/src/com/sun/jna/platform/win32/Gdi32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Gdi32.java similarity index 95% rename from src/com/sun/jna/platform/win32/Gdi32.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Gdi32.java index f11836aaa..10936e7b0 100644 --- a/src/com/sun/jna/platform/win32/Gdi32.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Gdi32.java @@ -14,19 +14,19 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; 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.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.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.DWORD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HBITMAP; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HDC; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HRGN; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinGDI.BITMAPINFO; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinGDI.BITMAPINFOHEADER; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinGDI.RGNDATA; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.PointerByReference; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; diff --git a/src/com/sun/jna/platform/win32/ICONINFO.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/ICONINFO.java similarity index 84% rename from src/com/sun/jna/platform/win32/ICONINFO.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/ICONINFO.java index c77a7b8b4..856087e43 100644 --- a/src/com/sun/jna/platform/win32/ICONINFO.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/ICONINFO.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Structure; -import com.sun.jna.platform.win32.WinDef.DWORD; -import com.sun.jna.platform.win32.WinDef.HBITMAP; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.DWORD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HBITMAP; import java.util.Arrays; import java.util.List; diff --git a/src/com/sun/jna/platform/win32/Kernel32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Kernel32.java similarity index 99% rename from src/com/sun/jna/platform/win32/Kernel32.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Kernel32.java index 9d7fa77e6..087524775 100644 --- a/src/com/sun/jna/platform/win32/Kernel32.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Kernel32.java @@ -14,11 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Native; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.LPVOID; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.NativeLongByReference; import com.sun.jna.win32.W32APIOptions; diff --git a/src/com/sun/jna/platform/win32/MEMORY_BASIC_INFORMATION.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/MEMORY_BASIC_INFORMATION.java similarity index 91% rename from src/com/sun/jna/platform/win32/MEMORY_BASIC_INFORMATION.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/MEMORY_BASIC_INFORMATION.java index 9f88033c2..52d283a6a 100644 --- a/src/com/sun/jna/platform/win32/MEMORY_BASIC_INFORMATION.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/MEMORY_BASIC_INFORMATION.java @@ -14,12 +14,12 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; import com.sun.jna.Structure; -import com.sun.jna.platform.win32.BaseTSD.SIZE_T; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.BaseTSD.SIZE_T; import java.util.Arrays; import java.util.List; diff --git a/src/com/sun/jna/platform/win32/PROCESSENTRY32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/PROCESSENTRY32.java similarity index 98% rename from src/com/sun/jna/platform/win32/PROCESSENTRY32.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/PROCESSENTRY32.java index 014cf0b71..f02aed91a 100644 --- a/src/com/sun/jna/platform/win32/PROCESSENTRY32.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/PROCESSENTRY32.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Pointer; import com.sun.jna.Structure; diff --git a/src/com/sun/jna/platform/win32/Psapi.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Psapi.java similarity index 89% rename from src/com/sun/jna/platform/win32/Psapi.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Psapi.java index d96280226..18cdda0ed 100644 --- a/src/com/sun/jna/platform/win32/Psapi.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Psapi.java @@ -14,10 +14,10 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Native; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.win32.StdCallLibrary; /** diff --git a/src/com/sun/jna/platform/win32/SHELLEXECUTEINFO.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHELLEXECUTEINFO.java similarity index 82% rename from src/com/sun/jna/platform/win32/SHELLEXECUTEINFO.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHELLEXECUTEINFO.java index 762df83e9..0a78192a5 100644 --- a/src/com/sun/jna/platform/win32/SHELLEXECUTEINFO.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHELLEXECUTEINFO.java @@ -14,15 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.WString; -import com.sun.jna.platform.win32.WinDef.HINSTANCE; -import com.sun.jna.platform.win32.WinDef.HWND; -import com.sun.jna.platform.win32.WinNT.HANDLE; -import com.sun.jna.platform.win32.WinReg.HKEY; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HINSTANCE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HWND; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinReg.HKEY; import java.util.Arrays; import java.util.List; diff --git a/src/com/sun/jna/platform/win32/SHFILEINFO.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHFILEINFO.java similarity index 90% rename from src/com/sun/jna/platform/win32/SHFILEINFO.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHFILEINFO.java index 50fe5669d..f6d0286ac 100644 --- a/src/com/sun/jna/platform/win32/SHFILEINFO.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/SHFILEINFO.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Structure; import com.sun.jna.platform.win32.WinDef.DWORD; -import com.sun.jna.platform.win32.WinDef.HICON; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.HICON; import java.util.Arrays; import java.util.List; diff --git a/src/com/sun/jna/platform/win32/Shell32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Shell32.java similarity index 88% rename from src/com/sun/jna/platform/win32/Shell32.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Shell32.java index 7d13cf242..03491f798 100644 --- a/src/com/sun/jna/platform/win32/Shell32.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Shell32.java @@ -14,11 +14,11 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Native; -import com.sun.jna.platform.win32.BaseTSD.DWORD_PTR; -import com.sun.jna.platform.win32.WinDef.UINT; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.BaseTSD.DWORD_PTR; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.UINT; import com.sun.jna.ptr.PointerByReference; import com.sun.jna.win32.StdCallLibrary; import com.sun.jna.win32.W32APIOptions; diff --git a/src/com/sun/jna/platform/win32/User32.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/User32.java similarity index 99% rename from src/com/sun/jna/platform/win32/User32.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/User32.java index 88c9c63b7..06fdf6add 100644 --- a/src/com/sun/jna/platform/win32/User32.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/User32.java @@ -14,14 +14,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Native; import com.sun.jna.Pointer; import com.sun.jna.Structure; import com.sun.jna.WString; -import com.sun.jna.platform.win32.BaseTSD.LONG_PTR; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.BaseTSD.LONG_PTR; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.ByteByReference; import com.sun.jna.ptr.IntByReference; import com.sun.jna.win32.StdCallLibrary; diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/W32Errors.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/W32Errors.java new file mode 100644 index 000000000..799579bdb --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/W32Errors.java @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; + +import com.sun.jna.platform.win32.WinError; +import com.sun.jna.platform.win32.WinNT.HRESULT; + +// TODO: Auto-generated Javadoc +/** + * 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). + * + * @param hr the hr + * @return true, if successful + */ + public static final boolean SUCCEEDED(int hr) { + return hr >= 0; + } + + /** + * and the inverse. + * + * @param hr the hr + * @return true, if successful + */ + public static final boolean FAILED(int hr) { + return hr < 0; + } + + /** + * Succeeded. + * + * @param hr the hr + * @return true, if successful + */ + public static final boolean SUCCEEDED(HRESULT hr) { + if (hr != null) { + return SUCCEEDED(hr.intValue()); + } else { + return false; + } + } + + /** + * Failed. + * + * @param hr the hr + * @return true, if successful + */ + public static final boolean FAILED(HRESULT hr) { + if (hr != null) { + return FAILED(hr.intValue()); + } else { + return false; + } + } + + /** + * Extract error code from HRESULT. + * + * @param hr the hr + * @return the int + */ + public static final int HRESULT_CODE(int hr) { + return hr & 0xFFFF; + } + + /** + * Extract error code from SCODE. + * + * @param sc the sc + * @return the int + */ + public static final int SCODE_CODE(int sc) { + return sc & 0xFFFF; + } + + /** + * Return the facility. + * + * @param hr the hr + * @return the int + */ + public static final int HRESULT_FACILITY(int hr) { + return (hr >>= 16) & 0x1fff; + } + + /** + * Scode facility. + * + * @param sc the sc + * @return the int + */ + public static final int SCODE_FACILITY(short sc) { + return (sc >>= 16) & 0x1fff; + } + + /** + * Return the severity. + * + * @param hr the hr + * @return the short + */ + public static short HRESULT_SEVERITY(int hr) { + return (short) ((hr >>= 31) & 0x1); + } + + /** + * Scode severity. + * + * @param sc the sc + * @return the short + */ + public static short SCODE_SEVERITY(short sc) { + return (short) ((sc >>= 31) & 0x1); + } + + /** + * Create an HRESULT value from component pieces. + * + * @param sev the sev + * @param fac the fac + * @param code the code + * @return the int + */ + public static int MAKE_HRESULT(short sev, short fac, short code) { + return ((sev << 31) | (fac << 16) | code); + } + + /** + * Make scode. + * + * @param sev the sev + * @param fac the fac + * @param code the code + * @return the int + */ + 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. + * + * @param x the x + * @return the int + */ + public static final int FILTER_HRESULT_FROM_FLT_NTSTATUS(int x) { + int f = FACILITY_USERMODE_FILTER_MANAGER; + return (((x) & 0x8000FFFF) | (f <<= 16)); + } +} diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Win32Exception.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Win32Exception.java new file mode 100644 index 000000000..ef621a3f3 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/Win32Exception.java @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; + +/** + * @author JPEXS + */ +/* 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. + */ +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)); + } +} diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinBase.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinBase.java similarity index 99% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinBase.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinBase.java index 025a6ed44..ddd3c2b8c 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinBase.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinBase.java @@ -14,14 +14,14 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Native; 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.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.ByteByReference; import com.sun.jna.win32.StdCallLibrary; import java.util.Arrays; diff --git a/src/com/sun/jna/platform/win32/WinDef.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinDef.java similarity index 99% rename from src/com/sun/jna/platform/win32/WinDef.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinDef.java index 46742c7f4..28e77ee3a 100644 --- a/src/com/sun/jna/platform/win32/WinDef.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinDef.java @@ -14,14 +14,14 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; 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.jpexs.decompiler.flash.gui.jna.platform.win32.BaseTSD.LONG_PTR; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.ByReference; import com.sun.jna.win32.StdCallLibrary; import java.awt.Rectangle; diff --git a/src/com/sun/jna/platform/win32/WinError.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinError.java similarity index 99% rename from src/com/sun/jna/platform/win32/WinError.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinError.java index 5bab301ea..c8cef5355 100644 --- a/src/com/sun/jna/platform/win32/WinError.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinError.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.platform.win32.WinNT.HRESULT; diff --git a/src/com/sun/jna/platform/win32/WinGDI.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinGDI.java similarity index 98% rename from src/com/sun/jna/platform/win32/WinGDI.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinGDI.java index 4b4ebbb8e..348f8e9aa 100644 --- a/src/com/sun/jna/platform/win32/WinGDI.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinGDI.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; /** * @author JPEXS diff --git a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinNT.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinNT.java similarity index 99% rename from libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinNT.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinNT.java index 24e054812..be4774d50 100644 --- a/libsrc/ffdec_lib/src/com/sun/jna/platform/win32/WinNT.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinNT.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU Lesser General Public * License along with this library. */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.FromNativeContext; import com.sun.jna.Memory; diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinReg.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinReg.java new file mode 100644 index 000000000..743c8cf83 --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinReg.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2010-2024 JPEXS, 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 3.0 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. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; + +import com.sun.jna.Native; +import com.sun.jna.Pointer; +import com.jpexs.decompiler.flash.gui.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 final class HKEYByReference extends ByReference { + + public HKEYByReference() { + this(null); + } + + public HKEYByReference(HKEY h) { + super(Native.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); +} diff --git a/src/com/sun/jna/platform/win32/WinUser.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinUser.java similarity index 99% rename from src/com/sun/jna/platform/win32/WinUser.java rename to src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinUser.java index df3e77d5f..0f0135cf3 100644 --- a/src/com/sun/jna/platform/win32/WinUser.java +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/WinUser.java @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.sun.jna.platform.win32; +package com.jpexs.decompiler.flash.gui.jna.platform.win32; import com.sun.jna.Callback; import com.sun.jna.Pointer; diff --git a/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/package-info.java b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/package-info.java new file mode 100644 index 000000000..221668c6e --- /dev/null +++ b/src/com/jpexs/decompiler/flash/gui/jna/platform/win32/package-info.java @@ -0,0 +1,4 @@ +/** + * Windows API functions and structures accessible via JNA. + */ +package com.jpexs.decompiler.flash.gui.jna.platform.win32; diff --git a/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java b/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java index b3ffad6a3..aa32a4321 100644 --- a/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java +++ b/src/com/jpexs/decompiler/flash/gui/pipes/FirstInstance.java @@ -19,10 +19,10 @@ package com.jpexs.decompiler.flash.gui.pipes; import com.jpexs.decompiler.flash.ApplicationInfo; import com.jpexs.decompiler.flash.gui.Main; import com.jpexs.decompiler.flash.gui.View; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Kernel32; import com.sun.jna.platform.win32.WinError; -import com.sun.jna.platform.win32.WinNT; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT; import java.awt.Window; import java.io.IOException; import java.io.ObjectInputStream; diff --git a/src/com/jpexs/decompiler/flash/gui/pipes/PipeInputStream.java b/src/com/jpexs/decompiler/flash/gui/pipes/PipeInputStream.java index 87e271487..3e0b39116 100644 --- a/src/com/jpexs/decompiler/flash/gui/pipes/PipeInputStream.java +++ b/src/com/jpexs/decompiler/flash/gui/pipes/PipeInputStream.java @@ -16,9 +16,9 @@ */ package com.jpexs.decompiler.flash.gui.pipes; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.IntByReference; import java.io.IOException; import java.io.InputStream; diff --git a/src/com/jpexs/decompiler/flash/gui/pipes/PipeOutputStream.java b/src/com/jpexs/decompiler/flash/gui/pipes/PipeOutputStream.java index 5e50137ef..e89f58d70 100644 --- a/src/com/jpexs/decompiler/flash/gui/pipes/PipeOutputStream.java +++ b/src/com/jpexs/decompiler/flash/gui/pipes/PipeOutputStream.java @@ -16,9 +16,9 @@ */ package com.jpexs.decompiler.flash.gui.pipes; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; import com.sun.jna.Platform; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.IntByReference; import java.io.IOException; import java.io.OutputStream; diff --git a/src/com/jpexs/process/win32/Win32Process.java b/src/com/jpexs/process/win32/Win32Process.java index e222985e5..b4b89ec00 100644 --- a/src/com/jpexs/process/win32/Win32Process.java +++ b/src/com/jpexs/process/win32/Win32Process.java @@ -18,7 +18,7 @@ package com.jpexs.process.win32; import com.jpexs.helpers.ProgressListener; import com.jpexs.process.Process; -import com.sun.jna.platform.win32.WinDef.DWORD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef.DWORD; import java.awt.image.BufferedImage; import java.io.File; import java.io.InputStream; diff --git a/src/com/jpexs/process/win32/Win32ProcessTools.java b/src/com/jpexs/process/win32/Win32ProcessTools.java index d6123080b..d785ad30b 100644 --- a/src/com/jpexs/process/win32/Win32ProcessTools.java +++ b/src/com/jpexs/process/win32/Win32ProcessTools.java @@ -21,22 +21,22 @@ import com.jpexs.process.ProcessTools; import com.sun.jna.Memory; import com.sun.jna.NativeLong; import com.sun.jna.Pointer; -import com.sun.jna.platform.win32.Advapi32; -import com.sun.jna.platform.win32.BITMAP; -import com.sun.jna.platform.win32.BaseTSD; -import com.sun.jna.platform.win32.Gdi32; -import com.sun.jna.platform.win32.ICONINFO; -import com.sun.jna.platform.win32.Kernel32; -import com.sun.jna.platform.win32.MEMORY_BASIC_INFORMATION; -import com.sun.jna.platform.win32.PROCESSENTRY32; -import com.sun.jna.platform.win32.Psapi; -import com.sun.jna.platform.win32.SHFILEINFO; -import com.sun.jna.platform.win32.Shell32; -import com.sun.jna.platform.win32.User32; -import com.sun.jna.platform.win32.WinBase; -import com.sun.jna.platform.win32.WinDef; -import com.sun.jna.platform.win32.WinNT; -import com.sun.jna.platform.win32.WinNT.HANDLE; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Advapi32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.BITMAP; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.BaseTSD; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Gdi32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.ICONINFO; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Kernel32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.MEMORY_BASIC_INFORMATION; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.PROCESSENTRY32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Psapi; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.SHFILEINFO; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.Shell32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.User32; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinBase; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinDef; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT; +import com.jpexs.decompiler.flash.gui.jna.platform.win32.WinNT.HANDLE; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.NativeLongByReference; import com.sun.jna.ptr.PointerByReference;