Exemple #1
0
 // ThrowSignature*
 private FieldTypeSignature[] parseZeroOrMoreThrowsSignatures() {
   List<FieldTypeSignature> ets = new ArrayList<>(3);
   while (current() == '^') {
     ets.add(parseThrowsSignature());
   }
   return ets.toArray(new FieldTypeSignature[ets.size()]);
 }
Exemple #2
0
 /** SuperclassSignature: ClassTypeSignature */
 private ClassTypeSignature[] parseSuperInterfaces() {
   List<ClassTypeSignature> cts = new ArrayList<>(5);
   while (current() == 'L') {
     cts.add(parseClassTypeSignature());
   }
   return cts.toArray(new ClassTypeSignature[cts.size()]);
 }
  public List<ReferenceType> visibleClasses() {
    List<ReferenceType> classes = null;
    try {
      Cache local = (Cache) getCache();

      if (local != null) {
        classes = local.visibleClasses;
      }
      if (classes == null) {
        JDWP.ClassLoaderReference.VisibleClasses.ClassInfo[] jdwpClasses =
            JDWP.ClassLoaderReference.VisibleClasses.process(vm, this).classes;
        classes = new ArrayList<ReferenceType>(jdwpClasses.length);
        for (int i = 0; i < jdwpClasses.length; ++i) {
          classes.add(vm.referenceType(jdwpClasses[i].typeID, jdwpClasses[i].refTypeTag));
        }
        classes = Collections.unmodifiableList(classes);
        if (local != null) {
          local.visibleClasses = classes;
          if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {
            vm.printTrace(
                description()
                    + " temporarily caching visible classes (count = "
                    + classes.size()
                    + ")");
          }
        }
      }
    } catch (JDWPException exc) {
      throw exc.toJDIException();
    }
    return classes;
  }
Exemple #4
0
 /**
  * Makes the given class visitor visit this field.
  *
  * @param cv a class visitor.
  */
 public void accept(final ClassVisitor cv) {
   FieldVisitor fv = cv.visitField(access, name, desc, signature, value);
   if (fv == null) {
     return;
   }
   int i, n;
   n = visibleAnnotations == null ? 0 : visibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = visibleAnnotations.get(i);
     an.accept(fv.visitAnnotation(an.desc, true));
   }
   n = invisibleAnnotations == null ? 0 : invisibleAnnotations.size();
   for (i = 0; i < n; ++i) {
     AnnotationNode an = invisibleAnnotations.get(i);
     an.accept(fv.visitAnnotation(an.desc, false));
   }
   n = visibleTypeAnnotations == null ? 0 : visibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = visibleTypeAnnotations.get(i);
     an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, true));
   }
   n = invisibleTypeAnnotations == null ? 0 : invisibleTypeAnnotations.size();
   for (i = 0; i < n; ++i) {
     TypeAnnotationNode an = invisibleTypeAnnotations.get(i);
     an.accept(fv.visitTypeAnnotation(an.typeRef, an.typePath, an.desc, false));
   }
   n = attrs == null ? 0 : attrs.size();
   for (i = 0; i < n; ++i) {
     fv.visitAttribute(attrs.get(i));
   }
   fv.visitEnd();
 }
Exemple #5
0
 // TypeSignature*
 private TypeSignature[] parseZeroOrMoreTypeSignatures() {
   List<TypeSignature> ts = new ArrayList<>();
   boolean stop = false;
   while (!stop) {
     switch (current()) {
       case 'B':
       case 'C':
       case 'D':
       case 'F':
       case 'I':
       case 'J':
       case 'S':
       case 'Z':
       case 'L':
       case 'T':
       case '[':
         {
           ts.add(parseTypeSignature());
           break;
         }
       default:
         stop = true;
     }
   }
   return ts.toArray(new TypeSignature[ts.size()]);
 }
 public static List<MemoryPoolMXBean> getMemoryPoolMXBeans() {
   MemoryPoolMXBean[] pools = MemoryImpl.getMemoryPools();
   List<MemoryPoolMXBean> list = new ArrayList<>(pools.length);
   for (MemoryPoolMXBean p : pools) {
     list.add(p);
   }
   return list;
 }
 public static List<MemoryManagerMXBean> getMemoryManagerMXBeans() {
   MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers();
   List<MemoryManagerMXBean> result = new ArrayList<>(mgrs.length);
   for (MemoryManagerMXBean m : mgrs) {
     result.add(m);
   }
   return result;
 }
 public static List<GarbageCollectorMXBean> getGarbageCollectorMXBeans() {
   MemoryManagerMXBean[] mgrs = MemoryImpl.getMemoryManagers();
   List<GarbageCollectorMXBean> result = new ArrayList<>(mgrs.length);
   for (MemoryManagerMXBean m : mgrs) {
     if (GarbageCollectorMXBean.class.isInstance(m)) {
       result.add(GarbageCollectorMXBean.class.cast(m));
     }
   }
   return result;
 }
Exemple #9
0
 /**
  * Checks that this field node is compatible with the given ASM API version. This methods checks
  * that this node, and all its nodes recursively, do not contain elements that were introduced in
  * more recent versions of the ASM API than the given version.
  *
  * @param api an ASM API version. Must be one of {@link Opcodes#ASM4} or {@link Opcodes#ASM5}.
  */
 public void check(final int api) {
   if (api == Opcodes.ASM4) {
     if (visibleTypeAnnotations != null && visibleTypeAnnotations.size() > 0) {
       throw new RuntimeException();
     }
     if (invisibleTypeAnnotations != null && invisibleTypeAnnotations.size() > 0) {
       throw new RuntimeException();
     }
   }
 }
 public static synchronized List<BufferPoolMXBean> getBufferPoolMXBeans() {
   if (bufferPools == null) {
     bufferPools = new ArrayList<>(2);
     bufferPools.add(
         createBufferPoolMXBean(
             j86.sun.misc.SharedSecrets.getJavaNioAccess().getDirectBufferPool()));
     bufferPools.add(createBufferPoolMXBean(j86.sun.nio.ch.FileChannelImpl.getMappedBufferPool()));
   }
   return bufferPools;
 }
 Type findType(String signature) throws ClassNotLoadedException {
   List<ReferenceType> types = visibleClasses();
   Iterator<ReferenceType> iter = types.iterator();
   while (iter.hasNext()) {
     ReferenceType type = iter.next();
     if (type.signature().equals(signature)) {
       return type;
     }
   }
   JNITypeParser parser = new JNITypeParser(signature);
   throw new ClassNotLoadedException(
       parser.typeName(), "Class " + parser.typeName() + " not loaded");
 }
Exemple #12
0
  /**
   * ClassTypeSignature: "L" PackageSpecifier_opt SimpleClassTypeSignature ClassTypeSignatureSuffix*
   * ";"
   */
  private ClassTypeSignature parseClassTypeSignature() {
    assert (current() == 'L');
    if (current() != 'L') {
      throw error("expected a class type");
    }
    advance();
    List<SimpleClassTypeSignature> scts = new ArrayList<>(5);
    scts.add(parsePackageNameAndSimpleClassTypeSignature());

    parseClassTypeSignatureSuffix(scts);
    if (current() != ';') throw error("expected ';' got '" + current() + "'");

    advance();
    return ClassTypeSignature.make(scts);
  }
Exemple #13
0
 /** TypeArguments: "<" TypeArgument+ ">" */
 private TypeArgument[] parseTypeArguments() {
   List<TypeArgument> tas = new ArrayList<>(3);
   assert (current() == '<');
   if (current() != '<') {
     throw error("expected '<'");
   }
   advance();
   tas.add(parseTypeArgument());
   while (current() != '>') {
     // (matches(current(),  '+', '-', 'L', '[', 'T', '*')) {
     tas.add(parseTypeArgument());
   }
   advance();
   return tas.toArray(new TypeArgument[tas.size()]);
 }
Exemple #14
0
 @Override
 public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
   AnnotationNode an = new AnnotationNode(desc);
   if (visible) {
     if (visibleAnnotations == null) {
       visibleAnnotations = new ArrayList<AnnotationNode>(1);
     }
     visibleAnnotations.add(an);
   } else {
     if (invisibleAnnotations == null) {
       invisibleAnnotations = new ArrayList<AnnotationNode>(1);
     }
     invisibleAnnotations.add(an);
   }
   return an;
 }
Exemple #15
0
 @Override
 public void visitAttribute(final Attribute attr) {
   if (attrs == null) {
     attrs = new ArrayList<Attribute>(1);
   }
   attrs.add(attr);
 }
Exemple #16
0
 /** FormalTypeParameters: "<" FormalTypeParameter+ ">" */
 private FormalTypeParameter[] parseFormalTypeParameters() {
   List<FormalTypeParameter> ftps = new ArrayList<>(3);
   assert (current() == '<'); // should not have been called at all
   if (current() != '<') {
     throw error("expected '<'");
   }
   advance();
   ftps.add(parseFormalTypeParameter());
   while (current() != '>') {
     int startingPosition = index;
     ftps.add(parseFormalTypeParameter());
     progress(startingPosition);
   }
   advance();
   return ftps.toArray(new FormalTypeParameter[ftps.size()]);
 }
Exemple #17
0
 /**
  * Process Win32-style command files for the specified command line arguments and return the
  * resulting arguments. A command file argument is of the form '@file' where 'file' is the name of
  * the file whose contents are to be parsed for additional arguments. The contents of the command
  * file are parsed using StreamTokenizer and the original '@file' argument replaced with the
  * resulting tokens. Recursive command files are not supported. The '@' character itself can be
  * quoted with the sequence '@@'.
  */
 public static String[] parse(String[] args) throws IOException {
   List<String> newArgs = new ArrayList<>(args.length);
   for (int i = 0; i < args.length; i++) {
     String arg = args[i];
     if (arg.length() > 1 && arg.charAt(0) == '@') {
       arg = arg.substring(1);
       if (arg.charAt(0) == '@') {
         newArgs.add(arg);
       } else {
         loadCmdFile(arg, newArgs);
       }
     } else {
       newArgs.add(arg);
     }
   }
   return newArgs.toArray(new String[newArgs.size()]);
 }
Exemple #18
0
 @Override
 public AnnotationVisitor visitTypeAnnotation(
     int typeRef, TypePath typePath, String desc, boolean visible) {
   TypeAnnotationNode an = new TypeAnnotationNode(typeRef, typePath, desc);
   if (visible) {
     if (visibleTypeAnnotations == null) {
       visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
     }
     visibleTypeAnnotations.add(an);
   } else {
     if (invisibleTypeAnnotations == null) {
       invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
     }
     invisibleTypeAnnotations.add(an);
   }
   return an;
 }
Exemple #19
0
 /**
  * Method addEncryptedKey
  *
  * @param encryptedKey
  * @throws XMLEncryptionException
  */
 public void add(EncryptedKey encryptedKey) throws XMLEncryptionException {
   if (encryptedKeys == null) {
     encryptedKeys = new ArrayList<EncryptedKey>();
   }
   encryptedKeys.add(encryptedKey);
   XMLCipher cipher = XMLCipher.getInstance();
   this.constructionElement.appendChild(cipher.martial(encryptedKey));
 }
Exemple #20
0
 /**
  * Method addX509Data
  *
  * @param x509data
  */
 public void add(X509Data x509data) {
   if (x509Datas == null) {
     x509Datas = new ArrayList<X509Data>();
   }
   x509Datas.add(x509data);
   this.constructionElement.appendChild(x509data.getElement());
   XMLUtils.addReturnToElement(this.constructionElement);
 }
Exemple #21
0
  /**
   * Method itemX509Data
   *
   * @param i
   * @return the asked X509Data element, null if the index is too big
   * @throws XMLSecurityException
   */
  public X509Data itemX509Data(int i) throws XMLSecurityException {
    if (x509Datas != null) {
      return x509Datas.get(i);
    }
    Element e =
        XMLUtils.selectDsNode(this.constructionElement.getFirstChild(), Constants._TAG_X509DATA, i);

    if (e != null) {
      return new X509Data(e, this.baseURI);
    }
    return null;
  }
Exemple #22
0
 public SoundbankResource[] getResources() {
   SoundbankResource[] resources = new SoundbankResource[layers.size() + samples.size()];
   int j = 0;
   for (int i = 0; i < layers.size(); i++) resources[j++] = layers.get(i);
   for (int i = 0; i < samples.size(); i++) resources[j++] = samples.get(i);
   return resources;
 }
Exemple #23
0
  /**
   * ClassBound: ":" FieldTypeSignature_opt
   *
   * <p>InterfaceBound: ":" FieldTypeSignature
   */
  private FieldTypeSignature[] parseBounds() {
    List<FieldTypeSignature> fts = new ArrayList<>(3);

    if (current() == ':') {
      advance();
      switch (current()) {
        case ':': // empty class bound
          break;

        default: // parse class bound
          fts.add(parseFieldTypeSignature());
      }

      // zero or more interface bounds
      while (current() == ':') {
        advance();
        fts.add(parseFieldTypeSignature());
      }
    } else error("Bound expected");

    return fts.toArray(new FieldTypeSignature[fts.size()]);
  }
Exemple #24
0
  /**
   * Returns all listeners in the map.
   *
   * @return an array of all listeners
   */
  public final synchronized L[] getListeners() {
    if (this.map == null) {
      return newArray(0);
    }
    List<L> list = new ArrayList<>();

    L[] listeners = this.map.get(null);
    if (listeners != null) {
      for (L listener : listeners) {
        list.add(listener);
      }
    }
    for (Entry<String, L[]> entry : this.map.entrySet()) {
      String name = entry.getKey();
      if (name != null) {
        for (L listener : entry.getValue()) {
          list.add(newProxy(name, listener));
        }
      }
    }
    return list.toArray(newArray(list.size()));
  }
Exemple #25
0
 private static void loadCmdFile(String name, List<String> args) throws IOException {
   Reader r = new BufferedReader(new FileReader(name));
   StreamTokenizer st = new StreamTokenizer(r);
   st.resetSyntax();
   st.wordChars(' ', 255);
   st.whitespaceChars(0, ' ');
   st.commentChar('#');
   st.quoteChar('"');
   st.quoteChar('\'');
   while (st.nextToken() != StreamTokenizer.TT_EOF) {
     args.add(st.sval);
   }
   r.close();
 }
Exemple #26
0
  /**
   * Method itemEncryptedKey
   *
   * @param i
   * @return the asked EncryptedKey element, null if the index is too big
   * @throws XMLSecurityException
   */
  public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException {
    if (encryptedKeys != null) {
      return encryptedKeys.get(i);
    }
    Element e =
        XMLUtils.selectXencNode(
            this.constructionElement.getFirstChild(), EncryptionConstants._TAG_ENCRYPTEDKEY, i);

    if (e != null) {
      XMLCipher cipher = XMLCipher.getInstance();
      cipher.init(XMLCipher.UNWRAP_MODE, null);
      return cipher.loadEncryptedKey(e);
    }
    return null;
  }
Exemple #27
0
 /**
  * Method lengthX509Data
  *
  * @return the number of the X509Data tags
  */
 public int lengthX509Data() {
   if (x509Datas != null) {
     return x509Datas.size();
   }
   return this.length(Constants.SignatureSpecNS, Constants._TAG_X509DATA);
 }
Exemple #28
0
 /** ClassTypeSignatureSuffix: "." SimpleClassTypeSignature */
 private void parseClassTypeSignatureSuffix(List<SimpleClassTypeSignature> scts) {
   while (current() == '.') {
     advance();
     scts.add(parseSimpleClassTypeSignature(true));
   }
 }
Exemple #29
0
 static {
   List<StorageResolver> list = new ArrayList<StorageResolver>(1);
   list.add(null);
   nullList = j86.java.util.Collections.unmodifiableList(list);
 }
Exemple #30
0
  /*
   * Parse a keystore domain configuration file and associated collection
   * of keystore passwords to create a collection of KeyStore.Builder.
   */
  private List<KeyStoreBuilderComponents> getBuilders(
      URI configuration, Map<String, KeyStore.ProtectionParameter> passwords) throws IOException {

    PolicyParser parser = new PolicyParser(true); // expand properties
    Collection<PolicyParser.DomainEntry> domains = null;
    List<KeyStoreBuilderComponents> builders = new ArrayList<>();
    String uriDomain = configuration.getFragment();

    try (InputStreamReader configurationReader =
        new InputStreamReader(PolicyUtil.getInputStream(configuration.toURL()), "UTF-8")) {
      parser.read(configurationReader);
      domains = parser.getDomainEntries();

    } catch (MalformedURLException mue) {
      throw new IOException(mue);

    } catch (PolicyParser.ParsingException pe) {
      throw new IOException(pe);
    }

    for (PolicyParser.DomainEntry domain : domains) {
      Map<String, String> domainProperties = domain.getProperties();

      if (uriDomain != null && (!uriDomain.equalsIgnoreCase(domain.getName()))) {
        continue; // skip this domain
      }

      if (domainProperties.containsKey(ENTRY_NAME_SEPARATOR)) {
        this.entryNameSeparator = domainProperties.get(ENTRY_NAME_SEPARATOR);
        // escape any regex meta characters
        char ch = 0;
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < this.entryNameSeparator.length(); i++) {
          ch = this.entryNameSeparator.charAt(i);
          if (REGEX_META.indexOf(ch) != -1) {
            s.append('\\');
          }
          s.append(ch);
        }
        this.entryNameSeparatorRegEx = s.toString();
      }

      Collection<PolicyParser.KeyStoreEntry> keystores = domain.getEntries();
      for (PolicyParser.KeyStoreEntry keystore : keystores) {
        String keystoreName = keystore.getName();
        Map<String, String> properties = new HashMap<>(domainProperties);
        properties.putAll(keystore.getProperties());

        String keystoreType = DEFAULT_KEYSTORE_TYPE;
        if (properties.containsKey(KEYSTORE_TYPE)) {
          keystoreType = properties.get(KEYSTORE_TYPE);
        }

        Provider keystoreProvider = null;
        if (properties.containsKey(KEYSTORE_PROVIDER_NAME)) {
          String keystoreProviderName = properties.get(KEYSTORE_PROVIDER_NAME);
          keystoreProvider = Security.getProvider(keystoreProviderName);
          if (keystoreProvider == null) {
            throw new IOException("Error locating JCE provider: " + keystoreProviderName);
          }
        }

        File keystoreFile = null;
        if (properties.containsKey(KEYSTORE_URI)) {
          String uri = properties.get(KEYSTORE_URI);

          try {
            if (uri.startsWith("file://")) {
              keystoreFile = new File(new URI(uri));
            } else {
              keystoreFile = new File(uri);
            }

          } catch (URISyntaxException | IllegalArgumentException e) {
            throw new IOException(
                "Error processing keystore property: " + "keystoreURI=\"" + uri + "\"", e);
          }
        }

        KeyStore.ProtectionParameter keystoreProtection = null;
        if (passwords.containsKey(keystoreName)) {
          keystoreProtection = passwords.get(keystoreName);

        } else if (properties.containsKey(KEYSTORE_PASSWORD_ENV)) {
          String env = properties.get(KEYSTORE_PASSWORD_ENV);
          String pwd = System.getenv(env);
          if (pwd != null) {
            keystoreProtection = new KeyStore.PasswordProtection(pwd.toCharArray());
          } else {
            throw new IOException(
                "Error processing keystore property: " + "keystorePasswordEnv=\"" + env + "\"");
          }
        } else {
          keystoreProtection = new KeyStore.PasswordProtection(null);
        }

        builders.add(
            new KeyStoreBuilderComponents(
                keystoreName, keystoreType, keystoreProvider, keystoreFile, keystoreProtection));
      }
      break; // skip other domains
    }
    if (builders.isEmpty()) {
      throw new IOException("Error locating domain configuration data " + "for: " + configuration);
    }

    return builders;
  }