use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ReplaceVariable method getReplacements.
/**
* Retrieve the set of variables that have the same type and are in scope
*
* @param node
* @return
*/
private Map<String, InsnList> getReplacements(MethodNode mn, String className, AbstractInsnNode node, Frame frame) {
Map<String, InsnList> variables = new HashMap<String, InsnList>();
if (node instanceof VarInsnNode) {
VarInsnNode var = (VarInsnNode) node;
try {
LocalVariableNode origVar = getLocal(mn, node, var.var);
// LocalVariableNode origVar = (LocalVariableNode) mn.localVariables.get(var.var);
logger.debug("Looking for replacements for " + origVar.name + " of type " + origVar.desc + " at index " + origVar.index);
// FIXXME: ASM gets scopes wrong, so we only use primitive vars?
// if (!origVar.desc.startsWith("L"))
variables.putAll(getLocalReplacements(mn, origVar.desc, node, frame));
variables.putAll(getFieldReplacements(mn, className, origVar.desc, node));
} catch (VariableNotFoundException e) {
logger.info("Could not find variable, not replacing it: " + var.var);
Iterator<?> it = mn.localVariables.iterator();
while (it.hasNext()) {
LocalVariableNode n = (LocalVariableNode) it.next();
logger.info(n.index + ": " + n.name);
}
logger.info(e.toString());
e.printStackTrace();
}
} else if (node instanceof FieldInsnNode) {
FieldInsnNode field = (FieldInsnNode) node;
if (field.owner.replace('/', '.').equals(className)) {
logger.info("Looking for replacements for static field " + field.name + " of type " + field.desc);
variables.putAll(getLocalReplacements(mn, field.desc, node, frame));
variables.putAll(getFieldReplacements(mn, className, field.desc, node));
}
} else if (node instanceof IincInsnNode) {
IincInsnNode incNode = (IincInsnNode) node;
try {
LocalVariableNode origVar = getLocal(mn, node, incNode.var);
variables.putAll(getLocalReplacementsInc(mn, origVar.desc, incNode, frame));
} catch (VariableNotFoundException e) {
logger.info("Could not find variable, not replacing it: " + incNode.var);
}
} else {
// throw new RuntimeException("Unknown type: " + node);
}
return variables;
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class ReplaceArithmeticOperator method getNextIndex.
/**
* <p>getNextIndex</p>
*
* @param mn a {@link org.objectweb.asm.tree.MethodNode} object.
* @return a int.
*/
@SuppressWarnings("rawtypes")
public static int getNextIndex(MethodNode mn) {
Iterator it = mn.localVariables.iterator();
int max = 0;
int next = 0;
while (it.hasNext()) {
LocalVariableNode var = (LocalVariableNode) it.next();
int index = var.index;
if (index >= max) {
max = index;
next = max + Type.getType(var.desc).getSize();
}
}
if (next == 0)
next = getNextIndexFromLoad(mn);
return next;
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method getLocal.
private LocalVariableNode getLocal(MethodNode mn, AbstractInsnNode node, int index) throws VariableNotFoundException {
int currentId = mn.instructions.indexOf(node);
for (Object v : mn.localVariables) {
LocalVariableNode localVar = (LocalVariableNode) v;
int startId = mn.instructions.indexOf(localVar.start);
int endId = mn.instructions.indexOf(localVar.end);
if (currentId >= startId && currentId <= endId && localVar.index == index)
return localVar;
}
throw new VariableNotFoundException("Could not find local variable " + index + " at position " + currentId + ", have variables: " + mn.localVariables.size());
}
use of org.objectweb.asm.tree.LocalVariableNode in project evosuite by EvoSuite.
the class InsertUnaryOperator method getName.
private String getName(MethodNode mn, AbstractInsnNode node) throws VariableNotFoundException {
if (node instanceof VarInsnNode) {
LocalVariableNode var = getLocal(mn, node, ((VarInsnNode) node).var);
return var.name;
} else if (node instanceof FieldInsnNode) {
return ((FieldInsnNode) node).name;
} else if (node instanceof IincInsnNode) {
IincInsnNode incNode = (IincInsnNode) node;
LocalVariableNode var = getLocal(mn, node, incNode.var);
return var.name;
} else {
throw new RuntimeException("Unknown variable node: " + node);
}
}
use of org.objectweb.asm.tree.LocalVariableNode in project DynamicSurroundings by OreCruncher.
the class SoundCrashFixStreamThread method transmorgrify.
@Override
public boolean transmorgrify(final ClassNode cn) {
final String name = "run";
final String sig = "()V";
final MethodNode m = findMethod(cn, sig, name);
if (m != null) {
logMethod(Transformer.log(), m, "Found!");
for (final Iterator<?> iterator = m.instructions.iterator(); iterator.hasNext(); ) {
AbstractInsnNode insn = (AbstractInsnNode) iterator.next();
if (insn instanceof MethodInsnNode && ((MethodInsnNode) insn).owner.equals("java/util/ListIterator") && ((MethodInsnNode) insn).name.equals("next")) {
insn = insn.getNext().getNext();
final LocalVariableNode var = findLocalVariable(m, "src");
if (var != null) {
m.instructions.insert(insn, new VarInsnNode(Opcodes.ASTORE, var.index));
m.instructions.insert(insn, new MethodInsnNode(Opcodes.INVOKESTATIC, "org/blockartistry/DynSurround/client/sound/fix/SoundFixMethods", "removeSource", "(Lpaulscode/sound/Source;)Lpaulscode/sound/Source;", false));
m.instructions.insert(insn, new VarInsnNode(Opcodes.ALOAD, var.index));
return true;
}
}
}
} else {
Transformer.log().error("Unable to locate method {}{}", name, sig);
}
Transformer.log().info("Unable to patch [{}]!", getClassName());
return false;
}
Aggregations