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

The following examples show how to use org.objectweb.asm.Opcodes#ACC_PRIVATE . 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: StaticInitMerger.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public MethodVisitor visitMethod(
    final int access,
    final String name,
    final String descriptor,
    final String signature,
    final String[] exceptions) {
  MethodVisitor methodVisitor;
  if ("<clinit>".equals(name)) {
    int newAccess = Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC;
    String newName = renamedClinitMethodPrefix + numClinitMethods++;
    methodVisitor = super.visitMethod(newAccess, newName, descriptor, signature, exceptions);

    if (mergedClinitVisitor == null) {
      mergedClinitVisitor = super.visitMethod(newAccess, name, descriptor, null, null);
    }
    mergedClinitVisitor.visitMethodInsn(Opcodes.INVOKESTATIC, owner, newName, descriptor, false);
  } else {
    methodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions);
  }
  return methodVisitor;
}
 
Example 2
Source File: JClassPatcher.java    From rscplus with GNU General Public License v3.0 6 votes vote down vote up
private String decodeAccess(int access) {
  String res = "";

  if ((access & Opcodes.ACC_PUBLIC) == Opcodes.ACC_PUBLIC) res += "public ";
  if ((access & Opcodes.ACC_PRIVATE) == Opcodes.ACC_PRIVATE) res += "private ";
  if ((access & Opcodes.ACC_PROTECTED) == Opcodes.ACC_PROTECTED) res += "protected ";

  if ((access & Opcodes.ACC_STATIC) == Opcodes.ACC_STATIC) res += "static ";
  if ((access & Opcodes.ACC_FINAL) == Opcodes.ACC_FINAL) res += "final ";
  if ((access & Opcodes.ACC_VOLATILE) == Opcodes.ACC_VOLATILE) res += "protected ";
  if ((access & Opcodes.ACC_SYNCHRONIZED) == Opcodes.ACC_SYNCHRONIZED) res += "synchronized ";
  if ((access & Opcodes.ACC_ABSTRACT) == Opcodes.ACC_ABSTRACT) res += "abstract ";
  if ((access & Opcodes.ACC_INTERFACE) == Opcodes.ACC_INTERFACE) res += "interface ";

  return res;
}
 
Example 3
Source File: PatternMatchedSection.java    From yGuard with MIT License 5 votes vote down vote up
public static Access valueOf( int asmAccess ) {

      if ( ( asmAccess & Opcodes.ACC_PUBLIC ) == Opcodes.ACC_PUBLIC ) {
        return PUBLIC;
      } else if ( ( asmAccess & Opcodes.ACC_PROTECTED ) == Opcodes.ACC_PROTECTED ) {
        return PROTECTED;
      } else if ( ( asmAccess & Opcodes.ACC_PRIVATE ) == Opcodes.ACC_PRIVATE ) {
        return PRIVATE;
      } else {
        return FRIENDLY;
      }
    }
 
Example 4
Source File: RenameMethods.java    From bytecode-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void obfuscate() {
    int stringLength = getStringLength();

    System.out.println("Obfuscating method names...");
    for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
        for (Object o : c.methods.toArray()) {
            MethodNode m = (MethodNode) o;
            if (m.access != Opcodes.ACC_ABSTRACT
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_STATIC
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_PUBLIC
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_PRIVATE
                    && m.access != Opcodes.ACC_ABSTRACT
                    + Opcodes.ACC_PROTECTED) {
                if (!m.name.equals("main") && !m.name.equals("<init>")
                        && !m.name.equals("<clinit>")) {
                    String newName = generateUniqueName(stringLength);
                    ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc,
                            null, newName, null);
                }
            }
        }
    }

    System.out.println("Obfuscated method names.");
}
 
Example 5
Source File: MethodRebaseResolver.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int getModifiers() {
    return Opcodes.ACC_SYNTHETIC
            | (methodDescription.isStatic() ? Opcodes.ACC_STATIC : EMPTY_MASK)
            | (methodDescription.isNative() ? Opcodes.ACC_NATIVE : EMPTY_MASK)
            | (instrumentedType.isInterface() ? Opcodes.ACC_PUBLIC : Opcodes.ACC_PRIVATE);
}
 
Example 6
Source File: SerialVersionUIDAdder.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public FieldVisitor visitField(
    final int access,
    final String name,
    final String desc,
    final String signature,
    final Object value) {
  // Get the class field information for step 4 of the algorithm. Also determine if the class
  // already has a SVUID.
  if (computeSvuid) {
    if ("serialVersionUID".equals(name)) {
      // Since the class already has SVUID, we won't be computing it.
      computeSvuid = false;
      hasSvuid = true;
    }
    // Collect the non private fields. Only the ACC_PUBLIC, ACC_PRIVATE, ACC_PROTECTED,
    // ACC_STATIC, ACC_FINAL, ACC_VOLATILE, and ACC_TRANSIENT flags are used when computing
    // serialVersionUID values.
    if ((access & Opcodes.ACC_PRIVATE) == 0
        || (access & (Opcodes.ACC_STATIC | Opcodes.ACC_TRANSIENT)) == 0) {
      int mods =
          access
              & (Opcodes.ACC_PUBLIC
                  | Opcodes.ACC_PRIVATE
                  | Opcodes.ACC_PROTECTED
                  | Opcodes.ACC_STATIC
                  | Opcodes.ACC_FINAL
                  | Opcodes.ACC_VOLATILE
                  | Opcodes.ACC_TRANSIENT);
      svuidFields.add(new Item(name, mods, desc));
    }
  }

  return super.visitField(access, name, desc, signature, value);
}
 
Example 7
Source File: InvokeDynamicHandler.java    From native-obfuscator with GNU General Public License v3.0 5 votes vote down vote up
public static void processIndy(ClassNode classNode, String methodName, InvokeDynamicInsnNode indy) {
    MethodNode indyWrapper = new MethodNode(Opcodes.ASM7,
            Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC,
            methodName, indy.desc, null, new String[0]);

    int localVarsPosition = 0;
    for (Type arg : Type.getArgumentTypes(indy.desc)) {
        indyWrapper.instructions.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition));
        localVarsPosition += arg.getSize();
    }

    indyWrapper.instructions.add(new InvokeDynamicInsnNode(indy.name, indy.desc, indy.bsm, indy.bsmArgs));
    indyWrapper.instructions.add(new InsnNode(Opcodes.ARETURN));
    classNode.methods.add(indyWrapper);
}
 
Example 8
Source File: DecompiledClassNode.java    From groovy with Apache License 2.0 5 votes vote down vote up
private MethodNode createMethodNode(final MethodStub method) {
    Supplier<MethodNode> methodNodeSupplier = () -> addAnnotations(method, MemberSignatureParser.createMethodNode(resolver, method));

    if ((method.accessModifiers & Opcodes.ACC_PRIVATE) != 0) {
        return new LazyMethodNode(methodNodeSupplier, method.methodName);
    }

    return methodNodeSupplier.get();
}
 
Example 9
Source File: StripVerifyingVisitor.java    From bazel 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) {
  if ((access & Opcodes.ACC_PRIVATE) != 0) {
    errors.add(String.format("Private method %s found in %s", name, className));
  }
  // We need to go deeper.
  return new StripVerifyingMethodVisitor(errors, className, name);
}
 
Example 10
Source File: RuleHelper.java    From custom-bytecode-analyzer with GNU General Public License v3.0 5 votes vote down vote up
public static int getOpcodeVisibility(String visibility) {
  if ("public".equals(visibility)) {
    return Opcodes.ACC_PUBLIC;
  }
  if ("protected".equals(visibility)) {
    return Opcodes.ACC_PROTECTED;
  }
  if ("private".equals(visibility)) {
    return Opcodes.ACC_PRIVATE;
  }
  return 0;
}
 
Example 11
Source File: Engine.java    From JReFrameworker with MIT License 4 votes vote down vote up
@SuppressWarnings("unused")
private static String getAccessModifiers(int access){
	LinkedList<String> modifiers = new LinkedList<String>();
	if((Opcodes.ACC_ABSTRACT & access) == Opcodes.ACC_ABSTRACT){
		modifiers.add("abstract");
	}
	if((Opcodes.ACC_ANNOTATION & access) == Opcodes.ACC_ANNOTATION){
		modifiers.add("annotation");
	}
	if((Opcodes.ACC_BRIDGE & access) == Opcodes.ACC_BRIDGE){
		modifiers.add("bridge");
	}
	if((Opcodes.ACC_DEPRECATED & access) == Opcodes.ACC_DEPRECATED){
		modifiers.add("deprecated");
	}
	if((Opcodes.ACC_ENUM & access) == Opcodes.ACC_ENUM){
		modifiers.add("enum");
	}
	if((Opcodes.ACC_FINAL & access) == Opcodes.ACC_FINAL){
		modifiers.add("final");
	}
	if((Opcodes.ACC_INTERFACE & access) == Opcodes.ACC_INTERFACE){
		modifiers.add("interface");
	}
	if((Opcodes.ACC_MANDATED & access) == Opcodes.ACC_MANDATED){
		modifiers.add("mandated");
	}
	if((Opcodes.ACC_NATIVE & access) == Opcodes.ACC_NATIVE){
		modifiers.add("native");
	}
	if((Opcodes.ACC_PRIVATE & access) == Opcodes.ACC_PRIVATE){
		modifiers.add("private");
	}
	if((Opcodes.ACC_PROTECTED & access) == Opcodes.ACC_PROTECTED){
		modifiers.add("protected");
	}
	if((Opcodes.ACC_PUBLIC & access) == Opcodes.ACC_PUBLIC){
		modifiers.add("public");
	}
	if((Opcodes.ACC_STATIC & access) == Opcodes.ACC_STATIC){
		modifiers.add("static");
	}
	if((Opcodes.ACC_STRICT & access) == Opcodes.ACC_STRICT){
		modifiers.add("strict");
	}
	if((Opcodes.ACC_SUPER & access) == Opcodes.ACC_SUPER){
		modifiers.add("super");
	}
	if((Opcodes.ACC_SYNCHRONIZED & access) == Opcodes.ACC_SYNCHRONIZED){
		modifiers.add("synchronized");
	}
	if((Opcodes.ACC_SYNTHETIC & access) == Opcodes.ACC_SYNTHETIC){
		modifiers.add("synthetic");
	}
	if((Opcodes.ACC_TRANSIENT & access) == Opcodes.ACC_TRANSIENT){
		modifiers.add("transient");
	}
	if((Opcodes.ACC_VARARGS & access) == Opcodes.ACC_VARARGS){
		modifiers.add("varargs");
	}
	if((Opcodes.ACC_VOLATILE & access) == Opcodes.ACC_VOLATILE){
		modifiers.add("volatile");
	}
	return modifiers.toString();
}
 
Example 12
Source File: RedirectionVisitor.java    From Stark with Apache License 2.0 4 votes vote down vote up
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
    int newAccess =
            access & (~(Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) | Opcodes.ACC_PUBLIC;
    super.visitInnerClass(name, outerName, innerName, newAccess);
}
 
Example 13
Source File: IncrementalVisitor.java    From AnoleFix with MIT License 4 votes vote down vote up
static AccessRight fromNodeAccess(int nodeAccess) {
    if ((nodeAccess & Opcodes.ACC_PRIVATE) != 0) return PRIVATE;
    if ((nodeAccess & Opcodes.ACC_PROTECTED) != 0) return PROTECTED;
    if ((nodeAccess & Opcodes.ACC_PUBLIC) != 0) return PUBLIC;
    return PACKAGE_PRIVATE;
}
 
Example 14
Source File: Textifier.java    From JReFrameworker with MIT License 4 votes vote down vote up
/**
 * Appends a string representation of the given access flags to {@link #stringBuilder}.
 *
 * @param accessFlags some access flags.
 */
private void appendAccess(final int accessFlags) {
  if ((accessFlags & Opcodes.ACC_PUBLIC) != 0) {
    stringBuilder.append("public ");
  }
  if ((accessFlags & Opcodes.ACC_PRIVATE) != 0) {
    stringBuilder.append("private ");
  }
  if ((accessFlags & Opcodes.ACC_PROTECTED) != 0) {
    stringBuilder.append("protected ");
  }
  if ((accessFlags & Opcodes.ACC_FINAL) != 0) {
    stringBuilder.append("final ");
  }
  if ((accessFlags & Opcodes.ACC_STATIC) != 0) {
    stringBuilder.append("static ");
  }
  if ((accessFlags & Opcodes.ACC_SYNCHRONIZED) != 0) {
    stringBuilder.append("synchronized ");
  }
  if ((accessFlags & Opcodes.ACC_VOLATILE) != 0) {
    stringBuilder.append("volatile ");
  }
  if ((accessFlags & Opcodes.ACC_TRANSIENT) != 0) {
    stringBuilder.append("transient ");
  }
  if ((accessFlags & Opcodes.ACC_ABSTRACT) != 0) {
    stringBuilder.append("abstract ");
  }
  if ((accessFlags & Opcodes.ACC_STRICT) != 0) {
    stringBuilder.append("strictfp ");
  }
  if ((accessFlags & Opcodes.ACC_SYNTHETIC) != 0) {
    stringBuilder.append("synthetic ");
  }
  if ((accessFlags & Opcodes.ACC_MANDATED) != 0) {
    stringBuilder.append("mandated ");
  }
  if ((accessFlags & Opcodes.ACC_ENUM) != 0) {
    stringBuilder.append("enum ");
  }
}
 
Example 15
Source File: ClassInstance.java    From tiny-remapper with GNU Lesser General Public License v3.0 4 votes vote down vote up
public boolean isPublicOrPrivate() {
	return (access & (Opcodes.ACC_PUBLIC | Opcodes.ACC_PRIVATE)) != 0;
}
 
Example 16
Source File: ClassDependenciesVisitor.java    From pushfish-android with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private static boolean isPrivate(int access) {
    return (access & Opcodes.ACC_PRIVATE) != 0;
}
 
Example 17
Source File: MixinPreProcessorStandard.java    From Mixin with MIT License 4 votes vote down vote up
protected boolean attachSpecialMethod(MixinTargetContext context, MixinMethodNode mixinMethod, SpecialMethod type) {
    
    AnnotationNode annotation = mixinMethod.getVisibleAnnotation(type.annotation);
    if (annotation == null) {
        return false;
    }
    
    if (type.isOverwrite) {
        this.checkMixinNotUnique(mixinMethod, type);
    }
    
    Method method = this.getSpecialMethod(mixinMethod, type);
    MethodNode target = context.findMethod(mixinMethod, annotation);
    if (target == null) {
        if (type.isOverwrite) {
            return false;
        }
        target = context.findRemappedMethod(mixinMethod);
        if (target == null) {
            throw new InvalidMixinException(this.mixin,
                    String.format("%s method %s in %s was not located in the target class %s. %s%s", type, mixinMethod.name, this.mixin,
                            context.getTarget(), context.getReferenceMapper().getStatus(),
                            MixinPreProcessorStandard.getDynamicInfo(mixinMethod)));
        }
        mixinMethod.name = method.renameTo(target.name);
    }
    
    if (Constants.CTOR.equals(target.name)) {
        throw new InvalidMixinException(this.mixin, String.format("Nice try! %s in %s cannot alias a constructor", mixinMethod.name, this.mixin));
    }
    
    if (!Bytecode.compareFlags(mixinMethod, target, Opcodes.ACC_STATIC)) {
        throw new InvalidMixinException(this.mixin, String.format("STATIC modifier of %s method %s in %s does not match the target", type,
                mixinMethod.name, this.mixin));
    }
    
    this.conformVisibility(context, mixinMethod, type, target);
    
    if (!target.name.equals(mixinMethod.name)) {
        if (type.isOverwrite && (target.access & Opcodes.ACC_PRIVATE) == 0) {
            throw new InvalidMixinException(this.mixin, "Non-private method cannot be aliased. Found " + target.name);
        }
        
        mixinMethod.name = method.renameTo(target.name);
    }
    
    return true;
}
 
Example 18
Source File: FieldCreatorImpl.java    From gizmo with Apache License 2.0 4 votes vote down vote up
public FieldCreatorImpl(FieldDescriptor fieldDescriptor) {
    this.fieldDescriptor = fieldDescriptor;
    this.modifiers = Opcodes.ACC_PRIVATE;
}
 
Example 19
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public int getModifiers() {
    return Opcodes.ACC_SYNTHETIC | Opcodes.ACC_FINAL | Opcodes.ACC_STATIC | (instrumentedType.isInterface()
            ? Opcodes.ACC_PUBLIC
            : Opcodes.ACC_PRIVATE);
}
 
Example 20
Source File: RedirectionVisitor.java    From Stark with Apache License 2.0 3 votes vote down vote up
/**
 * If a method/field is not private, make it public. This is to workaround the fact
 * <p>
 * <ul>
 * reload.dex are loaded from a different class loader but private methods/fields are accessed
 * through reflection, therefore you need visibility.
 * </ul>
 * <p>
 * remember that in Java, protected methods or fields can be accessed by classes in the same
 * package : {@see https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html}
 *
 * @param access the original class/method/field access.
 * @return the new access or the same one depending on the original access rights.
 */
private static int transformAccessForStark(int access) {
    AccessRight accessRight = AccessRight.fromNodeAccess(access);
    if (accessRight != AccessRight.PRIVATE) {
        access &= ~Opcodes.ACC_PROTECTED;
        access &= ~Opcodes.ACC_PRIVATE;
        return access | Opcodes.ACC_PUBLIC;
    }
    return access;
}