📄 registry.java
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************
package com.develop.jawin.win32;
import com.develop.jawin.*;
import com.develop.jawin.marshal.*;
import com.develop.io.*;
import com.develop.util.*;
import java.io.*;
public class Registry implements MarshalConstants
{
static private final FuncPtr fpOK;
static private final FuncPtr fpQV;
static private final FuncPtr fpCK;
static private final FuncPtr fpCrK;
static private final FuncPtr fpDK;
static private final FuncPtr fpEnum;
static
{
try {
fpOK = new FuncPtr("ADVAPI32.DLL", "RegOpenKeyW");
fpQV = new FuncPtr("ADVAPI32.DLL", "RegQueryValueExW");
fpCK = new FuncPtr("ADVAPI32.DLL", "RegCloseKey");
fpCrK = new FuncPtr("ADVAPI32.DLL", "RegCreateKeyW");
fpDK = new FuncPtr("ADVAPI32.DLL", "RegDeleteKeyW");
fpEnum = new FuncPtr("ADVAPI32.DLL", "RegEnumKeyW");
} catch (COMException ce) {
throw new COMError("Unable to load registry entry points");
}
}
public static int OpenKey(int key, String subkey)
throws IOException, COMException
{
return SharedStubs.invokeIGO(key, subkey, fpOK.getPeer(), CHECK_W32);
}
public static int CreateKey(int key, String subkey)
throws IOException, COMException
{
return SharedStubs.invokeIGO(key, subkey, fpCrK.getPeer(), CHECK_W32);
}
public static void DeleteKey(int key, String subkey)
throws IOException, COMException
{
SharedStubs.invokeIG_I(key, subkey, fpDK.getPeer(), CHECK_W32);
}
public static String QueryStringValue(int key, String subkey)
throws IOException, COMException
{
byte[] raw = RawQueryValue(key, subkey);
LittleEndianInputStream leis = new LittleEndianInputStream
(new ByteArrayInputStream(raw));
return leis.readUnicodeSz(raw.length/2);
}
public static byte[] RawQueryValue(int key, String subkey)
throws IOException, COMException
{
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
//top level args
leos.writeInt(key);
leos.writeStringUnicode(subkey);
leos.writeInt(0); //reserved
leos.writeInt(0); //type (ignore)
byte[] sizeRes = GenericStub.win32Invoke(fpQV.getPeer(),
"IGIIkA:T7:L20n4",
24, leos.size(),
nbs.getInternalBuffer(),
null);
int size = StructConverter.bytesIntoInt(sizeRes, 0);
leos.writeInt(size);
byte[] res = GenericStub.win32Invoke(fpQV.getPeer(),
"IGIIM" + size +"P4:T7:L16n" + size,
24, leos.size(),
nbs.getInternalBuffer(),
null);
return res;
}
public static void CloseKey(int key)
throws IOException, COMException
{
SharedStubs.invokeI_I(key, fpCK.getPeer(), CHECK_W32);
}
public static String RegEnumKey(int key, int index)
throws Exception
{
NakedByteStream nbs = new NakedByteStream();
LittleEndianOutputStream leos = new LittleEndianOutputStream(nbs);
int size = 520;
// top level args
leos.writeInt(key);
leos.writeInt(index);
leos.writeInt(size);
byte[] result;
try
{
result = GenericStub.win32Invoke(fpEnum.getPeer(),
"IIM" + size + "I:T7:L8n" + size,
16, 16,
nbs.getInternalBuffer(),
null);
}
catch (COMException e)
{
if (e.hresult == 0x80070103)
{
return null;
}
throw e;
}
LittleEndianInputStream leis = new LittleEndianInputStream
(new ByteArrayInputStream(result));
return leis.readUnicodeSz(result.length / 2);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -