List of usage examples for org.objectweb.asm Opcodes GETFIELD
int GETFIELD
To view the source code for org.objectweb.asm Opcodes GETFIELD.
Click Source Link
From source file:com.dank.analysis.impl.character.player.config.PlayerConfig.java
License:GNU General Public License
@Override public void evaluate(ClassNode cn) { for (final MethodNode mn : cn.methods) { // if (mn.desc.endsWith("()V")) { // for (final BasicBlock block : mn.graph()) { // if (block.count(new MemberQuery(Opcodes.PUTSTATIC, "[S")) == 2 && block.count(new MemberQuery(Opcodes.PUTSTATIC, "[[S")) == 2 && // block.count(new MemberQuery(Opcodes.GETSTATIC, "[S")) == 2 && block.count(new MemberQuery(Opcodes.GETSTATIC, "[[S")) == 2) { // System.out.println(cn.name + "." + mn.name); // FieldInsnNode fin = (FieldInsnNode) block.get(new MemberQuery(Opcodes.PUTSTATIC, "[S")); // Hook.CLIENT.put(new RSField(fin, "colorsToFind")); ///* ww w . j a v a 2 s . c o m*/ // fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 1); // Hook.CLIENT.put(new RSField(fin, "colorsToReplace")); // // fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 2); // Hook.CLIENT.put(new RSField(fin, "colorsToFind1")); // // fin = (FieldInsnNode) block.get(Opcodes.PUTSTATIC, 3); // Hook.CLIENT.put(new RSField(fin, "colorsToReplace1")); // // } // } // } if (!mn.isStatic() && !mn.desc.endsWith("V")) { for (final BasicBlock block : mn.graph()) { if (block.count(Opcodes.ILOAD) == 3 && block.count(FieldInsnNode.class) == 3) { final FieldInsnNode fin = (FieldInsnNode) block .get(new MemberQuery(Opcodes.GETFIELD, "[I")); if (fin == null) continue; Hook.PLAYER_CONFIG.put(new RSField(fin, "appearanceColors")); } } } } for (final FieldNode fn : cn.fields) { if (!fn.isStatic()) { FieldData fd = DynaFlowAnalyzer.getField(cn.name, fn.name); if (fn.desc.equals("Z")) { Hook.PLAYER_CONFIG.put(new RSField(fn, "female")); } else if (fn.desc.equals("I")) { Hook.PLAYER_CONFIG.put(new RSField(fn, "npcId")); } else if (fn.desc.equals("[I") && !fn.name.equals(Hook.PLAYER_CONFIG.get("appearanceColors").name)) { Hook.PLAYER_CONFIG.put(new RSField(fn, "appearance")); } else if (fn.desc.equals("J")) { boolean isAnimated = false; for (MethodData md : fd.referencedFrom) { if (new Wildcard("(?)V").matches(md.METHOD_DESC)) { isAnimated = true; break; } } if (isAnimated) Hook.PLAYER_CONFIG.put(new RSField(fn, "animatedModelId")); else Hook.PLAYER_CONFIG.put(new RSField(fn, "baseModelId")); } } } }
From source file:com.dank.analysis.impl.landscape.GroundItem.java
License:GNU General Public License
@Override public void evaluate(ClassNode cn) { for (final MethodNode mn : cn.methods) { if (Modifier.isStatic(mn.access) || !Modifier.isProtected(mn.access) || !mn.desc.startsWith("()L")) { continue; }//www .ja v a 2 s . c om for (final BasicBlock block : mn.graph()) { final MemberQuery query = new MemberQuery(Opcodes.GETFIELD, cn.name, "I"); FieldInsnNode fin = (FieldInsnNode) block.get(query); if (fin == null) continue; Hook.GROUND_ITEM.put(new RSField(fin, "id")); fin = (FieldInsnNode) block.getLast(query); if (fin == null) continue; Hook.GROUND_ITEM.put(new RSField(fin, "quantity")); } } }
From source file:com.dank.analysis.impl.misc.RuneScript.java
License:GNU General Public License
@Override public void evaluate(ClassNode cn) { for (final ClassNode c : getClassPath()) { for (final MethodNode mn : c.methods) { if (mn.isStatic() && mn.desc.endsWith(")" + Hook.RUNESCRIPT.getInternalDesc())) { Hook.CLIENT.put(new RSMethod(mn, "getRuneScript")); TreeBuilder.build(mn).accept(new RuneScriptVisitor()); }//w w w .j a v a 2 s . co m if (new Wildcard("(" + Hook.SCRIPT_EVENT.getInternalDesc() + "I?)V").matches(mn.desc)) { // System.out.println(TreeBuilder.build(mn)); TreeBuilder.build(mn).accept(new NodeVisitor() { @Override public void visitVariable(VariableNode node) { if (node.opcode() == Opcodes.ALOAD) { if (node.var() == 0) { FieldMemberNode fmn = (FieldMemberNode) node.preLayer(Opcodes.GETFIELD); if (fmn != null && fmn.owner().equals(Hook.SCRIPT_EVENT.getInternalName())) { } } } } }); } } } }
From source file:com.enea.jcarder.agent.instrument.StackAnalyzeMethodVisitor.java
License:GNU General Public License
public void visitFieldInsn(int opCode, String owner, String name, String desc) { mMethodVisitor.visitFieldInsn(opCode, owner, name, desc); switch (opCode) { case Opcodes.GETFIELD: pop();/*from ww w.j av a 2s. com*/ pushTextualDescription(owner + "." + name); break; case Opcodes.GETSTATIC: pushTextualDescription(owner + "." + name); break; default: clear(); } }
From source file:com.github.anba.es6draft.compiler.assembler.InstructionAssembler.java
License:Open Source License
public void getfield(Type owner, String name, Type desc) { methodVisitor.visitFieldInsn(Opcodes.GETFIELD, owner.internalName(), name, desc.descriptor()); stack.getfield(owner, desc); }
From source file:com.github.jasmo.obfuscate.InlineAccessors.java
License:Open Source License
@Override public void transform(Map<String, ClassNode> classMap) { this.classMap = classMap; for (ClassNode node : new ArrayList<>(classMap.values())) { for (FieldNode field : node.fields) { for (MethodNode method : new ArrayList<>(node.methods)) { if (isGetterFor(node, field, method)) { node.methods.remove(method); log.debug("Inlining getter {}.{}{}", node.name, method.name, method.desc); replace(Opcodes.GETFIELD, node, field, method); }/*w ww .j ava 2s .c om*/ if (isSetterFor(node, field, method)) { node.methods.remove(method); log.debug("Inlining setter {}.{}{}", node.name, method.name, method.desc); replace(Opcodes.PUTFIELD, node, field, method); } } } } }
From source file:com.github.jasmo.obfuscate.InlineAccessors.java
License:Open Source License
private Query[] getPattern(boolean get, ClassNode owner, FieldNode field) { Type type = Type.getType(field.desc); List<Query> queries = new LinkedList<>(); boolean local = local(field.access); if (local)/*w w w. j a v a2 s. c o m*/ queries.add(new Query("opcode", Opcodes.ALOAD, "var", 0)); if (get) { int opcode = local ? Opcodes.GETFIELD : Opcodes.GETSTATIC; queries.add(new Query("opcode", opcode, "owner", owner.name, "name", field.name, "desc", field.desc)); queries.add(new Query("opcode", type.getOpcode(Opcodes.IRETURN))); } else { int opcode = local ? Opcodes.PUTFIELD : Opcodes.PUTSTATIC; queries.add(new Query("opcode", type.getOpcode(Opcodes.ILOAD), "var", 0)); queries.add(new Query("opcode", opcode, "owner", owner.name, "name", field.name, "desc", field.desc)); queries.add(new Query("opcode", Opcodes.RETURN)); } return queries.toArray(new Query[queries.size()]); }
From source file:com.github.megatronking.stringfog.plugin.StringFogClassVisitor.java
License:Apache License
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); if (mv != null && !mIgnoreClass) { if ("<clinit>".equals(name)) { isClInitExists = true;/*from w w w. ja v a 2s . c o m*/ // If clinit exists meaning the static fields (not final) would have be inited here. mv = new MethodVisitor(Opcodes.ASM5, mv) { private String lastStashCst; @Override public void visitCode() { super.visitCode(); // Here init static final fields. for (ClassStringField field : mStaticFinalFields) { if (!canEncrypted(field.value)) { continue; } String originValue = field.value; String encryptValue = mStringFogImpl.encrypt(originValue, mKey); mMappingPrinter.output(getJavaClassName(), originValue, encryptValue); super.visitLdcInsn(encryptValue); super.visitMethodInsn(Opcodes.INVOKESTATIC, mFogClassName, "decrypt", "(Ljava/lang/String;)Ljava/lang/String;", false); super.visitFieldInsn(Opcodes.PUTSTATIC, mClassName, field.name, ClassStringField.STRING_DESC); } } @Override public void visitLdcInsn(Object cst) { // Here init static or static final fields, but we must check field name int 'visitFieldInsn' if (cst != null && cst instanceof String && canEncrypted((String) cst)) { lastStashCst = (String) cst; String originValue = lastStashCst; String encryptValue = mStringFogImpl.encrypt(originValue, mKey); mMappingPrinter.output(getJavaClassName(), originValue, encryptValue); super.visitLdcInsn(encryptValue); super.visitMethodInsn(Opcodes.INVOKESTATIC, mFogClassName, "decrypt", "(Ljava/lang/String;)Ljava/lang/String;", false); } else { lastStashCst = null; super.visitLdcInsn(cst); } } @Override public void visitFieldInsn(int opcode, String owner, String name, String desc) { if (mClassName.equals(owner) && lastStashCst != null) { boolean isContain = false; for (ClassStringField field : mStaticFields) { if (field.name.equals(name)) { isContain = true; break; } } if (!isContain) { for (ClassStringField field : mStaticFinalFields) { if (field.name.equals(name) && field.value == null) { field.value = lastStashCst; break; } } } } lastStashCst = null; super.visitFieldInsn(opcode, owner, name, desc); } }; } else if ("<init>".equals(name)) { // Here init final(not static) and normal fields mv = new MethodVisitor(Opcodes.ASM5, mv) { @Override public void visitLdcInsn(Object cst) { // We don't care about whether the field is final or normal if (cst != null && cst instanceof String && canEncrypted((String) cst)) { String originValue = (String) cst; String encryptValue = mStringFogImpl.encrypt(originValue, mKey); mMappingPrinter.output(getJavaClassName(), originValue, encryptValue); super.visitLdcInsn(encryptValue); super.visitMethodInsn(Opcodes.INVOKESTATIC, mFogClassName, "decrypt", "(Ljava/lang/String;)Ljava/lang/String;", false); } else { super.visitLdcInsn(cst); } } }; } else { mv = new MethodVisitor(Opcodes.ASM5, mv) { @Override public void visitLdcInsn(Object cst) { if (cst != null && cst instanceof String && canEncrypted((String) cst)) { // If the value is a static final field for (ClassStringField field : mStaticFinalFields) { if (cst.equals(field.value)) { super.visitFieldInsn(Opcodes.GETSTATIC, mClassName, field.name, ClassStringField.STRING_DESC); return; } } // If the value is a final field (not static) for (ClassStringField field : mFinalFields) { // if the value of a final field is null, we ignore it if (cst.equals(field.value)) { super.visitVarInsn(Opcodes.ALOAD, 0); super.visitFieldInsn(Opcodes.GETFIELD, mClassName, field.name, "Ljava/lang/String;"); return; } } // local variables String originValue = (String) cst; String encryptValue = mStringFogImpl.encrypt(originValue, mKey); mMappingPrinter.output(getJavaClassName(), originValue, encryptValue); super.visitLdcInsn(encryptValue); super.visitMethodInsn(Opcodes.INVOKESTATIC, mFogClassName, "decrypt", "(Ljava/lang/String;)Ljava/lang/String;", false); return; } super.visitLdcInsn(cst); } }; } } return mv; }
From source file:com.google.code.jconts.instrument.gen.AsyncMethodAdapter.java
License:Apache License
private void checkProlog() { // Generate only once (at the beginning) if (prologGenerated) { return;/* w w w. j a v a2s . com*/ } prologGenerated = true; // try...catch around the whole body. Should be added last (after all // other try..catch blocks). // Actually, we are making an assumption that reader will emit // visitTryCatchBlock BEFORE generating any bytecode. // We cannot call visitTryCatchBlock at the end since it should // be called before all its labels are visited (which we generate // in this block). mv.visitTryCatchBlock(tryLabel, dispatchLabel, catchLabel, null); // Goto to table switch dispatcher mv.visitJumpInsn(Opcodes.GOTO, dispatchLabel); // Wrap the whole original body with try...catch that will invoke // cont.setException(Throwable t) mv.visitLabel(tryLabel); // Restore the frame as it was before changing method arguments Type[] locs = info.entryLocals; Object[] frame = new Object[info.isStatic() ? locs.length : locs.length + 1]; // Frame if (!info.isStatic()) { frame[0] = info.owner; } int off = info.isStatic() ? 0 : 1; for (int i = 0; i < locs.length; ++i) { frame[off + i] = Frames.toFrameType(locs[i]); } mv.visitFrame(Opcodes.F_FULL, frame.length, frame, 0, new Object[0]); Label label = new Label(); dispatchTable.add(label); mv.visitLabel(label); if (!info.isStatic()) { locals.add(Type.getObjectType(info.owner)); } Collections.addAll(locals, locs); // Restore the original method arguments // argX = state.varX String[] names = info.entryLocalsVars; for (int i = 0; i < info.entryLocals.length; ++i) { // We go directly to target, introduced var used target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitFieldInsn(Opcodes.GETFIELD, info.stateClassName, names[i], info.entryLocals[i].getDescriptor()); mv.visitVarInsn(info.entryLocals[i].getOpcode(Opcodes.ISTORE), info.isStatic() ? i : i + 1); } }
From source file:com.google.code.jconts.instrument.gen.AsyncMethodAdapter.java
License:Apache License
@Override public void visitMethodInsn(int opcode, String owner, String name, String desc) { checkProlog();//from w w w . j av a 2s .co m if (opcode == Opcodes.INVOKESTATIC && ASYNC_NAME.equals(owner) && ARETURN_NAME.equals(name)) { if (ARETURN_VOID_DESC.equals(desc)) { mv.visitInsn(Opcodes.ACONST_NULL); } // state variable target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitFieldInsn(Opcodes.GETFIELD, info.stateClassName, CONTINUATION_FIELD, CONTINUATION_DESC); mv.visitInsn(Opcodes.SWAP); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, CONTINUATION_NAME, CONTINUATION_INVOKE_NAME, CONTINUATION_INVOKE_DESC); // Will be dropped while replacing ARETURN with RETURN. // FIXME: Should verify this value is NOT used. mv.visitInsn(Opcodes.ACONST_NULL); return; } if (opcode == Opcodes.INVOKESTATIC && ASYNC_NAME.equals(owner) && AWAIT_NAME.equals(name) && AWAIT_DESC.equals(desc)) { // Computation<T> is on stack // FIXME: ... // if (stack.size() != 1) { // throw new IllegalStateException( // "Stack preserving is not supported!"); // } int index = dispatchTable.size(); // Save state List<Type> l = new ArrayList<Type>(locals); if (!info.isStatic()) { l.remove(0); } // state.varX = locX String[] vars = info.tracker.stateFields(l.toArray(new Type[0])); for (int i = 0; i < vars.length; ++i) { // state variable target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitVarInsn(l.get(i).getOpcode(Opcodes.ILOAD), i + info.thisOffset); mv.visitFieldInsn(Opcodes.PUTFIELD, info.stateClassName, vars[i], l.get(i).getDescriptor()); } // Create instance of continuation // new Continuation([this, ]state, index); mv.visitTypeInsn(Opcodes.NEW, info.continuationClassName); mv.visitInsn(Opcodes.DUP); // "this' for new Continuation([this, ]state, index) if (!info.isStatic()) { mv.visitVarInsn(Opcodes.ALOAD, 0); } // state and index target.visitVarInsn(Opcodes.ALOAD, 0 + info.thisOffset); mv.visitIntInsn(Opcodes.BIPUSH, index); String ctorDesc; if (info.isStatic()) { ctorDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { info.stateType, Type.INT_TYPE }); } else { ctorDesc = Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] { Type.getObjectType(info.owner), info.stateType, Type.INT_TYPE }); } mv.visitMethodInsn(Opcodes.INVOKESPECIAL, info.continuationClassName, CTOR_NAME, ctorDesc); mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, COMPUTATION_NAME, COMPUTATION_EXECUTE_NAME, COMPUTATION_EXECUTE_DESC); super.visitInsn(Opcodes.RETURN); // Restore state // mv.visitFrame(Opcodes.F_SAME, 0, new Object[0], 0, new // Object[0]); Label label = new Label(); int invokeIndex = dispatchTable.size(); dispatchTable.add(label); // for invoke dispatchTable.add(label); // for setException mv.visitLabel(label); for (int i = 0; i < vars.length; ++i) { // state variable target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitFieldInsn(Opcodes.GETFIELD, info.stateClassName, vars[i], l.get(i).getDescriptor()); mv.visitVarInsn(l.get(i).getOpcode(Opcodes.ISTORE), i + info.thisOffset); } // if (index == invokeIndex) goto invokeLabel; Label invokeLabel = new Label(); target.visitVarInsn(Opcodes.ILOAD, 1 + info.thisOffset); mv.visitIntInsn(Opcodes.BIPUSH, invokeIndex); mv.visitJumpInsn(Opcodes.IF_ICMPEQ, invokeLabel); // Throw exception target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitFieldInsn(Opcodes.GETFIELD, info.stateClassName, "exception", THROWABLE_DESC); mv.visitInsn(Opcodes.ATHROW); // Push result value // invokeLabel: mv.visitLabel(invokeLabel); target.visitVarInsn(Opcodes.ALOAD, info.isStatic() ? 0 : 1); mv.visitFieldInsn(Opcodes.GETFIELD, info.stateClassName, "result", OBJECT_DESC); return; } super.visitMethodInsn(opcode, owner, name, desc); }