Skip to content

Commit 27a1699

Browse files
committed
Add 'LVT' lvt naming, verbose format of lvt_{index}_{version}_ useful in debugging.
1 parent ee4b460 commit 27a1699

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

src/main/java/de/oceanlabs/mcp/mcinjector/LVTNaming.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public enum LVTNaming
44
{
55
STRIP,
6-
FERNFLOWER
6+
FERNFLOWER,
7+
LVT
78
}

src/main/java/de/oceanlabs/mcp/mcinjector/MCInjectorImpl.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import de.oceanlabs.mcp.mcinjector.adaptors.GenerateMap;
4646
import de.oceanlabs.mcp.mcinjector.adaptors.JsonAttribute;
4747
import de.oceanlabs.mcp.mcinjector.adaptors.LVTFernflower;
48+
import de.oceanlabs.mcp.mcinjector.adaptors.LVTLvt;
4849
import de.oceanlabs.mcp.mcinjector.adaptors.LVTStrip;
4950
import de.oceanlabs.mcp.mcinjector.adaptors.ReadMarker;
5051

@@ -618,6 +619,7 @@ public byte[] processClass(byte[] cls, boolean readOnly)
618619
{
619620
case STRIP: ca = new LVTStrip (ca, this); break;
620621
case FERNFLOWER: ca = new LVTFernflower(ca, this); break;
622+
case LVT: ca = new LVTLvt (ca, this); break;
621623
}
622624

623625
ca = new JsonAttribute(ca, this);
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package de.oceanlabs.mcp.mcinjector.adaptors;
2+
3+
import java.util.Collections;
4+
import java.util.Comparator;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.logging.Logger;
8+
9+
import org.objectweb.asm.ClassVisitor;
10+
import org.objectweb.asm.MethodVisitor;
11+
import org.objectweb.asm.Opcodes;
12+
import org.objectweb.asm.tree.LocalVariableNode;
13+
import org.objectweb.asm.tree.MethodNode;
14+
15+
import de.oceanlabs.mcp.mcinjector.MCInjectorImpl;
16+
17+
public class LVTLvt extends ClassVisitor
18+
{
19+
private static final Logger log = Logger.getLogger("MCInjector");
20+
//private MCInjectorImpl mci;
21+
String className;
22+
23+
public LVTLvt(ClassVisitor cn, MCInjectorImpl mci)
24+
{
25+
super(Opcodes.ASM5, cn);
26+
//this.mci = mci;
27+
}
28+
29+
@Override
30+
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)
31+
{
32+
this.className = name;
33+
super.visit(version, access, name, signature, superName, interfaces);
34+
}
35+
36+
@Override
37+
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
38+
{
39+
return new MethodVisitor(api, cv.visitMethod(access, name, desc, signature, exceptions))
40+
{
41+
@Override
42+
public void visitEnd()
43+
{
44+
super.visitEnd();
45+
final MethodNode mn = MCInjectorImpl.getMethodNode(mv);
46+
if (mn.localVariables != null && mn.localVariables.size() > 0)
47+
{
48+
Collections.sort(mn.localVariables, new Comparator<LocalVariableNode>()
49+
{
50+
@Override
51+
public int compare(LocalVariableNode o1, LocalVariableNode o2)
52+
{
53+
if (o1.index < o2.index) return -1;
54+
if (o1.index > o2.index) return 1;
55+
int o1Start = mn.instructions.indexOf(o1.start);
56+
int o2Start = mn.instructions.indexOf(o2.start);
57+
if (o1Start < o2Start) return -1;
58+
if (o2Start > o2Start) return 1;
59+
return 0;
60+
}
61+
62+
});
63+
64+
Map<Integer, Integer> vers = new HashMap<Integer, Integer>();
65+
for (LocalVariableNode lvn : mn.localVariables)
66+
{
67+
if (0x2603 != lvn.name.charAt(0)) // Snowmen, added in 1.8.2? rename them
68+
continue;
69+
int ver = 0;
70+
if (vers.containsKey(lvn.index))
71+
{
72+
ver = vers.get(lvn.index);
73+
vers.put(lvn.index, ver + 1);
74+
}
75+
else
76+
{
77+
ver = 1;
78+
vers.put(lvn.index, 2);
79+
}
80+
String name = "lvt_" + lvn.index + "_" + ver + "_";
81+
log.info(" Renaming LVT: " + lvn.index + " " + lvn.name + " " + lvn.desc + " -> " + name);
82+
lvn.name = name;
83+
}
84+
}
85+
}
86+
};
87+
}
88+
}

0 commit comments

Comments
 (0)