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


Java ClassReader类代码示例

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


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

示例1: readJar

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
public static Application readJar(Path path) throws IOException {
	Application application = new Application();

	try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
		JarEntry entry;
		while ((entry = in.getNextJarEntry()) != null) {
			String name = entry.getName();
			if (!name.endsWith(".class")) continue;

			name = name.replaceAll(".class$", "");

			ClassNode node = new ClassNode();
			ClassReader reader = new ClassReader(in);
			reader.accept(node, ClassReader.SKIP_DEBUG);

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

	return application;
}
 
开发者ID:jonathanedgecombe,项目名称:mithril,代码行数:22,代码来源:Application.java

示例2: loadGameInfo

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
private GameInfo loadGameInfo(File file) {
    GameInfo.Builder builder = new GameInfo.Builder(file);

    try {
        JarFile jar = new JarFile(file);

        for (ZipEntry entry : Collections.list(jar.entries())) {
            if (!entry.getName().matches("(.+).(class)")) {
                continue;
            }

            ClassReader reader = new ClassReader(jar.getInputStream(entry));
            reader.accept(new GameClassVisitor(builder), 0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return builder.build();
}
 
开发者ID:Dragovorn,项目名称:gamecraft,代码行数:21,代码来源:GameManager.java

示例3: main

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
  final String k2 = "org/apache/drill/Pickle.class";
  final URL url = Resources.getResource(k2);
  final byte[] clazz = Resources.toByteArray(url);
  final ClassReader cr = new ClassReader(clazz);

  final ClassWriter cw = writer();
  final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
  final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
  cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);

  final byte[] output = cw.toByteArray();
  Files.write(output, new File("/src/scratch/bytes/S.class"));
  check(output);

  final DrillConfig c = DrillConfig.forClient();
  final SystemOptionManager m = new SystemOptionManager(c, new LocalPStoreProvider(c));
  m.init();
  try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
    ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
    Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
    clz.getMethod("x").invoke(null);
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:25,代码来源:ReplaceMethodInvoke.java

示例4: rewriteClass

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
/**
 * Writes a modified *.class file to the output JAR file.
 */
private void rewriteClass(
        JarEntry entry,
        InputStream inputStream,
        JarOutputStream outputStream) throws IOException {
    ClassReader classReader = new ClassReader(inputStream);
    ClassNode classNode = new ClassNode(Opcodes.ASM5);

    classReader.accept(classNode, EMPTY_FLAGS);
    
    modifyClass(classNode);
    
    ClassWriter classWriter = new ClassWriter(0);
    classNode.accept(classWriter);
    
    outputStream.putNextEntry(new ZipEntry(entry.getName()));
    outputStream.write(classWriter.toByteArray());
}
 
开发者ID:codezjx,项目名称:MockableJarGenerator,代码行数:21,代码来源:MockableJarGenerator.java

示例5: getClassDependencies

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
private Set<String> getClassDependencies(ClassRelevancyFilter filter, ClassReader reader) {
    Set<String> out = new HashSet<String>();
    char[] charBuffer = new char[reader.getMaxStringLength()];
    for (int i = 1; i < reader.getItemCount(); i++) {
        int itemOffset = reader.getItem(i);
        if (itemOffset > 0 && reader.readByte(itemOffset - 1) == 7) {
            // A CONSTANT_Class entry, read the class descriptor
            String classDescriptor = reader.readUTF8(itemOffset, charBuffer);
            Type type = Type.getObjectType(classDescriptor);
            while (type.getSort() == Type.ARRAY) {
                type = type.getElementType();
            }
            if (type.getSort() != Type.OBJECT) {
                // A primitive type
                continue;
            }
            String name = type.getClassName();
            if (filter.isRelevant(name)) {
                out.add(name);
            }
        }
    }
    return out;
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:25,代码来源:DefaultClassDependenciesAnalyzer.java

示例6: remapClasses

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
private void remapClasses(File scriptCacheDir, File relocalizedDir, RemappingScriptSource source) {
    ScriptSource origin = source.getSource();
    String className = origin.getClassName();
    if (!relocalizedDir.exists()) {
        relocalizedDir.mkdir();
    }
    File[] files = scriptCacheDir.listFiles();
    if (files != null) {
        for (File file : files) {
            String renamed = file.getName();
            if (renamed.startsWith(RemappingScriptSource.MAPPED_SCRIPT)) {
                renamed = className + renamed.substring(RemappingScriptSource.MAPPED_SCRIPT.length());
            }
            ClassWriter cv = new ClassWriter(0);
            BuildScriptRemapper remapper = new BuildScriptRemapper(cv, origin);
            try {
                ClassReader cr = new ClassReader(Files.toByteArray(file));
                cr.accept(remapper, 0);
                Files.write(cv.toByteArray(), new File(relocalizedDir, renamed));
            } catch (IOException ex) {
                throw UncheckedException.throwAsUncheckedException(ex);
            }
        }
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:26,代码来源:FileCacheBackedScriptClassCompiler.java

示例7: transform

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
public byte[] transform(String name, byte[] basicClass) {
	int i = 0;
	while (i < transformers.size()) {
		if (transformers.get(i).is(name)) {
			ClassNode classNode = new ClassNode();
			ClassReader classReader = new ClassReader(basicClass);
			classReader.accept(classNode, 0);

			transformers.get(i).transform(classNode);

			ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
			classNode.accept(writer);
			basicClass = writer.toByteArray();

			System.out.println("[" + MineCamera.MODID + "] Patched " + transformers.get(i).className + " ...");
			transformers.get(i).done();
			i++;
			// transformers.remove(i);
		} else
			i++;
	}
	return basicClass;
}
 
开发者ID:PorPit,项目名称:MineCamera,代码行数:24,代码来源:CamTransformer.java

示例8: findAndMergeSuperMaps

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
private void findAndMergeSuperMaps(String name)
{
    try
    {
        String superName = null;
        String[] interfaces = new String[0];
        byte[] classBytes = ClassPatchManager.INSTANCE.getPatchedResource(name, map(name), classLoader);
        if (classBytes != null)
        {
            ClassReader cr = new ClassReader(classBytes);
            superName = cr.getSuperName();
            interfaces = cr.getInterfaces();
        }
        mergeSuperMaps(name, superName, interfaces);
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:21,代码来源:FMLDeobfuscatingRemapper.java

示例9: 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

示例10: 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

示例11: process

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
JavaClasses process(ClassFileSource source) {
    ClassFileImportRecord importRecord = new ClassFileImportRecord();
    RecordAccessHandler accessHandler = new RecordAccessHandler(importRecord);
    ClassDetailsRecorder classDetailsRecorder = new ClassDetailsRecorder(importRecord);
    for (ClassFileLocation location : source) {
        try (InputStream s = location.openStream()) {
            JavaClassProcessor javaClassProcessor =
                    new JavaClassProcessor(location.getUri(), classDetailsRecorder, accessHandler);
            new ClassReader(s).accept(javaClassProcessor, 0);
            importRecord.addAll(javaClassProcessor.createJavaClass().asSet());
        } catch (Exception e) {
            LOG.warn(String.format("Couldn't import class from %s", location.getUri()), e);
        }
    }
    return new ClassGraphCreator(importRecord, getClassResolver(classDetailsRecorder)).complete();
}
 
开发者ID:TNG,项目名称:ArchUnit,代码行数:17,代码来源:ClassFileProcessor.java

示例12: 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

示例13: getCommonInterface

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
private String getCommonInterface(final ClassReader classReader1, final ClassReader classReader2) {
    final Set<String> interfaceHierarchy = new HashSet<String>();
    traversalInterfaceHierarchy(interfaceHierarchy, classReader1);

    if (isInterface(classReader2)) {
        if (interfaceHierarchy.contains(classReader2.getClassName())) {
            return classReader2.getClassName();
        }
    }

    final String interfaceInternalName = getImplementedInterface(interfaceHierarchy, classReader2);
    if (interfaceInternalName != null) {
        return interfaceInternalName;
    }
    return OBJECT_CLASS_INTERNAL_NAME;
}
 
开发者ID:willfleury,项目名称:prometheus-metrics-agent,代码行数:17,代码来源:ASMClassWriter.java

示例14: transform

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
@Override
    public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {

        if(className.startsWith(TransformConfig.getInstance().getPackageScan())) {
            logger.log(Level.INFO, "-------------------CLASS---------------------");
            logger.log(Level.INFO, "className: " + className);
            ClassReader cr = new ClassReader(classfileBuffer);
            ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);

            ClassVisitor classVisitor = new HookClassAdapter(Opcodes.ASM5, cw);
            cr.accept(classVisitor, ClassReader.SKIP_FRAMES);
//            try {
//                FileOutputStream fos = new FileOutputStream(new File("classMod.class"));
//                fos.write(cw.toByteArray());
//                fos.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }

            return cw.toByteArray();
        }
        return null;

    }
 
开发者ID:acmerli,项目名称:fastAOP,代码行数:25,代码来源:CatchBlockClassTransformer.java

示例15: transformCode

import org.objectweb.asm.ClassReader; //导入依赖的package包/类
public byte[] transformCode(String className, byte[] fb) {
        this.className = className;
        ClassReader cr = new ClassReader(fb);
//        ClassReader cr = new ClassReader(className);
        ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
        ClassVisitor cv = new ClassInsert(cw);
        cr.accept(cv, ClassReader.EXPAND_FRAMES);

        /*byte[] code = cw.toByteArray();
        File file = new File("Idtk.class");
        try {
            FileUtils.writeByteArrayToFile(file,code);
        }catch (IOException e){
            System.out.println("=======IOException=======");
        }*/
        return cw.toByteArray();
    }
 
开发者ID:Idtk,项目名称:Hotfix,代码行数:18,代码来源:ASMInsert.java


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