author | herrick |
Wed, 28 Aug 2019 11:30:40 -0400 | |
branch | JDK-8200758-branch |
changeset 57909 | c7de06ed4b54 |
parent 57391 | 970f28090a06 |
permissions | -rw-r--r-- |
57038 | 1 |
/* |
57106
ea870b9ce89a
8216492: Update copyright of all new jpackage fils to 2019
kcr
parents:
57067
diff
changeset
|
2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
57038 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
57039 | 26 |
package jdk.jpackage.internal; |
57038 | 27 |
|
28 |
import java.io.BufferedReader; |
|
29 |
import java.io.ByteArrayInputStream; |
|
30 |
import java.io.ByteArrayOutputStream; |
|
31 |
import java.io.IOException; |
|
32 |
import java.io.InputStreamReader; |
|
33 |
import java.io.PrintStream; |
|
34 |
import java.util.ArrayList; |
|
35 |
import java.util.List; |
|
36 |
||
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57039
diff
changeset
|
37 |
final class WindowsRegistry { |
57038 | 38 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
39 |
// Currently we only support HKEY_LOCAL_MACHINE. Native implementation will |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
40 |
// require support for additinal HKEY if needed. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
41 |
private static final int HKEY_LOCAL_MACHINE = 1; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
42 |
|
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
43 |
static { |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
44 |
System.loadLibrary("jpackage"); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
45 |
} |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
46 |
|
57038 | 47 |
private WindowsRegistry() {} |
48 |
||
49 |
/** |
|
50 |
* Reads the registry value for DisableRealtimeMonitoring. |
|
51 |
* @return true if DisableRealtimeMonitoring is set to 0x1, |
|
52 |
* false otherwise. |
|
53 |
*/ |
|
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57039
diff
changeset
|
54 |
static final boolean readDisableRealtimeMonitoring() { |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
55 |
final String subKey = "Software\\Microsoft\\" |
57038 | 56 |
+ "Windows Defender\\Real-Time Protection"; |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
57 |
final String value = "DisableRealtimeMonitoring"; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
58 |
int result = readDwordValue(HKEY_LOCAL_MACHINE, subKey, value, 0); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
59 |
return (result == 1); |
57038 | 60 |
} |
61 |
||
57067
9c17d779808e
8213425: Analyze output from Source code scanner and fix where needed.
herrick
parents:
57039
diff
changeset
|
62 |
static final List<String> readExclusionsPaths() { |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
63 |
List<String> result = new ArrayList<>(); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
64 |
final String subKey = "Software\\Microsoft\\" |
57038 | 65 |
+ "Windows Defender\\Exclusions\\Paths"; |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
66 |
long lKey = openRegistryKey(HKEY_LOCAL_MACHINE, subKey); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
67 |
if (lKey == 0) { |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
68 |
return result; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
69 |
} |
57038 | 70 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
71 |
String valueName; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
72 |
int index = 0; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
73 |
do { |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
74 |
valueName = enumRegistryValue(lKey, index); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
75 |
if (valueName != null) { |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
76 |
result.add(valueName); |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
77 |
index++; |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
78 |
} |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
79 |
} while (valueName != null); |
57038 | 80 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
81 |
closeRegistryKey(lKey); |
57038 | 82 |
|
83 |
return result; |
|
84 |
} |
|
85 |
||
86 |
/** |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
87 |
* Reads DWORD registry value. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
88 |
* |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
89 |
* @param key one of HKEY predefine value |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
90 |
* @param subKey registry sub key |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
91 |
* @param value value to read |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
92 |
* @param defaultValue default value in case if subKey or value not found |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
93 |
* or any other errors occurred |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
94 |
* @return value's data only if it was read successfully, otherwise |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
95 |
* defaultValue |
57038 | 96 |
*/ |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
97 |
private static native int readDwordValue(int key, String subKey, |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
98 |
String value, int defaultValue); |
57038 | 99 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
100 |
/** |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
101 |
* Open registry key. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
102 |
* |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
103 |
* @param key one of HKEY predefine value |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
104 |
* @param subKey registry sub key |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
105 |
* @return native handle to open key |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
106 |
*/ |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
107 |
private static native long openRegistryKey(int key, String subKey); |
57038 | 108 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
109 |
/** |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
110 |
* Enumerates the values for registry key. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
111 |
* |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
112 |
* @param lKey native handle to open key returned by openRegistryKey |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
113 |
* @param index index of value starting from 0. Increment until this |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
114 |
* function returns NULL which means no more values. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
115 |
* @return returns value or NULL if error or no more data |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
116 |
*/ |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
117 |
private static native String enumRegistryValue(long lKey, int index); |
57038 | 118 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
119 |
/** |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
120 |
* Close registry key. |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
121 |
* |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
122 |
* @param lKey native handle to open key returned by openRegistryKey |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
123 |
*/ |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
124 |
private static native void closeRegistryKey(long lKey); |
57038 | 125 |
|
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
126 |
/** |
57909
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57391
diff
changeset
|
127 |
* Compares two Windows paths regardless case and if paths |
c7de06ed4b54
8229979: jpackage cleanup src files, help text, and javadoc
herrick
parents:
57391
diff
changeset
|
128 |
* are short or long. |
57151
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
129 |
* |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
130 |
* @param path1 path to compare |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
131 |
* @param path2 path to compare |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
132 |
* @return true if paths point to same location |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
133 |
*/ |
38d0b67617e3
8217317: Create jpackage native library for windows
herrick
parents:
57106
diff
changeset
|
134 |
public static native boolean comparePaths(String path1, String path2); |
57038 | 135 |
} |