org.objectweb.asm.tree.ClassNode Java Examples

The following examples show how to use org.objectweb.asm.tree.ClassNode. 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: ASMMethodNodeAdapterAddDelegatorTest.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
private Class<?> addDelegatorMethod(final String targetClassName, final String superClassName, final String methodName) throws Exception {
    final ClassNode superClassNode = ASMClassNodeLoader.get(superClassName);
    List<MethodNode> methodNodes = superClassNode.methods;
    final MethodNode methodNode = findMethodNode(methodName, methodNodes);

    classLoader.setTargetClassName(targetClassName);
    classLoader.setCallbackHandler(new ASMClassNodeLoader.CallbackHandler() {
        @Override
        public void handle(final ClassNode classNode) {
            String[] exceptions = null;
            if (methodNode.exceptions != null) {
                exceptions = methodNode.exceptions.toArray(new String[0]);
            }

            final MethodNode newMethodNode = new MethodNode(methodNode.access, methodNode.name, methodNode.desc, methodNode.signature, exceptions);
            final ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter(classNode.name, newMethodNode);
            methodNodeAdapter.addDelegator(JavaAssistUtils.javaNameToJvmName(superClassName));
            classNode.methods.add(newMethodNode);
        }
    });
    return classLoader.loadClass(targetClassName);
}
 
Example #2
Source File: StringObfuscationCipherVMT11.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<String> findNeededContents(ClassNode cn, MethodNode mn) {
	ArrayList<String> neededContents = new ArrayList<>();
	for (AbstractInsnNode ain : mn.instructions.toArray()) {
		if (ain instanceof MethodInsnNode) {
			MethodInsnNode min = (MethodInsnNode) ain;
			if (min.owner.equals(cn.name) && !neededContents.contains(min.name + min.desc)) {
				neededContents.add(min.name + min.desc);
				neededContents.addAll(findNeededContents(cn, ClassUtils.getMethod(cn, min.name, min.desc)));
			}
		}
		if (ain instanceof FieldInsnNode) {
			FieldInsnNode fin = (FieldInsnNode) ain;
			if (fin.owner.equals(cn.name) && !neededContents.contains(fin.name + fin.desc)) {
				neededContents.add(fin.name + fin.desc);
			}
		}
	}
	return neededContents;
}
 
Example #3
Source File: RuntimeJarArchive.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Map<String, ClassNode> getClasses() {
  for (Class<?> c : ins.getAllLoadedClasses()) {
    String name = c.getName().replace('.', '/');
    if (!isRT(name) && !classes.containsKey(name)) {
      if (name.contains("$$") || systemClasses.contains(name) || name.contains("[") || !ins.isModifiableClass(c)) {
        continue;
      }
      try {
        ClassNode cn = Loader.classToNode(name);
        if (cn != null) {
          classes.put(name, cn);
          output.put(name, ASMUtils.getNodeBytes0(cn));
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  return classes;
}
 
Example #4
Source File: ApiDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private void checkExtendsClass(ClassContext context, ClassNode classNode, int classMinSdk,
        String signature) {
    int api = mApiDatabase.getClassVersion(signature);
    if (api > classMinSdk) {
        String fqcn = ClassContext.getFqcn(signature);
        String message = String.format(
                "Class requires API level %1$d (current min is %2$d): `%3$s`",
                api, classMinSdk, fqcn);

        String name = signature.substring(signature.lastIndexOf('/') + 1);
        name = name.substring(name.lastIndexOf('$') + 1);
        SearchHints hints = SearchHints.create(BACKWARD).matchJavaSymbol();
        int lineNumber = ClassContext.findLineNumber(classNode);
        Location location = context.getLocationForLine(lineNumber, name, null,
                hints);
        context.report(UNSUPPORTED, location, message);
    }
}
 
Example #5
Source File: JarUtils.java    From bytecode-viewer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new ClassNode instances from the provided byte[]
 *
 * @param bytez the class file's byte[]
 * @return the ClassNode instance
 */
public static ClassNode getNode(final byte[] bytez) throws Exception {
    ClassReader cr = new ClassReader(bytez);
    ClassNode cn = new ClassNode();
    try {
        cr.accept(cn, ClassReader.EXPAND_FRAMES);
    } catch (Exception e) {
        try {
            cr.accept(cn, ClassReader.SKIP_FRAMES);
        } catch (Exception e2) {
            throw e2;
        }
    }
    cr = null;
    return cn;
}
 
Example #6
Source File: AsmHelper.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
public static <T> Class<? extends T> createSubClass(Class<T> superClass, String nameSuffix, int constructorParams)
{
    ClassNode superNode = createClassNode(superClass);
    MethodNode constructor = findConstructor(superNode, constructorParams);
    String className = superClass.getName().replace('.', '/') + "_" + nameSuffix.replace(":", "_");

    ClassWriter cw = new ClassWriter(0);
    cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(superClass), null);

    // Constructor
    MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, constructor.name, constructor.desc, null, null);
    int[] opcodes = createLoadOpcodes(constructor);
    for (int i = 0; i < opcodes.length; i++)
    {
        mv.visitVarInsn(opcodes[i], i);
    }
    mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(superClass), constructor.name, constructor.desc, false);
    mv.visitInsn(RETURN);
    mv.visitMaxs(constructorParams + 1, constructorParams + 1);
    mv.visitEnd();

    byte[] byteCode = cw.toByteArray();

    return (Class<? extends T>) createClassFromBytes(className, byteCode);
}
 
Example #7
Source File: RedirectionVisitor.java    From Stark with Apache License 2.0 6 votes vote down vote up
/**
 * Add a new method in the list of unseen methods in the instrumentedClass hierarchy.
 *
 * @param name              the dispatching name that will be used for matching callers to the passed method.
 * @param instrumentedClass class that is being visited
 * @param superClass        the class or interface defining the passed method.
 * @param method            the method to study
 * @param methods           the methods arlready encountered in the ClassNode hierarchy
 * @return the newly added {@link MethodReference} of null if the method was not added for any
 * reason.
 */
@Nullable
private static MethodReference addNewMethod(
        String name,
        ClassNode instrumentedClass,
        ClassNode superClass,
        MethodNode method,
        Map<String, MethodReference> methods) {
    if (isAccessCompatibleWithStark(method.access)
            && !methods.containsKey(name)
            && (method.access & Opcodes.ACC_STATIC) == 0
            && isCallableFromSubclass(method, superClass, instrumentedClass)) {
        MethodReference methodReference = new MethodReference(method, superClass);
        methods.put(name, methodReference);
        return methodReference;
    }
    return null;
}
 
Example #8
Source File: MergeIdentifier.java    From JReFrameworker with MIT License 6 votes vote down vote up
private void extractMergeTypeAnnotationValues(ClassNode classNode, AnnotationNode annotation){
	if(classNode != null){
		int phaseValue = 1; // default to 1
		String superTypeValue = null;
		if(annotation.values != null){
	        for (int i = 0; i < annotation.values.size(); i += 2) {
	            String name = (String) annotation.values.get(i);
	            Object value = annotation.values.get(i + 1);
	            if(name.equals(PHASE)){
		        	phaseValue = (int) value;
		        } else if(name.equals(SUPERTYPE)){
	            	superTypeValue = ((String)value).replaceAll("\\.", "/");
	            }
	        }
	    }
		if(superTypeValue == null || superTypeValue.equals("")){
			superTypeValue = classNode.superName;
        }
		mergeTypeAnnotation = new MergeTypeAnnotation(phaseValue, superTypeValue);
	}
}
 
Example #9
Source File: MethodInterfaceTest.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void addMethod() throws Exception {
    final MethodNode methodNode = TestClassLoader.get("com.navercorp.test.pinpoint.jdk8.interfaces.SimpleClass", "welcome");
    final ASMMethodNodeAdapter methodNodeAdapter = new ASMMethodNodeAdapter("com/navercorp/test/pinpoint/jdk8/interfaces/SimpleClass", methodNode);

    final String targetInterfaceName = "com.navercorp.test.pinpoint.jdk8.interfaces.MethodInterface";
    TestClassLoader classLoader = new TestClassLoader();
    classLoader.addTargetClassName(targetInterfaceName);
    classLoader.setTrace(false);
    classLoader.setCallbackHandler(new CallbackHandler() {
        @Override
        public void handle(ClassNode classNode) {
            logger.debug("Add method class={}", classNode.name);
            ASMClassNodeAdapter classNodeAdapter = new ASMClassNodeAdapter(pluginContext, null, null, classNode);
            classNodeAdapter.copyMethod(methodNodeAdapter);
        }
    });
    logger.debug("Interface static method");
    Class<?> clazz = classLoader.loadClass(targetInterfaceName);
    Method method = clazz.getDeclaredMethod("welcome");
    method.invoke(null);
}
 
Example #10
Source File: DefineFinalityIdentifier.java    From JReFrameworker with MIT License 6 votes vote down vote up
private void extractDefineTypeFinalityAnnotationValues(ClassNode classNode, AnnotationNode annotation) {
	int phaseValue = 1; // default to 1
	String typeValue = null;
	Boolean finalityValue = null;
	if (annotation.values != null) {
	    for (int i = 0; i < annotation.values.size(); i += 2) {
	        String name = (String) annotation.values.get(i);
	        Object value = annotation.values.get(i + 1);
	        if(name.equals(PHASE)){
	        	phaseValue = (int) value;
	        } else if(name.equals(TYPE)){
	        	typeValue = ((String)value).replaceAll("\\.", "/");
	        } else if(name.equals(FINALITY)){
	        	finalityValue = (boolean) value;
	        }
	    }
	    if(typeValue != null && finalityValue != null){
	    	String className = typeValue;
	    	if(className.equals("")){
	    		className = classNode.superName;
	    	}
	    	targetTypes.add(new DefineTypeFinalityAnnotation(phaseValue, className, finalityValue));
	    }
	}
}
 
Example #11
Source File: WisdomModelVisitorTest.java    From wisdom with Apache License 2.0 6 votes vote down vote up
@Test
public void parseRegularModel() {
    Reporter reporter = new SystemReporter();
    ComponentWorkbench workbench = mock(ComponentWorkbench.class);
    when(workbench.getType()).thenReturn(Type.getType(MyComponent.class));
    when(workbench.getClassNode()).thenReturn(new ClassNode());
    when(workbench.getElements()).thenReturn(elements);

    FieldNode node = new FieldNode(Opcodes.ACC_PROTECTED, "model", Type.getDescriptor(Crud.class), null, null);

    WisdomModelVisitor visitor = new WisdomModelVisitor(workbench, reporter, node);
    visitor.visit("value", "entity");
    visitor.visitEnd();

    assertThat(elements).hasSize(1);
    Element element = elements.keySet().iterator().next();
    assertThat(element.getName()).isEqualTo("requires");
    assertThat(element.getAttribute("field")).isEqualTo("model");
    assertThat(element.getAttribute("filter")).contains("=entity)");

}
 
Example #12
Source File: MCStripTransformer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static byte[] transform(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);

    boolean changed = false;
    Iterator<MethodNode> it = cnode.methods.iterator();
    while (it.hasNext()) {
        MethodNode mnode = it.next();
        ReferenceDetector r = new ReferenceDetector();
        mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) {
        }, r));
        if (r.found) {
            it.remove();
            changed = true;
        }
    }
    if (changed) {
        bytes = ASMHelper.createBytes(cnode, 0);
    }
    return bytes;
}
 
Example #13
Source File: HideCodeTransformer.java    From obfuscator with MIT License 6 votes vote down vote up
@Override
public void visit(Map<String, ClassNode> classMap) {
    classMap.values().forEach(classNode -> {
        if (!(AccessUtil.isSynthetic(classNode.access) && classNode.visibleAnnotations == null))
            classNode.access |= ACC_SYNTHETIC;

        classNode.methods.forEach(methodNode -> {
            if (!AccessUtil.isSynthetic(methodNode.access))
                methodNode.access |= ACC_SYNTHETIC;

            if (!methodNode.name.startsWith("<") && AccessUtil.isBridge(methodNode.access))
                methodNode.access |= ACC_BRIDGE;
        });

        classNode.fields.forEach(fieldNode -> {
            if (!AccessUtil.isSynthetic(fieldNode.access))
                fieldNode.access |= ACC_SYNTHETIC;
        });
    });
}
 
Example #14
Source File: MappingProcessor.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Given a map of ClassNodes and mappings, returns a map of class names to
 * class bytes.
 * 
 * @param nodes
 * @param mappings
 * @return
 */
public static Map<String, byte[]> process(Map<String, ClassNode> nodes, Map<String, MappedClass> mappings, boolean useMaxs) {
	Map<String, byte[]> out = new HashMap<String, byte[]>();
	SkidRemapper mapper = new SkidRemapper(mappings);
	try {
		for (ClassNode cn : nodes.values()) {
			ClassWriter cw = new MappingClassWriter(mappings, useMaxs ? ClassWriter.COMPUTE_MAXS : ClassWriter.COMPUTE_FRAMES);
			ClassVisitor remapper = new ClassRemapper(cw, mapper);
			cn.accept(remapper);
			out.put(mappings.containsKey(cn.name) ? mappings.get(cn.name).getNewName() : cn.name, cw.toByteArray());
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	return out;
}
 
Example #15
Source File: LineNumberTransformer.java    From obfuscator with MIT License 6 votes vote down vote up
@Override
public void visit(Map<String, ClassNode> classMap) {
    classMap.values().forEach(classNode -> classNode.methods.forEach(methodNode ->
            Arrays.stream(methodNode.instructions.toArray()).forEachOrdered(ain -> {
                try {
                    final AbstractInsnNode current = ain.getNext();
                    if (current == null)
                        return;
                    if (!(current instanceof LineNumberNode))
                        return;

                    methodNode.instructions.iterator().set(new LineNumberNode(RandomUtil.nextInt(), ((LineNumberNode) current).start));
                } catch (Exception ignored) {
                }
            })));
}
 
Example #16
Source File: DecompilerTab.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
public void decompile(ClassNode cn, MethodNode mn, boolean deleteCache) {
  if (cn == null) {
    return;
  }
  Decompiler d = null;
  switch (decompiler) {
  case PROCYON:
    d = new ProcyonDecompiler(jbm, dp);
    break;
  case FERNFLOWER:
    d = new FernflowerDecompiler(jbm, dp);
    break;
  case CFR:
    d = new CFRDecompiler(jbm, dp);
    break;
  case KRAKATAU:
    d = new KrakatauDecompiler(jbm, dp);
    break;
  }
  d.setNode(cn, mn);
  if (deleteCache) {
    d.deleteCache();
  }
  d.start();
}
 
Example #17
Source File: JavaThread.java    From deobfuscator with Apache License 2.0 6 votes vote down vote up
public void start() {
    if (!started) {
        started = true;
        ClassNode classNode = context.dictionary.get(instance.type());
        if (classNode != null) {
            MethodNode method = classNode.methods.stream().filter(mn -> mn.name.equals("run") && mn.desc.equals("()V")).findFirst().orElse(null);
            if (method != null) {
                Context threadContext = new Context(context.provider);
                threadContext.dictionary = context.dictionary;
                threadContext.file = context.file;

                thread = new Thread(() -> MethodExecutor.execute(classNode, method, Collections.emptyList(), instance, threadContext));
                ThreadStore.addThread(thread.getId(), this);
                this.context = threadContext;

                thread.start();
                return;
            }
            throw new IllegalArgumentException("Could not find run() method on " + classNode.name);
        }
        throw new IllegalArgumentException("Could not find class " + instance.type());
    } else {
        throw new IllegalStateException("Thread already started");
    }
}
 
Example #18
Source File: AsmUtils.java    From Stark with Apache License 2.0 6 votes vote down vote up
/**
 * Read all directly implemented interfaces from the passed {@link ClassNode} instance.
 *
 * @param classNode           the class
 * @param classReaderProvider a provider to read class bytes from storage
 * @param interfacesList      a builder to store the list of AsmInterfaceNode for each directly
 *                            implemented interfaces, can be empty after method returns.
 * @return true if implemented interfaces could all be loaded, false otherwise.
 * @throws IOException when bytes cannot be read
 */
static boolean readInterfaces(
        @NonNull ClassNode classNode,
        @NonNull ClassNodeProvider classReaderProvider,
        @NonNull ImmutableList.Builder<AsmInterfaceNode> interfacesList)
        throws IOException {
    for (String anInterface : (List<String>) classNode.interfaces) {
        AsmInterfaceNode interfaceNode =
                readInterfaceHierarchy(classReaderProvider, anInterface, classNode);
        if (interfaceNode != null) {
            interfacesList.add(interfaceNode);
        } else {
            return false;
        }
    }
    return true;
}
 
Example #19
Source File: CheckClassAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
/**
 * Checks the given class.
 *
 * @param classReader the class to be checked.
 * @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be
 *     {@literal null}.
 * @param printResults whether to print the results of the bytecode verification.
 * @param printWriter where the results (or the stack trace in case of error) must be printed.
 */
public static void verify(
    final ClassReader classReader,
    final ClassLoader loader,
    final boolean printResults,
    final PrintWriter printWriter) {
  ClassNode classNode = new ClassNode();
  classReader.accept(
      new CheckClassAdapter(Opcodes.ASM7, classNode, false) {}, ClassReader.SKIP_DEBUG);

  Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName);
  List<MethodNode> methods = classNode.methods;

  List<Type> interfaces = new ArrayList<Type>();
  for (String interfaceName : classNode.interfaces) {
    interfaces.add(Type.getObjectType(interfaceName));
  }

  for (MethodNode method : methods) {
    SimpleVerifier verifier =
        new SimpleVerifier(
            Type.getObjectType(classNode.name),
            syperType,
            interfaces,
            (classNode.access & Opcodes.ACC_INTERFACE) != 0);
    Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier);
    if (loader != null) {
      verifier.setClassLoader(loader);
    }
    try {
      analyzer.analyze(classNode.name, method);
    } catch (AnalyzerException e) {
      e.printStackTrace(printWriter);
    }
    if (printResults) {
      printAnalyzerResult(method, analyzer, printWriter);
    }
  }
  printWriter.flush();
}
 
Example #20
Source File: MappingFactory.java    From zelixkiller with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a map of class names to mapped classes given a map of class names
 * to ClassNodes.
 * 
 * @param nodes
 * @return
 */
public static Map<String, MappedClass> mappingsFromNodes(Map<String, ClassNode> nodes) {
	Map<String, MappedClass> mappings = new HashMap<String, MappedClass>();
	for (ClassNode node : nodes.values()) {
		mappings = generateClassMapping(node, nodes, mappings);
	}
	for (String name : mappings.keySet()) {
		mappings = linkMappings(mappings.get(name), mappings);
	}
	return mappings;
}
 
Example #21
Source File: ClassMemberList.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public void setMethods(ClassNode cn) {
	root.removeAllChildren();
	for (MethodNode mn : cn.methods) {
		root.add(new MethodListNode(cn, mn));
	}
	this.model.reload();
	this.repaint();
}
 
Example #22
Source File: InstructionPanel.java    From Cafebabe with GNU General Public License v3.0 5 votes vote down vote up
public InstructionPanel(ClassNode cn, MethodNode mn) {
	this.setFocusable(false);
	this.setLayout(new BorderLayout());
	InstructionList il = new InstructionList(cn, mn);
	this.add(il, BorderLayout.CENTER);
	JPanel p = new JPanel();
	p.setLayout(new BorderLayout());
	p.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.gray));
	p.add(new AdressList(il), BorderLayout.CENTER);
	this.add(p, BorderLayout.WEST);
}
 
Example #23
Source File: BadAnnotationTransformer.java    From obfuscator with MIT License 5 votes vote down vote up
@Override
public void visit(Map<String, ClassNode> classMap) {
    classMap.values().forEach(classNode -> {
        if (classNode.visibleAnnotations == null)
            classNode.visibleAnnotations = new ArrayList<>();
        if (classNode.invisibleAnnotations == null)
            classNode.invisibleAnnotations = new ArrayList<>();

        classNode.visibleAnnotations.addAll(annotationSet);
        classNode.invisibleAnnotations.addAll(annotationSet);

        classNode.methods.forEach(methodNode -> {
            if (methodNode.visibleAnnotations == null)
                methodNode.visibleAnnotations = new ArrayList<>();
            if (methodNode.invisibleAnnotations == null)
                methodNode.invisibleAnnotations = new ArrayList<>();

            methodNode.visibleAnnotations.addAll(annotationSet);
            methodNode.invisibleAnnotations.addAll(annotationSet);
        });

        classNode.fields.forEach(fieldNode -> {
            if (fieldNode.visibleAnnotations == null)
                fieldNode.visibleAnnotations = new ArrayList<>();
            if (fieldNode.invisibleAnnotations == null)
                fieldNode.invisibleAnnotations = new ArrayList<>();

            fieldNode.visibleAnnotations.addAll(annotationSet);
            fieldNode.invisibleAnnotations.addAll(annotationSet);
        });
    });
}
 
Example #24
Source File: TemplateInjector.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public InjectionTemplate(String templateName) {
	this.templateName = templateName;

	/**
	 * Read the class node, scanning all the method implementations
	 */
	ClassNode cnode = getClassNode(templateName);

	for (MethodNode method : cnode.methods) {
		methodImplementations.add(method);
		method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
	}
}
 
Example #25
Source File: LintDriver.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns whether the given issue is suppressed in the given method.
 *
 * @param issue the issue to be checked, or null to just check for "all"
 * @param classNode the class containing the issue
 * @param method the method containing the issue
 * @param instruction the instruction within the method, if any
 * @return true if there is a suppress annotation covering the specific
 *         issue on this method
 */
public boolean isSuppressed(
        @Nullable Issue issue,
        @NonNull ClassNode classNode,
        @NonNull MethodNode method,
        @Nullable AbstractInsnNode instruction) {
    if (method.invisibleAnnotations != null) {
        @SuppressWarnings("unchecked")
        List<AnnotationNode> annotations = method.invisibleAnnotations;
        return isSuppressed(issue, annotations);
    }

    // Initializations of fields end up placed in generated methods (<init>
    // for members and <clinit> for static fields).
    if (instruction != null && method.name.charAt(0) == '<') {
        AbstractInsnNode next = LintUtils.getNextInstruction(instruction);
        if (next != null && next.getType() == AbstractInsnNode.FIELD_INSN) {
            FieldInsnNode fieldRef = (FieldInsnNode) next;
            FieldNode field = findField(classNode, fieldRef.owner, fieldRef.name);
            if (field != null && isSuppressed(issue, field)) {
                return true;
            }
        } else if (classNode.outerClass != null && classNode.outerMethod == null
                    && isAnonymousClass(classNode)) {
            if (isSuppressed(issue, classNode)) {
                return true;
            }
        }
    }

    return false;
}
 
Example #26
Source File: XXXdont_use_JCasCoverClassFactory.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
   * Create - no customization case
   *          not used for TOP or other built-in predefined types
   * @return the class as a byte array
   */
  byte[] createJCasCoverClass(TypeImpl type) {
    this.type = type;
    this.tsi = (TypeSystemImpl) type.getTypeSystem();
    typeJavaDescriptor = type.getJavaDescriptor();
    typeJavaClassName = type.getName().replace('.', '/');
    cn = new ClassNode(ASM5); // java 8
    cn.version = javaClassVersion;
    cn.access = ACC_PUBLIC + ACC_SUPER;
    cn.name = typeJavaClassName;   
    cn.superName = type.getSuperType().getName().replace('.', '/');
//    cn.interfaces = typeImpl.getInterfaceNamesArray();   // TODO
    
    // add the "type" field - this has the int type code
    cn.fields.add(new FieldNode(ACC_PUBLIC + ACC_FINAL + ACC_STATIC,
        "type", "I", null, null));
    
    // add field declares, and getters and setters, and special getters/setters for array things    
    type.getMergedStaticFeaturesIntroducedByThisType().stream()
          .forEach(this::addFeatureFieldGetSet);
 
    addStaticInitAndConstructors();
    
    
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    cn.accept(cw);
    return cw.toByteArray();
  }
 
Example #27
Source File: ClassHeirachyManager.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static SuperCache declareASM(byte[] bytes) {
	ClassNode node = ASMHelper.createClassNode(bytes);
	String name = toKey(node.name);

	SuperCache cache = getOrCreateCache(name);
	cache.superclass = toKey(node.superName.replace('/', '.'));
	cache.add(cache.superclass);
	for (String iclass : node.interfaces) {
		cache.add(toKey(iclass.replace('/', '.')));
	}

	return cache;
}
 
Example #28
Source File: MonitorVisitor.java    From Stark with Apache License 2.0 5 votes vote down vote up
@Nullable
protected static FieldNode getFieldByNameInClass(
        @NonNull String fieldName, @NonNull ClassNode classNode) {
    //noinspection unchecked ASM api.
    List<FieldNode> fields = classNode.fields;
    for (FieldNode field : fields) {
        if (field.name.equals(fieldName)) {
            return field;
        }
    }
    return null;
}
 
Example #29
Source File: FirstOrderHelper.java    From buck with Apache License 2.0 5 votes vote down vote up
public static void addTypesAndDependencies(
    Iterable<Type> scenarioTypes,
    Iterable<ClassNode> allClasses,
    ImmutableSet.Builder<String> classNamesBuilder) {
  FirstOrderHelper helper = new FirstOrderHelper(scenarioTypes, classNamesBuilder);
  helper.addDependencies(allClasses);
}
 
Example #30
Source File: JVMMethodProvider.java    From deobfuscator with Apache License 2.0 5 votes vote down vote up
private static void initObject(Context context, String className, JavaValue object) { 
    ClassNode classNode = context.dictionary.get(className);
    if (classNode != null) {
        for (FieldNode field : classNode.fields) {
            switch (field.desc) { 
                case "B": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, (byte) 0, context);
                    break; 
                case "S": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, (short) 0, context);
                    break; 
                case "I": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, 0, context);
                    break; 
                case "J": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, 0L, context);
                    break; 
                case "F": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, 0.0, context);
                    break; 
                case "D": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, 0.0D, context);
                    break; 
                case "C": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, (char) 0, context);
                    break; 
                case "Z": 
                    context.provider.setField(classNode.name, field.name, field.desc, object, false, context);
                    break; 
            } 
        } 
    } else { 
        throw new RuntimeException("Could not initialize class " + className); 
    } 
}