Java Code Examples for org.objectweb.asm.Opcodes#ACC_STATIC

The following examples show how to use org.objectweb.asm.Opcodes#ACC_STATIC . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTFClassVisitor.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * this method is called for each method presented in the visited class.
 * 
 * @param
 * 
 * @return void
 */

public MethodVisitor visitMethod(int access, String name, String desc,
		String signature, String[] exceptions) {

	if (jobClassList == null) {
		jobClassList = new ArrayList<String>();
	}
	if (name.equalsIgnoreCase("main")
			&& access == Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC
			&& desc.equals("([Ljava/lang/String;)V")) {
		className = className.replace(FULLY_QUALIFIED_CLASS_SEPARATOR, DOT);
		logger.debug("Job class  : " + className);
		jobClassList.add(className);
	}
	return cv.visitMethod(access, name, desc, signature, exceptions);
}
 
Example 2
Source File: GeneratorAdapter.java    From Concurnas with MIT License 5 votes vote down vote up
/**
 * Returns the index of the given method argument in the frame's local variables array.
 *
 * @param arg the index of a method argument.
 * @return the index of the given method argument in the frame's local variables array.
 */
private int getArgIndex(final int arg) {
  int index = (access & Opcodes.ACC_STATIC) == 0 ? 1 : 0;
  for (int i = 0; i < arg; i++) {
    index += argumentTypes[i].getSize();
  }
  return index;
}
 
Example 3
Source File: ClassDepLister.java    From depan with Apache License 2.0 5 votes vote down vote up
@Override
public MethodVisitor visitMethod(int access, String name, String desc,
    String signature, String[] exceptions) {

  // the method itself
  MethodElement m = new MethodElement(desc, name, mainClass);

  JavaRelation r = null;
  if ((Opcodes.ACC_STATIC & access) != 0) {
    r = JavaRelation.STATIC_METHOD;
  } else {
    r = JavaRelation.MEMBER_METHOD;
  }
  builder.newDep(mainClass, m, r);

  // arguments dependencies
  for (Type t : Type.getArgumentTypes(desc)) {
    builder.newDep(m, TypeNameUtil.fromDescriptor(t.getDescriptor()),
        JavaRelation.TYPE);
  }

  // return-type dependency
  TypeElement type = TypeNameUtil.fromDescriptor(
      Type.getReturnType(desc).getDescriptor());
  builder.newDep(m, type, JavaRelation.READ);

  return asmFactory.buildMethodVisitor(builder, m);
}
 
Example 4
Source File: InstanceVariableCountingVisitor.java    From AVM with MIT License 5 votes vote down vote up
@Override
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
    // If this is an instance field, add it to our count.  We don't restrict static fields.
    if (Opcodes.ACC_STATIC != (Opcodes.ACC_STATIC & access)) {
        this.instanceVariableCount += 1;
    }
    return super.visitField(access, name, descriptor, signature, value);
}
 
Example 5
Source File: CheckParserUsagesDT.java    From sql-layer with GNU Affero General Public License v3.0 5 votes vote down vote up
public void addField(int access, String fieldName) {
    if ((access & Opcodes.ACC_PUBLIC) > 0) {
        if ((access & Opcodes.ACC_STATIC) == 0) {
            fields.add(new Field(this.name, fieldName));
            if (logger.isWarnEnabled()) {
                logger.warn(getJavaName() + " has a public field: " + fieldName);
            }
        }
    }
}
 
Example 6
Source File: DalvikStatsTool.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    int access, String name, String desc, String signature, Object value) {
  // For non-static fields, Field objects are 16 bytes.
  if ((access & Opcodes.ACC_STATIC) == 0) {
    footprint += 16;
  }

  Objects.requireNonNull(className, "Must not call visitField before visit");
  fieldReferenceBuilder.add(DalvikMemberReference.of(className, name, desc));

  return fieldVisitor;
}
 
Example 7
Source File: SerialVersionUIDAdder.java    From Concurnas with MIT License 5 votes vote down vote up
/**
 * Adds a final static serialVersionUID field to the class, with the given value.
 *
 * @param svuid the serialVersionUID field value.
 */
// DontCheck(AbbreviationAsWordInName): can't be renamed (for backward binary compatibility).
protected void addSVUID(final long svuid) {
  FieldVisitor fieldVisitor =
      super.visitField(
          Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "serialVersionUID", "J", null, svuid);
  if (fieldVisitor != null) {
    fieldVisitor.visitEnd();
  }
}
 
Example 8
Source File: SerialVersionUIDAdder.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public MethodVisitor visitMethod(
    final int access,
    final String name,
    final String descriptor,
    final String signature,
    final String[] exceptions) {
  // Get constructor and method information (step 5 and 7). Also determine if there is a class
  // initializer (step 6).
  if (computeSvuid) {
    if (CLINIT.equals(name)) {
      hasStaticInitializer = true;
    }
    // Collect the non private constructors and methods. Only the ACC_PUBLIC, ACC_PRIVATE,
    // ACC_PROTECTED, ACC_STATIC, ACC_FINAL, ACC_SYNCHRONIZED, ACC_NATIVE, ACC_ABSTRACT and
    // ACC_STRICT flags are used.
    int mods =
        access
            & (Opcodes.ACC_PUBLIC
                | Opcodes.ACC_PRIVATE
                | Opcodes.ACC_PROTECTED
                | Opcodes.ACC_STATIC
                | Opcodes.ACC_FINAL
                | Opcodes.ACC_SYNCHRONIZED
                | Opcodes.ACC_NATIVE
                | Opcodes.ACC_ABSTRACT
                | Opcodes.ACC_STRICT);

    if ((access & Opcodes.ACC_PRIVATE) == 0) {
      if ("<init>".equals(name)) {
        svuidConstructors.add(new Item(name, mods, descriptor));
      } else if (!CLINIT.equals(name)) {
        svuidMethods.add(new Item(name, mods, descriptor));
      }
    }
  }

  return super.visitMethod(access, name, descriptor, signature, exceptions);
}
 
Example 9
Source File: MethodDependencyVisitor.java    From AVM with MIT License 5 votes vote down vote up
public MethodDependencyVisitor(String methodName, String methodDescriptor, int access,
    MethodVisitor mv) {
    super(Opcodes.ASM6, mv);
    // the concatenation of name + descriptor is a unique identifier for every method in a class
    this.methodIdentifier = methodName + methodDescriptor;
    this.isStatic = (access & Opcodes.ACC_STATIC) != 0;
}
 
Example 10
Source File: IncrementalSupportVisitor.java    From AnoleFix with MIT License 5 votes vote down vote up
/**
 * Ensures that the class contains a $change field used for referencing the
 * IncrementalChange dispatcher.
 * <p/>
 * Also updates package_private visiblity to public so we can call into this class from
 * outside the package.
 */
@Override
public void visit(int version, int access, String name, String signature, String superName,
                  String[] interfaces) {
    visitedClassName = name;
    visitedSuperName = superName;

    super.visitField(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC
                    | Opcodes.ACC_VOLATILE | Opcodes.ACC_SYNTHETIC,
            "$change", getRuntimeTypeName(CHANGE_TYPE), null, null);
    access = transformClassAccessForInstantRun(access);
    super.visit(version, access, name, signature, superName, interfaces);
}
 
Example 11
Source File: JSondeClassTransformer.java    From jsonde with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public MethodVisitor visitMethod(
        int access,
        String name,
        String desc,
        String signature,
        String[] exceptions) {

    long methodId = Profiler.getProfiler().registerMethod(
            classId, access, name, desc, signature, exceptions
    );

    MethodVisitor methodVisitor = super.visitMethod(
            access,
            name,
            desc,
            signature,
            exceptions
    );

    if (
            ("loadClass".equals(name) &&
                    ("(Ljava/lang/String;)Ljava/lang/Class;".equals(desc) ||
                            "(Ljava/lang/String;Z)Ljava/lang/Class;".equals(desc))
            )
            ) {

        if (0 == (access & Opcodes.ACC_STATIC)) {
            methodVisitor = new JSondeClassLoaderMethodTransformer(methodVisitor);
        }

    }

    if (instrumentClass) {
        methodVisitor = new JSondeMethodTransformer(
                methodId,
                methodVisitor,
                access,
                name,
                desc,
                className,
                parentClassName
        );
    }

    return methodVisitor;

}
 
Example 12
Source File: ClassInfo.java    From Mixin with MIT License 4 votes vote down vote up
public boolean isStatic() {
    return (this.modifiers & Opcodes.ACC_STATIC) != 0;
}
 
Example 13
Source File: Textifier.java    From Concurnas with MIT License 4 votes vote down vote up
@Override
public Textifier visitMethod(
    final int access,
    final String name,
    final String descriptor,
    final String signature,
    final String[] exceptions) {
  stringBuilder.setLength(0);
  stringBuilder.append('\n');
  if ((access & Opcodes.ACC_DEPRECATED) != 0) {
    stringBuilder.append(tab).append(DEPRECATED);
  }
  stringBuilder.append(tab);
  appendRawAccess(access);

  if (signature != null) {
    stringBuilder.append(tab);
    appendDescriptor(METHOD_SIGNATURE, signature);
    stringBuilder.append(tab);
    appendJavaDeclaration(name, signature);
  }

  stringBuilder.append(tab);
  appendAccess(access & ~(Opcodes.ACC_VOLATILE | Opcodes.ACC_TRANSIENT));
  if ((access & Opcodes.ACC_NATIVE) != 0) {
    stringBuilder.append("native ");
  }
  if ((access & Opcodes.ACC_VARARGS) != 0) {
    stringBuilder.append("varargs ");
  }
  if ((access & Opcodes.ACC_BRIDGE) != 0) {
    stringBuilder.append("bridge ");
  }
  if ((this.access & Opcodes.ACC_INTERFACE) != 0
      && (access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_STATIC)) == 0) {
    stringBuilder.append("default ");
  }

  stringBuilder.append(name);
  appendDescriptor(METHOD_DESCRIPTOR, descriptor);
  if (exceptions != null && exceptions.length > 0) {
    stringBuilder.append(" throws ");
    for (String exception : exceptions) {
      appendDescriptor(INTERNAL_NAME, exception);
      stringBuilder.append(' ');
    }
  }

  stringBuilder.append('\n');
  text.add(stringBuilder.toString());
  return addNewTextifier(null);
}
 
Example 14
Source File: Globalizer.java    From Concurnas with MIT License 4 votes vote down vote up
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
locallyDefinedFields.add(name + desc);

//String cClass = this.className.peek();

if(className.contains("$")) {//if nested class method needs to be public
	access = makePublic(access);
}

if(staticLambdaClasses != null && isNonGlobalerORPrimordial(className, null, name, staticLambdaClasses, clloader)) {
	return super.visitField(access, name, desc, signature, value);
}

boolean shared = false;
boolean isStatic = Modifier.isStatic(access);
if(isStatic){//skip if static...
	try {
		shared = this.clloader.getDetector().classForName(className).getField(name).isShared;
	} catch (Throwable e) {
		//throw new RuntimeException("Cannot find class: "+ cClass + " as " + e.getMessage(), e);
	}
	
	if(!shared) {//but dont skip if shared
		getGlobName();//may not have a clinit so we call it anyway
		
		if(isEnumCls){
			if(name.equals("ENUM$VALUES")){
				access = Opcodes.ACC_PUBLIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC;
			}
			return super.visitField(access, name, desc, signature, value);
		}
		
		return null;
	}
}

OwnerNameDesc me = new OwnerNameDesc(className, name);
if(this.shouldbeForcedPublicField.contains(me) || className.contains("AtomicBoolean")){
	//if the field is used in subclass/function which is static, then force it public (bit of a hack, should use psar)
	access = ACC_PUBLIC;
	if(shared && isStatic) {
		access += ACC_STATIC;
	}
}

return super.visitField(access, name, desc, signature, value);
  }
 
Example 15
Source File: GizmoClassVisitor.java    From gizmo with Apache License 2.0 4 votes vote down vote up
public FieldVisitor visitField(final int access, final String name, final String descriptor, final String signature, final Object value) {
    //     int ACC_PUBLIC = 0x0001; // class, field, method
    //    int ACC_PRIVATE = 0x0002; // class, field, method
    //    int ACC_PROTECTED = 0x0004; // class, field, method
    //    int ACC_STATIC = 0x0008; // field, method
    //    int ACC_FINAL = 0x0010; // class, field, method, parameter
    //    int ACC_SUPER = 0x0020; // class
    //    int ACC_SYNCHRONIZED = 0x0020; // method
    //    int ACC_OPEN = 0x0020; // module
    //    int ACC_TRANSITIVE = 0x0020; // module requires
    //    int ACC_VOLATILE = 0x0040; // field
    //    int ACC_BRIDGE = 0x0040; // method
    //    int ACC_STATIC_PHASE = 0x0040; // module requires
    //    int ACC_VARARGS = 0x0080; // method
    //    int ACC_TRANSIENT = 0x0080; // field
    //    int ACC_NATIVE = 0x0100; // method
    //    int ACC_INTERFACE = 0x0200; // class
    //    int ACC_ABSTRACT = 0x0400; // class, method
    //    int ACC_STRICT = 0x0800; // method
    //    int ACC_SYNTHETIC = 0x1000; // class, field, method, parameter, module *
    //    int ACC_ANNOTATION = 0x2000; // class
    //    int ACC_ENUM = 0x4000; // class(?) field inner
    //    int ACC_MANDATED = 0x8000; // parameter, module, module *
    //    int ACC_MODULE = 0x8000; // class
    append("// Access:");
    for (int mods = access; mods != 0;) {
        int mod = Integer.lowestOneBit(mods);
        switch (mod) {
            case Opcodes.ACC_PUBLIC: {
                append(" public");
                break;
            }
            case Opcodes.ACC_PRIVATE: {
                append(" private");
                break;
            }
            case Opcodes.ACC_PROTECTED: {
                append(" protected");
                break;
            }
            case Opcodes.ACC_STATIC: {
                append(" static");
                break;
            }
            case Opcodes.ACC_FINAL: {
                append(" final");
                break;
            }
            case Opcodes.ACC_VOLATILE: {
                append(" volatile");
                break;
            }
            case Opcodes.ACC_TRANSIENT: {
                append(" transient");
                break;
            }
            case Opcodes.ACC_SYNTHETIC: {
                append(" synthetic");
                break;
            }
            case Opcodes.ACC_ENUM: {
                append(" enum");
                break;
            }
        }
        mods ^= mod;
    }
    newLine();
    append("Field ").append(name).append(" : ").append(Type.getType(descriptor)).newLine().newLine();
    return super.visitField(access, name, descriptor, signature, value);
}
 
Example 16
Source File: NumberObfuscationTransformer.java    From obfuscator with MIT License 4 votes vote down vote up
@Override
    public void process(ProcessorCallback callback, ClassNode node) {
        if (!enabled.getObject()) return;

        int i = 0;
        String fieldName = NameUtils.generateFieldName(node.name);
        List<Integer> integerList = new ArrayList<>();
        for (MethodNode method : node.methods) {
            for (AbstractInsnNode abstractInsnNode : method.instructions.toArray()) {
                if (abstractInsnNode == null) {
                    throw new RuntimeException("AbstractInsnNode is null. WTF?");
                }
                if (NodeUtils.isIntegerNumber(abstractInsnNode)) {
                    int number = NodeUtils.getIntValue(abstractInsnNode);

                    if (number == Integer.MIN_VALUE) {
                        continue;
                    }
//                    if (abstractInsnNode instanceof LdcInsnNode && ((LdcInsnNode) abstractInsnNode).cst instanceof Number && ((int) ((LdcInsnNode) abstractInsnNode).cst) == Integer.MIN_VALUE) {
//                        System.out.println(((LdcInsnNode) abstractInsnNode).cst + "/" + number);
//                    }
                    if (!Modifier.isInterface(node.access)
//                            && mode == 1
                            && extractToArray.getObject()
                    ) {
                        int containedSlot = -1;
                        int j = 0;
                        for (Integer integer : integerList) {
                            if (integer == number) containedSlot = j;
                            j++;
                        }
                        if (containedSlot == -1) integerList.add(number);
                        method.instructions.insertBefore(abstractInsnNode, new FieldInsnNode(Opcodes.GETSTATIC, node.name, fieldName, "[I"));
                        method.instructions.insertBefore(abstractInsnNode, NodeUtils.generateIntPush(containedSlot == -1 ? i : containedSlot));
                        method.instructions.insertBefore(abstractInsnNode, new InsnNode(Opcodes.IALOAD));
                        method.instructions.remove(abstractInsnNode);
                        if (containedSlot == -1) i++;
                        method.maxStack += 2;
                    } else {
                        method.maxStack += 4;

                        method.instructions.insertBefore(abstractInsnNode, getInstructionsMultipleTimes(number, random.nextInt(2) + 1));
                        method.instructions.remove(abstractInsnNode);
                    }
                }
            }
        }
        if (i != 0) {
            node.fields.add(new FieldNode(((node.access & Opcodes.ACC_INTERFACE) != 0 ? Opcodes.ACC_PUBLIC : Opcodes.ACC_PRIVATE) | (node.version > Opcodes.V1_8 ? 0 : Opcodes.ACC_FINAL) | Opcodes.ACC_STATIC, fieldName, "[I", null, null));
            MethodNode clInit = NodeUtils.getMethod(node, "<clinit>");
            if (clInit == null) {
                clInit = new MethodNode(Opcodes.ACC_STATIC, "<clinit>", "()V", null, new String[0]);
                node.methods.add(clInit);
            }
            if (clInit.instructions == null)
                clInit.instructions = new InsnList();

            InsnList toAdd = new InsnList();

//            if (clInit.instructions.getFirst() == null)
//                clInit.instructions.insert(NodeUtils.generateIntPush(i));
//            else
            toAdd.add(NodeUtils.generateIntPush(i));

            toAdd.add(new IntInsnNode(Opcodes.NEWARRAY, Opcodes.T_INT));
//            toAdd.insert(new IntInsnNode(Opcodes.NEWARRAY, 0));
            toAdd.add(new FieldInsnNode(Opcodes.PUTSTATIC, node.name, fieldName, "[I"));

            for (int j = 0; j < i; j++) {
                toAdd.add(new FieldInsnNode(Opcodes.GETSTATIC, node.name, fieldName, "[I"));
                toAdd.add(NodeUtils.generateIntPush(j));
                toAdd.add(getInstructionsMultipleTimes(integerList.get(j), random.nextInt(2) + 1));
                toAdd.add(new InsnNode(Opcodes.IASTORE));
            }

            MethodNode generateIntegers = new MethodNode(((node.access & Opcodes.ACC_INTERFACE) != 0 ? Opcodes.ACC_PUBLIC : Opcodes.ACC_PRIVATE) | Opcodes.ACC_STATIC, NameUtils.generateMethodName(node, "()V"), "()V", null, new String[0]);
            generateIntegers.instructions = toAdd;
            generateIntegers.instructions.add(new InsnNode(Opcodes.RETURN));
            generateIntegers.maxStack = 6;
            node.methods.add(generateIntegers);

            if (clInit.instructions == null || clInit.instructions.getFirst() == null) {
                clInit.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, node.name, generateIntegers.name, generateIntegers.desc, false));
                clInit.instructions.add(new InsnNode(Opcodes.RETURN));
            } else {
                clInit.instructions.insertBefore(clInit.instructions.getFirst(), new MethodInsnNode(Opcodes.INVOKESTATIC, node.name, generateIntegers.name, generateIntegers.desc, false));
            }
//            clInit.maxStack = Math.max(clInit.maxStack, 6);
        }
        inst.setWorkDone();
    }
 
Example 17
Source File: MethodInfo.java    From pitest with Apache License 2.0 4 votes vote down vote up
public boolean isStatic() {
  return ((this.access & Opcodes.ACC_STATIC) != 0);
}
 
Example 18
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Override
protected int getBaseModifiers() {
    return methodDescription.isStatic()
            ? Opcodes.ACC_STATIC
            : EMPTY_MASK;
}
 
Example 19
Source File: Field.java    From OSRS-Deobfuscator with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public boolean isStatic()
{
	return (accessFlags & Opcodes.ACC_STATIC) != 0;
}
 
Example 20
Source File: LocalVariablesSorter.java    From JByteMod-Beta with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Constructs a new {@link LocalVariablesSorter}.
 *
 * @param api the ASM API version implemented by this visitor. Must be one of {@link
 *     Opcodes#ASM4}, {@link Opcodes#ASM5}, {@link Opcodes#ASM6} or {@link
 *     Opcodes#ASM7_EXPERIMENTAL}.
 * @param access access flags of the adapted method.
 * @param descriptor the method's descriptor (see {@link Type}).
 * @param methodVisitor the method visitor to which this adapter delegates calls.
 */
protected LocalVariablesSorter(
    final int api, final int access, final String descriptor, final MethodVisitor methodVisitor) {
  super(api, methodVisitor);
  nextLocal = (Opcodes.ACC_STATIC & access) == 0 ? 1 : 0;
  for (Type argumentType : Type.getArgumentTypes(descriptor)) {
    nextLocal += argumentType.getSize();
  }
  firstLocal = nextLocal;
}