本文整理汇总了Java中com.sun.jna.Memory.setByte方法的典型用法代码示例。如果您正苦于以下问题:Java Memory.setByte方法的具体用法?Java Memory.setByte怎么用?Java Memory.setByte使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sun.jna.Memory
的用法示例。
在下文中一共展示了Memory.setByte方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: errToString
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Converts a C API error code to an error message
*
* @param err error code
* @return error message
*/
public static String errToString(short err) {
if (err==0)
return "";
Memory retBuffer = new Memory(256);
short outStrLength = NotesNativeAPI.get().OSLoadString(0, err, retBuffer, (short) 255);
if (outStrLength==0) {
return "";
}
Memory newRetBuffer = new Memory(outStrLength);
for (int i=0; i<outStrLength; i++) {
newRetBuffer.setByte(i, retBuffer.getByte(i));
}
String message = NotesStringUtils.fromLMBCS(newRetBuffer, outStrLength);
return message;
}
示例2: _getUserIdFromVault
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Internal helper method to fetch the ID from the ID vault.
*
* @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
* @param password Password to id file being uploaded to the vault
* @param idPath if not null, path to where the download ID file should be created or overwritten
* @param rethKFC64 if not null, returns the hKFC handle to the in-memory id for 64 bit
* @param rethKFC32 if not null, returns the hKFC handle to the in-memory id for 32 bit
* @param serverName Name of server to contact
* @return the vault server name
* @throws NotesError in case of problems, e.g. ERR 22792 Wrong Password
*/
private static String _getUserIdFromVault(String userName, String password, String idPath, LongByReference rethKFC64, IntByReference rethKFC32, String serverName) {
String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
{
Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
}
if (serverNameParamMem!=null) {
byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
}
else {
serverNameMem.setByte(0, (byte) 0);
}
}
short result;
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC64, serverNameMem, 0, (short) 0, null);
}
else {
result = NotesNativeAPI32.get().SECidfGet(userNameCanonicalMem, passwordMem, idPathMem, rethKFC32, serverNameMem, 0, (short) 0, null);
}
NotesErrorUtils.checkResult(result);
int vaultServerNameLength = 0;
for (int i=0; i<serverNameMem.size(); i++) {
vaultServerNameLength = i;
if (serverNameMem.getByte(i) == 0) {
break;
}
}
String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
return vaultServerName;
}
示例3: syncUserIdWithVault
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Will open the ID file name provided, locate a vault server, synch the ID file contents to the vault,
* then return the synched content. If successful the vault server name is returned.
* @param userName Name of user whose ID is being put into vault - either abbreviated or canonical format
* @param password Password to id file being uploaded to the vault
* @param idPath Path to where the download ID file should be created or overwritten
* @param serverName Name of server to contact
* @return sync result
*/
public static SyncResult syncUserIdWithVault(String userName, String password, String idPath, String serverName) {
String userNameCanonical = NotesNamingUtils.toCanonicalName(userName);
Memory userNameCanonicalMem = NotesStringUtils.toLMBCS(userNameCanonical, true);
Memory passwordMem = NotesStringUtils.toLMBCS(password, true);
Memory idPathMem = NotesStringUtils.toLMBCS(idPath, true);
Memory serverNameMem = new Memory(NotesConstants.MAXPATH);
{
Memory serverNameParamMem = NotesStringUtils.toLMBCS(serverName, true);
if (serverNameParamMem!=null && (serverNameParamMem.size() > NotesConstants.MAXPATH)) {
throw new IllegalArgumentException("Servername length cannot exceed MAXPATH ("+NotesConstants.MAXPATH+" characters)");
}
if (serverNameParamMem!=null) {
byte[] serverNameParamArr = serverNameParamMem.getByteArray(0, (int) serverNameParamMem.size());
serverNameMem.write(0, serverNameParamArr, 0, serverNameParamArr.length);
}
else {
serverNameMem.setByte(0, (byte) 0);
}
}
LongByReference phKFC64 = new LongByReference();
IntByReference phKFC32 = new IntByReference();
IntByReference retdwFlags = new IntByReference();
short result;
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECKFMOpen (phKFC64, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
}
else {
result = NotesNativeAPI32.get().SECKFMOpen (phKFC32, idPathMem, passwordMem, NotesConstants.SECKFM_open_All, 0, null);
}
NotesErrorUtils.checkResult(result);
try {
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC64, serverNameMem, 0, (short) 0, null, retdwFlags);
}
else {
result = NotesNativeAPI32.get().SECidfSync(userNameCanonicalMem, passwordMem, idPathMem, phKFC32, serverNameMem, 0, (short) 0, null, retdwFlags);
}
NotesErrorUtils.checkResult(result);
}
finally {
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().SECKFMClose(phKFC64, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
}
else {
result = NotesNativeAPI32.get().SECKFMClose(phKFC32, NotesConstants.SECKFM_close_WriteIdFile, 0, null);
}
NotesErrorUtils.checkResult(result);
}
NotesErrorUtils.checkResult(result);
int vaultServerNameLength = 0;
for (int i=0; i<serverNameMem.size(); i++) {
vaultServerNameLength = i;
if (serverNameMem.getByte(i) == 0) {
break;
}
}
String vaultServerName = NotesStringUtils.fromLMBCS(serverNameMem, vaultServerNameLength);
SyncResult syncResult = new SyncResult(vaultServerName, retdwFlags.getValue());
return syncResult;
}
示例4: addText
import com.sun.jna.Memory; //导入方法依赖的package包/类
@Override
public void addText(String txt, TextStyle textStyle, FontStyle fontStyle, boolean createParagraphOnLinebreak) {
checkHandle();
if (isClosed())
throw new NotesError(0, "CompoundText already closed");
Memory txtMem = NotesStringUtils.toLMBCS(txt, false);
Memory lineDelimMem = new Memory(3);
lineDelimMem.setByte(0, (byte) '\r');
lineDelimMem.setByte(1, (byte) '\n');
lineDelimMem.setByte(2, (byte) 0);
int fontId;
if (fontStyle==null) {
fontId = getDefaultFontId();
}
else {
FontId fontIdObj = fontStyle.getAdapter(FontId.class);
if (fontIdObj==null)
throw new NotesError(0, "Unable to get FontId from FontStyle");
fontId = fontIdObj.getFontId();
}
int dwStyleID = textStyle==null ? NotesConstants.STYLE_ID_SAMEASPREV : getStyleId(textStyle);
Pointer nlsInfoPtr = NotesNativeAPI.get().OSGetLMBCSCLS();
short result;
int dwFlags = NotesConstants.COMP_PRESERVE_LINES | NotesConstants.COMP_PARA_BLANK_LINE;
if (createParagraphOnLinebreak) {
dwFlags = dwFlags | NotesConstants.COMP_PARA_LINE;
}
if (PlatformUtils.is64Bit()) {
result = NotesNativeAPI64.get().CompoundTextAddTextExt(m_handle64, dwStyleID, fontId, txtMem, (int) txtMem.size(),
lineDelimMem, dwFlags, nlsInfoPtr);
}
else {
result = NotesNativeAPI32.get().CompoundTextAddTextExt(m_handle32, dwStyleID, fontId, txtMem, (int) txtMem.size(),
lineDelimMem, dwFlags, nlsInfoPtr);
}
NotesErrorUtils.checkResult(result);
m_hasData=true;
}
示例5: constructNetPath
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Constructs a network path of a database (server!!path with proper encoding)
*
* @param server server or null
* @param filePath filepath
* @return LMBCS encoded path
*/
private static Memory constructNetPath(String server, String filePath) {
if (server==null)
server = "";
if (filePath==null)
throw new NullPointerException("filePath is null");
server = NotesNamingUtils.toCanonicalName(server);
String idUserName = IDUtils.getCurrentUsername();
boolean isOnServer = IDUtils.isOnServer();
if (!"".equals(server)) {
if (isOnServer) {
String serverCN = NotesNamingUtils.toCommonName(server);
String currServerCN = NotesNamingUtils.toCommonName(idUserName);
if (serverCN.equalsIgnoreCase(currServerCN)) {
//switch to "" as servername if server points to the server the API is running on
server = "";
}
}
}
Memory dbServerLMBCS = NotesStringUtils.toLMBCS(server, true);
Memory dbFilePathLMBCS = NotesStringUtils.toLMBCS(filePath, true);
Memory retFullNetPath = new Memory(NotesConstants.MAXPATH);
short result = NotesNativeAPI.get().OSPathNetConstruct(null, dbServerLMBCS, dbFilePathLMBCS, retFullNetPath);
NotesErrorUtils.checkResult(result);
//reduce length of retDbPathName
int newLength = 0;
for (int i=0; i<retFullNetPath.size(); i++) {
byte b = retFullNetPath.getByte(i);
if (b==0) {
newLength = i;
break;
}
}
byte[] retFullNetPathArr = retFullNetPath.getByteArray(0, newLength);
Memory reducedFullNetPathMem = new Memory(newLength+1);
reducedFullNetPathMem.write(0, retFullNetPathArr, 0, retFullNetPathArr.length);
reducedFullNetPathMem.setByte(newLength, (byte) 0);
return reducedFullNetPathMem;
}
示例6: stopWindowsProcessWMClosed
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Sends {@code WM_CLOSE} to the specified Windows {@link Process}.
*
* @param processInfo the {@link ProcessInfo} referencing the
* {@link Process} to send to.
* @return {@code true} if {@code WM_CLOSE} was sent, {@code false}
* otherwise.
*/
protected boolean stopWindowsProcessWMClosed(@Nonnull ProcessInfo processInfo) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(
"Attempting to stop timed out process \"{}\" ({}) with WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
HANDLE hProc = Kernel32.INSTANCE.OpenProcess(
Kernel32.SYNCHRONIZE | Kernel32.PROCESS_TERMINATE,
false,
processInfo.getPID()
);
if (hProc == null) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace(
"Failed to get Windows handle for process \"{}\" ({}) during WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
return false;
}
final Memory posted = new Memory(1);
posted.setByte(0, (byte) 0);
Memory dwPID = new Memory(4);
dwPID.setInt(0, processInfo.getPID());
User32.INSTANCE.EnumWindows(new WNDENUMPROC() {
@Override
public boolean callback(HWND hWnd, Pointer data) {
IntByReference dwID = new IntByReference();
User32.INSTANCE.GetWindowThreadProcessId(hWnd, dwID);
if (dwID.getValue() == data.getInt(0)) {
User32.INSTANCE.PostMessage(hWnd, User32.WM_CLOSE, new WPARAM(0), new LPARAM(0));
posted.setByte(0, (byte) 1);
}
return true;
}
}, dwPID);
Kernel32.INSTANCE.CloseHandle(hProc);
if (LOGGER.isTraceEnabled()) {
if (posted.getByte(0) > 0) {
LOGGER.trace(
"WM_CLOSE sent to process \"{}\" ({}) with PostMessage",
processInfo.getName(),
processInfo.getPID()
);
} else {
LOGGER.trace(
"Can't find any Windows belonging to process \"{}\" ({}), unable to send WM_CLOSE",
processInfo.getName(),
processInfo.getPID()
);
}
}
return posted.getByte(0) > 0;
}
示例7: writeMemory
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Writes data to an area of memory in a specified process. The entire area
* to be written to must be accessible or the operation fails.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/ms681674(v=vs.85).aspx">
* MSDN webpage#WriteProcessMemory function</a>
* @param process
* A handle to the process memory to be modified. The handle must
* have
* {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_WRITE
* PROCESS_VM_WRITE} and
* {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_OPERATION
* PROCESS_VM_OPERATION} access to the process.
* @param address
* A pointer to the base address in the specified process to
* which data is written. Before data transfer occurs, the system
* verifies that all data in the base address and memory of the
* specified size is accessible for write access, and if it is
* not accessible, the function fails.
* @param data
* A buffer that contains data to be written in the address space
* of the specified process. Read from left to right, i.e. from
* the lower to the higher indices.
* @throws Win32Exception
* If the operation was not successful
*/
public static void writeMemory(final HANDLE process, final long address, final byte[] data) throws Win32Exception {
final int size = data.length;
final Memory toWrite = new Memory(size);
for (int i = 0; i < size; i++) {
toWrite.setByte(i, data[i]);
}
Kernel32Util.writeProcessMemory(process, address, toWrite, size, null);
}
示例8: writeMemoryReversely
import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
* Writes data reversely to an area of memory in a specified process. The
* entire area to be written to must be accessible or the operation fails.
*
* @see <a href=
* "https://msdn.microsoft.com/en-us/library/ms681674(v=vs.85).aspx">
* MSDN webpage#WriteProcessMemory function</a>
* @param process
* A handle to the process memory to be modified. The handle must
* have
* {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_WRITE
* PROCESS_VM_WRITE} and
* {@link de.zabuza.memeaterbug.winapi.Process#PROCESS_VM_OPERATION
* PROCESS_VM_OPERATION} access to the process.
* @param address
* A pointer to the base address in the specified process to
* which data is written. Before data transfer occurs, the system
* verifies that all data in the base address and memory of the
* specified size is accessible for write access, and if it is
* not accessible, the function fails.
* @param data
* A buffer that contains data to be written reversely in the
* address space of the specified process. Read from right to
* left, i.e. from the higher to the lower indices.
* @throws Win32Exception
* If the operation was not successful
*/
public static void writeMemoryReversely(final HANDLE process, final long address, final byte[] data)
throws Win32Exception {
final int size = data.length;
final Memory toWrite = new Memory(size);
final int lastIndex = size - 1;
for (int i = 0; i < size; i++) {
toWrite.setByte(i, data[lastIndex - i]);
}
Kernel32Util.writeProcessMemory(process, address, toWrite, size, null);
}