Java Code Examples for com.sun.jna.Pointer

The following examples show how to use com.sun.jna.Pointer. These examples are extracted from open source projects. 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
/**
 * Finds all windows
 * @param onlyJapanese limit window search to ones containing Japanese text
 * @return a map of all titles and their window pointers.
 */
public static Map<String, Pointer> findAllWindows(boolean onlyJapanese)
{
    if(!isKernelAvailable())return null;

    HashMap<String, Pointer> windows = new HashMap<>();

    user32.EnumWindows((hWnd, data) ->
    {
        //hWnd is the window pointer, data is usually return data (unused)
        String text = getWindowName(hWnd);
        if(text != null && (!onlyJapanese || Japanese.isJapaneseWriting(text)))
        {
            windows.put(text, hWnd);
        }
        return true;
    }, null);
    return windows;
}
 
Example 2
Source Project: unidbg   Source File: ARM32SyscallHandler.java    License: Apache License 2.0 6 votes vote down vote up
private int write(Unicorn u, Emulator<?> emulator) {
    int fd = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R0)).intValue();
    Pointer buffer = UnicornPointer.register(emulator, ArmConst.UC_ARM_REG_R1);
    int count = ((Number) u.reg_read(ArmConst.UC_ARM_REG_R2)).intValue();
    byte[] data = buffer.getByteArray(0, count);
    if (log.isDebugEnabled()) {
        log.debug("write fd=" + fd + ", buffer=" + buffer + ", count=" + count);
    }

    FileIO file = fdMap.get(fd);
    if (file == null) {
        emulator.getMemory().setErrno(UnixEmulator.EBADF);
        return -1;
    }
    return file.write(data);
}
 
Example 3
public static BufferedImage extractExeIcon(String fullExeFile, int index, boolean large) {
    PointerByReference iconsLargeRef = new PointerByReference();
    PointerByReference iconsSmallRef = new PointerByReference();
    int cnt = Shell32.INSTANCE.ExtractIconEx(fullExeFile, index, iconsLargeRef, iconsSmallRef, new WinDef.UINT(1)).intValue();
    if (cnt == 0) {
        return null;
    }
    Pointer iconsLarge = iconsLargeRef.getPointer();
    Pointer iconsSmall = iconsSmallRef.getPointer();

    WinDef.HICON icon;
    if (large) {
        icon = new WinDef.HICON(iconsLarge.getPointer(0));
    } else {
        icon = new WinDef.HICON(iconsSmall.getPointer(0));
    }

    BufferedImage ic = iconToImage(icon);

    User32.INSTANCE.DestroyIcon(icon);
    return ic;
}
 
Example 4
Source Project: djl   Source File: MxNDManager.java    License: Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public MxSparseNDArray createCSR(Buffer data, long[] indptr, long[] indices, Shape shape) {
    SparseFormat fmt = SparseFormat.CSR;
    DataType dataType = DataType.fromBuffer(data);
    MxNDArray indptrNd = create(new Shape(indptr.length), DataType.INT64);
    indptrNd.set(indptr);
    MxNDArray indicesNd = create(new Shape(indices.length), DataType.INT64);
    indicesNd.set(indices);
    Pointer handle =
            JnaUtils.createSparseNdArray(
                    fmt,
                    device,
                    shape,
                    dataType,
                    new DataType[] {indptrNd.getDataType(), indicesNd.getDataType()},
                    new Shape[] {indptrNd.getShape(), indicesNd.getShape()},
                    false);
    MxSparseNDArray sparse = create(handle, fmt);
    MxNDArray dataNd = create(new Shape(data.remaining()), dataType);
    dataNd.set(data);
    JnaUtils.ndArraySyncCopyFromNdArray(sparse, dataNd, -1);
    JnaUtils.ndArraySyncCopyFromNdArray(sparse, indptrNd, 0);
    JnaUtils.ndArraySyncCopyFromNdArray(sparse, indicesNd, 1);
    return sparse;
}
 
Example 5
Source Project: unidbg   Source File: ARM32SyscallHandler.java    License: Apache License 2.0 5 votes vote down vote up
private int accept(Emulator<AndroidFileIO> emulator) {
    RegisterContext context = emulator.getContext();
    int sockfd = context.getIntArg(0);
    Pointer addr = context.getPointerArg(1);
    Pointer addrlen = context.getPointerArg(2);
    return accept(emulator, sockfd, addr, addrlen, 0);
}
 
Example 6
Source Project: domino-jna   Source File: INotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public short CalEntryAction(
int hDB,
Memory pszUID,
Memory pszRecurID,
int dwAction,
int dwRange,
Memory pszComments,
NotesCalendarActionDataStruct pExtActionInfo,
int dwFlags,
Pointer pCtx);
 
Example 7
Source Project: domino-jna   Source File: NotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public native short NSFProfileSetField(
long hDB,
Memory ProfileName,
short ProfileNameLength,
Memory UserName,
short UserNameLength,
Memory FieldName,
short FieldNameLength,
short Datatype,
Pointer Value,
int ValueLength);
 
Example 8
Source Project: djl   Source File: MockMxnetLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayDetach(Pointer handle, PointerByReference out) {
    if (functions.containsKey("MXNDArrayDetach")) {
        return functions.get("MXNDArrayDetach").apply(new Object[] {handle, out});
    }
    return 0;
}
 
Example 9
Source Project: djl   Source File: MockMxnetLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXCachedOpRegisterOpHook(
        Pointer handle, CachedOpMonitorCallback callback, byte monitor_all) {
    if (functions.containsKey("MXCachedOpRegisterOpHook")) {
        return functions
                .get("MXCachedOpRegisterOpHook")
                .apply(new Object[] {handle, callback, monitor_all});
    }
    return 0;
}
 
Example 10
public static WinNotesNamesListHeader32Struct newInstance(final Pointer p) {
	return AccessController.doPrivileged(new PrivilegedAction<WinNotesNamesListHeader32Struct>() {

		@Override
		public WinNotesNamesListHeader32Struct run() {
			return new WinNotesNamesListHeader32Struct(p);
		}});
}
 
Example 11
Source Project: DDMQ   Source File: TransientStorePool.java    License: Apache License 2.0 5 votes vote down vote up
public void destroy() {
    for (ByteBuffer byteBuffer : availableBuffers) {
        final long address = ((DirectBuffer) byteBuffer).address();
        Pointer pointer = new Pointer(address);
        LibC.INSTANCE.munlock(pointer, new NativeLong(fileSize));
    }
}
 
Example 12
Source Project: domino-jna   Source File: INotesNativeAPI64.java    License: Apache License 2.0 5 votes vote down vote up
public short CompoundTextAddParagraphExt(
long hCompound,
int dwStyleID,
int FontID,
Memory pchText,
int dwTextLen,
Pointer pInfo);
 
Example 13
@Test
void unregisterCameraStateEvent() {
    when(edsdkLibrary().EdsSetCameraStateEventHandler(eq(fakeCamera), any(), any(), (Pointer) isNull())).thenReturn(new NativeLong(0));

    spyCameraStateEventLogic.unregisterCameraStateEvent(fakeCamera);

    verify(edsdkLibrary(), times(1)).EdsSetCameraStateEventHandler(eq(fakeCamera), any(), any(), (Pointer) isNull());
}
 
Example 14
Source Project: netbeans   Source File: MacProvider.java    License: Apache License 2.0 5 votes vote down vote up
public void delete(String key) {
    try {
        byte[] serviceName = key.getBytes("UTF-8");
        byte[] accountName = "NetBeans".getBytes("UTF-8");
        Pointer[] itemRef = new Pointer[1];
        error("find (for delete)", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName,
                accountName.length, accountName, null, null, itemRef));
        if (itemRef[0] != null) {
            error("delete", SecurityLibrary.LIBRARY.SecKeychainItemDelete(itemRef[0]));
            SecurityLibrary.LIBRARY.CFRelease(itemRef[0]);
        }
    } catch (UnsupportedEncodingException x) {
        LOG.log(Level.WARNING, null, x);
    }
}
 
Example 15
Source Project: djl   Source File: MockMxnetLibrary.java    License: Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public int MXNDArrayToDLPack(Pointer handle, PointerByReference out_dlpack) {
    if (functions.containsKey("MXNDArrayToDLPack")) {
        return functions.get("MXNDArrayToDLPack").apply(new Object[] {handle, out_dlpack});
    }
    return 0;
}
 
Example 16
Source Project: domino-jna   Source File: NotesNativeAPI32.java    License: Apache License 2.0 5 votes vote down vote up
public native short MIMEGetEntityData(
int hNote,
Pointer pME,
short wDataType,
int dwOffset,
int dwRetBytes,
IntByReference phData,
IntByReference pdwDataLen);
 
Example 17
Source Project: domino-jna   Source File: HtmlApi_UrlComponentStruct.java    License: Apache License 2.0 5 votes vote down vote up
public static HtmlApi_UrlComponentStruct newInstance(final Pointer peer) {
	return AccessController.doPrivileged(new PrivilegedAction<HtmlApi_UrlComponentStruct>() {

		@Override
		public HtmlApi_UrlComponentStruct run() {
			return new HtmlApi_UrlComponentStruct(peer);
		}
	});
}
 
Example 18
Source Project: snowflake-jdbc   Source File: SecureStorageManagerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public int SecKeychainItemModifyContent(
    Pointer itemRef,
    Pointer attrList,
    int length,
    byte[] data)
{
  MockMacKeychainManager.replaceCredential(itemRef, length, data);
  return SecureStorageAppleManager.SecurityLib.ERR_SEC_SUCCESS;
}
 
Example 19
Source Project: unidbg   Source File: UnixSyscallHandler.java    License: Apache License 2.0 5 votes vote down vote up
protected final int sigprocmask(Emulator<?> emulator, int how, Pointer set, Pointer oldset) {
    if (log.isDebugEnabled()) {
        log.debug("sigprocmask how=" + how + ", set=" + set + ", oldset=" + oldset);
    }
    emulator.getMemory().setErrno(UnixEmulator.EINVAL);
    return -1;
}
 
Example 20
Source Project: domino-jna   Source File: NotesNativeAPI32.java    License: Apache License 2.0 4 votes vote down vote up
public native short SchSrvRetrieveExt(Pointer pClientNames, NotesUniversalNoteIdStruct pApptUnid,
NotesTimeDateStruct pApptOrigDate, int dwOptions, NotesTimeDatePairStruct pInterval, Pointer pNames,
Pointer pDetails, Pointer piCalList, Memory pszProxyUserName, Memory pszProxyPassword,
IntByReference rethCntnr);
 
Example 21
Source Project: netbeans   Source File: MacNetworkProxy.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public NetworkProxySettings getNetworkProxySettings() {
    boolean resolved = false;
    
    LOGGER.log(Level.FINE, "Mac system proxy resolver started."); //NOI18N
    Pointer settingsDictionary = cfNetworkLibrary.CFNetworkCopySystemProxySettings();

    Pointer autoDiscoveryEnable = cfLibrary.CFDictionaryGetValue(settingsDictionary, getKeyCFStringRef(KEY_AUTO_DISCOVERY_ENABLE));
    if (getIntFromCFNumberRef(autoDiscoveryEnable) != 0) {
        LOGGER.log(Level.INFO, "Mac system proxy resolver: auto detect"); //NOI18N                                    
        resolved = true;
    }
    
    Pointer pacEnable = cfLibrary.CFDictionaryGetValue(settingsDictionary, getKeyCFStringRef(KEY_PAC_ENABLE));
    if (getIntFromCFNumberRef(pacEnable) != 0) {
        Pointer[] pacUrlPointer = new Pointer[1];
        if (cfLibrary.CFDictionaryGetValueIfPresent(settingsDictionary, getKeyCFStringRef(KEY_PAC_URL), pacUrlPointer)) {
            String pacUrl = getStringFromCFStringRef(pacUrlPointer[0]);
            
            LOGGER.log(Level.INFO, "Mac system proxy resolver: auto - PAC ({0})", pacUrl); //NOI18N
            return new NetworkProxySettings(pacUrl);
        }
    }
    
    Pointer httpEnable = cfLibrary.CFDictionaryGetValue(settingsDictionary, getKeyCFStringRef(KEY_HTTP_ENABLE));
    Pointer httpsEnable = cfLibrary.CFDictionaryGetValue(settingsDictionary, getKeyCFStringRef(KEY_HTTPS_ENABLE));
    Pointer socksEnable = cfLibrary.CFDictionaryGetValue(settingsDictionary, getKeyCFStringRef(KEY_SOCKS_ENABLE));
    if (getIntFromCFNumberRef(httpEnable) != 0 || getIntFromCFNumberRef(httpsEnable) != 0 || getIntFromCFNumberRef(socksEnable) != 0) {
        String httpHost = getStringFromCFStringRef(getValueIfExists(settingsDictionary, KEY_HTTP_HOST));
        String httpPort = getStringFromCFNumberRef(getValueIfExists(settingsDictionary, KEY_HTTP_PORT));
        String httpsHost = getStringFromCFStringRef(getValueIfExists(settingsDictionary, KEY_HTTPS_HOST));
        String httpsPort = getStringFromCFNumberRef(getValueIfExists(settingsDictionary, KEY_HTTPS_PORT));
        String socksHost = getStringFromCFStringRef(getValueIfExists(settingsDictionary, KEY_SOCKS_HOST));
        String socksPort = getStringFromCFNumberRef(getValueIfExists(settingsDictionary, KEY_SOCKS_PORT));            
        String[] noProxyHosts = getNoProxyHosts(getValueIfExists(settingsDictionary, KEY_EXCEPTIONS_LIST));
        
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - http host ({0})", httpHost); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - http port ({0})", httpPort); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - https host ({0})", httpsHost); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - https port ({0})", httpsPort); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - socks host ({0})", socksHost); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - socks port ({0})", socksPort); //NOI18N
        LOGGER.log(Level.INFO, "Mac system proxy resolver: manual - no proxy hosts ({0})", getStringFromArray(noProxyHosts)); //NOI18N
        
        return new NetworkProxySettings(httpHost, httpPort, httpsHost, httpsPort, socksHost, socksPort, noProxyHosts);
    }
    
    return new NetworkProxySettings(resolved);
}
 
Example 22
Source Project: domino-jna   Source File: NotesNativeAPI32.java    License: Apache License 2.0 4 votes vote down vote up
public native short CalReadRange(int hDB, NotesTimeDateStruct.ByValue tdStart, NotesTimeDateStruct.ByValue tdEnd, int dwViewSkipCount,
int dwMaxReturnCount, int dwReturnMask, int dwReturnMaskExt, Pointer pFilterInfo,
IntByReference hRetCalData, ShortByReference retCalBufferLength, IntByReference hRetUIDData,
IntByReference retNumEntriesProcessed, ShortByReference retSignalFlags, int dwFlags, Pointer pCtx);
 
Example 23
Source Project: domino-jna   Source File: INotesNativeAPI.java    License: Apache License 2.0 4 votes vote down vote up
public short ListGetText (Pointer pList,
boolean fPrefixDataType,
short entryNumber,
Memory retTextPointer,
ShortByReference retTextLength);
 
Example 24
Source Project: djl   Source File: JnaUtils.java    License: Apache License 2.0 4 votes vote down vote up
public static void waitToWrite(Pointer ndArray) {
    checkNDArray(ndArray, "wait to write");
    checkCall(LIB.MXNDArrayWaitToWrite(ndArray));
}
 
Example 25
Source Project: lept4j   Source File: L_Heap.java    License: Apache License 2.0 4 votes vote down vote up
public L_Heap(Pointer peer) {
	super(peer);
	read();
}
 
Example 26
Source Project: netcdf-java   Source File: Nc4Iosp.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private Array decodeVlen(DataType dt, int pos, ByteBuffer bbuff) throws IOException {
  Array array;
  int n = (int) bbuff.getLong(pos); // Note that this does not increment the buffer position
  long addr = getNativeAddr(pos + com.sun.jna.Native.POINTER_SIZE, bbuff);
  Pointer p = new Pointer(addr);
  Object data;
  switch (dt) {
    case BOOLEAN: /* byte[] */
    case ENUM1:
    case BYTE:
      data = p.getByteArray(0, n);
      break;
    case ENUM2:
    case SHORT: /* short[] */
      data = p.getShortArray(0, n);
      break;
    case ENUM4:
    case INT: /* int[] */
      data = p.getIntArray(0, n);
      break;
    case LONG: /* long[] */
      data = p.getLongArray(0, n);
      break;
    case FLOAT: /* float[] */
      data = p.getFloatArray(0, n);
      break;
    case DOUBLE: /* double[] */
      data = p.getDoubleArray(0, n);
      break;
    case CHAR: /* char[] */
      data = p.getCharArray(0, n);
      break;
    case STRING: /* String[] */
      // For now we need to use p.getString()
      // because p.getStringArray(int,int) does not exist
      // in jna version 3.0.9, but does exist in
      // verssion 4.0 and possibly some intermediate versions
      String[] stringdata = new String[n];
      for (int i = 0; i < n; i++)
        stringdata[i] = p.getString(i * 8);
      data = stringdata;
      break;
    case OPAQUE:
    case STRUCTURE:
    default:
      throw new IllegalStateException();
  }
  array = Array.factory(dt, new int[] {n}, data);
  return array;
}
 
Example 27
Source Project: lept4j   Source File: L_ByteBuffer.java    License: Apache License 2.0 4 votes vote down vote up
public L_ByteBuffer(Pointer peer) {
	super(peer);
               read();
}
 
Example 28
Source Project: unidbg   Source File: MyARM64SyscallHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected long ptrace(Emulator<?> emulator) {
    RegisterContext context = emulator.getContext();
    int request = context.getIntArg(0);
    int pid = context.getIntArg(1);
    UnicornPointer addr = context.getPointerArg(2);
    Pointer data = context.getPointerArg(3);
    String msg = "ptrace request=0x" + Integer.toHexString(request) + ", pid=" + pid + ", addr=" + addr + ", data=" + data + ", LR=" + context.getLRPointer();
    switch (request) {
        case PTrace.PTRACE_ATTACH:
        case PTrace.PTRACE_CONT:
        case PTrace.PTRACE_DETACH:
        case PTrace.PTRACE_KILL:
        case PTrace.PTRACE_POKETEXT:
            break;
        case PTrace.PTRACE_POKEDATA: {
            addr.setPointer(0, data);
            break;
        }
        case PTrace.PTRACE_PEEKTEXT: {
            long val = addr.getLong(0);
            data.setLong(0, val);
            break;
        }
        case PTrace.PTRACE_GETREGSET: {
            if (addr.toUIntPeer() == PTrace.NT_PRSTATUS) {
                Arm64Register register = new Arm64Register(data);
                register.fill(emulator.getUnicorn());
                register.pack();
                System.out.println(register);
                break;
            } else {
                throw new UnsupportedOperationException();
            }
        }
        /*case PTrace.PTRACE_PEEKUSR: {
            int off = (int) addr.toUIntPeer() / 4;
            int reg = ArmConst.UC_ARM_REG_INVALID;
            if (off == Reg32.ARM_pc) {
                reg = ArmConst.UC_ARM_REG_PC;
            } else {
                msg += (", off=" + off);
            }
            if (reg != ArmConst.UC_ARM_REG_INVALID) {
                data.setInt(0, ArmRegister.readReg(u, reg));
                break;
            }
        }*/
        default:
            System.err.println(msg);
            emulator.attach().debug();
            return -1;
    }
    return 0;
}
 
Example 29
Source Project: lept4j   Source File: L_Stack.java    License: Apache License 2.0 4 votes vote down vote up
public L_Stack(Pointer peer) {
	super(peer);
	read();
}
 
Example 30
Source Project: djl   Source File: JnaUtils.java    License: Apache License 2.0 4 votes vote down vote up
private static void checkNDArray(Pointer pointer, String msg) {
    if (pointer == null) {
        throw new IllegalArgumentException(
                "Tried to " + msg + " an MXNet NDArray that was already closed");
    }
}