public static void main(String args[]) throws InterruptedException { Pointer pointer; System.out.println("running in " + System.getProperty("sun.arch.data.model")); System.out.println("Loading dll"); autoHotKeyDll lib = (autoHotKeyDll) Native.loadLibrary("AutoHotkey.dll", autoHotKeyDll.class); System.out.println("initialisation"); lib.ahktextdll(new WString(""), new WString(""), new WString("")); // Thread.sleep(100); // lib.addFile(new WString(System.getProperty("user.dir") + "\\lib.ahk"), 1); // Thread.sleep(1000); // System.out.println("function call"); // System.out.println("return:" + lib.ahkFunction(new WString("function"),new WString(""),new WString(""),new // WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new WString(""),new // WString(""),new WString("")).getString(0)); Thread.sleep(1000); System.out.println("displaying cbBox"); lib.ahkExec(new WString("Send {Right}")); Thread.sleep(1000); }
public Pointer loadFromInputStream(final InputStream in, String schemaName) { final byte[] buffer = new byte[1024]; IfcEngineInterface.StreamCallback fn = new IfcEngineInterface.StreamCallback() { public int invoke(Pointer pointer) { try { int read = in.read(buffer, 0, 1024); if (read == -1) { return -1; } ByteBuffer byteBuffer = pointer.getByteBuffer(0, read); byteBuffer.put(buffer, 0, read); return read; } catch (IOException e) { } return -1; } }; callBacks.add(fn); return engine.xxxxOpenModelByStream(0, fn, schemaName); }
public InstanceDerivedTransformationMatrix(Pointer model, Pointer instance, double _11, double _12, double _13, double _14, double _21, double _22, double _23, double _24, double _31, double _32, double _33, double _34, double _41, double _42, double _43, double _44) { this.model = model; this.instance = instance; this._11 = _11; this._12 = _12; this._13 = _13; this._14 = _14; this._21 = _21; this._22 = _22; this._23 = _23; this._24 = _24; this._31 = _31; this._32 = _32; this._33 = _33; this._34 = _34; this._41 = _41; this._42 = _42; this._43 = _43; this._44 = _44; }
public char[] read(String key) { try { byte[] serviceName = key.getBytes("UTF-8"); byte[] accountName = "NetBeans".getBytes("UTF-8"); int[] dataLength = new int[1]; Pointer[] data = new Pointer[1]; error("find", SecurityLibrary.LIBRARY.SecKeychainFindGenericPassword(null, serviceName.length, serviceName, accountName.length, accountName, dataLength, data, null)); if (data[0] == null) { return null; } byte[] value = data[0].getByteArray(0, dataLength[0]); // XXX ought to call SecKeychainItemFreeContent return new String(value, "UTF-8").toCharArray(); } catch (UnsupportedEncodingException x) { LOG.log(Level.WARNING, null, x); return null; } }
public float[] owlGetMappedItem(Pointer model, Pointer instance, long owlInstance) { Memory memory = new Memory(16 * 4 * getPlatformMultiplier()); LongByReference owlInstanceReference = new LongByReference(); owlInstanceReference.setValue(owlInstance); engine.owlGetMappedItem(model, instance, owlInstanceReference, memory); if (getPlatformMultiplier() == 2) { double[] doubleArray = memory.getDoubleArray(0, 16); float[] floatArray = new float[16]; for (int i=0; i<16; i++) { floatArray[i] = (float)doubleArray[i]; } return floatArray; } else { return memory.getFloatArray(0, 16); } }
public static void main(String[] args) { final User32 user32 = User32.INSTANCE; user32.EnumWindows(new User32.WNDENUMPROC() { int count; public boolean callback(Pointer hWnd, Pointer userData) { byte[] windowText = new byte[512]; user32.GetWindowTextA(hWnd, windowText, 512); String wText = Native.toString(windowText); wText = (wText.isEmpty()) ? "" : "; text: " + wText; System.out.println("Found window " + hWnd + ", total " + ++count + wText); return true; } }, null); }
private Pointer findDefaultMode(final Pointer runLoop) { final Pointer modes = cf.CFRunLoopCopyAllModes(runLoop); if (modes != Pointer.NULL) { final int modesCount = cf.CFArrayGetCount(modes).intValue(); for (int i=0; i< modesCount; i++) { final Pointer mode = cf.CFArrayGetValueAtIndex(modes, new NativeLong(i)); if (mode != Pointer.NULL && DEFAULT_RUN_LOOP_MODE.equals(cf.CFStringGetCStringPtr(mode, ENC_MAC_ROMAN))) { return mode; } } } return null; }
/** * It's a heavy init method. */ public void init() { for (int i = 0; i < poolSize; i++) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(fileSize); final long address = ((DirectBuffer) byteBuffer).address(); Pointer pointer = new Pointer(address); LibC.INSTANCE.mlock(pointer, new NativeLong(fileSize)); availableBuffers.offer(byteBuffer); } }
@Override public void init() { super.init(); WindowManager.createWindow(handle, window, true); long hwndGLFW = glfwGetWin32Window(window.getID()); HWND hwnd = new HWND(Pointer.createConstant(hwndGLFW)); WindowProc proc = new WindowProc() { @Override public long invoke(long hw, int uMsg, long wParam, long lParam) { if (hw == hwndGLFW) switch (uMsg) { case WM_WINDOWPOSCHANGING: WINDOWPOS pos = new WINDOWPOS(new Pointer(lParam)); pos.flags |= SWP_NOZORDER | SWP_NOACTIVATE; pos.write(); break; } return org.lwjgl.system.windows.User32.DefWindowProc(hw, uMsg, wParam, lParam); } }; User32.INSTANCE.SetWindowLongPtr(hwnd, GWL_WNDPROC, Pointer.createConstant(proc.address())); User32Ext.INSTANCE.SetWindowLongPtr(hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW); User32Ext.INSTANCE.SetWindowLongPtr(hwnd, GWL_STYLE, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); User32.INSTANCE.SetWindowPos(hwnd, new HWND(Pointer.createConstant(HWND_BOTTOM)), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); wallpaper = window.getResourceLoader().loadNVGTexture(getCurrentDesktopWallpaper(), true); TaskManager.addTask(() -> window.setVisible(true)); }
/** * @param name C type : const char*<br> * @param codec_ids C type : AVCodecID*<br> * @param priv_class C type : const AVClass*<br> * @param init C type : init_callback*<br> * @param filter C type : filter_callback*<br> * @param close C type : close_callback* */ public AVBitStreamFilter(Pointer name, IntByReference codec_ids, Pointer priv_class, int priv_data_size, org.ffmpeg.avfilter6.AVFilter.init_callback init, filter_callback filter, close_callback close) { super(); this.name = name; this.codec_ids = codec_ids; this.priv_class = priv_class; this.priv_data_size = priv_data_size; this.init = init; this.filter = filter; this.close = close; }
@Override public void invoke(Pointer streamRef, Pointer clientCallBackInfo, NativeLong numEvents, Pointer eventPaths, Pointer eventFlags, Pointer eventIds) { final long st = System.currentTimeMillis(); final int length = numEvents.intValue(); final Pointer[] pointers = eventPaths.getPointerArray(0, length); int flags[]; if (eventFlags == null) { flags = new int[length]; LOG.log(DEBUG_LOG_LEVEL, "FSEventStreamCallback eventFlags == null, expected int[] of size {0}", length); //NOI18N } else { flags = eventFlags.getIntArray(0, length); } for (int i=0; i<length; i++) { final Pointer p = pointers[i]; int flag = flags[i]; final String path = p.getString(0); if ((flag & kFSEventStreamEventFlagMustScanSubDirs) == kFSEventStreamEventFlagMustScanSubDirs || (flag & kFSEventStreamEventFlagMount) == kFSEventStreamEventFlagMount || (flag & kFSEventStreamEventFlagUnmount) == kFSEventStreamEventFlagUnmount) { events.add(ALL_CHANGE); } else { events.add(path); } LOG.log(DEBUG_LOG_LEVEL, "Event on {0}", new Object[]{path}); } LOG.log(PERF_LOG_LEVEL, "Callback time: {0}", (System.currentTimeMillis() - st)); }
@Override public void setPointer(Pointer p) { if (immutable) { throw new UnsupportedOperationException("immutable reference"); } super.setPointer(p); }
public HANDLE getValue() { Pointer p = getPointer().getPointer(0); if (p == null) return null; if (INVALID_HANDLE_VALUE.getPointer().equals(p)) return INVALID_HANDLE_VALUE; HANDLE h = new HANDLE(); h.setPointer(p); return h; }
@Override public int apply(Pointer opaque, Pointer buf, int buf_size) { try { byte[] tempbuf = new byte[buf_size]; int readLen = stream.read(tempbuf, 0, buf_size); if (readLen == -1) return AVERROR_EOF; buf.write(0, tempbuf, 0, readLen); return readLen; } catch (Exception ex) { return -1; } }
/** * Converts CFString object to String. * * @param cfStringPointer Pointer to CFString object * @return String from CFString */ private String getStringFromCFStringRef(Pointer cfStringPointer) { if (cfStringPointer != null) { long lenght = cfLibrary.CFStringGetLength(cfStringPointer); long maxSize = cfLibrary.CFStringGetMaximumSizeForEncoding(lenght, 0x08000100); // 0x08000100 = UTF-8 Pointer buffer = new Memory(maxSize); if (cfLibrary.CFStringGetCString(cfStringPointer, buffer, maxSize, 0x08000100)) { // 0x08000100 = UTF-8 return buffer.getString(0L); } } return null; }
/** * Gets recognized text. * * @param filename input file name. Needed only for reading a UNLV zone * file. * @param pageNum page number; needed for hocr paging. * @return the recognized text */ protected String getOCRText(String filename, int pageNum) { if (filename != null && !filename.isEmpty()) { api.TessBaseAPISetInputName(handle, filename); } Pointer utf8Text = renderedFormat == RenderedFormat.HOCR ? api.TessBaseAPIGetHOCRText(handle, pageNum - 1) : api.TessBaseAPIGetUTF8Text(handle); String str = utf8Text.getString(0); api.TessDeleteText(utf8Text); return str; }
int SecKeychainAddGenericPassword( Pointer keychain, int serviceNameLength, byte[] serviceName, int accountNameLength, byte[] accountName, int passwordLength, byte[] passwordData, Pointer itemRef );
static void windowsImpl() { if (!Constants.WINDOWS) { throw new IllegalStateException("bug: should not be trying to initialize ActiveProcessLimit for an unsupported OS"); } JNAKernel32Library lib = JNAKernel32Library.getInstance(); // create a new Job Pointer job = lib.CreateJobObjectW(null, null); if (job == null) { throw new UnsupportedOperationException("CreateJobObject: " + Native.getLastError()); } try { // retrieve the current basic limits of the job int clazz = JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION_CLASS; JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION limits = new JNAKernel32Library.JOBOBJECT_BASIC_LIMIT_INFORMATION(); limits.write(); if (!lib.QueryInformationJobObject(job, clazz, limits.getPointer(), limits.size(), null)) { throw new UnsupportedOperationException("QueryInformationJobObject: " + Native.getLastError()); } limits.read(); // modify the number of active processes to be 1 (exactly the one process we will add to the job). limits.ActiveProcessLimit = 1; limits.LimitFlags = JNAKernel32Library.JOB_OBJECT_LIMIT_ACTIVE_PROCESS; limits.write(); if (!lib.SetInformationJobObject(job, clazz, limits.getPointer(), limits.size())) { throw new UnsupportedOperationException("SetInformationJobObject: " + Native.getLastError()); } // assign ourselves to the job if (!lib.AssignProcessToJobObject(job, lib.GetCurrentProcess())) { throw new UnsupportedOperationException("AssignProcessToJobObject: " + Native.getLastError()); } } finally { lib.CloseHandle(job); } logger.debug("Windows ActiveProcessLimit initialization successful"); }
public boolean plan() { ArrayList<PoseSteering> finalPath = new ArrayList<PoseSteering>(); for (int i = 0; i < this.goal.length; i++) { Pose start_ = null; Pose goal_ = this.goal[i]; if (i == 0) start_ = this.start; else start_ = this.goal[i-1]; path = new PointerByReference(); pathLength = new IntByReference(); if (collisionCircleCenters == null) { if (!INSTANCE.plan(mapFilename, mapResolution, robotRadius, start_.getX(), start_.getY(), start_.getTheta(), goal_.getX(), goal_.getY(), goal_.getTheta(), path, pathLength, distanceBetweenPathPoints, turningRadius)) return false; } else { double[] xCoords = new double[collisionCircleCenters.length]; double[] yCoords = new double[collisionCircleCenters.length]; int numCoords = collisionCircleCenters.length; for (int j = 0; j < collisionCircleCenters.length; j++) { xCoords[j] = collisionCircleCenters[j].x; yCoords[j] = collisionCircleCenters[j].y; } System.out.println("Path planning with " + collisionCircleCenters.length + " circle positions"); if (this.mapFilename != null) { if (!INSTANCE.plan_multiple_circles(mapFilename, mapResolution, robotRadius, xCoords, yCoords, numCoords, start_.getX(), start_.getY(), start_.getTheta(), goal_.getX(), goal_.getY(), goal_.getTheta(), path, pathLength, distanceBetweenPathPoints, turningRadius)) return false; } else { if (!INSTANCE.plan_multiple_circles_nomap(xCoords, yCoords, numCoords, start_.getX(), start_.getY(), start_.getTheta(), goal_.getX(), goal_.getY(), goal_.getTheta(), path, pathLength, distanceBetweenPathPoints, turningRadius)) return false; } } final Pointer pathVals = path.getValue(); final PathPose valsRef = new PathPose(pathVals); valsRef.read(); int numVals = pathLength.getValue(); PathPose[] pathPoses = (PathPose[])valsRef.toArray(numVals); if (i == 0) finalPath.add(new PoseSteering(pathPoses[0].x, pathPoses[0].y, pathPoses[0].theta, 0.0)); for (int j = 1; j < pathPoses.length; j++) finalPath.add(new PoseSteering(pathPoses[j].x, pathPoses[j].y, pathPoses[j].theta, 0.0)); INSTANCE.cleanupPath(pathVals); } this.pathPS = finalPath.toArray(new PoseSteering[finalPath.size()]); return true; }
public static boolean inject(int processID, String dllName) { DWORD_PTR processAccess = new DWORD_PTR(0x43A); HANDLE hProcess = kernel32.OpenProcess(processAccess, new BOOL(false), new DWORD_PTR(processID)); if(hProcess == null) { System.out.println("Handle was NULL! Error: " + kernel32.GetLastError()); return false; } DWORD_PTR loadLibraryAddress = kernel32.GetProcAddress(kernel32.GetModuleHandle("KERNEL32"), "LoadLibraryA"); if(loadLibraryAddress.intValue() == 0) { System.out.println("Could not find LoadLibrary! Error: " + kernel32.GetLastError()); return false; } LPVOID dllNameAddress = kernel32.VirtualAllocEx(hProcess, null, (dllName.length() + 1), new DWORD_PTR(0x3000), new DWORD_PTR(0x4)); if(dllNameAddress == null) { System.out.println("dllNameAddress was NULL! Error: " + kernel32.GetLastError()); return false; } Pointer m = new Memory(dllName.length() + 1); m.setString(0, dllName); boolean wpmSuccess = kernel32.WriteProcessMemory(hProcess, dllNameAddress, m, dllName.length(), null).booleanValue(); if(!wpmSuccess) { System.out.println("WriteProcessMemory failed! Error: " + kernel32.GetLastError()); return false; } DWORD_PTR threadHandle = kernel32.CreateRemoteThread(hProcess, 0, 0, loadLibraryAddress, dllNameAddress, 0, 0); if(threadHandle.intValue() == 0) { System.out.println("threadHandle was invalid! Error: " + kernel32.GetLastError()); return false; } kernel32.CloseHandle(hProcess); return true; }
static void tryVirtualLock() { JNAKernel32Library kernel = JNAKernel32Library.getInstance(); Pointer process = null; try { process = kernel.GetCurrentProcess(); // By default, Windows limits the number of pages that can be locked. // Thus, we need to first increase the working set size of the JVM by // the amount of memory we wish to lock, plus a small overhead (1MB). SizeT size = new SizeT(JvmInfo.jvmInfo().getMem().getHeapInit().getBytes() + (1024 * 1024)); if (!kernel.SetProcessWorkingSetSize(process, size, size)) { logger.warn("Unable to lock JVM memory. Failed to set working set size. Error code {}", Native.getLastError()); } else { JNAKernel32Library.MemoryBasicInformation memInfo = new JNAKernel32Library.MemoryBasicInformation(); long address = 0; while (kernel.VirtualQueryEx(process, new Pointer(address), memInfo, memInfo.size()) != 0) { boolean lockable = memInfo.State.longValue() == JNAKernel32Library.MEM_COMMIT && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_NOACCESS) != JNAKernel32Library.PAGE_NOACCESS && (memInfo.Protect.longValue() & JNAKernel32Library.PAGE_GUARD) != JNAKernel32Library.PAGE_GUARD; if (lockable) { kernel.VirtualLock(memInfo.BaseAddress, new SizeT(memInfo.RegionSize.longValue())); } // Move to the next region address += memInfo.RegionSize.longValue(); } LOCAL_MLOCKALL = true; } } catch (UnsatisfiedLinkError e) { // this will have already been logged by Kernel32Library, no need to repeat it } finally { if (process != null) { kernel.CloseHandle(process); } } }
/** try to install our custom rule profile into sandbox_init() to block execution */ private static void macImpl(Path tmpFile) throws IOException { // first be defensive: we can give nice errors this way, at the very least. boolean supported = Constants.MAC_OS_X; if (supported == false) { throw new IllegalStateException("bug: should not be trying to initialize seatbelt for an unsupported OS"); } // we couldn't link methods, could be some really ancient OS X (< Leopard) or some bug if (libc_mac == null) { throw new UnsupportedOperationException("seatbelt unavailable: could not link methods. requires Leopard or above."); } // write rules to a temporary file, which will be passed to sandbox_init() Path rules = Files.createTempFile(tmpFile, "es", "sb"); Files.write(rules, Collections.singleton(SANDBOX_RULES)); boolean success = false; try { PointerByReference errorRef = new PointerByReference(); int ret = libc_mac.sandbox_init(rules.toAbsolutePath().toString(), SANDBOX_NAMED, errorRef); // if sandbox_init() fails, add the message from the OS (e.g. syntax error) and free the buffer if (ret != 0) { Pointer errorBuf = errorRef.getValue(); RuntimeException e = new UnsupportedOperationException("sandbox_init(): " + errorBuf.getString(0)); libc_mac.sandbox_free_error(errorBuf); throw e; } logger.debug("OS X seatbelt initialization successful"); success = true; } finally { if (success) { Files.delete(rules); } else { IOUtils.deleteFilesIgnoringExceptions(rules); } } }
/** * Return derived properties from the 3D visualisation. * * @param model * Unique number identifying the model in the opened file. * @param instance * A numeric instanceID that uniquely identifies an instance. * @return InstanceDerivedProperties object */ public InstanceDerivedProperties getInstanceDerivedPropertiesInModelling(int model, Pointer instance) { DoubleByReference pH = new DoubleByReference(); DoubleByReference pW = new DoubleByReference(); DoubleByReference pT = new DoubleByReference(); engine.getInstanceDerivedPropertiesInModelling(model, instance, pH, pW, pT); double height = pH.getValue(); double width = pW.getValue(); double thickness = pT.getValue(); return new InstanceDerivedProperties(model, instance, height, width, thickness); }
public InstanceTransformationMatrix getInstanceTransformationMatrix(Pointer model, Pointer instance) { DoubleByReference p_11 = new DoubleByReference(); DoubleByReference p_12 = new DoubleByReference(); DoubleByReference p_13 = new DoubleByReference(); DoubleByReference p_14 = new DoubleByReference(); DoubleByReference p_21 = new DoubleByReference(); DoubleByReference p_22 = new DoubleByReference(); DoubleByReference p_23 = new DoubleByReference(); DoubleByReference p_24 = new DoubleByReference(); DoubleByReference p_31 = new DoubleByReference(); DoubleByReference p_32 = new DoubleByReference(); DoubleByReference p_33 = new DoubleByReference(); DoubleByReference p_34 = new DoubleByReference(); DoubleByReference p_41 = new DoubleByReference(); DoubleByReference p_42 = new DoubleByReference(); DoubleByReference p_43 = new DoubleByReference(); DoubleByReference p_44 = new DoubleByReference(); engine.getInstanceDerivedTransformationMatrix(model, instance, p_11, p_12, p_13, p_14, p_21, p_22, p_23, p_24, p_31, p_32, p_33, p_34, p_41, p_42, p_43, p_44); double _11 = p_11.getValue(); double _12 = p_12.getValue(); double _13 = p_13.getValue(); double _14 = p_14.getValue(); double _21 = p_21.getValue(); double _22 = p_22.getValue(); double _23 = p_23.getValue(); double _24 = p_24.getValue(); double _31 = p_31.getValue(); double _32 = p_32.getValue(); double _33 = p_33.getValue(); double _34 = p_34.getValue(); double _41 = p_41.getValue(); double _42 = p_42.getValue(); double _43 = p_43.getValue(); double _44 = p_44.getValue(); return new InstanceTransformationMatrix(model, instance, _11, _12, _13, _14, _21, _22, _23, _24, _31, _32, _33, _34, _41, _42, _43, _44); }
int st_mobile_tracker_106_track_face_action( Pointer handle, byte[] image, int pixel_format, int image_width, int image_height, int image_stride, int orientation, PointerByReference p_face_action_array, IntByReference p_faces_count );
public AVDeviceInfoList(Pointer peer) { super(peer); }
public Pointer internalGetInstanceFromP21Line(Pointer modelId, int expressId) { return engine.internalGetInstanceFromP21Line(modelId, expressId); }
Pointer getPointer() { return database; }
public AVProgram(Pointer peer) { super(peer); }
public SHELLTRAYDATA(Pointer pointer) { super(pointer); read(); }
public AVCodecDefault(Pointer peer) { super(peer); }
public TessMutableIterator(Pointer address) { super(address); }
public av_intfloat32(Pointer peer) { super(peer); }
public st_mobile_106_t(Pointer p) { super(p); }
public HANDLEByReference(HANDLE h) { super(Pointer.SIZE); setValue(h); }
/** @param url_context C type : void* */ public AVIODirContext(Pointer url_context) { super(); this.url_context = url_context; }
public AVOptionRange(Pointer peer) { super(peer); }
public static native boolean TerminateProcess(Pointer processHandle, int exitCode) throws LastErrorException;
public AVOption(Pointer peer) { super(peer); }
public ws2811_channel_t(Pointer peer) { super(peer); }