use of org.objectweb.asm.tree.LabelNode in project Random-Things by lumien231.
the class ClassTransformer method patchRenderLivingBase.
private byte[] patchRenderLivingBase(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found RenderLivingBase Class: " + classNode.name);
MethodNode canRenderName = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_177070_b"))) {
canRenderName = mn;
break;
}
}
if (canRenderName != null) {
logger.log(Level.DEBUG, "- Found canRenderName (1/1)");
LabelNode l1 = new LabelNode(new Label());
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 1));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "canRenderName", "(Lnet/minecraft/entity/EntityLivingBase;)Z", false));
toInsert.add(new JumpInsnNode(IFGT, l1));
toInsert.add(new InsnNode(ICONST_0));
toInsert.add(new InsnNode(IRETURN));
toInsert.add(l1);
canRenderName.instructions.insert(toInsert);
}
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 Random-Things by lumien231.
the class ClassTransformer method patchLiquidBlock.
private byte[] patchLiquidBlock(byte[] basicClass) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(basicClass);
classReader.accept(classNode, 0);
logger.log(Level.DEBUG, "Found BlockLiquid Class: " + classNode.name);
MethodNode shouldSideBeRendered = null;
for (MethodNode mn : classNode.methods) {
if (mn.name.equals(MCPNames.method("func_176225_a"))) {
shouldSideBeRendered = mn;
break;
}
}
if (shouldSideBeRendered != null) {
logger.log(Level.DEBUG, " - Found shouldSideBeRendered (1/1)");
LabelNode l1 = new LabelNode(new Label());
InsnList toInsert = new InsnList();
toInsert.add(new VarInsnNode(ALOAD, 0));
toInsert.add(new VarInsnNode(ALOAD, 1));
toInsert.add(new VarInsnNode(ALOAD, 2));
toInsert.add(new VarInsnNode(ALOAD, 3));
toInsert.add(new MethodInsnNode(INVOKESTATIC, asmHandler, "shouldLiquidSideBeRendered", "(Lnet/minecraft/block/BlockLiquid;Lnet/minecraft/world/IBlockAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/EnumFacing;)I", false));
toInsert.add(new InsnNode(DUP));
toInsert.add(new JumpInsnNode(IFLT, l1));
toInsert.add(new InsnNode(IRETURN));
toInsert.add(l1);
toInsert.add(new InsnNode(POP));
shouldSideBeRendered.instructions.insert(toInsert);
}
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 openj9 by eclipse.
the class ClassFileCompare method compareLabels.
private void compareLabels(MethodNode method1, List<LabelNode> list1, MethodNode method2, List<LabelNode> list2, String description) {
if (nullCheck(list1, list2, description)) {
return;
}
/*
* Copy and sort label nodes by index
*/
Collections.sort(list1, labelNodeComparatorFor(method1));
Collections.sort(list2, labelNodeComparatorFor(method2));
/*
* Compare label nodes
*/
if (list1.size() != list2.size()) {
reportDifference(description + ": label nodes differ: " + list1.size() + ", " + list2.size());
} else {
Iterator<LabelNode> iter = list1.iterator();
int index = 0;
for (LabelNode labelNode2 : list2) {
LabelNode labelNode1 = iter.next();
compare(method1, labelNode1, method2, labelNode2, description + "[" + index + "]");
index++;
}
}
}
use of org.objectweb.asm.tree.LabelNode in project phosphor by gmu-swe.
the class TaintTrackingClassVisitor method generateNativeWrapper.
private void generateNativeWrapper(MethodNode m, String methodNameToCall, boolean skipUnboxing) {
String[] exceptions = new String[m.exceptions.size()];
exceptions = (String[]) m.exceptions.toArray(exceptions);
Type[] argTypes = Type.getArgumentTypes(m.desc);
boolean isPreAllocReturnType = TaintUtils.isPreAllocReturnType(m.desc);
String newDesc = "(";
LinkedList<LocalVariableNode> lvsToVisit = new LinkedList<LocalVariableNode>();
LabelNode start = new LabelNode(new Label());
LabelNode end = new LabelNode(new Label());
for (Type t : argTypes) {
if (t.getSort() == Type.ARRAY) {
if (t.getElementType().getSort() != Type.OBJECT && t.getDimensions() == 1) {
newDesc += TaintUtils.getShadowTaintType(t.getDescriptor());
}
} else if (t.getSort() != Type.OBJECT) {
newDesc += Configuration.TAINT_TAG_DESC;
}
if (t.getSort() == Type.ARRAY && t.getElementType().getSort() != Type.OBJECT && t.getDimensions() > 1)
newDesc += MultiDTaintedArray.getTypeForType(t).getDescriptor();
else
newDesc += t.getDescriptor();
}
Type origReturn = Type.getReturnType(m.desc);
Type newReturn = TaintUtils.getContainerReturnType(origReturn);
if (Configuration.IMPLICIT_TRACKING)
newDesc += Type.getDescriptor(ControlTaintTagStack.class);
if (m.name.equals("<init>"))
newDesc += Type.getDescriptor(TaintSentinel.class);
if (isPreAllocReturnType)
newDesc += newReturn.getDescriptor();
newDesc += ")" + newReturn.getDescriptor();
MethodVisitor mv;
if (m.name.equals("<init>")) {
mv = super.visitMethod(m.access & ~Opcodes.ACC_NATIVE, m.name, newDesc, m.signature, exceptions);
} else
mv = super.visitMethod(m.access & ~Opcodes.ACC_NATIVE, m.name + TaintUtils.METHOD_SUFFIX + (skipUnboxing ? "$$NOUNBOX" : ""), newDesc, m.signature, exceptions);
NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(className, m.access, m.name, newDesc, mv);
MethodVisitor soc = new SpecialOpcodeRemovingMV(an, false, className, false);
LocalVariableManager lvs = new LocalVariableManager(m.access, newDesc, soc, an, mv, generateExtraLVDebug);
lvs.setPrimitiveArrayAnalyzer(new PrimitiveArrayAnalyzer(newReturn));
GeneratorAdapter ga = new GeneratorAdapter(lvs, m.access, m.name + TaintUtils.METHOD_SUFFIX, newDesc);
if (isInterface) {
ga.visitEnd();
return;
}
ga.visitCode();
ga.visitLabel(start.getLabel());
String descToCall = m.desc;
boolean isUntaggedCall = false;
if (methodNameToCall.contains("$$PHOSPHORUNTAGGED")) {
descToCall = TaintUtils.remapMethodDescForUninst(descToCall);
isUntaggedCall = true;
}
int idx = 0;
if ((m.access & Opcodes.ACC_STATIC) == 0) {
ga.visitVarInsn(Opcodes.ALOAD, 0);
lvsToVisit.add(new LocalVariableNode("this", "L" + className + ";", null, start, end, idx));
idx++;
}
for (Type t : argTypes) {
if (t.getSort() == Type.ARRAY) {
if (t.getElementType().getSort() != Type.OBJECT && t.getDimensions() == 1) {
lvsToVisit.add(new LocalVariableNode("phosphorNativeWrapArg" + idx, TaintUtils.getShadowTaintType(t.getDescriptor()), null, start, end, idx));
idx++;
}
} else if (t.getSort() != Type.OBJECT) {
lvsToVisit.add(new LocalVariableNode("phosphorNativeWrapArg" + idx, Configuration.TAINT_TAG_DESC, null, start, end, idx));
idx++;
}
ga.visitVarInsn(t.getOpcode(Opcodes.ILOAD), idx);
lvsToVisit.add(new LocalVariableNode("phosphorNativeWrapArg" + idx, t.getDescriptor(), null, start, end, idx));
if (!skipUnboxing) {
if (t.getDescriptor().equals("[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;")) {
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MultiDTaintedArray.class), "unboxCK_ATTRIBUTE", "([Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;)[Lsun/security/pkcs11/wrapper/CK_ATTRIBUTE;", false);
} else if (t.getDescriptor().equals("Ljava/lang/Object;") || (t.getSort() == Type.ARRAY && t.getElementType().getDescriptor().equals("Ljava/lang/Object;"))) {
// Need to make sure that it's not a boxed primitive array
ga.visitInsn(Opcodes.DUP);
ga.visitInsn(Opcodes.DUP);
Label isOK = new Label();
ga.visitTypeInsn(Opcodes.INSTANCEOF, "[" + Type.getDescriptor((!Configuration.MULTI_TAINTING ? LazyArrayIntTags.class : LazyArrayObjTags.class)));
ga.visitInsn(Opcodes.SWAP);
ga.visitTypeInsn(Opcodes.INSTANCEOF, Type.getInternalName((!Configuration.MULTI_TAINTING ? LazyArrayIntTags.class : LazyArrayObjTags.class)));
ga.visitInsn(Opcodes.IOR);
ga.visitJumpInsn(Opcodes.IFEQ, isOK);
if (isUntaggedCall)
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName(MultiDTaintedArray.class), "unbox1D", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
else {
if (className.equals("sun/misc/Unsafe"))
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxRawOnly1D", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
else
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxRaw", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
}
if (t.getSort() == Type.ARRAY)
ga.visitTypeInsn(Opcodes.CHECKCAST, t.getInternalName());
FrameNode fn = TaintAdapter.getCurrentFrameNode(an);
ga.visitLabel(isOK);
TaintAdapter.acceptFn(fn, lvs);
} else if (!isUntaggedCall && t.getSort() == Type.ARRAY && t.getDimensions() > 1 && t.getElementType().getSort() != Type.OBJECT) {
// Need to unbox it!!
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "unboxRaw", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
ga.visitTypeInsn(Opcodes.CHECKCAST, t.getInternalName());
}
}
idx += t.getSize();
}
int opcode;
if ((m.access & Opcodes.ACC_STATIC) == 0) {
opcode = Opcodes.INVOKESPECIAL;
} else
opcode = Opcodes.INVOKESTATIC;
if (m.name.equals("<init>") && methodNameToCall.contains("$$PHOSPHORUNTAGGED")) {
// call with uninst sentinel
descToCall = descToCall.substring(0, descToCall.indexOf(')')) + Type.getDescriptor(UninstrumentedTaintSentinel.class) + ")" + descToCall.substring(descToCall.indexOf(')') + 1);
ga.visitInsn(Opcodes.ACONST_NULL);
ga.visitMethodInsn(opcode, className, m.name, descToCall, false);
} else
ga.visitMethodInsn(opcode, className, methodNameToCall, descToCall, false);
if (origReturn != newReturn) {
if (origReturn.getSort() == Type.ARRAY) {
if (origReturn.getDimensions() > 1) {
// System.out.println(an.stack + " > " + newReturn);
Label isOK = new Label();
ga.visitInsn(Opcodes.DUP);
ga.visitJumpInsn(Opcodes.IFNULL, isOK);
ga.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
// // public static Object[] initWithEmptyTaints(Object[] ar, int componentType, int dims) {
ga.visitIntInsn(Opcodes.BIPUSH, origReturn.getElementType().getSort());
ga.visitIntInsn(Opcodes.BIPUSH, origReturn.getDimensions());
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "initWithEmptyTaints", "([Ljava/lang/Object;II)Ljava/lang/Object;", false);
FrameNode fn = TaintAdapter.getCurrentFrameNode(an);
fn.stack.set(fn.stack.size() - 1, "java/lang/Object");
ga.visitLabel(isOK);
TaintAdapter.acceptFn(fn, lvs);
ga.visitTypeInsn(Opcodes.CHECKCAST, newReturn.getDescriptor());
} else {
TaintAdapter.createNewTaintArray(origReturn.getDescriptor(), an, lvs, lvs);
ga.visitInsn(Opcodes.SWAP);
// // ga.visitInsn(Opcodes.SWAP);
// ga.visitTypeInsn(Opcodes.NEW, newReturn.getInternalName()); //T V N
// ga.visitInsn(Opcodes.DUP_X2); //N T V N
// ga.visitInsn(Opcodes.DUP_X2); //N N T V N
// ga.visitInsn(Opcodes.POP); //N N T V
// ga.visitMethodInsn(Opcodes.INVOKESPECIAL, newReturn.getInternalName(), "<init>", "([I" + origReturn.getDescriptor() + ")V");
// int retIdx = lvs.getPreAllocedReturnTypeVar(newReturn);
// an.visitVarInsn(Opcodes.ALOAD, retIdx);
// ga.visitInsn(Opcodes.SWAP);
// ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "val", origReturn.getDescriptor());
// an.visitVarInsn(Opcodes.ALOAD, retIdx);
// ga.visitInsn(Opcodes.SWAP);
// ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "taint", Configuration.TAINT_TAG_ARRAYDESC);
// an.visitVarInsn(Opcodes.ALOAD, retIdx);
}
} else {
// TODO here's where we store to the pre-alloc'ed container
if (origReturn.getSize() == 1) {
int retIdx = lvs.getPreAllocedReturnTypeVar(newReturn);
an.visitVarInsn(Opcodes.ALOAD, retIdx);
ga.visitInsn(Opcodes.SWAP);
ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "val", origReturn.getDescriptor());
an.visitVarInsn(Opcodes.ALOAD, retIdx);
Configuration.taintTagFactory.generateEmptyTaint(ga);
Configuration.taintTagFactory.propogateTagNative(className, m.access, m.name, m.desc, mv);
ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "taint", Configuration.TAINT_TAG_DESC);
an.visitVarInsn(Opcodes.ALOAD, retIdx);
} else {
int retIdx = lvs.getPreAllocedReturnTypeVar(newReturn);
an.visitVarInsn(Opcodes.ALOAD, retIdx);
ga.visitInsn(Opcodes.DUP_X2);
ga.visitInsn(Opcodes.POP);
ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "val", origReturn.getDescriptor());
an.visitVarInsn(Opcodes.ALOAD, retIdx);
Configuration.taintTagFactory.generateEmptyTaint(ga);
Configuration.taintTagFactory.propogateTagNative(className, m.access, m.name, m.desc, mv);
ga.visitFieldInsn(Opcodes.PUTFIELD, newReturn.getInternalName(), "taint", Configuration.TAINT_TAG_DESC);
an.visitVarInsn(Opcodes.ALOAD, retIdx);
// ga.visitInsn(Opcodes.ARETURN);
}
// if (origReturn.getSize() == 1)
// ga.visitInsn(Opcodes.SWAP);
// else {
// ga.visitInsn(Opcodes.DUP_X2);
// ga.visitInsn(Opcodes.POP);
// }
// ga.visitMethodInsn(Opcodes.INVOKESTATIC, newReturn.getInternalName(), "valueOf", "(I" + origReturn.getDescriptor() + ")" + newReturn.getDescriptor());
}
} else if (origReturn.getSort() != Type.VOID && (origReturn.getDescriptor().equals("Ljava/lang/Object;") || origReturn.getDescriptor().equals("[Ljava/lang/Object;"))) {
// Check to see if the top of the stack is a primitive array, adn if so, box it.
if (!isUntaggedCall) {
ga.visitMethodInsn(Opcodes.INVOKESTATIC, Type.getInternalName((Configuration.MULTI_TAINTING ? MultiDTaintedArrayWithObjTag.class : MultiDTaintedArrayWithIntTag.class)), "boxIfNecessary", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
if (origReturn.getSort() == Type.ARRAY)
ga.visitTypeInsn(Opcodes.CHECKCAST, "[Ljava/lang/Object;");
}
}
ga.visitLabel(end.getLabel());
ga.returnValue();
if (isPreAllocReturnType) {
lvsToVisit.add(new LocalVariableNode("phosphorReturnHolder", newReturn.getDescriptor(), null, start, end, lvs.getPreAllocedReturnTypeVar(newReturn)));
}
for (LocalVariableNode n : lvsToVisit) n.accept(ga);
ga.visitMaxs(0, 0);
ga.visitEnd();
}
use of org.objectweb.asm.tree.LabelNode in project phosphor by gmu-swe.
the class LocalVariableManager method freeTmpLV.
public void freeTmpLV(int idx) {
for (TmpLV v : tmpLVs) {
if (v.idx == idx && v.inUse) {
Label lbl = new Label();
super.visitLabel(lbl);
curLocalIdxToLVNode.get(v.idx).end = new LabelNode(lbl);
v.inUse = false;
v.owner = null;
if (idx < analyzer.locals.size())
analyzer.locals.set(idx, Opcodes.TOP);
return;
}
}
// System.err.println(tmpLVs);
throw new IllegalArgumentException("asked to free tmp lv " + idx + " but couldn't find it?");
}
Aggregations