Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* */ package rg;
- /* */
- /* */ import java.lang.reflect.InvocationTargetException;
- /* */ import java.lang.reflect.Method;
- /* */ import java.util.ArrayList;
- /* */ import java.util.HashMap;
- /* */ import java.util.List;
- /* */ import java.util.Map;
- /* */ import java.util.prefs.Preferences;
- /* */
- /* */ public class WinRegistry
- /* */ {
- /* */ public static final int HKEY_CURRENT_USER = -2147483647;
- /* */ public static final int HKEY_LOCAL_MACHINE = -2147483646;
- /* */ public static final int REG_SUCCESS = 0;
- /* */ public static final int REG_NOTFOUND = 2;
- /* */ public static final int REG_ACCESSDENIED = 5;
- /* */ public static final int KEY_WOW64_32KEY = 512;
- /* */ public static final int KEY_WOW64_64KEY = 256;
- /* */ private static final int KEY_ALL_ACCESS = 983103;
- /* */ private static final int KEY_READ = 131097;
- /* 35 */ private static Preferences userRoot = Preferences.userRoot();
- /* 36 */ private static Preferences systemRoot = Preferences.systemRoot();
- /* 37 */ private static Class<? extends Preferences> userClass = userRoot.getClass();
- /* 38 */ private static Method regOpenKey = null;
- /* 39 */ private static Method regCloseKey = null;
- /* 40 */ private static Method regQueryValueEx = null;
- /* 41 */ private static Method regEnumValue = null;
- /* 42 */ private static Method regQueryInfoKey = null;
- /* 43 */ private static Method regEnumKeyEx = null;
- /* 44 */ private static Method regCreateKeyEx = null;
- /* 45 */ private static Method regSetValueEx = null;
- /* 46 */ private static Method regDeleteKey = null;
- /* 47 */ private static Method regDeleteValue = null;
- /* */
- /* */ public static String readString(int hkey, String key, String valueName, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 96 */ if (hkey == -2147483646) {
- /* 97 */ return readString(systemRoot, hkey, key, valueName, wow64);
- /* */ }
- /* 99 */ if (hkey == -2147483647) {
- /* 100 */ return readString(userRoot, hkey, key, valueName, wow64);
- /* */ }
- /* */
- /* 103 */ throw new IllegalArgumentException("hkey=" + hkey);
- /* */ }
- /* */
- /* */ public static Map<String, String> readStringValues(int hkey, String key, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 122 */ if (hkey == -2147483646) {
- /* 123 */ return readStringValues(systemRoot, hkey, key, wow64);
- /* */ }
- /* 125 */ if (hkey == -2147483647) {
- /* 126 */ return readStringValues(userRoot, hkey, key, wow64);
- /* */ }
- /* */
- /* 129 */ throw new IllegalArgumentException("hkey=" + hkey);
- /* */ }
- /* */
- /* */ public static List<String> readStringSubKeys(int hkey, String key, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 148 */ if (hkey == -2147483646) {
- /* 149 */ return readStringSubKeys(systemRoot, hkey, key, wow64);
- /* */ }
- /* 151 */ if (hkey == -2147483647) {
- /* 152 */ return readStringSubKeys(userRoot, hkey, key, wow64);
- /* */ }
- /* */
- /* 155 */ throw new IllegalArgumentException("hkey=" + hkey);
- /* */ }
- /* */
- /* */ public static void createKey(int hkey, String key)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 171 */ if (hkey == -2147483646) {
- /* 172 */ int[] ret = createKey(systemRoot, hkey, key);
- /* 173 */ regCloseKey.invoke(systemRoot, new Object[] { new Integer(ret[0]) });
- /* */ }
- /* 175 */ else if (hkey == -2147483647) {
- /* 176 */ int[] ret = createKey(userRoot, hkey, key);
- /* 177 */ regCloseKey.invoke(userRoot, new Object[] { new Integer(ret[0]) });
- /* */ }
- /* */ else {
- /* 180 */ throw new IllegalArgumentException("hkey=" + hkey);
- /* */ }
- /* */ int[] ret;
- /* 182 */ if (ret[1] != 0)
- /* 183 */ throw new IllegalArgumentException("rc=" + ret[1] + " key=" + key);
- /* */ }
- /* */
- /* */ public static void writeStringValue(int hkey, String key, String valueName, String value, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 204 */ if (hkey == -2147483646) {
- /* 205 */ writeStringValue(systemRoot, hkey, key, valueName, value, wow64);
- /* */ }
- /* 207 */ else if (hkey == -2147483647) {
- /* 208 */ writeStringValue(userRoot, hkey, key, valueName, value, wow64);
- /* */ }
- /* */ else
- /* 211 */ throw new IllegalArgumentException("hkey=" + hkey);
- /* */ }
- /* */
- /* */ public static void deleteKey(int hkey, String key)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 226 */ int rc = -1;
- /* 227 */ if (hkey == -2147483646) {
- /* 228 */ rc = deleteKey(systemRoot, hkey, key);
- /* */ }
- /* 230 */ else if (hkey == -2147483647) {
- /* 231 */ rc = deleteKey(userRoot, hkey, key);
- /* */ }
- /* 233 */ if (rc != 0)
- /* 234 */ throw new IllegalArgumentException("rc=" + rc + " key=" + key);
- /* */ }
- /* */
- /* */ public static void deleteValue(int hkey, String key, String value, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 253 */ int rc = -1;
- /* 254 */ if (hkey == -2147483646) {
- /* 255 */ rc = deleteValue(systemRoot, hkey, key, value, wow64);
- /* */ }
- /* 257 */ else if (hkey == -2147483647) {
- /* 258 */ rc = deleteValue(userRoot, hkey, key, value, wow64);
- /* */ }
- /* 260 */ if (rc != 0)
- /* 261 */ throw new IllegalArgumentException("rc=" + rc + " key=" + key + " value=" + value);
- /* */ }
- /* */
- /* */ private static int deleteValue(Preferences root, int hkey, String key, String value, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 269 */ int[] handles = (int[])regOpenKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key), new Integer(0xF003F | wow64) });
- /* */
- /* 272 */ if (handles[1] != 0) {
- /* 273 */ return handles[1];
- /* */ }
- /* 275 */ int rc = ((Integer)regDeleteValue.invoke(root, new Object[] { new Integer(handles[0]), toCstr(value) })).intValue();
- /* */
- /* 278 */ regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* 279 */ return rc;
- /* */ }
- /* */
- /* */ private static int deleteKey(Preferences root, int hkey, String key)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 286 */ int rc = ((Integer)regDeleteKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key) })).intValue();
- /* */
- /* 289 */ return rc;
- /* */ }
- /* */
- /* */ private static String readString(Preferences root, int hkey, String key, String value, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 296 */ int[] handles = (int[])regOpenKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key), new Integer(0x20019 | wow64) });
- /* */
- /* 299 */ if (handles[1] != 0) {
- /* 300 */ return null;
- /* */ }
- /* 302 */ byte[] valb = (byte[])regQueryValueEx.invoke(root, new Object[] { new Integer(handles[0]), toCstr(value) });
- /* */
- /* 305 */ regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* 306 */ return valb != null ? new String(valb).trim() : null;
- /* */ }
- /* */
- /* */ private static Map<String, String> readStringValues(Preferences root, int hkey, String key, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 313 */ HashMap results = new HashMap();
- /* 314 */ int[] handles = (int[])regOpenKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key), new Integer(0x20019 | wow64) });
- /* */
- /* 317 */ if (handles[1] != 0) {
- /* 318 */ return null;
- /* */ }
- /* 320 */ int[] info = (int[])regQueryInfoKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* */
- /* 324 */ int count = info[2];
- /* 325 */ int maxlen = info[3];
- /* 326 */ for (int index = 0; index < count; index++) {
- /* 327 */ byte[] name = (byte[])regEnumValue.invoke(root, new Object[] { new Integer(handles[0]), new Integer(index), new Integer(maxlen + 1) });
- /* */
- /* 330 */ String value = readString(hkey, key, new String(name), wow64);
- /* 331 */ results.put(new String(name).trim(), value);
- /* */ }
- /* 333 */ regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* 334 */ return results;
- /* */ }
- /* */
- /* */ private static List<String> readStringSubKeys(Preferences root, int hkey, String key, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 341 */ List results = new ArrayList();
- /* 342 */ int[] handles = (int[])regOpenKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key), new Integer(0x20019 | wow64) });
- /* */
- /* 345 */ if (handles[1] != 0) {
- /* 346 */ return null;
- /* */ }
- /* 348 */ int[] info = (int[])regQueryInfoKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* */
- /* 352 */ int count = info[0];
- /* 353 */ int maxlen = info[3];
- /* 354 */ for (int index = 0; index < count; index++) {
- /* 355 */ byte[] name = (byte[])regEnumKeyEx.invoke(root, new Object[] { new Integer(handles[0]), new Integer(index), new Integer(maxlen + 1) });
- /* */
- /* 358 */ results.add(new String(name).trim());
- /* */ }
- /* 360 */ regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* 361 */ return results;
- /* */ }
- /* */
- /* */ private static int[] createKey(Preferences root, int hkey, String key)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 368 */ return (int[])regCreateKeyEx.invoke(root, new Object[] { new Integer(hkey), toCstr(key) });
- /* */ }
- /* */
- /* */ private static void writeStringValue(Preferences root, int hkey, String key, String valueName, String value, int wow64)
- /* */ throws IllegalArgumentException, IllegalAccessException, InvocationTargetException
- /* */ {
- /* 377 */ int[] handles = (int[])regOpenKey.invoke(root, new Object[] { new Integer(hkey), toCstr(key), new Integer(0xF003F | wow64) });
- /* */
- /* 380 */ regSetValueEx.invoke(root, new Object[] { new Integer(handles[0]), toCstr(valueName), toCstr(value) });
- /* */
- /* 383 */ regCloseKey.invoke(root, new Object[] { new Integer(handles[0]) });
- /* */ }
- /* */
- /* */ private static byte[] toCstr(String str)
- /* */ {
- /* 389 */ byte[] result = new byte[str.length() + 1];
- /* */
- /* 391 */ for (int i = 0; i < str.length(); i++) {
- /* 392 */ result[i] = ((byte)str.charAt(i));
- /* */ }
- /* 394 */ result[str.length()] = 0;
- /* 395 */ return result;
- /* */ }
- /* */
- /* */ static
- /* */ {
- /* */ try
- /* */ {
- /* 51 */ regOpenKey = userClass.getDeclaredMethod("WindowsRegOpenKey", new Class[] { Integer.TYPE, [B.class, Integer.TYPE });
- /* 52 */ regOpenKey.setAccessible(true);
- /* 53 */ regCloseKey = userClass.getDeclaredMethod("WindowsRegCloseKey", new Class[] { Integer.TYPE });
- /* 54 */ regCloseKey.setAccessible(true);
- /* 55 */ regQueryValueEx = userClass.getDeclaredMethod("WindowsRegQueryValueEx", new Class[] { Integer.TYPE, [B.class });
- /* 56 */ regQueryValueEx.setAccessible(true);
- /* 57 */ regEnumValue = userClass.getDeclaredMethod("WindowsRegEnumValue", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
- /* 58 */ regEnumValue.setAccessible(true);
- /* 59 */ regQueryInfoKey = userClass.getDeclaredMethod("WindowsRegQueryInfoKey1", new Class[] { Integer.TYPE });
- /* 60 */ regQueryInfoKey.setAccessible(true);
- /* 61 */ regEnumKeyEx = userClass.getDeclaredMethod("WindowsRegEnumKeyEx", new Class[] { Integer.TYPE, Integer.TYPE, Integer.TYPE });
- /* 62 */ regEnumKeyEx.setAccessible(true);
- /* 63 */ regCreateKeyEx = userClass.getDeclaredMethod("WindowsRegCreateKeyEx", new Class[] { Integer.TYPE, [B.class });
- /* 64 */ regCreateKeyEx.setAccessible(true);
- /* 65 */ regSetValueEx = userClass.getDeclaredMethod("WindowsRegSetValueEx", new Class[] { Integer.TYPE, [B.class, [B.class });
- /* 66 */ regSetValueEx.setAccessible(true);
- /* 67 */ regDeleteValue = userClass.getDeclaredMethod("WindowsRegDeleteValue", new Class[] { Integer.TYPE, [B.class });
- /* 68 */ regDeleteValue.setAccessible(true);
- /* 69 */ regDeleteKey = userClass.getDeclaredMethod("WindowsRegDeleteKey", new Class[] { Integer.TYPE, [B.class });
- /* 70 */ regDeleteKey.setAccessible(true);
- /* */ }
- /* */ catch (Exception e) {
- /* 73 */ e.printStackTrace();
- /* */ }
- /* */ }
- /* */ }
- /* Location: C:\Users\Alexamdre\AppData\Local\Temp\Install.jar
- * Qualified Name: rg.WinRegistry
- * JD-Core Version: 0.6.2
- */
Advertisement
Add Comment
Please, Sign In to add comment