Java Code Examples for com.sun.jna.Native#WCHAR_SIZE
The following examples show how to use
com.sun.jna.Native#WCHAR_SIZE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Advapi32Util.java From jpexs-decompiler with GNU General Public License v3.0 | 6 votes |
public EventLogRecord(Pointer pevlr) { _record = new EVENTLOGRECORD(pevlr); _source = pevlr.getString(_record.size(), true); // data if (_record.DataLength.intValue() > 0) { _data = pevlr.getByteArray(_record.DataOffset.intValue(), _record.DataLength.intValue()); } // strings if (_record.NumStrings.intValue() > 0) { ArrayList<String> strings = new ArrayList<>(); int count = _record.NumStrings.intValue(); long offset = _record.StringOffset.intValue(); while (count > 0) { String s = pevlr.getString(offset, true); strings.add(s); offset += s.length() * Native.WCHAR_SIZE; offset += Native.WCHAR_SIZE; count--; } _strings = strings.toArray(new String[strings.size()]); } }
Example 2
Source File: Advapi32Util.java From jpexs-decompiler with GNU General Public License v3.0 | 5 votes |
/** * 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<String> result = new ArrayList<>(); int offset = 0; while (offset < data.size()) { String s = data.getString(offset, 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); } } }
Example 3
Source File: Advapi32Util.java From jpexs-decompiler with GNU General Public License v3.0 | 4 votes |
/** * Get a table of registry values. * * @param hKey Registry key. * @return Table of values. */ public static TreeMap<String, Object> 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<String, Object> 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, 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<String> result = new ArrayList<>(); int offset = 0; while (offset < stringData.size()) { String s = stringData.getString(offset, 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; }