use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.
the class ClassTransformer method patchInventoryPlayer.
private byte[] patchInventoryPlayer(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found InventoryPlayer Class: " + classNode.name);
MethodNode dropAllItems = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_70436_m"))) {
dropAllItems = mn;
break;
}
}
if (dropAllItems != null) {
logger.log(Level.DEBUG, " - Found dropAllItems (1/2)");
for (int i = 0; i < dropAllItems.instructions.size(); i++) {
AbstractInsnNode ain = dropAllItems.instructions.get(i);
if (ain instanceof JumpInsnNode) {
JumpInsnNode jin = (JumpInsnNode) ain;
if (jin.getOpcode() == Opcodes.IFNE) {
AbstractInsnNode before = dropAllItems.instructions.get(i - 1);
if (before instanceof MethodInsnNode && ((MethodInsnNode) before).name.equals(MCPNames.method("func_190926_b"))) {
LabelNode l0 = jin.label;
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new VarInsnNode(ILOAD, 3));
toInsert.add(new VarInsnNode(ALOAD, 4));
toInsert.add(new MethodInsnNode(Opcodes.INVOKESTATIC, asmHandler, "shouldPlayerDrop", "(Lnet/minecraft/entity/player/InventoryPlayer;ILnet/minecraft/item/ItemStack;)Z", false));
toInsert.add(new JumpInsnNode(IFEQ, l0));
dropAllItems.instructions.insert(jin, toInsert);
i += 5;
logger.log(Level.DEBUG, " - Patched dropAllItems (2/2)");
}
}
}
}
}
CustomClassWriter writer = new CustomClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.LabelNode in project CodeChickenLib by Chicken-Bones.
the class ASMBlock method mergeLabels.
/**
* Pulls all common labels from other into this
* @return this
*/
public ASMBlock mergeLabels(ASMBlock other) {
if (labels.isEmpty() || other.labels.isEmpty())
return this;
// common labels, give them our nodes
HashMap<LabelNode, LabelNode> labelMap = list.identityLabelMap();
for (Entry<String, LabelNode> entry : other.labels.entrySet()) {
LabelNode old = labels.get(entry.getKey());
if (old != null)
labelMap.put(old, entry.getValue());
}
HashSet<LabelNode> usedLabels = new HashSet<LabelNode>();
for (AbstractInsnNode insn = other.list.list.getFirst(); insn != null; insn = insn.getNext()) if (insn.getType() == LABEL)
usedLabels.add((LabelNode) insn);
replaceLabels(labelMap, usedLabels);
return this;
}
use of org.objectweb.asm.tree.LabelNode in project spring-loaded by spring-projects.
the class TypeDiffComputer method sameLookupSwitchInsn.
@SuppressWarnings("unchecked")
private static boolean sameLookupSwitchInsn(AbstractInsnNode o, AbstractInsnNode n) {
if (!(n instanceof LookupSwitchInsnNode)) {
return false;
}
LookupSwitchInsnNode lsio = (LookupSwitchInsnNode) o;
LookupSwitchInsnNode lsin = (LookupSwitchInsnNode) n;
if (sameLabels(lsio.dflt, lsin.dflt)) {
return false;
}
List<Integer> keyso = lsio.keys;
List<Integer> keysn = lsin.keys;
if (keyso.size() != keysn.size()) {
return false;
}
for (int i = 0, max = keyso.size(); i < max; i++) {
if (keyso.get(i) != keysn.get(i)) {
return false;
}
}
List<LabelNode> labelso = lsio.labels;
List<LabelNode> labelsn = lsin.labels;
if (labelso.size() != labelsn.size()) {
return false;
}
for (int i = 0, max = labelso.size(); i < max; i++) {
if (!sameLabelNode(labelso.get(i), labelsn.get(i))) {
return false;
}
}
return true;
}
use of org.objectweb.asm.tree.LabelNode in project pinpoint by naver.
the class ASMMethodVariables method initLocalVariables.
// new method only.
public void initLocalVariables(final InsnList instructions) {
// find enter & exit instruction.
final LabelNode variableStartLabelNode = new LabelNode();
final LabelNode variableEndLabelNode = new LabelNode();
if (instructions.getFirst() != null) {
instructions.insertBefore(instructions.getFirst(), variableStartLabelNode);
} else {
instructions.insert(variableStartLabelNode);
}
instructions.insert(instructions.getLast(), variableEndLabelNode);
if (!isStatic()) {
addLocalVariable("this", Type.getObjectType(this.declaringClassInternalName).getDescriptor(), variableStartLabelNode, variableEndLabelNode);
}
for (Type type : this.argumentTypes) {
addLocalVariable(JavaAssistUtils.javaClassNameToVariableName(type.getClassName()), type.getDescriptor(), variableStartLabelNode, variableEndLabelNode);
}
}
use of org.objectweb.asm.tree.LabelNode in project maple-ir by LLVM-but-worse.
the class LookupSwitchInsnNodeSerializer method deserialize.
@Override
public LookupSwitchInsnNode deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject jsonObject = (JsonObject) json;
LabelNode dflt = context.deserialize(jsonObject.get("dflt"), LabelNode.class);
List<Integer> keysList = context.deserialize(jsonObject.get("keys"), List.class);
List<LabelNode> labelsList = context.deserialize(jsonObject.get("labels"), List.class);
int[] keys = new int[keysList.size()];
for (int i = 0; i < keys.length; i++) {
keys[i] = keysList.get(i);
}
LabelNode[] labels = new LabelNode[labelsList.size()];
for (int i = 0; i < labels.length; i++) {
labels[i] = labelsList.get(i);
}
return new LookupSwitchInsnNode(dflt, keys, labels);
}
Aggregations