use of org.objectweb.asm.tree.LocalVariableNode in project soot by Sable.
the class AsmMethodSource method getLocal.
private Local getLocal(int idx) {
if (idx >= maxLocals)
throw new IllegalArgumentException("Invalid local index: " + idx);
Integer i = idx;
Local l = locals.get(i);
if (l == null) {
String name;
if (localVars != null) {
name = null;
for (LocalVariableNode lvn : localVars) {
if (lvn.index == idx) {
name = lvn.name;
break;
}
}
/* normally for try-catch blocks */
if (name == null)
name = "l" + idx;
} else {
name = "l" + idx;
}
l = Jimple.v().newLocal(name, UnknownType.v());
locals.put(i, l);
}
return l;
}
use of org.objectweb.asm.tree.LocalVariableNode in project bytecode-viewer by Konloch.
the class ASMResourceUtil method renameClassNode.
public static void renameClassNode(final String oldName, final String newName) {
for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (InnerClassNode oo : c.innerClasses) {
if (oo.innerName != null && oo.innerName.equals(oldName))
oo.innerName = newName;
if (oo.name.equals(oldName))
oo.name = newName;
if (oo.outerName != null && oo.outerName.equals(oldName))
oo.outerName = newName;
}
if (c.signature != null)
c.signature = c.signature.replace(oldName, newName);
if (c.superName.equals(oldName))
c.superName = newName;
for (Object o : c.fields.toArray()) {
FieldNode f = (FieldNode) o;
f.desc = f.desc.replace(oldName, newName);
}
for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o;
if (m.localVariables != null)
for (LocalVariableNode node : m.localVariables) node.desc = node.desc.replace(oldName, newName);
if (m.signature != null)
m.signature = m.signature.replace(oldName, newName);
for (int i = 0; i < m.exceptions.size(); i++) if (m.exceptions.get(i).equals(oldName))
m.exceptions.set(i, newName);
for (AbstractInsnNode i : m.instructions.toArray()) {
if (i instanceof TypeInsnNode) {
TypeInsnNode t = (TypeInsnNode) i;
if (t.desc.equals(oldName))
t.desc = newName;
}
if (i instanceof MethodInsnNode) {
MethodInsnNode mi = (MethodInsnNode) i;
if (mi.owner.equals(oldName))
mi.owner = newName;
mi.desc = mi.desc.replace(oldName, newName);
}
if (i instanceof FieldInsnNode) {
FieldInsnNode fi = (FieldInsnNode) i;
if (fi.owner.equals(oldName))
fi.owner = newName;
fi.desc = fi.desc.replace(oldName, newName);
}
}
}
}
}
use of org.objectweb.asm.tree.LocalVariableNode in project Random-Things by lumien231.
the class ClassTransformer method patchEntityRenderer.
private byte[] patchEntityRenderer(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found EntityRenderer Class: " + classNode.name);
MethodNode renderRainSnow = null;
MethodNode addRainParticles = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_78474_d"))) {
renderRainSnow = mn;
} else if (mn.name.equals(MCPNames.method("func_78484_h"))) {
addRainParticles = mn;
}
}
if (renderRainSnow != null) {
logger.log(Level.DEBUG, "- Found renderRainSnow");
VarInsnNode insnPoint = null;
for (int i = 0; i < renderRainSnow.instructions.size(); i++) {
AbstractInsnNode ain = renderRainSnow.instructions.get(i);
if (ain instanceof MethodInsnNode) {
MethodInsnNode min = (MethodInsnNode) ain;
if (min.name.equals(MCPNames.method("func_76738_d"))) {
logger.log(Level.DEBUG, "- Found canRain");
insnPoint = (VarInsnNode) renderRainSnow.instructions.get(i - 1);
}
if (min.name.equals(MCPNames.method("func_76746_c"))) {
logger.log(Level.DEBUG, "- Found getEnableSnow");
int jumpCounter = i + 1;
int worldIndex = 5;
int blockPosIndex = 21;
// Optifine Why :'(
for (LocalVariableNode lv : renderRainSnow.localVariables) {
if (lv.desc.equals("Lnet/minecraft/client/multiplayer/WorldClient;") || lv.desc.equals("Lnet/minecraft/world/World;")) {
worldIndex = lv.index;
} else if (lv.desc.equals("Lnet/minecraft/util/math/BlockPos$MutableBlockPos;")) {
blockPosIndex = lv.index;
}
}
AbstractInsnNode jumpNode;
while (!((jumpNode = renderRainSnow.instructions.get(jumpCounter)) instanceof JumpInsnNode)) {
jumpCounter++;
}
JumpInsnNode jin = (JumpInsnNode) jumpNode;
LabelNode labelNode = jin.label;
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, worldIndex));
toInsert.add(new VarInsnNode(ALOAD, blockPosIndex));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRain", "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Z", false));
toInsert.add(new JumpInsnNode(IFEQ, labelNode));
renderRainSnow.instructions.insertBefore(insnPoint, toInsert);
i += 4;
}
}
}
}
if (addRainParticles != null) {
logger.log(Level.DEBUG, "- Found addRainParticles");
for (int i = 0; i < addRainParticles.instructions.size(); i++) {
AbstractInsnNode ain = addRainParticles.instructions.get(i);
if (ain instanceof JumpInsnNode) {
JumpInsnNode jin = (JumpInsnNode) ain;
if (jin.getOpcode() == Opcodes.IF_ICMPGT) {
LabelNode jumpTarget = jin.label;
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 3));
toInsert.add(new VarInsnNode(ALOAD, 15));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRain", "(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)Z", false));
toInsert.add(new JumpInsnNode(IFEQ, jumpTarget));
addRainParticles.instructions.insert(jin, toInsert);
break;
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.LocalVariableNode in project cassandra by apache.
the class MonitorMethodTransformer method reset.
void reset(Label start, Label end) {
instructions.clear();
tryCatchBlocks.clear();
if (visibleLocalVariableAnnotations != null)
visibleLocalVariableAnnotations.clear();
if (invisibleLocalVariableAnnotations != null)
invisibleLocalVariableAnnotations.clear();
Type[] args = Type.getArgumentTypes(desc);
// remove all local variables that aren't parameters and the `this` parameter
maxLocals = args.length == 1 && Type.VOID_TYPE.equals(args[0]) ? 0 : args.length;
if (isInstanceMethod)
++maxLocals;
// sort our local variables and remove those that aren't parameters
localVariables.sort(Comparator.comparingInt(c -> c.index));
ListIterator<LocalVariableNode> it = localVariables.listIterator();
while (it.hasNext()) {
LocalVariableNode cur = it.next();
if (cur.index >= maxLocals) {
it.remove();
} else {
it.set(new LocalVariableNode(cur.name, cur.desc, cur.signature, getLabelNode(start), getLabelNode(end), cur.index));
switch(cur.desc.charAt(0)) {
case 'J':
case 'D':
// doubles and longs take two local variable positions
++maxLocals;
}
}
}
// save the number of pure-parameters for use elsewhere
maxLocalParams = maxLocals;
}
use of org.objectweb.asm.tree.LocalVariableNode in project pinpoint by naver.
the class ASMMethodVariables method addLocalVariable.
int addLocalVariable(final String name, final String desc, final LabelNode start, final LabelNode end) {
int index = this.nextLocals;
this.nextLocals += 1;
final LocalVariableNode node = new LocalVariableNode(name, desc, null, start, end, index);
this.methodNode.localVariables.add(node);
return index;
}
Aggregations