Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.PointerByReference


    }
   
    public void testLookupAccountName() {
    IntByReference pSid = new IntByReference(0);
    IntByReference pDomain = new IntByReference(0);
    PointerByReference peUse = new PointerByReference();
    String accountName = "Administrator";
    assertFalse(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, null, pSid, null, pDomain, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
    assertTrue(pSid.getValue() > 0);
    Memory sidMemory = new Memory(pSid.getValue());
    PSID pSidMemory = new PSID(sidMemory);
    char[] referencedDomainName = new char[pDomain.getValue() + 1];
    assertTrue(Advapi32.INSTANCE.LookupAccountName(
        null, accountName, pSidMemory, pSid, referencedDomainName, pDomain, peUse));
    assertEquals(SID_NAME_USE.SidTypeUser, peUse.getPointer().getInt(0));
    assertTrue(Native.toString(referencedDomainName).length() > 0);
    }
View Full Code Here


      int sidLength = Advapi32.INSTANCE.GetLengthSid(sid.getValue());
      assertTrue(sidLength > 0);
      // lookup account
      IntByReference cchName = new IntByReference();
      IntByReference cchReferencedDomainName = new IntByReference();
      PointerByReference peUse = new PointerByReference();
      assertFalse(Advapi32.INSTANCE.LookupAccountSid(null, sid.getValue(),
          null, cchName, null, cchReferencedDomainName, peUse));
    assertEquals(W32Errors.ERROR_INSUFFICIENT_BUFFER, Kernel32.INSTANCE.GetLastError());
      assertTrue(cchName.getValue() > 0);
      assertTrue(cchReferencedDomainName.getValue() > 0);
    char[] referencedDomainName = new char[cchReferencedDomainName.getValue()];
    char[] name = new char[cchName.getValue()];
      assertTrue(Advapi32.INSTANCE.LookupAccountSid(null, sid.getValue(),
          name, cchName, referencedDomainName, cchReferencedDomainName, peUse));
    assertEquals(5, peUse.getPointer().getInt(0)); // SidTypeWellKnownGroup
    String nameString = Native.toString(name);
    String referencedDomainNameString = Native.toString(referencedDomainName);
    assertTrue(nameString.length() > 0);
    assertEquals("Everyone", nameString);
    assertTrue(referencedDomainNameString.length() == 0);
View Full Code Here

    public void testConvertSid() {
      String sidString = EVERYONE;
      PSIDByReference sid = new PSIDByReference();
      assertTrue(Advapi32.INSTANCE.ConvertStringSidToSid(
          sidString, sid));
      PointerByReference convertedSidStringPtr = new PointerByReference();
      assertTrue(Advapi32.INSTANCE.ConvertSidToStringSid(
          sid.getValue(), convertedSidStringPtr));
      String convertedSidString = convertedSidStringPtr.getValue().getWideString(0);
      assertEquals(convertedSidString, sidString);
      assertEquals(null, Kernel32.INSTANCE.LocalFree(convertedSidStringPtr.getValue()));
      assertEquals(null, Kernel32.INSTANCE.LocalFree(sid.getValue().getPointer()));
    }
View Full Code Here

      assertTrue(Advapi32.INSTANCE.CreateWellKnownSid(WELL_KNOWN_SID_TYPE.WinWorldSid,
          null, pSid, cbSid));
      assertTrue(Advapi32.INSTANCE.IsWellKnownSid(pSid,
          WELL_KNOWN_SID_TYPE.WinWorldSid));
      assertTrue(cbSid.getValue() <= WinNT.SECURITY_MAX_SID_SIZE);
      PointerByReference convertedSidStringPtr = new PointerByReference();
      assertTrue(Advapi32.INSTANCE.ConvertSidToStringSid(
          pSid, convertedSidStringPtr));
      String convertedSidString = convertedSidStringPtr.getValue().getWideString(0);
      assertEquals(EVERYONE, convertedSidString);
    }
View Full Code Here

    GUID guid = Ole32Util
        .getGUIDFromString("{00021401-0000-0000-C000-000000000046}"); // Shell object
    GUID riid = Ole32Util
        .getGUIDFromString("{000214EE-0000-0000-C000-000000000046}"); // IShellLinkA

    PointerByReference pDispatch = new PointerByReference();

    HRESULT hr = Ole32.INSTANCE.CoCreateInstance(guid, null, // pOuter =
                                  // null, no
                                  // aggregation
        WTypes.CLSCTX_LOCAL_SERVER, riid, pDispatch);
    assertTrue(W32Errors.SUCCEEDED(hr.intValue()));
    assertTrue(!pDispatch.equals(Pointer.NULL));
    // We leak this iUnknown reference because we don't have the JNACOM lib
    // here to wrap the native iUnknown pointer and call iUnknown.release()
    if (W32Errors.SUCCEEDED(hrCI.intValue()))
      Ole32.INSTANCE.CoUninitialize();
  }
View Full Code Here

    public void testCryptProtectUnprotectData() {
      DATA_BLOB pDataIn = new DATA_BLOB("hello world");
      DATA_BLOB pDataEncrypted = new DATA_BLOB();
      assertTrue(Crypt32.INSTANCE.CryptProtectData(pDataIn, "description",
          null, null, null, 0, pDataEncrypted));
      PointerByReference pDescription = new PointerByReference();
      DATA_BLOB pDataDecrypted = new DATA_BLOB();
      assertTrue(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
          null, null, null, 0, pDataDecrypted));
      assertEquals("description", pDescription.getValue().getWideString(0));
      assertEquals("hello world", pDataDecrypted.pbData.getString(0));
      Kernel32.INSTANCE.LocalFree(pDataEncrypted.pbData);
      Kernel32.INSTANCE.LocalFree(pDataDecrypted.pbData);
      Kernel32.INSTANCE.LocalFree(pDescription.getValue());
    }
View Full Code Here

      DATA_BLOB pDataIn = new DATA_BLOB("hello world");
      DATA_BLOB pDataEncrypted = new DATA_BLOB();
      DATA_BLOB pEntropy = new DATA_BLOB("entropy");
      assertTrue(Crypt32.INSTANCE.CryptProtectData(pDataIn, "description",
          pEntropy, null, null, 0, pDataEncrypted));
      PointerByReference pDescription = new PointerByReference();
      DATA_BLOB pDataDecrypted = new DATA_BLOB();
      // can't decrypt without entropy
      assertFalse(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
          null, null, null, 0, pDataDecrypted));
      // decrypt with entropy
      assertTrue(Crypt32.INSTANCE.CryptUnprotectData(pDataEncrypted, pDescription,
          pEntropy, null, null, 0, pDataDecrypted));
      assertEquals("description", pDescription.getValue().getWideString(0));
      assertEquals("hello world", pDataDecrypted.pbData.getString(0));
      Kernel32.INSTANCE.LocalFree(pDataEncrypted.pbData);
      Kernel32.INSTANCE.LocalFree(pDataDecrypted.pbData);
      Kernel32.INSTANCE.LocalFree(pDescription.getValue());
    }   
View Full Code Here

        // Check module information
        Pointer fp = CallbackReference.getFunctionPointer(cb);
        NativeLibrary kernel32 = NativeLibrary.getInstance("kernel32", W32APIOptions.DEFAULT_OPTIONS);
        Function f = kernel32.getFunction("GetModuleHandleExW");
        final int GET_MODULE_HANDLE_FROM_ADDRESS = 0x4;
        PointerByReference pref = new PointerByReference();
        int result = f.invokeInt(new Object[] { new Integer(GET_MODULE_HANDLE_FROM_ADDRESS), fp, pref });
        assertTrue("GetModuleHandleEx(fptr) failed: " + Native.getLastError(), result != 0);

        f = kernel32.getFunction("GetModuleFileNameW");
        char[] buf = new char[1024];
        result = f.invokeInt(new Object[] { pref.getValue(), buf, buf.length });
        assertTrue("GetModuleFileName(fptr) failed: " + Native.getLastError(), result != 0);

        f = kernel32.getFunction("GetModuleHandleW");
        Pointer handle = f.invokePointer(new Object[] { Native.jnidispatchPath != null ? Native.jnidispatchPath : "jnidispatch" });
        assertNotNull("GetModuleHandle(\"jnidispatch\") failed: " + Native.getLastError(), handle);
        assertEquals("Wrong module HANDLE for DLL function pointer", handle, pref.getValue());

        // Check slot re-use
        Map refs = new WeakHashMap(callbackCache());
        assertTrue("Callback not cached", refs.containsKey(cb));
        CallbackReference ref = (CallbackReference)refs.get(cb);
View Full Code Here

    public void testNetGetJoinInformation() {
    IntByReference bufferType = new IntByReference();
      assertEquals(W32Errors.ERROR_INVALID_PARAMETER, Netapi32.INSTANCE.NetGetJoinInformation(
          null, null, bufferType));
      PointerByReference lpNameBuffer = new PointerByReference();
      assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetGetJoinInformation(
          null, lpNameBuffer, bufferType));
      assertTrue(lpNameBuffer.getValue().getString(0).length() > 0);
      assertTrue(bufferType.getValue() > 0);
      assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
          lpNameBuffer.getValue()));
    }
View Full Code Here

          lpNameBuffer.getValue()));
    }
   
    public void testNetGetLocalGroups() {
      for(int i = 0; i < 2; i++) {
      PointerByReference bufptr = new PointerByReference();
      IntByReference entriesRead = new IntByReference();
      IntByReference totalEntries = new IntByReference();   
        assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetLocalGroupEnum(null, i, bufptr,
            LMCons.MAX_PREFERRED_LENGTH,
            entriesRead,
            totalEntries,
            null));
        assertTrue(entriesRead.getValue() > 0);
        assertEquals(totalEntries.getValue(), entriesRead.getValue());
        assertEquals(W32Errors.ERROR_SUCCESS, Netapi32.INSTANCE.NetApiBufferFree(
            bufptr.getValue()));
      }
    }
View Full Code Here

TOP

Related Classes of com.sun.jna.ptr.PointerByReference

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.