Package com.sun.jna

Examples of com.sun.jna.Memory


        public NativeArgs(String progname, String[] args) {
            //
            // Allocate some native memory to pass the args down to the native layer
            //
            argsCopy = new Memory[args.length + 2];
            argvMemory = new Memory(argsCopy.length * Pointer.SIZE);
           
            //
            // Insert the program name as argv[0]
            //
            Memory arg = new Memory(progname.length() + 4);
            arg.setString(0, progname, false);
            argsCopy[0] = arg;
           
            for (int i = 0; i < args.length; i++) {
                arg = new Memory(args[i].length() + 1);
                arg.setString(0, args[i], false);
                argsCopy[i + 1] = arg;
            }
            argvMemory.write(0, argsCopy, 0, argsCopy.length);
            argvRef = new PointerByReference(argvMemory);
            argcRef = new IntByReference(args.length + 1);
View Full Code Here


    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)
View Full Code Here

            if (readVirtualMemoryToStructure(peb.ProcessParameters, userParams))
            {
              // System.out.println("MaximumLength "+userParams.CommandLine.MaximumLength);
              if (userParams.CommandLine.MaximumLength > 0)
              {
                Memory stringBuffer = new Memory(userParams.CommandLine.MaximumLength);
                // System.out.println(""+3);
                if (readVirtualMemoryToMemory(userParams.CommandLine.Buffer, stringBuffer))
                  result = stringBuffer.getString(0, true);
              }         
             
              if (userParams.CurrentDirectoryPath.MaximumLength > 0)
              {
                Memory stringBuffer = new Memory(userParams.CurrentDirectoryPath.MaximumLength);
                if (readVirtualMemoryToMemory(userParams.CurrentDirectoryPath.Buffer, stringBuffer))
                  _workingDir = stringBuffer.getString(0, true);
              }
              if (userParams.WindowTitle.MaximumLength > 0)
              {
                Memory stringBuffer = new Memory(userParams.WindowTitle.MaximumLength);
                if (readVirtualMemoryToMemory(userParams.WindowTitle.Buffer, stringBuffer))
                  _title = stringBuffer.getString(0, true);
              }
              if (userParams.Environment != null)
              {
                // get size of environment strings
                MEMORY_BASIC_INFORMATION memInfo = new MEMORY_BASIC_INFORMATION();
                int memInfoSize = memInfo.size(); //x64 = 48, x32 = 28
                int bytesRead = MyKernel32.INSTANCE.VirtualQueryEx(hProcess.getPointer(), userParams.Environment, memInfo.getPointer(),
                    memInfoSize);
                memInfo.read();
                if (bytesRead == 0)
                {
                  _logger.warning("error getting environment in VirtualQueryEx " + Native.getLastError());
                }
                else if (MyKernel32.PAGE_NOACCESS == memInfo.Protect || MyKernel32.PAGE_EXECUTE == memInfo.Protect)
                {
                  _logger.warning("error getting environment in VirtualQueryEx no access right");
                }
                else
                {
                  long envSize = Math.min(Pointer.nativeValue(memInfo.RegionSize), 32767); //Max Size http://msdn.microsoft.com/en-us/library/ms682653%28v=vs.85%29.aspx       
                 
                  Memory mem = new Memory(envSize);
                  readProcessMemory(userParams.Environment, mem);

                  List<String> envStrings = new ArrayList<String>();
                  String env = null;
                  int l = 0;
                  while (!"".equals(env))
                  {
                    env = mem.getString(l, true);
                    if (env != null && env.length() != 0)
                    {
                      envStrings.add(env);
                      l += env.length() * 2 + 2;
                    }
View Full Code Here

            {
              // System.out.println("MaximumLength " +
              // userParams.CommandLine.MaximumLength);
              // System.out.println("Length " +
              // userParams.CommandLine.Length);
              Memory stringBuffer = new Memory(userParams.CommandLine.Length);
              // System.out.println("64 " + 3);
              if (readVirtualMemoryToMemory(userParams.CommandLine.Buffer, stringBuffer))
                result = stringBuffer.getString(0, true);
            }

          }
      }
    }
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;
    }
View Full Code Here

  {
    if (english)
      objectName = translate(objectName);
    Bag bag = new HashBag();
    int pdhStatus = Pdhdll.ERROR_SUCCESS;
    Memory szCounterListBuffer = null;
    IntByReference dwCounterListSize = new IntByReference();
    Memory szInstanceListBuffer = null;
    IntByReference dwInstanceListSize = new IntByReference();
    String szThisInstance = null;

    // Determine the required buffer size for the data.
    pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real time
        // source
        null, // local machine
        objectName, // object to enumerate
        szCounterListBuffer, // pass NULL and 0
        dwCounterListSize, // to get length required
        szInstanceListBuffer, // buffer size
        dwInstanceListSize, //
        Pdhdll.PERF_DETAIL_WIZARD, // counter detail level
        0);

    if (pdhStatus == Pdhdll.PDH_MORE_DATA)
    {
      // Allocate the buffers and try the call again.
      szCounterListBuffer = new Memory(dwCounterListSize.getValue() * 4);
      szInstanceListBuffer = new Memory((dwInstanceListSize.getValue() * 4));

      if ((szCounterListBuffer != null) && (szInstanceListBuffer != null))
      {
        pdhStatus = Pdhdll.INSTANCE.PdhEnumObjectItemsA(null, // real
            // time
            // source
            null, // local machine
            objectName, // object to enumerate
            szCounterListBuffer, // buffer to receive counter
            // list
            dwCounterListSize, szInstanceListBuffer, // buffer to
            // receive
            // instance
            // list
            dwInstanceListSize, Pdhdll.PERF_DETAIL_WIZARD, // counter
            // detail
            // level
            0);

        if (pdhStatus == Pdhdll.ERROR_SUCCESS)
        {
          // System.out.println ("Enumerating Processes:");

          // Walk the instance list. The list can contain one
          // or more null-terminated strings. The last string
          // is followed by a second null-terminator.
          int i = 0;
          for (szThisInstance = szInstanceListBuffer.getString(0); szThisInstance != null && szThisInstance.length() > 0; i += szThisInstance
              .length() + 1, szThisInstance = szInstanceListBuffer.getString(i))
          {
            // System.out.println( szThisInstance);
            bag.add(szThisInstance);

          }
View Full Code Here

    // System.out.println(">> "+ret + " " +
    // Integer.toHexString(hkey.getValue()));

    int BufferSize = 1;
    int BYTEINCREMENT = 1024;
    Memory PerfData = new Memory(BufferSize);
    PerfData.clear();
    IntByReference PBufferSize = new IntByReference();

    PBufferSize.setValue(BufferSize);

    // System.out.println("Allocating memory...");
    for (ret = Advapi32.INSTANCE.RegQueryValueExA(hkey.getValue(), "Counter", null, null, PerfData, PBufferSize); ret == Advapi32.ERROR_MORE_DATA; ret = Advapi32.INSTANCE
        .RegQueryValueExA(hkey.getValue(), "Counter", null, null, PerfData, PBufferSize))
    {

      // Get a buffer that is big enough.

      BufferSize += BYTEINCREMENT;
      PBufferSize = new IntByReference();
      PBufferSize.setValue(BufferSize);
      PerfData = new Memory(BufferSize);
      PerfData.clear();
    }
    // System.out.println("Final buffer size is " +PBufferSize.getValue());
    if (ret != Pdhdll.ERROR_SUCCESS)
      System.out.println(Integer.toHexString(ret));
    else
    {
      String key;
      String counter;
      int i = 0;
      while (i < PBufferSize.getValue())
      {
        key = PerfData.getString(i);
        i += key.length() + 1;
        counter = PerfData.getString(i);
        i += counter.length() + 1;
        // System.out.println(counter+":"+key);
        if (counter.length() > 0 && key.length() > 0)
          try
          {
View Full Code Here

  {
    readIndexMap();
    Integer index = (Integer) _indexes.get(name);
    if (index == null)
      return name;
    Memory buff = new Memory(256);
    IntByReference buffSize = new IntByReference();
    buffSize.setValue(256);
    if (Pdhdll.INSTANCE.PdhLookupPerfNameByIndexA(null, index.intValue(), buff, buffSize) == Pdhdll.ERROR_SUCCESS)
      return buff.getString(0);
    return name;
  }
View Full Code Here

      Pointer cluster = Clusapi.INSTANCE.OpenCluster(null);
      Pointer hEnum = Clusapi.INSTANCE.ClusterOpenEnum(cluster, Clusapi.CLUSTER_ENUM_GROUP);
      int dwIndex = 0;
      IntByReference lpdwType = new IntByReference();
      IntByReference lpcchName = new IntByReference();
      Memory lpszName = new Memory(256);
      lpszName.clear();
      lpcchName.setValue(256);
      int result = 0;
      do
      {
        result = Clusapi.INSTANCE.ClusterEnum(hEnum, dwIndex, lpdwType, lpszName, lpcchName);
        if (result == Clusapi.ERROR_SUCCESS)
        {
          String group = lpszName.getString(0, true);
          ClusterGroupInfo info = getGroupNodeInfo(cluster, group);
          if (info != null)
            activeNode = info.getLocation();
        }
        dwIndex++;
View Full Code Here

      if (hGroup == null)
        throw new RuntimeException("Clusapi call to OpenClusterGroup returned err code " + MyKernel32.INSTANCE.GetLastError());

      IntByReference lpcchNodeName = new IntByReference();
      Memory lpszNodeName = new Memory(256);
      lpszNodeName.clear();
      lpcchNodeName.setValue(256);

      int state = Clusapi.INSTANCE.GetClusterGroupState(hGroup, lpszNodeName, lpcchNodeName);
      String location = lpszNodeName.getString(0, true);

      if (state == Clusapi.CLUSTER_GROUP_STATE_UNKNOWN)
        _log.severe("unknown group state for group " + groupName + " err code " + MyKernel32.INSTANCE.GetLastError());

      result = new ClusterGroupInfo(groupName, state, location);
View Full Code Here

TOP

Related Classes of com.sun.jna.Memory

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.