use of org.objectweb.asm.tree.AbstractInsnNode in project Random-Things by lumien231.
the class ClassTransformer method patchVillageChurch.
private byte[] patchVillageChurch(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found VillagePiece Church Class: " + classNode.name);
MethodNode addComponentParts = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_74875_a"))) {
addComponentParts = mn;
}
}
if (addComponentParts != null) {
logger.log(Level.DEBUG, " - Found addComponentParts");
for (int i = 0; i < addComponentParts.instructions.size(); i++) {
AbstractInsnNode ain = addComponentParts.instructions.get(i);
if (ain instanceof InsnNode) {
InsnNode in = (InsnNode) ain;
if (in.getOpcode() == Opcodes.IRETURN) {
logger.log(Level.DEBUG, " - Patched addComponentParts");
AbstractInsnNode before = addComponentParts.instructions.get(i - 1);
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 1));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 2));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 3));
toInsert.add(new VarInsnNode(Opcodes.ALOAD, 0));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "lumien/randomthings/worldgen/WorldGenPeaceCandle", "addComponentParts", "(Lnet/minecraft/world/World;Ljava/util/Random;Lnet/minecraft/world/gen/structure/StructureBoundingBox;Lnet/minecraft/world/gen/structure/StructureVillagePieces$Church;)V", false));
i += 5;
addComponentParts.instructions.insertBefore(before, toInsert);
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.AbstractInsnNode in project openj9 by eclipse.
the class ClassFileCompare method compareInstructions.
private void compareInstructions(ClassNode clazz1, MethodNode method1, ClassNode clazz2, MethodNode method2) {
if (nullCheck(method1.instructions, method2.instructions, "Instructions (" + method1.name + ")")) {
return;
}
if (method1.instructions.size() != method2.instructions.size()) {
reportDifference("Method " + method1.name + ": instructions differ: " + method1.instructions.size() + ", " + method2.instructions.size());
} else {
@SuppressWarnings("unchecked") Iterator<AbstractInsnNode> iter1 = method1.instructions.iterator();
@SuppressWarnings("unchecked") Iterator<AbstractInsnNode> iter2 = method2.instructions.iterator();
int index = 0;
while (iter1.hasNext()) {
AbstractInsnNode instruction1 = iter1.next();
AbstractInsnNode instruction2 = iter2.next();
if (instruction1.getOpcode() != instruction2.getOpcode()) {
/* Check for J9 opcode mapping */
compareJ9OpcodeMapping(clazz2, method2, instruction1, instruction2, index);
} else {
switch(instruction1.getType()) {
case INSN:
/* Do nothing */
break;
case INT_INSN:
compare(((IntInsnNode) instruction1).operand, ((IntInsnNode) instruction2).operand, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
break;
case VAR_INSN:
compare(((VarInsnNode) instruction1).var, ((VarInsnNode) instruction2).var, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
break;
case TYPE_INSN:
compare(((TypeInsnNode) instruction1).desc, ((TypeInsnNode) instruction2).desc, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
break;
case FIELD_INSN:
{
FieldInsnNode fieldInsn1 = (FieldInsnNode) instruction1;
FieldInsnNode fieldInsn2 = (FieldInsnNode) instruction2;
compare(fieldInsn1.owner, fieldInsn2.owner, "Owning class name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
compare(fieldInsn1.name, fieldInsn2.name, "Field name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
compare(fieldInsn1.desc, fieldInsn2.desc, "Descriptor of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
break;
}
case METHOD_INSN:
{
MethodInsnNode methodInsn1 = (MethodInsnNode) instruction1;
MethodInsnNode methodInsn2 = (MethodInsnNode) instruction2;
compare(methodInsn1.owner, methodInsn2.owner, "Owning class name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
compare(methodInsn1.name, methodInsn2.name, "Method name of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
compare(methodInsn1.desc, methodInsn2.desc, "Descriptor of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
break;
}
case INVOKE_DYNAMIC_INSN:
compareInvokeDynamic((InvokeDynamicInsnNode) instruction1, (InvokeDynamicInsnNode) instruction2, method1, index);
break;
case JUMP_INSN:
compare(method1, ((JumpInsnNode) instruction1).label, method2, ((JumpInsnNode) instruction2).label, "Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
break;
case LABEL:
/* Do nothing */
break;
case LDC_INSN:
if (!((LdcInsnNode) instruction1).cst.equals(((LdcInsnNode) instruction2).cst)) {
reportDifference("Operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") differ: " + ((LdcInsnNode) instruction1).cst + ", " + ((LdcInsnNode) instruction2).cst);
}
break;
case IINC_INSN:
{
IincInsnNode iincInsn1 = (IincInsnNode) instruction1;
IincInsnNode iincInsn2 = (IincInsnNode) instruction2;
compare(iincInsn1.var, iincInsn2.var, "Variable operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
compare(iincInsn1.incr, iincInsn2.incr, "Increment operands of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
break;
}
case TABLESWITCH_INSN:
{
TableSwitchInsnNode tableSwitchInsn1 = (TableSwitchInsnNode) instruction1;
TableSwitchInsnNode tableSwitchInsn2 = (TableSwitchInsnNode) instruction2;
compare(tableSwitchInsn1.min, tableSwitchInsn2.min, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") minimum key value", false);
compare(tableSwitchInsn1.max, tableSwitchInsn2.max, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") maximum key value", false);
compare(method1, tableSwitchInsn1.dflt, method2, tableSwitchInsn2.dflt, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") default_handler_block");
compareLabels(method1, tableSwitchInsn1.labels, method2, tableSwitchInsn2.labels, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") handler_blocks");
break;
}
case LOOKUPSWITCH_INSN:
{
LookupSwitchInsnNode lookupSwitchInsn1 = (LookupSwitchInsnNode) instruction1;
LookupSwitchInsnNode lookupSwitchInsn2 = (LookupSwitchInsnNode) instruction2;
compare(method1, lookupSwitchInsn1.dflt, method2, lookupSwitchInsn2.dflt, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") default_handler_block");
compare(lookupSwitchInsn1.keys, lookupSwitchInsn2.keys, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") key values");
compareLabels(method1, lookupSwitchInsn1.labels, method2, lookupSwitchInsn2.labels, Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ") handler_blocks");
break;
}
case MULTIANEWARRAY_INSN:
{
MultiANewArrayInsnNode arrayInsn1 = (MultiANewArrayInsnNode) instruction1;
MultiANewArrayInsnNode arrayInsn2 = (MultiANewArrayInsnNode) instruction2;
compare(arrayInsn1.desc, arrayInsn2.desc, "Desc operand of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")");
compare(arrayInsn1.dims, arrayInsn2.dims, "Dimension operand of " + Printer.OPCODES[instruction1.getOpcode()] + " (" + method1.name + ":" + index + ")", false);
break;
}
case FRAME:
{
FrameNode frameInsn1 = (FrameNode) instruction1;
FrameNode frameInsn2 = (FrameNode) instruction2;
compare(frameInsn1.type, frameInsn2.type, "Stack map frame (" + method1.name + ":" + index + ") frame type", false);
compareFrames(frameInsn1.local, frameInsn2.local, "Stack map frame (" + method1.name + ":" + index + ") types of the local variables");
compareFrames(frameInsn1.stack, frameInsn2.stack, "Stack map frame (" + method1.name + ":" + index + ") types of the operand stack elements");
}
break;
case LINE:
{
assert shouldCompareDebugInfo;
LineNumberNode lineInsn1 = (LineNumberNode) instruction1;
LineNumberNode lineInsn2 = (LineNumberNode) instruction2;
compare(lineInsn1.line, lineInsn2.line, "Line number (" + method1.name + ":" + index + ") line No.", false);
compare(method1, lineInsn1.start, method2, lineInsn2.start, "Line number (" + method1.name + ":" + index + ") offset of the 1st instruction");
break;
}
default:
assert false;
}
}
index++;
}
}
}
use of org.objectweb.asm.tree.AbstractInsnNode in project Galacticraft by micdoodle8.
the class InsnComparator method getImportantList.
public static InsnListSection getImportantList(InsnListSection list) {
if (list.size() == 0) {
return list;
}
Set<LabelNode> controlFlowLabels = getControlFlowLabels(list);
Map<LabelNode, LabelNode> labelMap = Maps.asMap(controlFlowLabels, new Function<LabelNode, LabelNode>() {
@Override
public LabelNode apply(LabelNode input) {
return input;
}
});
InsnListSection importantNodeList = new InsnListSection();
for (AbstractInsnNode insn : list) {
if (insnImportant(insn, controlFlowLabels)) {
importantNodeList.add(insn.clone(labelMap));
}
}
return importantNodeList;
}
use of org.objectweb.asm.tree.AbstractInsnNode 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.AbstractInsnNode in project DynamicSurroundings by OreCruncher.
the class PatchSoundManagerPlayTime method transmorgrify.
@Override
public boolean transmorgrify(final ClassNode cn) {
final String[] names = { "playSound", "func_148611_c" };
final String sig = "(Lnet/minecraft/client/audio/ISound;)V";
final MethodNode m = findMethod(cn, sig, names);
if (m != null) {
logMethod(Transformer.log(), m, "Found!");
for (int i = 0; i < m.instructions.size(); i++) {
final AbstractInsnNode node = m.instructions.get(i);
if (node instanceof IntInsnNode) {
final IntInsnNode intNode = (IntInsnNode) node;
if (intNode.operand == 20) {
m.instructions.set(node, new IntInsnNode(Opcodes.BIPUSH, 0));
return true;
}
}
}
} else {
Transformer.log().error("Unable to locate method {}{}", names[0], sig);
}
Transformer.log().info("Unable to patch [{}]!", getClassName());
return false;
}
Aggregations