本文整理汇总了Java中org.objectweb.asm.tree.InsnNode类的典型用法代码示例。如果您正苦于以下问题:Java InsnNode类的具体用法?Java InsnNode怎么用?Java InsnNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InsnNode类属于org.objectweb.asm.tree包,在下文中一共展示了InsnNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visit
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
@Override
public void visit(UnOp node) {
if (node.op() == UnOp.Op.NOT) {
il.add(new VarInsnNode(ALOAD, slot(node.arg())));
il.add(ConversionMethods.booleanValueOf());
il.add(new InsnNode(ICONST_1));
il.add(new InsnNode(IXOR));
il.add(BoxedPrimitivesMethods.box(Type.BOOLEAN_TYPE, Type.getType(Boolean.class)));
} else {
ResumptionPoint rp = newResumptionPoint();
il.add(rp.save());
il.add(loadExecutionContext());
il.add(new VarInsnNode(ALOAD, slot(node.arg())));
il.add(DispatchMethods.dynamic(dispatchMethodName(node.op()), 1));
il.add(rp.resume());
il.add(retrieve_0());
}
il.add(new VarInsnNode(ASTORE, slot(node.dest())));
}
示例2: staticCpuWithdraw
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
private void staticCpuWithdraw(int cost) {
switch (context.compilerSettings.cpuAccountingMode()) {
case NO_CPU_ACCOUNTING: {
// no-op
break;
}
case IN_EVERY_BASIC_BLOCK: {
ResumptionPoint rp = newResumptionPoint();
il.add(rp.save());
il.add(loadExecutionContext());
il.add(new InsnNode(DUP));
il.add(ASMUtils.loadInt(cost));
il.add(ExecutionContextMethods.registerTicks());
il.add(ExecutionContextMethods.checkCallYield());
il.add(rp.resume());
break;
}
default:
throw new UnsupportedOperationException(
"Unsupported CPU accounting mode: " + context.compilerSettings.cpuAccountingMode());
}
}
示例3: resumptionHandler
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
protected InsnList resumptionHandler(LabelNode label) {
InsnList il = new InsnList();
il.add(label);
il.add(ASMUtils.frameSame1(UnresolvedControlThrowable.class));
il.add(createSnapshot());
// register snapshot with the control exception
il.add(new MethodInsnNode(
INVOKEVIRTUAL,
Type.getInternalName(UnresolvedControlThrowable.class),
"resolve",
Type.getMethodType(
Type.getType(ResolvedControlThrowable.class),
Type.getType(Resumable.class),
Type.getType(Object.class)).getDescriptor(),
false));
// rethrow
il.add(new InsnNode(ATHROW));
return il;
}
示例4: transform
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
@Override
public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) {
method.tryCatchBlocks.clear();
method.localVariables.clear();
method.instructions.clear();
/* this.loginHandlerList.put(SteamIdAsString, loginHandler); */
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0));
method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "com/wurmonline/server/steam/SteamHandler", "loginHandlerList", "Ljava/util/Map;"));
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1));
method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2));
method.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true));
method.instructions.add(new InsnNode(Opcodes.POP));
/* return true; */
method.instructions.add(new InsnNode(Opcodes.ICONST_1));
method.instructions.add(new InsnNode(Opcodes.IRETURN));
}
示例5: loadInt
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
public static AbstractInsnNode loadInt(int i) {
switch (i) {
case -1: return new InsnNode(ICONST_M1);
case 0: return new InsnNode(ICONST_0);
case 1: return new InsnNode(ICONST_1);
case 2: return new InsnNode(ICONST_2);
case 3: return new InsnNode(ICONST_3);
case 4: return new InsnNode(ICONST_4);
case 5: return new InsnNode(ICONST_5);
default: {
if (i >= Byte.MIN_VALUE && i <= Byte.MAX_VALUE) return new IntInsnNode(BIPUSH, i);
else if (i >= Short.MIN_VALUE && i <= Short.MAX_VALUE) return new IntInsnNode(SIPUSH, i);
else return new LdcInsnNode(i);
}
}
}
示例6: convertArrayLoadInsn
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
private void convertArrayLoadInsn(InsnNode insn) {
StackFrame frame = getFrame(insn);
Operand[] out = frame.out();
Operand opr;
if (out == null) {
Operand indx = popImmediate();
Operand base = popImmediate();
ArrayRef ar = Jimple.v().newArrayRef(
base.stackOrValue(), indx.stackOrValue());
indx.addBox(ar.getIndexBox());
base.addBox(ar.getBaseBox());
opr = new Operand(insn, ar);
frame.in(indx, base);
frame.boxes(ar.getIndexBox(), ar.getBaseBox());
frame.out(opr);
} else {
opr = out[0];
frame.mergeIn(pop(), pop());
}
int op = insn.getOpcode();
if (op == DALOAD || op == LALOAD)
pushDual(opr);
else
push(opr);
}
示例7: convertArrayStoreInsn
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
private void convertArrayStoreInsn(InsnNode insn) {
int op = insn.getOpcode();
boolean dword = op == LASTORE || op == DASTORE;
StackFrame frame = getFrame(insn);
if (!units.containsKey(insn)) {
Operand valu = dword ? popImmediateDual() : popImmediate();
Operand indx = popImmediate();
Operand base = popLocal();
ArrayRef ar = Jimple.v().newArrayRef(
base.stackOrValue(), indx.stackOrValue());
indx.addBox(ar.getIndexBox());
base.addBox(ar.getBaseBox());
AssignStmt as = Jimple.v().newAssignStmt(ar, valu.stackOrValue());
valu.addBox(as.getRightOpBox());
frame.in(valu, indx, base);
frame.boxes(as.getRightOpBox(),
ar.getIndexBox(), ar.getBaseBox());
setUnit(insn, as);
} else {
frame.mergeIn(dword ? popDual() : pop(), pop(), pop());
}
}
示例8: testNonEmptyFilter
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
/** Test. */
@Test
public void testNonEmptyFilter() throws Exception {
final String className = SampleClass.class.getName();
IMethodFilter filter = new EmptyMethodFilter();
MethodNode methodNode;
methodNode = new MethodNode();
methodNode.instructions = new InsnList();
methodNode.instructions.add(new InsnNode(Opcodes.NOP));
methodNode.maxLocals = 0;
methodNode.maxStack = 0;
assertFalse(analyze(filter, className, "empty", "()V", methodNode));
methodNode = new MethodNode();
methodNode.instructions = new InsnList();
methodNode.instructions.add(new InsnNode(Opcodes.ICONST_1));
methodNode.instructions.add(new InsnNode(Opcodes.IRETURN));
methodNode.maxLocals = 0;
methodNode.maxStack = 1;
assertTrue(analyze(filter, className, "returnTrue", "()Z", methodNode));
}
示例9: getDefaultLdcNode
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
static AbstractInsnNode getDefaultLdcNode(Type type) {
switch (type.getSort()) {
case Type.INT:
return getIntNode(0);
case Type.BOOLEAN:
return new LdcInsnNode(false);
case Type.BYTE:
return new LdcInsnNode((byte) 0);
case Type.SHORT:
return new LdcInsnNode((short) 0);
case Type.LONG:
return new LdcInsnNode(0L);
case Type.FLOAT:
return new LdcInsnNode(0F);
case Type.DOUBLE:
return new LdcInsnNode(0D);
case Type.CHAR:
return new LdcInsnNode((char) 0);
default:
return new InsnNode(ACONST_NULL);
}
}
示例10: markClinitCallback
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
public static void markClinitCallback(ClassNode node, Runnable... runnables) {
callback_mapping.get(node.name).addAll(Arrays.asList(runnables));
for (String i : node.interfaces)
if (i.equals(CALLBACK_FLAG_DESC))
return;
node.interfaces.add(CALLBACK_FLAG_DESC);
MethodNode clinit = null;
for (MethodNode method : node.methods)
if (method.name.equals("<clinit>")) {
clinit = method;
break;
}
boolean flag = clinit == null;
if (flag)
node.methods.add(clinit = new MethodNode(0, "<clinit>", "()V", null, null));
InsnList list = new InsnList();
list.add(new LdcInsnNode(node.name));
list.add(new MethodInsnNode(INVOKESTATIC, "index/alchemy/core/asm/transformer/AlchemyTransformerManager",
"callback", "(Ljava/lang/String;)V", false));
if (flag)
list.add(new InsnNode(RETURN));
clinit.instructions.insert(list);
}
示例11: transform
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
ClassReader reader = new ClassReader(basicClass);
ClassNode node = new ClassNode(ASM5);
reader.accept(node, 0);
node.methods.removeIf(m -> !m.name.equals("<init>"));
node.methods.stream()
.map(m -> m.instructions)
.peek(InsnList::clear)
.peek(l -> l.add(new VarInsnNode(ALOAD, 0)))
.peek(l -> l.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false)))
.forEach(l -> l.add(new InsnNode(RETURN)));
node.interfaces.clear();
node.superName = "java/lang/Object";
node.innerClasses.clear();
ClassWriter writer = ASMHelper.newClassWriter(0);
node.accept(writer);
return writer.toByteArray();
}
示例12: patchMenu
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
private void patchMenu(ClassNode node) {
Logger.Info("Patching menu (" + node.name + ".class)");
Iterator<MethodNode> methodNodeList = node.methods.iterator();
while (methodNodeList.hasNext()) {
MethodNode methodNode = methodNodeList.next();
// Menu swap hook
if (methodNode.name.equals("e") && methodNode.desc.equals("(II)V")) {
AbstractInsnNode first = methodNode.instructions.getFirst();
LabelNode label = new LabelNode();
methodNode.instructions.insertBefore(first, new VarInsnNode(Opcodes.ALOAD, 0));
methodNode.instructions.insertBefore(first, new MethodInsnNode(Opcodes.INVOKESTATIC, "Game/Menu", "switchList", "(Ljava/lang/Object;)Z"));
methodNode.instructions.insertBefore(first, new JumpInsnNode(Opcodes.IFGT, label));
methodNode.instructions.insertBefore(first, new InsnNode(Opcodes.RETURN));
methodNode.instructions.insertBefore(first, label);
}
}
}
示例13: hookClassVariable
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
/**
* TODO: Complete JavaDoc
*
* @param methodNode
* @param owner The class of the variable to be hooked
* @param var The variable to be hooked
* @param desc
* @param newClass The class the hooked variable will be stored in
* @param newVar The variable name the hooked variable will be stored in
* @param newDesc
* @param canRead Specifies if the hooked variable should be readable
* @param canWrite Specifies if the hooked variable should be writable
*/
private void hookClassVariable(MethodNode methodNode, String owner, String var, String desc, String newClass, String newVar, String newDesc, boolean canRead,
boolean canWrite) {
Iterator<AbstractInsnNode> insnNodeList = methodNode.instructions.iterator();
while (insnNodeList.hasNext()) {
AbstractInsnNode insnNode = insnNodeList.next();
int opcode = insnNode.getOpcode();
if (opcode == Opcodes.GETFIELD || opcode == Opcodes.PUTFIELD) {
FieldInsnNode field = (FieldInsnNode)insnNode;
if (field.owner.equals(owner) && field.name.equals(var) && field.desc.equals(desc)) {
if (opcode == Opcodes.GETFIELD && canWrite) {
methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.GETSTATIC, newClass, newVar, newDesc));
methodNode.instructions.insert(insnNode, new InsnNode(Opcodes.POP));
} else if (opcode == Opcodes.PUTFIELD && canRead) {
methodNode.instructions.insertBefore(insnNode, new InsnNode(Opcodes.DUP_X1));
methodNode.instructions.insert(insnNode, new FieldInsnNode(Opcodes.PUTSTATIC, newClass, newVar, newDesc));
}
}
}
}
}
示例14: returnNode
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
public static void returnNode(ListIterator<AbstractInsnNode> iterator, String paramType) {
//(Ljava/lang/String;IDCBSJZF)V
if ("I".equals(paramType)
|| "C".equals(paramType)
|| "B".equals(paramType)
|| "S".equals(paramType)
|| "Z".equals(paramType)
) {
iterator.add(new InsnNode(Opcodes.IRETURN));
} else if ("J".equals(paramType)) {
iterator.add(new InsnNode(Opcodes.LRETURN));
} else if ("F".equals(paramType)) {
iterator.add(new InsnNode(Opcodes.FRETURN));
} else if ("D".equals(paramType)) {
iterator.add(new InsnNode(Opcodes.DRETURN));
} else if ("V".equals(paramType)) {
iterator.add(new InsnNode(Opcodes.RETURN));
} else {
iterator.add(new InsnNode(Opcodes.ARETURN));
}
}
示例15: addObfuscatedLong
import org.objectweb.asm.tree.InsnNode; //导入依赖的package包/类
private void addObfuscatedLong(ListIterator<AbstractInsnNode> iterator, long l) {
boolean negative = l < 0;
iterator.add(
new LdcInsnNode
(
negative?-l:l
)
);
int val = ((rand.nextInt(10) + 1) * 2) + (negative?1:0);
for(int i = 0; i < val; i++)
iterator.add(
new InsnNode
(
LNEG
)
);
}