use of org.objectweb.asm.tree.LdcInsnNode in project evosuite by EvoSuite.
the class CastClassAnalyzer method handleMethodNode.
/**
* Add all possible calls for a given method
*
* @param mn
*/
@SuppressWarnings("unchecked")
public void handleMethodNode(ClassNode cn, MethodNode mn, int depth) {
if (mn.signature != null) {
logger.debug("Visiting signature: " + mn.signature);
CollectParameterTypesVisitor visitor = new CollectParameterTypesVisitor(cn.name);
new SignatureReader(mn.signature).accept(visitor);
for (Type castType : visitor.getClasses()) {
if (!castClassMap.containsKey(castType)) {
logger.debug("Adding new cast class from signature visitor: " + castType);
castClassMap.put(castType, depth + 1);
}
}
}
InsnList instructions = mn.instructions;
Iterator<AbstractInsnNode> iterator = instructions.iterator();
// TODO: This really shouldn't be here but in its own class
while (iterator.hasNext()) {
AbstractInsnNode insn = iterator.next();
if (insn.getOpcode() == Opcodes.CHECKCAST) {
TypeInsnNode typeNode = (TypeInsnNode) insn;
Type castType = Type.getObjectType(typeNode.desc);
while (castType.getSort() == Type.ARRAY) {
castType = castType.getElementType();
}
logger.debug("Adding new cast class from cast: " + castType);
if (!castClassMap.containsKey(castType))
castClassMap.put(castType, depth + 1);
} else if (insn.getOpcode() == Opcodes.INSTANCEOF) {
TypeInsnNode typeNode = (TypeInsnNode) insn;
Type castType = Type.getObjectType(typeNode.desc);
while (castType.getSort() == Type.ARRAY) {
castType = castType.getElementType();
}
logger.debug("Adding new cast class from instanceof: " + castType);
if (!castClassMap.containsKey(castType))
castClassMap.put(castType, depth + 1);
} else if (insn.getOpcode() == Opcodes.LDC) {
LdcInsnNode ldcNode = (LdcInsnNode) insn;
if (ldcNode.cst instanceof Type) {
Type type = (Type) ldcNode.cst;
while (type.getSort() == Type.ARRAY) {
type = type.getElementType();
}
if (!castClassMap.containsKey(type))
castClassMap.put(type, depth + 1);
}
}
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project Random-Things by lumien231.
the class ClassTransformer method patchEntityLivingBase.
private byte[] patchEntityLivingBase(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found EntityLivingBase Class: " + classNode.name);
MethodNode updatePotionEffects = null;
MethodNode travel = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_70679_bo"))) {
updatePotionEffects = mn;
} else if (mn.name.equals(MCPNames.method("func_191986_a"))) {
travel = mn;
}
}
if (updatePotionEffects != null) {
logger.log(Level.DEBUG, "- Found updatePotionEffects (1/2)");
for (int i = 0; i < updatePotionEffects.instructions.size(); i++) {
AbstractInsnNode ain = updatePotionEffects.instructions.get(i);
if (ain instanceof FieldInsnNode) {
FieldInsnNode fin = (FieldInsnNode) ain;
if (fin.name.equals(MCPNames.field("field_70180_af"))) {
AbstractInsnNode aload = updatePotionEffects.instructions.get(i - 1);
InsnList toInsert = new InsnList();
LabelNode l1 = new LabelNode(new Label());
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldRenderPotionParticles", "(Lnet/minecraft/entity/EntityLivingBase;)Z", false));
toInsert.add(new JumpInsnNode(IFGT, l1));
toInsert.add(new InsnNode(RETURN));
toInsert.add(l1);
updatePotionEffects.instructions.insertBefore(aload, toInsert);
break;
}
}
}
}
if (travel != null) {
logger.log(Level.DEBUG, "- Found travel (2/2)");
for (int i = 0; i < travel.instructions.size(); i++) {
AbstractInsnNode ain = travel.instructions.get(i);
if (ain instanceof LdcInsnNode) {
LdcInsnNode lin = (LdcInsnNode) ain;
if (lin.cst.equals(new Float("0.91"))) {
AbstractInsnNode next = travel.instructions.get(i + 1);
if (next.getOpcode() == Opcodes.FMUL) {
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new FieldInsnNode(GETFIELD, "net/minecraft/entity/EntityLivingBase", MCPNames.field("field_70170_p"), "Lnet/minecraft/world/World;"));
toInsert.add(new VarInsnNode(ALOAD, 5));
toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/world/World", MCPNames.method("func_180495_p"), "(Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/block/state/IBlockState;", false));
toInsert.add(new MethodInsnNode(INVOKEINTERFACE, "net/minecraft/block/state/IBlockState", MCPNames.method("func_177230_c"), "()Lnet/minecraft/block/Block;", true));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "slipFix", "(FLnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/block/Block;)F", false));
travel.instructions.insert(next, toInsert);
i += 6;
}
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.LdcInsnNode in project Random-Things by lumien231.
the class ClassTransformer method patchRenderItem.
private byte[] patchRenderItem(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found RenderItem Class: " + classNode.name);
MethodNode renderEffect = null;
MethodNode renderItem = null;
MethodNode renderQuads = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_191966_a"))) {
renderEffect = mn;
} else if (mn.name.equals(MCPNames.method("func_180454_a")) && mn.desc.equals("(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/IBakedModel;)V")) {
renderItem = mn;
} else if (mn.name.equals(MCPNames.method("func_191970_a"))) {
renderQuads = mn;
}
}
if (renderEffect != null) {
logger.log(Level.DEBUG, "- Found renderEffect (1/3)");
renderEffect.instructions.insert(new MethodInsnNode(INVOKESTATIC, asmHandler, "preEnchantment", "()V", false));
for (int i = 0; i < renderEffect.instructions.size(); i++) {
AbstractInsnNode ain = renderEffect.instructions.get(i);
if (ain instanceof LdcInsnNode) {
LdcInsnNode lin = (LdcInsnNode) ain;
if (lin.cst.equals(new Integer(-8372020))) {
logger.log(Level.DEBUG, "- Found Texture Binding");
renderEffect.instructions.insert(lin, new MethodInsnNode(INVOKESTATIC, asmHandler, "enchantmentColorHook", "(I)I", false));
}
} else if (ain.getOpcode() == RETURN) {
renderEffect.instructions.insertBefore(ain, new MethodInsnNode(INVOKESTATIC, asmHandler, "postEnchantment", "()V", false));
i++;
}
}
}
if (renderItem != null) {
boolean found = false;
logger.log(Level.DEBUG, "- Found renderItem (2/3) (" + renderItem.desc + ")");
for (int i = 0; i < renderItem.instructions.size(); i++) {
AbstractInsnNode ain = renderItem.instructions.get(i);
if (ain instanceof MethodInsnNode) {
MethodInsnNode min = (MethodInsnNode) ain;
if (!found) {
if (min.name.equals(MCPNames.method("func_191966_a"))) {
logger.log(Level.DEBUG, "- Found renderEffect calling");
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 1));
toInsert.add(new FieldInsnNode(PUTSTATIC, asmHandler, "currentlyRendering", "Lnet/minecraft/item/ItemStack;"));
renderItem.instructions.insertBefore(min, toInsert);
toInsert = new InsnList();
toInsert.add(new InsnNode(ACONST_NULL));
toInsert.add(new FieldInsnNode(PUTSTATIC, asmHandler, "currentlyRendering", "Lnet/minecraft/item/ItemStack;"));
renderItem.instructions.insert(min, toInsert);
found = true;
}
}
if (min.name.equals(MCPNames.method("func_179022_a"))) {
LabelNode l1 = new LabelNode(new Label());
LabelNode l2 = new LabelNode(new Label());
logger.log(Level.DEBUG, "- Inserting TE Item Renderer");
InsnList insertBefore = new InsnList();
insertBefore.add(new FieldInsnNode(GETSTATIC, "lumien/randomthings/client/RandomThingsTEItemRenderer", "instance", "Llumien/randomthings/client/RandomThingsTEItemRenderer;"));
insertBefore.add(new VarInsnNode(ALOAD, 1));
insertBefore.add(new MethodInsnNode(INVOKEVIRTUAL, "lumien/randomthings/client/RandomThingsTEItemRenderer", "renderByItem", "(Lnet/minecraft/item/ItemStack;)Z", false));
insertBefore.add(new JumpInsnNode(IFEQ, l2));
insertBefore.add(new InsnNode(POP));
insertBefore.add(new InsnNode(POP));
insertBefore.add(new JumpInsnNode(GOTO, l1));
insertBefore.add(l2);
InsnList insertAfter = new InsnList();
insertAfter.add(l1);
renderItem.instructions.insertBefore(min, insertBefore);
renderItem.instructions.insert(min, insertAfter);
i += 8;
}
}
}
}
if (renderQuads != null) {
logger.log(Level.DEBUG, "- Found renderQuads (3/3) (" + renderQuads.desc + ")");
String luminousHandler = "lumien/randomthings/handler/LuminousHandler";
InsnList startInsrt = new InsnList();
startInsrt.add(new VarInsnNode(ALOAD, 4));
startInsrt.add(new VarInsnNode(ALOAD, 1));
startInsrt.add(new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookStart", "(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/BufferBuilder;)V", false));
renderQuads.instructions.insert(startInsrt);
for (int i = 0; i < renderQuads.instructions.size(); i++) {
AbstractInsnNode ain = renderQuads.instructions.get(i);
if (ain instanceof MethodInsnNode) {
MethodInsnNode min = (MethodInsnNode) ain;
if (min.name.equals("renderQuadColor")) {
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 8));
toInsert.add(new MethodInsnNode(INVOKEVIRTUAL, "net/minecraft/client/renderer/block/model/BakedQuad", MCPNames.method("func_178211_c"), "()I", false));
toInsert.add(new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookPre", "(I)V", false));
toInsert.add(new InsnNode(POP));
toInsert.add(new VarInsnNode(ALOAD, 4));
toInsert.add(new VarInsnNode(ILOAD, 9));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "getColorFromItemStack", "(Lnet/minecraft/item/ItemStack;I)I", false));
renderQuads.instructions.insertBefore(min, toInsert);
i += 7;
renderQuads.instructions.insert(min, new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookPost", "()V", false));
}
} else if (ain.getOpcode() == RETURN) {
renderQuads.instructions.insertBefore(ain, new MethodInsnNode(INVOKESTATIC, luminousHandler, "luminousHookEnd", "()V", false));
i++;
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.LdcInsnNode in project runelite by runelite.
the class InstructionDeserializer method deserialize.
@Override
public AbstractInsnNode deserialize(JsonElement var1, Type var2, JsonDeserializationContext var3) {
JsonObject var4 = (JsonObject) var1;
int var5 = var4.get("opcode").getAsInt();
if (var5 != 21 && var5 != 25 && var5 != 58 && var5 != 54 && var5 != 22 && var5 != 55) {
String var7;
String var8;
String var10;
if (var5 != 184 && var5 != 182 && var5 != 183) {
if (var5 == 18) {
try {
return new LdcInsnNode(Integer.valueOf(var4.get("cst").getAsInt()));
} catch (Exception var9) {
return new LdcInsnNode(var4.get("cst").getAsString());
}
} else if (var5 != 187 && var5 != 189) {
if (var5 != 16 && var5 != 17) {
if (var5 != 179 && var5 != 178 && var5 != 180 && var5 != 181) {
return new InsnNode(var5);
} else {
var10 = var4.get("owner").getAsString();
var7 = var4.get("name").getAsString();
var8 = var4.get("desc").getAsString();
return new FieldInsnNode(var5, var10, var7, var8);
}
} else {
return new IntInsnNode(var5, var4.get("operand").getAsInt());
}
} else {
return new TypeInsnNode(var5, var4.get("desc").getAsString());
}
} else {
var10 = var4.get("owner").getAsString();
var7 = var4.get("name").getAsString();
var8 = var4.get("desc").getAsString();
return new MethodInsnNode(var5, var10, var7, var8);
}
} else {
int var6 = var4.get("var").getAsInt();
return new VarInsnNode(var5, var6);
}
}
use of org.objectweb.asm.tree.LdcInsnNode in project bytecode-viewer by Konloch.
the class RegexInsnFinder method getInsString.
private static String getInsString(AbstractInsnNode ain) {
String insnString = "";
switch(ain.getType()) {
case AbstractInsnNode.INT_INSN:
final IntInsnNode iin = (IntInsnNode) ain;
insnString += "{" + iin.operand + "}";
break;
case AbstractInsnNode.LDC_INSN:
final LdcInsnNode lin = (LdcInsnNode) ain;
insnString += "{" + lin.cst.toString().replace("}", "\\}") + "}";
break;
case AbstractInsnNode.VAR_INSN:
final VarInsnNode vin = (VarInsnNode) ain;
insnString += "_" + vin.var;
break;
case AbstractInsnNode.IINC_INSN:
final IincInsnNode iiin = (IincInsnNode) ain;
insnString += "{" + iiin.var + "," + iiin.incr + "}";
break;
case AbstractInsnNode.FIELD_INSN:
final FieldInsnNode fin = (FieldInsnNode) ain;
insnString += "{" + fin.desc + "," + fin.owner + "," + fin.name + "}";
break;
case AbstractInsnNode.METHOD_INSN:
final MethodInsnNode min = (MethodInsnNode) ain;
insnString += "{" + min.desc + "," + min.owner + "," + min.name + "}";
break;
case AbstractInsnNode.TYPE_INSN:
final TypeInsnNode tin = (TypeInsnNode) ain;
insnString += "{" + tin.desc + "}";
break;
case AbstractInsnNode.MULTIANEWARRAY_INSN:
final MultiANewArrayInsnNode manain = (MultiANewArrayInsnNode) ain;
insnString += "{" + manain.dims + "," + manain.desc + "}";
break;
}
return insnString;
}
Aggregations