Beispiel #1
0
 void expand(File jar, File dir) throws IOException {
   JarFile jarFile = new JarFile(jar);
   try {
     Enumeration<JarEntry> entries = jarFile.entries();
     while (entries.hasMoreElements()) {
       JarEntry je = entries.nextElement();
       if (!je.isDirectory()) {
         copy(jarFile.getInputStream(je), new File(dir, je.getName()));
       }
     }
   } finally {
     jarFile.close();
   }
 }
Beispiel #2
0
  public static void unzipInteralZip(
      ClassLoader classLoader, String resourcePath, File libDir, boolean debug) {
    if (debug) System.out.println("Extracting " + resourcePath);
    libDir.mkdir();
    URL resource = classLoader.getResource(resourcePath);
    if (resource == null) {
      System.err.println("Could not find the " + resourcePath + " on classpath!");
      System.exit(1);
    }
    class PrintDot extends TimerTask {
      public void run() {
        System.out.print(".");
      }
    }
    Timer timer = new Timer();
    PrintDot task = new PrintDot();
    timer.schedule(task, 0, 2000);

    try {

      BufferedInputStream bis = new BufferedInputStream(resource.openStream());
      JarInputStream jis = new JarInputStream(bis);
      JarEntry je = null;
      while ((je = jis.getNextJarEntry()) != null) {
        java.io.File f =
            new java.io.File(libDir.toString() + java.io.File.separator + je.getName());
        if (je.isDirectory()) {
          f.mkdir();
          continue;
        }
        File parentDir = new File(f.getParent());
        if (!parentDir.exists()) {
          parentDir.mkdir();
        }
        FileOutputStream fileOutStream = new FileOutputStream(f);
        writeStreamTo(jis, fileOutStream, 8 * KB);
        if (f.getPath().endsWith("pack.gz")) {
          unpack(f);
          fileOutStream.close();
          f.delete();
        }
      }

    } catch (Exception exc) {
      task.cancel();
      exc.printStackTrace();
    }
    task.cancel();
  }
Beispiel #3
0
  /**
   * Enables to get the name of an object in the spoken language thanks to the jar file
   *
   * @param jarName the file that contains the object classes
   * @return the object name in the spoken language
   */
  private String getLangName(File jarName) {
    String name = null;

    try {
      URL url = jarName.toURI().toURL();
      JarInputStream jarFile = new JarInputStream(url.openStream());
      JarEntry jarEntry = jarFile.getNextJarEntry();
      while (jarEntry != null) {
        if (!jarEntry.isDirectory()
            && jarEntry.getName().contains(Configuration.instance().getLanguage())) {
          int lang_index = jarEntry.getName().lastIndexOf(Configuration.instance().getLanguage());
          name = jarEntry.getName().substring(lang_index + 3, jarEntry.getName().length() - 6);
        }
        jarEntry = jarFile.getNextJarEntry();
      }
    } catch (Exception e) {
      LOG.error("Error getLangName " + jarName + " " + e);
    }
    return name;
  }
  /**
   * This method scans to see which entry we're parsing and keeps various state information
   * depending on what type of file is being parsed.
   */
  public void beginEntry(JarEntry je, ManifestEntryVerifier mev) throws IOException {
    if (je == null) return;

    if (debug != null) {
      debug.println("beginEntry " + je.getName());
    }

    String name = je.getName();

    /*
     * Assumptions:
     * 1. The manifest should be the first entry in the META-INF directory.
     * 2. The .SF/.DSA/.EC files follow the manifest, before any normal entries
     * 3. Any of the following will throw a SecurityException:
     *    a. digest mismatch between a manifest section and
     *       the SF section.
     *    b. digest mismatch between the actual jar entry and the manifest
     */

    if (parsingMeta) {
      String uname = name.toUpperCase(Locale.ENGLISH);
      if ((uname.startsWith("META-INF/") || uname.startsWith("/META-INF/"))) {

        if (je.isDirectory()) {
          mev.setEntry(null, je);
          return;
        }

        if (uname.equals(JarFile.MANIFEST_NAME) || uname.equals(JarIndex.INDEX_NAME)) {
          return;
        }

        if (SignatureFileVerifier.isBlockOrSF(uname)) {
          /* We parse only DSA, RSA or EC PKCS7 blocks. */
          parsingBlockOrSF = true;
          baos.reset();
          mev.setEntry(null, je);
          return;
        }

        // If a META-INF entry is not MF or block or SF, they should
        // be normal entries. According to 2 above, no more block or
        // SF will appear. Let's doneWithMeta.
      }
    }

    if (parsingMeta) {
      doneWithMeta();
    }

    if (je.isDirectory()) {
      mev.setEntry(null, je);
      return;
    }

    // be liberal in what you accept. If the name starts with ./, remove
    // it as we internally canonicalize it with out the ./.
    if (name.startsWith("./")) name = name.substring(2);

    // be liberal in what you accept. If the name starts with /, remove
    // it as we internally canonicalize it with out the /.
    if (name.startsWith("/")) name = name.substring(1);

    // only set the jev object for entries that have a signature
    // (either verified or not)
    if (sigFileSigners.get(name) != null || verifiedSigners.get(name) != null) {
      mev.setEntry(name, je);
      return;
    }

    // don't compute the digest for this entry
    mev.setEntry(null, je);

    return;
  }