Package com.sun.jna.ptr

Examples of com.sun.jna.ptr.PointerByReference


        GObjectAPI.GParamSpec propertySpec = findProperty(property);
        if (propertySpec == null) {
            throw new IllegalArgumentException("Unknown property: " + property);
        }

        PointerByReference refPtr = new PointerByReference();
        GOBJECT_API.g_object_get(this, property, refPtr, null);

        if (refPtr != null) {
            Pointer ptr = refPtr.getValue();
            return ptr;
        } else {
            throw new IllegalArgumentException("Got NULL pointer for property="+property);
        }
    }
View Full Code Here


    {
      System.err.println("Could not get commandline");
    }
    else
      System.out.println("Command line of " + pid + ": " + result._cmd);
    PointerByReference hToken = new PointerByReference();
    HANDLE hp = new HANDLE();
    hp.setPointer(hProcess.getPointer());
    if (MyAdvapi.INSTANCE.OpenProcessToken(hp, MyAdvapi.TOKEN_READ, hToken))
    {
      IntByReference dwSize = new IntByReference();
      MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(), MyAdvapi.TokenUser, null, 0, dwSize);
      {
        Memory pTokenUser = new Memory(dwSize.getValue());
        if (MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(), MyAdvapi.TokenUser, pTokenUser, dwSize.getValue(), dwSize))
        {
          MyAdvapi.TOKEN_USER tokenUser = new MyAdvapi.TOKEN_USER(pTokenUser);
          Pointer lpSid = tokenUser.User.Sid;
          Memory lpName = new Memory(256);
          IntByReference cchName = new IntByReference();
          cchName.setValue(256);
          Memory lpReferencedDomainName = new Memory(256);
          IntByReference cchReferencedDomainName = new IntByReference();
          cchReferencedDomainName.setValue(256);
          IntByReference peUse = new IntByReference();
          if (MyAdvapi.INSTANCE.LookupAccountSidW(null, lpSid, lpName, cchName, lpReferencedDomainName, cchReferencedDomainName, peUse))

            result._user = lpReferencedDomainName.getString(0, true) + "\\" + lpName.getString(0, true);
          ;
          // System.out.println(result._user);
        }
      }
      if (result._user == null)
        System.out.println("could not get user name OS error #" + MyKernel32.INSTANCE.GetLastError());
      MyKernel32.INSTANCE.CloseHandle(hToken.getValue());
    }
    return result;
  }
View Full Code Here

          sa.nLength = sa.size();
          sa.lpSecurityDescriptor = null;
          sa.bInheritHandle = true;// 1; // true otherwise streams are
          // not piped
        }
        inRead = new PointerByReference();
        inWrite = new PointerByReference();
        outRead = new PointerByReference();
        outWrite = new PointerByReference();
        errRead = new PointerByReference();
        errWrite = new PointerByReference();

        if (MyKernel32.INSTANCE.CreatePipe(inRead, inWrite, sa, 0) == 0 || MyKernel32.INSTANCE.CreatePipe(outRead, outWrite, sa, 0) == 0
            || MyKernel32.INSTANCE.CreatePipe(errRead, errWrite, sa, 0) == 0)
        {
          log("Error in CreatePipe " + Integer.toHexString(MyKernel32.INSTANCE.GetLastError()));
          return false;
        }

        _startupInfo.dwFlags = MyKernel32.STARTF_USESTDHANDLES;
        _startupInfo.hStdInput = inRead.getValue();
        _startupInfo.hStdOutput = outWrite.getValue();
        _startupInfo.hStdError = errWrite.getValue();

        if (!MyKernel32.INSTANCE.SetHandleInformation(inWrite.getValue(), MyKernel32.HANDLE_FLAG_INHERIT, 0)
            || !MyKernel32.INSTANCE.SetHandleInformation(outRead.getValue(), MyKernel32.HANDLE_FLAG_INHERIT, 0)
            || !MyKernel32.INSTANCE.SetHandleInformation(errRead.getValue(), MyKernel32.HANDLE_FLAG_INHERIT, 0)
            // for some unknown reason: if we add the following
            // lines we do not get "operation on non socket" error
            // in mina
            || !MyKernel32.INSTANCE.SetHandleInformation(inWrite.getValue(), MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE,
                MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE)
            || !MyKernel32.INSTANCE.SetHandleInformation(outRead.getValue(), MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE,
                MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE)
            || !MyKernel32.INSTANCE.SetHandleInformation(errRead.getValue(), MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE,
                MyKernel32.HANDLE_FLAG_PROTECT_FROM_CLOSE))

        {
          log("error in set handle -> abort start");
          return false;
        }
        if (this._redirectErrorStream)
          MyKernel32.INSTANCE.SetHandleInformation(errRead.getValue(), MyKernel32.HANDLE_FLAG_INHERIT, 0);

      }

      int creationFlag = 0;
      if (!_visible)
      {
        creationFlag |= MyKernel32.CREATE_NO_WINDOW | MyKernel32.CREATE_UNICODE_ENVIRONMENT;
        _startupInfo.lpTitle = null;
      }
      else
      {
        creationFlag |= MyKernel32.CREATE_NEW_CONSOLE | MyKernel32.CREATE_UNICODE_ENVIRONMENT;
        _startupInfo.lpTitle = new WString(_title);

        if (_minimized)
        {
          _startupInfo.wShowWindow |= MyKernel32.SW_SHOWMINIMIZED | MyKernel32.SW_SHOWNOACTIVATE;
          _startupInfo.dwFlags |= MyKernel32.STARTF_USESHOWWINDOW;
        }

      }

      creationFlag |= getPriorityFlag();

      // do not inherit handles. otherwise resources are not freed if
      // parent is killed
      // inherit only when we need to pipe the streams
      _startupInfo.write();
      WString cmd = new WString(_cmd);
      WString wDir = getWorkingDir() == null ? null : new WString(getWorkingDir());
      String stdUser = standardizeUser(_user);
      StringBlock environment = null;
      WString[] env = null;
      if (_environment.size() != 0)
      {
        env = new WString[_environment.size()];
        int i = 0;
        for (String[] entry : _environment)
        {
          env[i++] = new WString(entry[0] + "=" + entry[1]);
        }
        environment = new StringBlock(env);
      }
      if (_desktop != null)
      {
        _startupInfo.lpDesktop = new WString(_desktop);
        log("setting desktop "+_desktop);
      }

       if (_logonActiveSession)
        {
          log("start process in active session");
          int session = 0xFFFFFFFF;
          // wait until we have an active session
          while (session == 0xFFFFFFFF)
          {
            session = MyKernel32.INSTANCE.WTSGetActiveConsoleSessionId();
            if (session == 0xFFFFFFFF)
              Thread.sleep(1000);
            log("active session: "+session);
          }

         
          PointerByReference phToken = new PointerByReference();
         
          // wait for a user to log on to the session
          boolean userLoggedOn = false;
          int retries = 0;
          while (!userLoggedOn)
          {
          result = MyWtsapi32.INSTANCE.WTSQueryUserToken(session, phToken);
          userLoggedOn = result || MyKernel32.INSTANCE.GetLastError() != 1008;
          if (!userLoggedOn)
          {
            Thread.sleep(1000);
            retries++;
          }
          }
          // if user just logged on: wait for the desktop to get up.
          // TODO evntl. add a configuration property for the time to wait.
          if (retries > 0)
            Thread.sleep(10000);
         
          if (!doesUserHavePrivilege(MyAdvapi.SE_TCB_NAME))
            log("WARNING: Process does not have the SE_TCB_NAME privilege !!");

          // start the application
          if (result)
          {
            log("got session token: "+phToken.getValue());
            PointerByReference phNewToken = new PointerByReference();
            result = MyAdvapi.INSTANCE.DuplicateTokenEx(phToken.getValue(), 0x2000000, null, 0, 1, phNewToken);
            if (result)
            {
              log("duplicated token: "+phNewToken.getValue());
              //_startupInfo.lpDesktop = new WString("winsta0\\default");
              creationFlag = 0;
              creationFlag |= MyKernel32.CREATE_NO_WINDOW | MyKernel32.CREATE_UNICODE_ENVIRONMENT;
              creationFlag |= getPriorityFlag();
              result = MyAdvapi.INSTANCE.CreateProcessAsUserW(phNewToken.getValue(), null, cmd, null, null, _pipeStreams, creationFlag,
                  null, new WString(getWorkingDir()), _startupInfo, _processInformation);
              log("started "+result);
            }
          }

        }
       else
      if (stdUser == null || stdUser.equals(currentUser()))
      {
        result = MyKernel32.INSTANCE.CreateProcessW(null, cmd, null, null, _pipeStreams, creationFlag, environment, wDir, _startupInfo,
            _processInformation);
      }
      else
      {
        WString user = null;
        ;
        WString domain = null;
        ;
        int i = _user.lastIndexOf("\\");
        if (i > 0)
        {
          user = new WString(_user.substring(_user.lastIndexOf("\\") + 1));
          domain = new WString(_user.substring(0, _user.lastIndexOf("\\")));
        }
        else
          user = new WString(_user);
        WString password = null;
        if (_password != null)
          password = new WString(_password);

        log("current user :: requested user: " + currentUserName() + " :: " + stdUser);
        // in windows 2008: system user seems to be <computername>$
        // could not find documentation on this.
        if (!("SYSTEM".equals(currentUserName()) || currentUserName().endsWith("$")))
        {
          // createProcessWithLogon : cmd line is only 1024 char long
          // parent process is not current process.
          // -> use CreateProcessAsUser
          // result = MyAdvapi.INSTANCE.CreateProcessWithLogonW(user,
          // domain, password, MyAdvapi.LOGON_WITH_PROFILE, null, cmd,
          // creationFlag, null, wDir, _startupInfo,
          // _processInformation);

          /**/
          PointerByReference phToken = new PointerByReference();

          String stUser = user.toString();
          String stDomain = domain == null ? null : domain.toString();
          String stPassword = password == null ? "" : password.toString();
          result = true;
          // result = MyAdvapi.INSTANCE.LogonUserA(stUser, stDomain,
          // stPassword, MyAdvapi.LOGON32_LOGON_NEW_CREDENTIALS,
          // MyAdvapi.LOGON32_PROVIDER_WINNT50, phToken);
          if (result)
          {
            // HANDLE hCurrentProcess =
            // MyKernel32.INSTANCE.GetCurrentProcess();
            // PointerByReference hTokenSelf = new
            // PointerByReference();
            // result =
            // MyAdvapi.INSTANCE.OpenProcessToken(hCurrentProcess,
            // MyAdvapi.TOKEN_READ | MyAdvapi.TOKEN_WRITE |
            // MyAdvapi.TOKEN_DUPLICATE |
            // MyAdvapi.TOKEN_IMPERSONATE, hTokenSelf );
            /*
             * Memory pSD = new
             * Memory(MyAdvapi.SECURITY_DESCRIPTOR_MIN_LENGTH);
             * pSD.clear(); if (result) result =
             * MyAdvapi.INSTANCE.InitializeSecurityDescriptor(pSD,
             * MyAdvapi.SECURITY_DESCRIPTOR_REVISION);
             *
             * if (result) result =
             * MyAdvapi.INSTANCE.SetSecurityDescriptorDacl(pSD,
             * true, null, false);
             */
            if (result)
            {

              /*
               * SECURITY_ATTRIBUTES sap = new
               * SECURITY_ATTRIBUTES(); sap.clear(); sap.nLength =
               * sap.size(); sap.lpSecurityDescriptor = pSD;
               * sap.bInheritHandle = false;
               */
              // result =
              // MyAdvapi.INSTANCE.ImpersonateLoggedOnUser(phToken.getValue());
              /**/// System.out.println(MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME));
              // System.out.println(MyAdvapi.SE_INCREASE_QUOTA_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_INCREASE_QUOTA_NAME));
              // System.out.println(MyAdvapi.SE_DEBUG_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_DEBUG_NAME));
              // System.out.println(MyAdvapi.SE_TCB_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_TCB_NAME));
              // */
              /**/if (result)
              {
                // result =
                // setPrivilege(hTokenSelf.getValue(),
                // MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME, true)
                // && setPrivilege(hTokenSelf.getValue(),
                // MyAdvapi.SE_INCREASE_QUOTA_NAME, true)
                // && setPrivilege(hTokenSelf.getValue(),
                // MyAdvapi.SE_DEBUG_NAME, true)
                // && setPrivilege(hTokenSelf.getValue(),
                // MyAdvapi.SE_TCB_NAME, true)
                ;
              }
              // System.out.println(MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME));
              // System.out.println(MyAdvapi.SE_INCREASE_QUOTA_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_INCREASE_QUOTA_NAME));
              // System.out.println(MyAdvapi.SE_DEBUG_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_DEBUG_NAME));
              // System.out.println(MyAdvapi.SE_TCB_NAME+" "+this.doesUserHavePrivilege(MyAdvapi.SE_TCB_NAME));
              // */
              // MyKernel32.INSTANCE.CloseHandle(hTokenSelf.getValue());
              if (!doesUserHavePrivilege(MyAdvapi.SE_ASSIGNPRIMARYTOKEN_NAME))
                log("Process does not have the SE_ASSIGNPRIMARYTOKEN_NAME privilege !!");

              if (!doesUserHavePrivilege(MyAdvapi.SE_INCREASE_QUOTA_NAME))
                log("Process does not have the SE_INCREASE_QUOTA_NAME privilege !!");

              result = MyAdvapi.INSTANCE.LogonUserA(stUser, stDomain, stPassword, MyAdvapi.LOGON32_LOGON_INTERACTIVE,
                  MyAdvapi.LOGON32_PROVIDER_DEFAULT, phToken);
              if (result)
                // result =
                // MyAdvapi.INSTANCE.CreateProcessWithLogonW(user,
                // domain, password,
                // MyAdvapi.LOGON_NETCREDENTIALS_ONLY, null,
                // cmd, creationFlag, null, wDir, _startupInfo,
                // _processInformation);
                result = MyAdvapi.INSTANCE.CreateProcessAsUserW(phToken.getValue(), null, cmd, null, // sap,
                    null, true,// _pipeStreams,
                    creationFlag, null, null,// getWorkingDir(),
                    _startupInfo, _processInformation);
            }

          }
          /**/

        }
        else
        {
          /*
           * _startupInfo = new STARTUPINFO(); _startupInfo.clear();
           * _processInformation = new PROCESS_INFORMATION();
           * _processInformation.clear();
           */
          PointerByReference phToken = new PointerByReference();

          String stUser = user.toString();
          String stDomain = domain == null ? null : domain.toString();
          String stPassword = password == null ? "" : password.toString();

          result = MyAdvapi.INSTANCE.LogonUserW(user, domain, password, MyAdvapi.LOGON32_LOGON_INTERACTIVE,
              MyAdvapi.LOGON32_PROVIDER_DEFAULT, phToken);
          log("logonUserA " + result);
          if (result)
          {
            // result =
            // MyAdvapi.INSTANCE.ImpersonateLoggedOnUser(phToken.getValue());
            if (result)
              // result =
              // MyAdvapi.INSTANCE.CreateProcessWithLogonW(user,
              // domain, password,
              // MyAdvapi.LOGON_NETCREDENTIALS_ONLY, null, cmd,
              // creationFlag, null, wDir, _startupInfo,
              // _processInformation);
              result = MyAdvapi.INSTANCE.CreateProcessAsUserW(phToken.getValue(), null, cmd, null, null, _pipeStreams, creationFlag,
                  null, new WString(getWorkingDir()), _startupInfo, _processInformation);

          }

        }
View Full Code Here

  }

  boolean doesUserHavePrivilege(String lpPrivilegeName)

  {
    PointerByReference hToken = new PointerByReference();
    IntByReference dwSize = new IntByReference();
    Memory lpPrivileges;
    MyAdvapi.LUID PrivilegeLuid = new MyAdvapi.LUID();
    int i;
    boolean bResult = false;

    if (!MyAdvapi.INSTANCE.OpenProcessToken(MyKernel32.INSTANCE.GetCurrentProcess(), MyAdvapi.INSTANCE.TOKEN_QUERY, hToken))
      return false;

    MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(), MyAdvapi.TokenPrivileges, null, 0, dwSize);

    lpPrivileges = new Memory(dwSize.getValue());

    if (!MyAdvapi.INSTANCE.GetTokenInformation(hToken.getValue(), MyAdvapi.TokenPrivileges, lpPrivileges, dwSize.getValue(), dwSize))
    {
      return false;
    }

    MyKernel32.INSTANCE.CloseHandle(hToken.getValue());

    if (!MyAdvapi.INSTANCE.LookupPrivilegeValueA(null, lpPrivilegeName, PrivilegeLuid))
    {
      return false;
    }
View Full Code Here

      PDH_FMT_COUNTERVALUE pdhCounterValue = new PDH_FMT_COUNTERVALUE();
      pdhCounterValue.size();
      int ret = Pdhdll.INSTANCE.PdhCollectQueryData(_hQuery.getValue());
      if (ret != Pdhdll.ERROR_SUCCESS)
        System.out.println(Integer.toHexString(ret));
      PointerByReference result = new PointerByReference();
      ret = Pdhdll.INSTANCE.PdhGetFormattedCounterValue(_hCounter.getValue(), Pdhdll.PDH_FMT_DOUBLE, null, pdhCounterValue.getPointer());
      if (ret != Pdhdll.ERROR_SUCCESS)
        System.out.println(Integer.toHexString(ret));
      else
      {
View Full Code Here

      PDH_FMT_COUNTERVALUE pdhCounterValue = new PDH_FMT_COUNTERVALUE();
      pdhCounterValue.size();
      int ret = Pdhdll.INSTANCE.PdhCollectQueryData(_hQuery.getValue());
      if (ret != Pdhdll.ERROR_SUCCESS)
        System.out.println(Integer.toHexString(ret));
      PointerByReference result = new PointerByReference();
      ret = Pdhdll.INSTANCE.PdhGetFormattedCounterValue(_hCounter.getValue(), Pdhdll.PDH_FMT_LONG, null, pdhCounterValue.getPointer());
      if (ret != Pdhdll.ERROR_SUCCESS)
        System.out.println(Integer.toHexString(ret));
      else
      {
View Full Code Here

    }
    public Object getNativeMemory() {
        return ((JNAMemoryIO) getMemoryIO()).slice(offset).getMemory();
    }
    private static final long ptr2long(Pointer ptr) {
        return new PointerByReference(ptr).getPointer().getInt(0);
    }
View Full Code Here

            }
        }

        @Override
        public void putPointer(long offset, Pointer value) {
            PointerByReference ref = new PointerByReference(value);
            if (Platform.getPlatform().longSize() == 32) {
                putInt(offset, ref.getPointer().getInt(0));
            } else {
                putLong(offset, ref.getPointer().getLong(0));
            }
        }
View Full Code Here

                    byte[] bytes = new byte[size];
                    byteBuffer.get(bytes);
                    String message = new String(bytes);
                    if(message.length() > 0) {
                        // Get the information about the object that emitted the log statement
                        PointerByReference modulePointer = new PointerByReference();
                        PointerByReference filePointer = new PointerByReference();
                        IntByReference linePointer = new IntByReference();
                        libvlc.libvlc_log_get_context(ctx, modulePointer, filePointer, linePointer);
                        PointerByReference namePointer = new PointerByReference();
                        PointerByReference headerPointer = new PointerByReference();
                        IntByReference idPointer = new IntByReference();
                        libvlc.libvlc_log_get_object(ctx, namePointer, headerPointer, idPointer);
                        String module = getString(modulePointer);
                        String file = getString(filePointer);
                        Integer line = linePointer.getValue();
View Full Code Here

     * @param media media descriptor
     * @return track info
     */
    private List<TrackInfo> getTrackInfo(libvlc_media_t media, Set<TrackType> types) {
        Logger.debug("newGetTrackInfo(media={},types={})", media, types);
        PointerByReference tracksPointer = new PointerByReference();
        int numberOfTracks = libvlc.libvlc_media_tracks_get(media, tracksPointer);
        Logger.debug("numberOfTracks={}", numberOfTracks);
        List<TrackInfo> result = new ArrayList<TrackInfo>(numberOfTracks);
        if(numberOfTracks > 0) {
            Pointer[] tracks = tracksPointer.getValue().getPointerArray(0, numberOfTracks);
            for(Pointer track : tracks) {
                libvlc_media_track_t trackInfo = new libvlc_media_track_t(track);
                switch(libvlc_track_type_t.valueOf(trackInfo.i_type)) {
                    case libvlc_track_unknown:
                        if(types == null || types.contains(TrackType.UNKNOWN)) {
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.