当前位置: 首页>>代码示例>>Java>>正文


Java Memory.write方法代码示例

本文整理汇总了Java中com.sun.jna.Memory.write方法的典型用法代码示例。如果您正苦于以下问题:Java Memory.write方法的具体用法?Java Memory.write怎么用?Java Memory.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.sun.jna.Memory的用法示例。


在下文中一共展示了Memory.write方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: protect

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Protect the specified byte range
 *
 * @param data the data to protect
 * @return the the protected form the data
 */
public static byte[] protect(byte[] data) throws MasterPasswordUnavailableException {
  if(data.length == 0) {
    return data;
  }
  Memory input = new Memory(data.length);
  input.write(0, data, 0, data.length);
  Crypt32.DATA_BLOB in = new Crypt32.DATA_BLOB();
  in.cbData = new W32API.DWORD(data.length);
  in.pbData = input;
  Crypt32.DATA_BLOB out = new Crypt32.DATA_BLOB();
  out.pbData = Pointer.NULL;
  Crypt32 crypt = Crypt32.INSTANCE;
  Kernel32 kernel = Kernel32.INSTANCE;
  boolean rc = crypt.CryptProtectData(in, "Master Key", Pointer.NULL, Pointer.NULL, Pointer.NULL, new W32API.DWORD(0), out);
  return getBytes(out, kernel, rc);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:WindowsCryptUtils.java

示例2: unprotect

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Unprotect the specified byte range
 *
 * @param data the data to protect
 * @return the the protected form the data
 */
public static byte[] unprotect(byte[] data) throws MasterPasswordUnavailableException {
  if(data.length == 0) {
    return data;
  }
  Memory input = new Memory(data.length);
  input.write(0, data, 0, data.length);
  Crypt32.DATA_BLOB in = new Crypt32.DATA_BLOB();
  in.cbData = new W32API.DWORD(data.length);
  in.pbData = input;
  Crypt32.DATA_BLOB out = new Crypt32.DATA_BLOB();
  out.pbData = Pointer.NULL;
  Crypt32 crypt = Crypt32.INSTANCE;
  Kernel32 kernel = Kernel32.INSTANCE;
  boolean rc = crypt.CryptUnprotectData(in, Pointer.NULL, Pointer.NULL, Pointer.NULL, Pointer.NULL, new W32API.DWORD(0), out);
  return getBytes(out, kernel, rc);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:WindowsCryptUtils.java

示例3: get

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Converts an LMBCS string to a Java String. If already cached, no native call is made.
 * 
 * @param lmbcsString LMBCS string
 * @return converted string
 */
public static String get(LMBCSString lmbcsString) {
	LRULMBCCache cache = getCache();
	
	String stringFromCache = cache.get(lmbcsString);
	String convertedString;
	
	if (stringFromCache==null) {
		byte[] dataArr = lmbcsString.getData();
		
		boolean isPureAscii = true;
		for (int i=0; i < dataArr.length; i++) {
			byte b = dataArr[i];
			if (b <= 0x1f || b >= 0x80) {
				isPureAscii = false;
				break;
			}
		}
		
		if (isPureAscii) {
			String asciiStr = new String(dataArr, Charset.forName("ASCII"));
			cache.put(lmbcsString, asciiStr);
			return asciiStr;
		}
		
		Memory dataMem = new Memory(dataArr.length);
		dataMem.write(0, dataArr, 0, dataArr.length);
		
		boolean skipAsciiCheck = true;
		convertedString = NotesStringUtils.fromLMBCS(dataMem, dataArr.length, skipAsciiCheck);
		cache.put(lmbcsString, convertedString);
	}
	else {
		convertedString = stringFromCache;
	}
	return convertedString;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:43,代码来源:LMBCSStringConversionCache.java

示例4: recalculateChecksum

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Recalculates the checksum fields matching the given {@link Enums.CalcChecksumsOption options}.
 *
 * @param options Drive the recalculateChecksum function.
 * @throws WinDivertException Whenever the DLL call sets a LastError different by 0 (Success) or 997 (Overlapped I/O
 *                            is in progress).
 */
public void recalculateChecksum(Enums.CalcChecksumsOption... options) throws WinDivertException {
    int flags = 0;
    for (Enums.CalcChecksumsOption option : options) {
        flags |= option.getValue();
    }
    byte[] rawBytes = getRaw();
    Memory memory = new Memory(rawBytes.length);
    memory.write(0, rawBytes, 0, rawBytes.length);
    WinDivertDLL.INSTANCE.WinDivertHelperCalcChecksums(memory, rawBytes.length, flags);
    throwExceptionOnGetLastError();

    Util.setBytesAtOffset(raw, 0, rawBytes.length,
            memory.getByteArray(0, rawBytes.length));
}
 
开发者ID:ffalcinelli,项目名称:jdivert,代码行数:22,代码来源:Packet.java

示例5: store

import com.sun.jna.Memory; //导入方法依赖的package包/类
void store(byte[] data) {
    cbData = data.length;
    pbData = new Memory(data.length);
    pbData.write(0, data, 0, cbData);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:Win32Protect.java

示例6: _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;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:53,代码来源:IDUtils.java

示例7: 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;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:78,代码来源:IDUtils.java

示例8: 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;
}
 
开发者ID:klehmann,项目名称:domino-jna,代码行数:53,代码来源:NotesDatabase.java

示例9: send

import com.sun.jna.Memory; //导入方法依赖的package包/类
/**
 * Injects a packet into the headers stack.<br>
 * Recalculates the checksum before sending unless {@code recalculateChecksum=false} is passed:<ul>
 * <li>If {@code recalculateChecksum=true} then checksums are calculated using the given {@link Enums.CalcChecksumsOption options}.</li>
 * <li>If {@code recalculateChecksum=false} then {@link Enums.CalcChecksumsOption options} are ignored.</li>
 * </ul>
 * The return value is the number of bytes actually sent.
 * <p>
 * The injected packet may be one received from {@link com.github.ffalcinelli.jdivert.WinDivert#recv() recv}, or a modified version, or a completely new packet.
 * Injected packets can be captured and diverted again by other WinDivert handles with lower priorities.
 * </p><p>
 * The remapped function is {@code WinDivertSend}:
 * </p>
 * <pre>{@code
 * BOOL WinDivertSend(
 *      __in HANDLE handle,
 *      __in PVOID pPacket,
 *      __in UINT packetLen,
 *      __in PWINDIVERT_ADDRESS pAddr,
 *      __out_opt UINT *sendLen
 * );
 * }</pre>
 * <p>
 * For more info on the C call visit: <a href="http://reqrypt.org/windivert-doc.html#divert_send">http://reqrypt.org/windivert-doc.html#divert_send</a>
 *
 * @param packet              The {@link com.github.ffalcinelli.jdivert.Packet Packet} to send
 * @param recalculateChecksum Whether to recalculate the checksums or pass the {@link com.github.ffalcinelli.jdivert.Packet packet} as is.
 * @param options             A set of {@link Enums.CalcChecksumsOption options} to use when recalculating checksums.
 * @return The number of bytes actually sent
 * @throws WinDivertException Whenever the DLL call sets a LastError different by 0 (Success) or 997 (Overlapped I/O
 *                            is in progress)
 */
public int send(Packet packet, boolean recalculateChecksum, CalcChecksumsOption... options) throws WinDivertException {
    if (recalculateChecksum) {
        packet.recalculateChecksum(options);
    }
    IntByReference sendLen = new IntByReference();
    byte[] raw = packet.getRaw();
    Memory buffer = new Memory(raw.length);

    buffer.write(0, raw, 0, raw.length);
    dll.WinDivertSend(handle, buffer, raw.length, packet.getWinDivertAddress().getPointer(), sendLen);
    throwExceptionOnGetLastError();
    return sendLen.getValue();
}
 
开发者ID:ffalcinelli,项目名称:jdivert,代码行数:46,代码来源:WinDivert.java


注:本文中的com.sun.jna.Memory.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。