本文整理汇总了Java中com.sun.jna.Memory.getString方法的典型用法代码示例。如果您正苦于以下问题:Java Memory.getString方法的具体用法?Java Memory.getString怎么用?Java Memory.getString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.Memory
的用法示例。
在下文中一共展示了Memory.getString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: translate
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Translate.
*
* @param name
* the name
*
* @return the string
*/
static String translate(String name)
{
readIndexMap();
Integer index = (Integer) _indexes.get(name);
if (index == null)
return name;
Memory buff = new Memory(256);
IntByReference buffSize = new IntByReference();
buffSize.setValue(256);
if (Pdhdll.INSTANCE.PdhLookupPerfNameByIndexA(null, index.intValue(),
buff, buffSize) == Pdhdll.ERROR_SUCCESS)
return buff.getString(0);
return name;
}
示例2: getActiveNode
import com.sun.jna.Memory; //导入方法依赖的package包/类
public String getActiveNode()
{
String activeNode = null;
try
{
Pointer cluster = Clusapi.INSTANCE.OpenCluster(null);
Pointer hEnum = Clusapi.INSTANCE.ClusterOpenEnum(cluster,
Clusapi.CLUSTER_ENUM_GROUP);
int dwIndex = 0;
IntByReference lpdwType = new IntByReference();
IntByReference lpcchName = new IntByReference();
Memory lpszName = new Memory(256);
lpszName.clear();
lpcchName.setValue(256);
int result = 0;
do
{
result = Clusapi.INSTANCE.ClusterEnum(hEnum, dwIndex, lpdwType,
lpszName, lpcchName);
if (result == Clusapi.ERROR_SUCCESS)
{
String group = lpszName.getString(0, true);
ClusterGroupInfo info = getGroupNodeInfo(cluster, group);
if (info != null)
activeNode = info.getLocation();
}
dwIndex++;
}
while (result == 0);
}
catch (Exception ex)
{
_log.log(Level.SEVERE, "Error getting cluster information", ex);
}
return activeNode;
}
示例3: getGroupNodeInfo
import com.sun.jna.Memory; //导入方法依赖的package包/类
private ClusterGroupInfo getGroupNodeInfo(Pointer cluster, String groupName)
{
ClusterGroupInfo result = null;
try
{
Pointer hGroup = Clusapi.INSTANCE.OpenClusterGroup(cluster,
new WString(groupName));
if (hGroup == null)
throw new RuntimeException(
"Clusapi call to OpenClusterGroup returned err code "
+ MyKernel32.INSTANCE.GetLastError());
IntByReference lpcchNodeName = new IntByReference();
Memory lpszNodeName = new Memory(256);
lpszNodeName.clear();
lpcchNodeName.setValue(256);
int state = Clusapi.INSTANCE.GetClusterGroupState(hGroup,
lpszNodeName, lpcchNodeName);
String location = lpszNodeName.getString(0, true);
if (state == Clusapi.CLUSTER_GROUP_STATE_UNKNOWN)
_log.severe("unknown group state for group " + groupName
+ " err code " + MyKernel32.INSTANCE.GetLastError());
result = new ClusterGroupInfo(groupName, state, location);
MyKernel32.INSTANCE.CloseHandle(hGroup);
}
catch (Exception e)
{
_log.log(Level.SEVERE, "Error while getting GroupActiveNode", e);
}
return result;
}
示例4: getWorkingDirInternal
import com.sun.jna.Memory; //导入方法依赖的package包/类
protected String getWorkingDirInternal()
{
String result = "";
String cwd;
boolean success = false;
String procCwd = "/proc/" + getPid() + "/cwd";
try
{
short BUFSIZE = 4096;
Memory dir = new Memory(BUFSIZE);
dir.clear();
if (CLibrary.INSTANCE.getcwd(dir, BUFSIZE) != null)
{
cwd = dir.getString(0);
dir.clear();
if (CLibrary.INSTANCE.chdir(procCwd) == 0)
{
if (CLibrary.INSTANCE.getcwd(dir, BUFSIZE) != null)
{
result = new File(dir.getString(0)).getCanonicalPath();
success = true;
}
// Restore starting directory ( if different )
CLibrary.INSTANCE.chdir(cwd);
}
}
if (!success)
System.out
.println("error reading process working dir -> please edit wrapper.working.dir in configuration file");
}
catch (IOException e)
{
}
return result;
// -KBG: short BUFSIZE = 512;
// -KBG: Memory result = new Memory(BUFSIZE);
// -KBG: result.clear();
// -KBG: short size = CLibrary.INSTANCE.readlink(f, result, (short)
// (BUFSIZE - 1));
// -KBG: if (size <= 0)
// -KBG: {
// -KBG:
// System.out.println("error reading process working dir -> please edit wrapper.working.dir in configuration file");
// -KBG: return f;
// -KBG: }
// -KBG: result.setByte((long) size, (byte) 0);
// -KBG: return result.getString(0);
/*
* String result = null; File f = new File("/proc/" + getPid() +
* "/cwd"); try { result = f.getCanonicalPath(); } catch (IOException e)
* { e.printStackTrace(); } return result;
*/
}
示例5: getProcess
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Gets the process.
*
* @param pid
* the pid
*
* @return the process
*/
public static Process getProcess(int pid)
{
WindowsXPProcess result = new WindowsXPProcess();
HANDLE hProcess = MyKernel32.INSTANCE.OpenProcess(
MyKernel32.PROCESS_ALL_ACCESS, false, pid);
if (hProcess == null)
hProcess = MyKernel32.INSTANCE.OpenProcess(
MyKernel32.PROCESS_QUERY_INFORMATION, false, pid);
if (hProcess == null)
return null;
result._pid = pid;
result._processInformation = new PROCESS_INFORMATION();
result._processInformation.dwProcessId = pid;
result._processInformation.hProcess = hProcess;
result._cmd = result.getCommandLineInternal();
// this does not always work (why ??), if so try again, then this
// normally does
// on win64 PEB of 64 bit cannot be accessed from wow -> use wmi
if (result._cmd.equals("?"))
result._cmd = result.getCommandLineInternalWMI();
if ("?".equals(result._cmd))
{
System.err.println("Could not get commandline");
}
// else
// System.out.println("Command line of " + pid + ": " + result._cmd);
PointerByReference hToken = new PointerByReference();
HANDLE hp = new HANDLE();
hp.setPointer(hProcess.getPointer());
if (MyAdvapi.INSTANCE.OpenProcessToken(hp, MyAdvapi.TOKEN_READ, hToken))
{
IntByReference dwSize = new IntByReference();
MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(),
MyAdvapi.TokenUser, null, 0, dwSize);
{
Memory pTokenUser = new Memory(dwSize.getValue());
if (MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(),
MyAdvapi.TokenUser, pTokenUser, dwSize.getValue(),
dwSize))
{
MyAdvapi.TOKEN_USER tokenUser = new MyAdvapi.TOKEN_USER(
pTokenUser);
Pointer lpSid = tokenUser.User.Sid;
Memory lpName = new Memory(256);
IntByReference cchName = new IntByReference();
cchName.setValue(256);
Memory lpReferencedDomainName = new Memory(256);
IntByReference cchReferencedDomainName = new IntByReference();
cchReferencedDomainName.setValue(256);
IntByReference peUse = new IntByReference();
if (MyAdvapi.INSTANCE.LookupAccountSidW(null, lpSid,
lpName, cchName, lpReferencedDomainName,
cchReferencedDomainName, peUse))
result._user = lpReferencedDomainName
.getString(0, true)
+ "\\"
+ lpName.getString(0, true);
;
// System.out.println(result._user);
}
}
if (result._user == null)
System.out.println("could not get user name OS error #"
+ MyKernel32.INSTANCE.GetLastError());
MyKernel32.INSTANCE.CloseHandle(hToken.getValue());
}
return result;
}
示例6: getCommandLineInternal64
import com.sun.jna.Memory; //导入方法依赖的package包/类
String getCommandLineInternal64()
{
log("get command internal 64 " + getPid());
String result = "?";
PROCESS_BASIC_INFORMATION pbi = null;
pbi = new PROCESS_BASIC_INFORMATION();
IntByReference returnLength = new IntByReference();
HANDLE hProcess = _processInformation.hProcess;
int size = pbi.size();
int ret = Ntdll.INSTANCE.ZwQueryInformationProcess(hProcess, (byte) 0,
pbi.getPointer(), size, returnLength);
if (ret == 0)
{
pbi.read();
if (pbi.PebBaseAddress != null)
{
PEB64 peb = new PEB64();
// System.out.println("64 " + 1);
if (readVirtualMemoryToStructure(pbi.PebBaseAddress, peb))
if (peb.ProcessParameters != null)
{
RTL_USER_PROCESS_PARAMETERS userParams = new RTL_USER_PROCESS_PARAMETERS();
// System.out.println("64 " + 2);
if (readVirtualMemoryToStructure(peb.ProcessParameters,
userParams))
{
// System.out.println("MaximumLength " +
// userParams.CommandLine.MaximumLength);
// System.out.println("Length " +
// userParams.CommandLine.Length);
Memory stringBuffer = new Memory(
userParams.CommandLine.Length);
// System.out.println("64 " + 3);
if (readVirtualMemoryToMemory(
userParams.CommandLine.Buffer, stringBuffer))
result = stringBuffer.getString(0, true);
}
}
}
}
else
log("pid " + _pid + " ZwQueryInformationProcess returns "
+ Integer.toHexString(ret));
return result;
}
示例7: getGroupInfo
import com.sun.jna.Memory; //导入方法依赖的package包/类
public Set<ClusterGroupInfo> getGroupInfo()
{
Pointer hCluster = Clusapi.INSTANCE.OpenCluster(null);
if (hCluster == null)
throw new RuntimeException(
"Clusapi call to OpenClusterGroup returned err code "
+ MyKernel32.INSTANCE.GetLastError());
Pointer hEnum = Clusapi.INSTANCE.ClusterOpenEnum(hCluster,
Clusapi.CLUSTER_ENUM_GROUP);
if (hEnum == null)
throw new RuntimeException(
"Clusapi call to ClusterOpenEnum returned err code "
+ MyKernel32.INSTANCE.GetLastError());
Set<ClusterGroupInfo> result = new LinkedHashSet<ClusterGroupInfo>();
try
{
IntByReference lpdwType = new IntByReference();
IntByReference lpcchName = new IntByReference(0);
Memory lpszName = new Memory(256);
int dwIndex = 0;
int returnValue = 0;
do
{
lpdwType.setValue(0);
lpcchName.setValue(0);
lpszName.clear();
lpcchName.setValue(256);
returnValue = Clusapi.INSTANCE.ClusterEnum(hEnum, dwIndex,
lpdwType, lpszName, lpcchName);
if (returnValue == Clusapi.ERROR_SUCCESS)
{
String group = lpszName.getString(0, true);
ClusterGroupInfo info = getGroupNodeInfo(hCluster, group);
if (info != null)
result.add(info);
}
if ((returnValue != Clusapi.ERROR_NO_MORE_ITEMS)
&& (returnValue != Clusapi.ERROR_SUCCESS))
_log.log(Level.SEVERE, "strange returnValue from ClusApi"
+ returnValue);
dwIndex++;
}
while (returnValue == 0);
}
catch (Exception e)
{
_log.log(Level.SEVERE,
"Error while getting Cluster group information", e);
}
finally
{
MyKernel32.INSTANCE.CloseHandle(hEnum);
MyKernel32.INSTANCE.CloseHandle(hCluster);
}
return result;
}
示例8: readString
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Reads a string from the given address using the given encoding.
*
* @param address
* Address to start reading from
* @param encoding
* Encoding to use
* @param length
* Length of the string to read, as amount of characters
* @param sizeOfOneChar
* The size of one character in the given encoding, in bytes
* @return The string read from the given address
* @throws UnsupportedEncodingException
* If the given encoding is not supported
*/
public String readString(final long address, final String encoding, final int length, final int sizeOfOneChar)
throws UnsupportedEncodingException {
if (!Charset.availableCharsets().keySet().contains(encoding)) {
throw new UnsupportedEncodingException();
}
final Memory output = Kernel32Util.readMemory(this.mProcess.getHandle(), address, sizeOfOneChar * length);
return output.getString(0, encoding);
}