Skip to content

Commit

Permalink
add version info to manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jun 18, 2024
1 parent 5ca2d3d commit f4bb4a2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class DowngradeJar : Jar(), DowngradeFlags {
)
}

inputFile.asFile.get().toPath().readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp ->
tempOutput.toPath().readZipInputStreamFor("META-INF/MANIFEST.MF", false) { inp ->
// write to temp file
val inpTmp = temporaryDir.toPath().resolve("input-manifest.MF")
inpTmp.outputStream(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING).use { out ->
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/xyz/wagyourtail/jvmdg/cli/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Set;

public class Flags {
public static final String jvmdgVersion = Flags.class.getPackage().getImplementationVersion();

public int classVersion = Opcodes.V1_8;
public File api = null;
public boolean quiet = Boolean.getBoolean(Constants.QUIET);
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/xyz/wagyourtail/jvmdg/compile/PathDowngrader.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package xyz.wagyourtail.jvmdg.compile;

import xyz.wagyourtail.jvmdg.ClassDowngrader;
import xyz.wagyourtail.jvmdg.cli.Flags;
import xyz.wagyourtail.jvmdg.util.*;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.instrument.IllegalClassFormatException;
import java.net.URL;
import java.net.URLClassLoader;
Expand All @@ -16,6 +18,8 @@
import java.util.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.atomic.AtomicReference;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

public class PathDowngrader {

Expand Down Expand Up @@ -118,6 +122,17 @@ public byte[] apply(String s) {
throw new IOException("Failed to downgrade " + path, e);
}
}
} else if (path.toString().equals("META-INF/MANIFEST.MF")) {
// add version number to manifest
try(InputStream is = Files.newInputStream(path)) {
Manifest manifest = new Manifest(is);
Attributes attr = manifest.getMainAttributes();
attr.put("JvmDowngrader-Version", Flags.jvmdgVersion);

try (OutputStream os = Files.newOutputStream(outFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
manifest.write(os);
}
}
} else {
// strip signatures since downgraded classes will not have the same signatures
if (path.toString().startsWith("META-INF/") && (path.toString().endsWith(".SF") || path.toString().endsWith(".DSA") || path.toString().endsWith(".RSA"))) {
Expand Down

0 comments on commit f4bb4a2

Please sign in to comment.