当前位置: 首页>>代码示例>>Java>>正文


Java ClassReader.accept方法代码示例

本文整理汇总了Java中org.objectweb.asm.ClassReader.accept方法的典型用法代码示例。如果您正苦于以下问题:Java ClassReader.accept方法的具体用法?Java ClassReader.accept怎么用?Java ClassReader.accept使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.ClassReader的用法示例。


在下文中一共展示了ClassReader.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: readClassAsEntry

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static Map<String, Set<String>> readClassAsEntry(InputStream input) {
  HashMap<String, Set<String>> map = new HashMap<>(); 
  try {
    ClassReader reader = new ClassReader(input);
    String className = reader.getClassName().replace('/', '.');
    reader.accept(new ClassVisitor(Opcodes.ASM6) {
      @Override
      public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
        String methodName = className + '.' + name;
        map.computeIfAbsent(methodName, __ -> new HashSet<>()).add(methodName + desc);
        return null;
      }
    }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG);
  } catch(IOException e) {
    throw new UncheckedIOException(e);
  }
  return map;
}
 
开发者ID:forax,项目名称:moduletools,代码行数:19,代码来源:JITTraceReader.java

示例2: checkAnnotationContent

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void checkAnnotationContent(Path inputPath, Path outputPath)
    throws IOException, ExecutionException {
  ClassReader classReader = new ClassReader(new FileInputStream(inputPath.toFile()));
  ReadSourceDebugExtensionAttribute sourceDebugExtensionReader =
      new ReadSourceDebugExtensionAttribute(Opcodes.ASM5, null);
  classReader.accept(sourceDebugExtensionReader, 0);

  DexInspector dexInspector =
      new DexInspector(outputPath.resolve("classes.dex"), getGeneratedProguardMap());
  ClassSubject classSubject = dexInspector.clazz("HelloKt");

  AnnotationSubject annotationSubject =
      classSubject.annotation("dalvik.annotation.SourceDebugExtension");
  Assert.assertTrue(annotationSubject.isPresent());
  DexAnnotationElement[] annotationElement = annotationSubject.getAnnotation().elements;
  Assert.assertNotNull(annotationElement);
  Assert.assertTrue(annotationElement.length == 1);
  Assert.assertEquals("value", annotationElement[0].name.toString());
  Assert.assertTrue(annotationElement[0].value instanceof DexValueString);
  Assert.assertEquals(
      sourceDebugExtensionReader.debugSourceExtension,
      ((DexValueString) annotationElement[0].value).value.toSourceString());
}
 
开发者ID:inferjay,项目名称:r8,代码行数:24,代码来源:JSR45Tests.java

示例3: readJar

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
public static Map<String, ClassNode> readJar(JarFile file, boolean skipDebug) throws IOException {
    Map<String, ClassNode> classes = new HashMap<>();

    Enumeration<JarEntry> entries = file.entries();

    while (entries.hasMoreElements()) {
        JarEntry entry = entries.nextElement();

        String name = entry.getName();

        if (name.endsWith(".class")) {
            try (InputStream inputStream = file.getInputStream(entry)) {
                ClassReader reader = new ClassReader(inputStream);

                ClassNode node = new ClassNode();
                reader.accept(node, (skipDebug ? ClassReader.SKIP_DEBUG : 0) | ClassReader.SKIP_FRAMES);

                classes.put(node.name, node);
            }
        }
    }

    return classes;
}
 
开发者ID:UniquePassive,项目名称:osrs-exploits,代码行数:25,代码来源:JarUtil.java

示例4: analyzeClassesForLocalDeadCode

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void analyzeClassesForLocalDeadCode(String dir, Set<String> classesToVisit)
		throws IOException, XMLStreamException {
	for (final String className : classesToVisit) {
		if (isInterrupted()) {
			break;
		}
		// les classes *SoapBindingStub générées par Apache Axis
		// contiennent beaucoup des variables locales non utilisées,
		// mais il est inutile de le signaler puisque c'est généré par Axis
		if (!className.endsWith("SoapBindingStub")) {
			final ClassNode classNode = new ClassNode();
			final ClassReader classReader = createClassReader(dir, className);
			classReader.accept(classNode, ClassReader.EXPAND_FRAMES);

			for (final MethodNode methodNode : (List<MethodNode>) classNode.methods) {
				analyzeMethodForLocalDeadCode(dir, className, classNode, methodNode);
				analyzeMethodForSelfAssignments(className, methodNode);
				if (Factory.createStringToStringAnalyzer(methodNode).analyze()) {
					report.reportStringToString(className, methodNode);
					suspectCount++;
				}
			}
		}
	}
}
 
开发者ID:evernat,项目名称:dead-code-detector,代码行数:27,代码来源:DeadCodeDetector.java

示例5: generateTests

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void generateTests() throws IOException {
  ClassReader cr = new ClassReader(new FileInputStream(classNamePath.toFile()));
  ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
  cr.accept(
      new ClassVisitor(Opcodes.ASM5, cw) {
        @Override
        public void visitEnd() {
          generateMethodTest1(cw);
          generateMethodTest2(cw);
          generateMethodTest3(cw);
          generateMethodTest4(cw);
          generateMethodTest5(cw);
          generateMethodTest6(cw);
          generateMethodTest7(cw);
          generateMethodTest8(cw);
          generateMethodTest9(cw);
          generateMethodTest10(cw);
          generateMethodTest11(cw);
          generateMethodTest12(cw);
          generateMethodTest13(cw);
          generateMethodMain(cw);
          super.visitEnd();
        }
      }, 0);
  new FileOutputStream(classNamePath.toFile()).write(cw.toByteArray());
}
 
开发者ID:inferjay,项目名称:r8,代码行数:27,代码来源:TestGenerator.java

示例6: process

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile, String message) throws Throwable {
    ZipFile zipFile = new ZipFile(jarFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
                try (InputStream in = zipFile.getInputStream(entry)) {
                    ClassReader cr = new ClassReader(in);
                    ClassNode classNode = new ClassNode();
                    cr.accept(classNode, 0);

                    messageInjector(classNode, message);

                    ClassWriter cw = new ClassWriter(0);
                    classNode.accept(cw);
                    ZipEntry newEntry = new ZipEntry(entry.getName());
                    newEntry.setTime(System.currentTimeMillis());
                    out.putNextEntry(newEntry);
                    writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
                }
            } else {
                entry.setTime(System.currentTimeMillis());
                out.putNextEntry(entry);
                writeToFile(out, zipFile.getInputStream(entry));
            }
        }
    } finally {
        zipFile.close();
        out.close();
        if (!messagegotinjected) {
            // throw new IllegalStateException("Could not find Bukkit onEnable or onLoad method.");
            throw new IllegalStateException("Could not find Bukkit onEnable method.");
        }
    }
}
 
开发者ID:ItzSomebody,项目名称:BukkitPlugin-Message-Injector,代码行数:38,代码来源:Injector.java

示例7: extractApiClassFrom

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
/**
 * Extracts an API class from a given original class.
 *
 * @param originalClassReader the reader containing the original class
 * @return bytecode of the API class extracted from the original class
 */
public byte[] extractApiClassFrom(ClassReader originalClassReader) {
    ClassWriter apiClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    originalClassReader.accept(
        new ApiMemberSelector(new MethodStubbingApiMemberAdapter(apiClassWriter), apiIncludesPackagePrivateMembers),
        ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
    return apiClassWriter.toByteArray();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:14,代码来源:ApiClassExtractor.java

示例8: transform

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private static byte[] transform(byte[] serverClass, boolean isObfuscated, transformType type)
{
    System.out.println("MALMO: Attempting to transform MinecraftServer");
    try
    {
        ClassNode cnode = new ClassNode();
        ClassReader creader = new ClassReader(serverClass);
        creader.accept(cnode, 0);
        
        switch (type)
        {
        case SERVER:
            overclockServer(cnode, isObfuscated);
            break;
        case RENDERER:
            overclockRenderer(cnode, isObfuscated);
            break;
        }
        
        ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
        cnode.accept(cwriter);
        return cwriter.toByteArray();
    }
    catch (Exception e)
    {
        System.out.println("MALMO FAILED to transform MinecraftServer - overclocking not available!");
    }
    return serverClass;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:30,代码来源:OverclockingClassTransformer.java

示例9: load

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public Map<String, ClassNode> load() throws IOException {
    Map<String, ClassNode> clses = new HashMap<String, ClassNode>();
    for (String name : classes.keySet()) {
        ClassNode   node   = new ClassNode();
        ClassReader reader = new ClassReader(classes.get(name));
        reader.accept(node, ClassReader.SKIP_FRAMES | ClassReader.SKIP_DEBUG);
        clses.put(node.name.replace(".class", ""), node);
    }
    return clses;
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:12,代码来源:ClassArchive.java

示例10: getFieldType

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private String getFieldType(String owner, String name)
{
    if (fieldDescriptions.containsKey(owner))
    {
        return fieldDescriptions.get(owner).get(name);
    }
    synchronized (fieldDescriptions)
    {
        try
        {
            byte[] classBytes = ClassPatchManager.INSTANCE.getPatchedResource(owner, map(owner).replace('/', '.'), classLoader);
            if (classBytes == null)
            {
                return null;
            }
            ClassReader cr = new ClassReader(classBytes);
            ClassNode classNode = new ClassNode();
            cr.accept(classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
            Map<String,String> resMap = Maps.newHashMap();
            for (FieldNode fieldNode : classNode.fields) {
                resMap.put(fieldNode.name, fieldNode.desc);
            }
            fieldDescriptions.put(owner, resMap);
            return resMap.get(name);
        }
        catch (IOException e)
        {
            FMLRelaunchLog.log(Level.ERROR,e, "A critical exception occurred reading a class file %s", owner);
        }
        return null;
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:33,代码来源:FMLDeobfuscatingRemapper.java

示例11: readClass

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
static ClassNode readClass(Path path) {
	try {
		ClassReader reader = new ClassReader(Files.readAllBytes(path));
		ClassNode cn = new ClassNode();
		reader.accept(cn, ClassReader.EXPAND_FRAMES);

		return cn;
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:12,代码来源:ClassEnvironment.java

示例12: apply

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public byte[] apply(byte[] origin) {
    ClassReader reader = new ClassReader(origin);
    PredicateClassVisitor precondition = new PredicateClassVisitor();
    reader.accept(precondition, SKIP_DEBUG | SKIP_FRAMES);
    if (!precondition.isAttemptToVisitR()) {
        return origin;
    }
    // don't pass reader to the writer.
    // or it will copy 'CONSTANT POOL' that contains no used entries to lead proguard running failed!
    ClassWriter writer = new ClassWriter(0);
    ClassVisitor visitor = new ShrinkRClassVisitor(writer, rSymbols);
    reader.accept(visitor, 0);
    return writer.toByteArray();
}
 
开发者ID:yrom,项目名称:shrinker,代码行数:16,代码来源:ClassTransform.java

示例13: transform

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
    if(!name.equals(authClassNameObf) && !name.equals(authClassNameDeobf)) return bytes;

    ClassNode clazz = new ClassNode();
    ClassReader reader = new ClassReader(bytes);
    reader.accept(clazz, 0);

    boolean patched = false;

    for(MethodNode method : clazz.methods) {
        String mn = method.name;
        if(!mn.equals(acceptMethodNameSrg)) {
            if(!mn.equals(acceptMethodNameObf) && !mn.equals(acceptMethodNameDeobf)) continue;
            if(!method.desc.equals(acceptMethodDesc)) continue;
        }

        for(int i = 0; i < method.instructions.size(); i++) {
            AbstractInsnNode node = method.instructions.get(i);
            if(node instanceof LabelNode) {
                patchMethod(clazz, method, (LabelNode)node);
                patched = true;
                break;
            }
        }
    }

    if(!patched) return bytes;

    ClassWriter writer = new ClassWriter(0);
    clazz.accept(writer);
    return writer.toByteArray();
}
 
开发者ID:Guichaguri,项目名称:BOHA,代码行数:34,代码来源:BlockTransformer.java

示例14: verify

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
/**
 * Checks a given class.
 * 
 * @param cr
 *            a <code>ClassReader</code> that contains bytecode for the
 *            analysis.
 * @param loader
 *            a <code>ClassLoader</code> which will be used to load
 *            referenced classes. This is useful if you are verifiying
 *            multiple interdependent classes.
 * @param dump
 *            true if bytecode should be printed out not only when errors
 *            are found.
 * @param pw
 *            write where results going to be printed
 */
public static void verify(final ClassReader cr, final ClassLoader loader,
        final boolean dump, final PrintWriter pw) {
    ClassNode cn = new ClassNode();
    cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);

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

    List<Type> interfaces = new ArrayList<Type>();
    for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) {
        interfaces.add(Type.getObjectType(i.next()));
    }

    for (int i = 0; i < methods.size(); ++i) {
        MethodNode method = methods.get(i);
        SimpleVerifier verifier = new SimpleVerifier(
                Type.getObjectType(cn.name), syperType, interfaces,
                (cn.access & Opcodes.ACC_INTERFACE) != 0);
        Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
        if (loader != null) {
            verifier.setClassLoader(loader);
        }
        try {
            a.analyze(cn.name, method);
            if (!dump) {
                continue;
            }
        } catch (Exception e) {
            e.printStackTrace(pw);
        }
        printAnalyzerResult(method, a, pw);
    }
    pw.flush();
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:52,代码来源:CheckClassAdapter.java

示例15: analyzeClasses

import org.objectweb.asm.ClassReader; //导入方法依赖的package包/类
private void analyzeClasses(String dir, Set<String> classesToVisit) throws IOException {
	final ClassVisitor classVisitor = Factory
			.createCallersClassVisitor(result.createCallersMethodVisitor());
	for (final String className : classesToVisit) {
		if (isInterrupted()) {
			break;
		}
		final ClassReader classReader = createClassReader(dir, className);
		classReader.accept(classVisitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
	}
}
 
开发者ID:evernat,项目名称:dead-code-detector,代码行数:12,代码来源:DeadCodeDetector.java


注:本文中的org.objectweb.asm.ClassReader.accept方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。