-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBytecodeDowngrader.java
More file actions
39 lines (33 loc) · 1.45 KB
/
BytecodeDowngrader.java
File metadata and controls
39 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import org.objectweb.asm.*;
import java.io.*;
import java.nio.file.*;
public class BytecodeDowngrader {
public static void downgradeClass(String inputPath, String outputPath) throws IOException {
byte[] classBytes = Files.readAllBytes(Paths.get(inputPath));
ClassReader reader = new ClassReader(classBytes);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor versionChanger = new ClassVisitor(Opcodes.ASM9, writer) {
@Override
public void visit(int version, int access, String name,
String signature, String superName, String[] interfaces) {
super.visit(Opcodes.V1_3, access, name, signature, superName, interfaces);
}
};
reader.accept(versionChanger, ClassReader.SKIP_FRAMES);
Files.write(Paths.get(outputPath), writer.toByteArray());
}
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("Usage: java BytecodeDowngrader <input.class> <output.class>");
System.exit(1);
}
try {
downgradeClass(args[0], args[1]);
System.out.println("Successfully downgraded bytecode to Java 1.3 (version 47)");
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
System.exit(1);
}
}
}