Java Code Examples for com.sun.jna.Pointer#nativeValue()

The following examples show how to use com.sun.jna.Pointer#nativeValue() . 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
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * @see NativeCalls#killProcess(int)
 */
@Override
public boolean killProcess(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_TERMINATE, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final boolean result = Kernel32.TerminateProcess(procHandle, -1);
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in killing the process
    return false;
  }
}
 
Example 2
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * @see NativeCalls#isProcessActive(int)
 */
@Override
public boolean isProcessActive(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_QUERY_INFORMATION, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final IntByReference status = new IntByReference();
      final boolean result = Kernel32.GetExitCodeProcess(procHandle, status)
          && status != null && status.getValue() == Kernel32.STILL_ACTIVE;
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in getting process status
    return false;
  }
}
 
Example 3
Source File: mman.java    From domino-jna with Apache License 2.0 6 votes vote down vote up
/**
 * Map the given region of the given file descriptor into memory.
 * Returns a Pointer to the newly mapped memory throws an
 * IOException on error.<br>
 * <br>
 * The contents of a file mapping (as opposed to an anonymous mapping;
 * see MAP_ANONYMOUS below), are initialized using length bytes starting
 * at offset offset in the file (or other object) referred to by the
 * file descriptor fd.  offset must be a multiple of the page size as
 * returned by sysconf(_SC_PAGE_SIZE).
 * 
 * @param len number of bytes to map
 * @param prot describes the desired memory protection of the mapping: {@link #PROT_NONE}, {@link #PROT_READ}, {@link #PROT_WRITE}, {@link #PROT_EXEC}
 * @param flags flags
 * @param fd file descriptor
 * @param off offset to start mapping, must be a multiple of the page size as returned by sysconf(_SC_PAGE_SIZE)
 * @return pointer
 */
public static Pointer mmap(long len, int prot, int flags, int fd, long off) {

	// we don't really have a need to change the recommended pointer.
	Pointer addr = new Pointer(0);

	Pointer result = CLibrary.mmap(addr,
			new NativeLong(len),
			prot,
			flags,
			fd,
			new NativeLong(off));

	if(Pointer.nativeValue(result) == -1) {
		throw new RuntimeException("mmap failed: " + errno.strerror());
	}

	return result;

}
 
Example 4
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * @see NativeCalls#isProcessActive(int)
 */
@Override
public boolean isProcessActive(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_QUERY_INFORMATION, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final IntByReference status = new IntByReference();
      final boolean result = Kernel32.GetExitCodeProcess(procHandle, status)
          && status != null && status.getValue() == Kernel32.STILL_ACTIVE;
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in getting process status
    return false;
  }
}
 
Example 5
Source File: NativeCallsJNAImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
/**
 * @see NativeCalls#killProcess(int)
 */
@Override
public boolean killProcess(final int processId) {
  try {
    final Pointer procHandle = Kernel32.OpenProcess(
        Kernel32.PROCESS_TERMINATE, false, processId);
    final long hval;
    if (procHandle == null || (hval = Pointer.nativeValue(procHandle)) ==
        Kernel32.INVALID_HANDLE || hval == 0) {
      return false;
    }
    else {
      final boolean result = Kernel32.TerminateProcess(procHandle, -1);
      Kernel32.CloseHandle(procHandle);
      return result;
    }
  } catch (LastErrorException le) {
    // some problem in killing the process
    return false;
  }
}
 
Example 6
Source File: MouseEventReceiver.java    From Simplified-JNA with MIT License 6 votes vote down vote up
@Override
public LRESULT callback(int nCode, WPARAM wParam, MOUSEHOOKSTRUCT info) {
	boolean cancel = false;
	int code = wParam.intValue();
	if (code == WM_MOUSEMOVE) {
		cancel = onMouseMove(info.hwnd, info.pt);
	} else if (code == WM_MOUSESCROLL) {
		boolean down = Pointer.nativeValue(info.hwnd.getPointer()) == 4287102976L;
		cancel = onMouseScroll(down, info.hwnd, info.pt);
	} else if (code == WM_MOUSELDOWN || code == WM_MOUSERDOWN || code == WM_MOUSEMDOWN) {
		onMousePress(MouseButtonType.fromWParam(code), info.hwnd, info.pt);
	} else if (code == WM_MOUSELUP || code == WM_MOUSERUP || code == WM_MOUSEMUP) {
		onMouseRelease(MouseButtonType.fromWParam(code), info.hwnd, info.pt);
	}
	if (cancel) {
		return new LRESULT(1);
	}
	Pointer ptr = info.getPointer();
	long peer = Pointer.nativeValue(ptr);
	return User32.INSTANCE.CallNextHookEx(getHookManager().getHhk(this), nCode, wParam, new LPARAM(peer));
}
 
Example 7
Source File: MacProcess.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
@Override
public Process write(Pointer address, MemoryBuffer buffer) {
	if (mac.vm_write(task(), address, buffer, buffer.size()) != 0) {
		throw new RuntimeException("Write memory failed at address " + Pointer.nativeValue(address) + " size " + buffer.size());
	}
	return this;
}
 
Example 8
Source File: UnixProcess.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
@Override
public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) {
	populate(address, buffer);
	if (unix.process_vm_readv(id(), local, 1, remote, 1, 0) != size) {
		throw new RuntimeException("Read memory failed at address " + Pointer.nativeValue(address) + " size " + size);
	}
	return buffer;
}
 
Example 9
Source File: KeyEventReceiver.java    From Simplified-JNA with MIT License 5 votes vote down vote up
@Override
public LRESULT callback(int nCode, WPARAM wParam, KBDLLHOOKSTRUCT info) {
	int code = wParam.intValue();
	boolean cancel = onKeyUpdate(SystemState.from(code), PressState.from(code), info.time, info.vkCode);
	if (cancel) {
		return new LRESULT(1);
	}
	Pointer ptr = info.getPointer();
	long peer = Pointer.nativeValue(ptr);
	return User32.INSTANCE.CallNextHookEx(getHookManager().getHhk(this), nCode, wParam, new LPARAM(peer));
}
 
Example 10
Source File: FxDemo.java    From java-example with MIT License 5 votes vote down vote up
private long getWindowHandle(Stage stage) {
    long handle = -1;
    try {
    	WinDef.HWND hWnd = User32.INSTANCE.FindWindow(null, WINDOW_TITLE);
    	handle = Pointer.nativeValue(hWnd.getPointer());
    } catch (Throwable e) {
        logger.error("Error getting Window Pointer", e);
    }
    logger.info(String.format("Stage hwnd %d", handle));
    return handle;
}
 
Example 11
Source File: MacProcess.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
@Override
public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) {
	if (mac.vm_read(task(), address, size, buffer, INT_BY_REF) != 0 || INT_BY_REF.getValue() != size) {
		throw new RuntimeException("Read memory failed at address " + Pointer.nativeValue(address) + " size " + size);
	}
	Pointer.nativeValue(buffer, Pointer.nativeValue(buffer.getPointer(0)));
	return buffer;
}
 
Example 12
Source File: MultiFaceInfo.java    From arcface with MIT License 5 votes vote down vote up
private void parseData() {
	rects = new Rect[faceNum];
	orients = new int[faceNum];
	if (faceNum > 0) {
		for (int i = 0; i < faceNum; i++) {
			rects[i] = new Rect(new Pointer(Pointer.nativeValue(faceRect.getPointer()) + faceRect.size() * i));
			orients[i] = faceOrient.getPointer().getInt(i * 4);
		}
	}
}
 
Example 13
Source File: UnixProcess.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
@Override
public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) {
	populate(address, buffer);
	if (unix.process_vm_readv(id(), local, 1, remote, 1, 0) != size) {
		throw new RuntimeException("Read memory failed at address " + Pointer.nativeValue(address) + " size " + size);
	}
	return buffer;
}
 
Example 14
Source File: Module.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
public Module(Process process, String name, Pointer pointer, long size) {
    this.process = process;
    this.name = name;
    this.address = Pointer.nativeValue(pointer);
    this.size = (int) size;
    this.pointer = pointer;
}
 
Example 15
Source File: MacProcess.java    From Java-Memory-Manipulation with Apache License 2.0 5 votes vote down vote up
@Override
public MemoryBuffer read(Pointer address, int size, MemoryBuffer buffer) {
	if (mac.vm_read(task(), address, size, buffer, INT_BY_REF) != 0 || INT_BY_REF.getValue() != size) {
		throw new RuntimeException("Read memory failed at address " + Pointer.nativeValue(address) + " size " + size);
	}
	Pointer.nativeValue(buffer, Pointer.nativeValue(buffer.getPointer(0)));
	return buffer;
}
 
Example 16
Source File: Cacheable.java    From Java-Memory-Manipulation with Apache License 2.0 4 votes vote down vote up
public static Pointer pointer(long address) {
	Pointer.nativeValue(cachedPointer, address);
	return cachedPointer;
}
 
Example 17
Source File: MemoryFromPointer.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
public MemoryFromPointer(Pointer ptr, long size) {
	super();
	this.peer = Pointer.nativeValue(ptr);
	this.size = size;
}
 
Example 18
Source File: Cacheable.java    From Java-Memory-Manipulation with Apache License 2.0 4 votes vote down vote up
public static Pointer pointer(long address) {
	Pointer.nativeValue(cachedPointer, address);
	return cachedPointer;
}
 
Example 19
Source File: MIMEStream.java    From domino-jna with Apache License 2.0 4 votes vote down vote up
@Override
public int getHandle32() {
	return m_hMIMEStream==null ? 0 : (int) (Pointer.nativeValue(m_hMIMEStream) & 0xffffffff);
}
 
Example 20
Source File: LibGmp.java    From jna-gmp with Apache License 2.0 2 votes vote down vote up
/**
 * Constructs an mpz_t from a Pointer.
 *
 * @param from an block of native memory at least {@link #SIZE} bytes large
 */
public mpz_t(Pointer from) {
  this(Pointer.nativeValue(from));
}