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


Java CheckClassAdapter类代码示例

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


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

示例1: classNodeToBytes

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
private byte[] classNodeToBytes(ClassNode classNode) {
  ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
  classNode.accept(writer);
  byte[] bytes = writer.toByteArray();

  // verify bytecode

  if (verifyAndPrint) {
    ClassReader reader = new ClassReader(bytes);
    ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.out));
    ClassVisitor checker = new CheckClassAdapter(tracer, true);
    reader.accept(checker, 0);
  }

  return bytes;
}
 
开发者ID:kroepke,项目名称:luna,代码行数:17,代码来源:ASMBytecodeEmitter.java

示例2: checkGeneratedClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
/**
 * Verify class bytecode
 *
 * @param classBytes Class data
 * @return Class data, if it was valid
 * @throws ClassFormatError If class wasn't valid
 */
@Contract("null -> fail")
public static byte[] checkGeneratedClass(byte[] classBytes) throws ClassFormatError {
    Ensure.notNull(classBytes, "Class data shouldn't be null!");
    ClassReader cr = new ClassReader(classBytes);
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    try {
        CheckClassAdapter.verify(cr, false, pw);
    }
    catch (Exception ignored) {}
    if(sw.toString().length() > 0) {
        throw new ClassFormatError(sw.toString());
    }
    return classBytes;
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:23,代码来源:Validate.java

示例3: DrillCheckClassAdapter

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
/**
 * See {@link org.objectweb.asm.util.CheckClassAdapter#CheckClassAdapter(ClassVisitor, boolean)}.
 * @param api the api version
 */
protected DrillCheckClassAdapter(final int api, final ClassVisitor cv,
    final boolean checkDataFlow) {
  super(api);

  /*
   * We set up a chain of class visitors:
   * this -> InnerAccessStripper -> CheckClassAdapter -> AccessRestorer -> cv
   * Note the AccessRestorer references accessStripper to get the original
   * access bits; the inner class could not be constructed before the call to
   * super(), hence the need to set the delegate after that.
   */
  accessStripper = new InnerClassAccessStripper(api, new CheckClassAdapter(
      new AccessRestorer(api, cv), checkDataFlow));
  setDelegate(accessStripper);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:DrillCheckClassAdapter.java

示例4: write

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
@Override
public void write(File file) throws IOException {
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
    try {
        for (Iterator<ClassNode> itr = iterator(); itr.hasNext(); ) {
            ClassNode   node   = itr.next();
            ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
            node.accept(new CheckClassAdapter(writer, true));
            byte[] bytes = writer.toByteArray();
            jos.putNextEntry(new JarEntry(node.name.concat(".class")));
            jos.write(bytes);
        }
    } finally {
        jos.close();
    }
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:17,代码来源:JarArchive.java

示例5: publicize

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
private static void publicize(Path inPath, Path outPath) throws IOException {
	try (JarInputStream in = new JarInputStream(Files.newInputStream(inPath))) {
		try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(outPath))) {
			JarEntry entry;
			while ((entry = in.getNextJarEntry()) != null) {
				if (entry.isDirectory()) {
					continue;
				}

				String name = entry.getName();
				out.putNextEntry(new JarEntry(name));

				if (name.endsWith(".class")) {
					ClassWriter writer = new ClassWriter(0);

					ClassReader reader = new ClassReader(in);
					reader.accept(new CheckClassAdapter(new ClassDefinalizer(new ClassPublicizer(writer)), true), 0);

					out.write(writer.toByteArray());
				} else {
					ByteStreams.copy(in, out);
				}
			}
		}
	}
}
 
开发者ID:jonathanedgecombe,项目名称:anvil,代码行数:27,代码来源:Publicizer.java

示例6: classNodeToBytes

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
private byte[] classNodeToBytes(ClassNode classNode) {
	ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
	classNode.accept(writer);
	byte[] bytes = writer.toByteArray();

	// verify bytecode

	if (verifyAndPrint) {
		ClassReader reader = new ClassReader(bytes);
		ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.out));
		ClassVisitor checker = new CheckClassAdapter(tracer, true);
		reader.accept(checker, 0);
	}

	return bytes;
}
 
开发者ID:mjanicek,项目名称:rembulan,代码行数:17,代码来源:ASMBytecodeEmitter.java

示例7: validateClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
/**
 * Validate a generated class
 *
 * @param reader The class to read
 * @param loader The appropriate class loader
 * @throws RuntimeException On bad validation
 */
public static void validateClass(ClassReader reader, ClassLoader loader) {
	StringWriter writer = new StringWriter();
	PrintWriter printWriter = new PrintWriter(writer);

	Exception error = null;
	try {
		CheckClassAdapter.verify(reader, loader, false, printWriter);
	} catch (Exception e) {
		error = e;
	}

	String contents = writer.toString();
	if (error != null || contents.length() > 0) {
		throw new IllegalStateException(writer.toString(), error);
	}
}
 
开发者ID:SquidDev-CC,项目名称:CCTweaks-Lua,代码行数:24,代码来源:AsmUtils.java

示例8: instrumentClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
private void instrumentClass(String className,
                                    Function<ClassVisitor, ClassVisitor> createShuffler,
                                    ZipFile rt, ZipOutputStream outZip) throws IOException {
    InputStream classStream = null;
    try {
        classStream = rt.getInputStream(rt.getEntry(className));
    } catch (IOException exc) {
        Logger.getGlobal().log(Level.WARNING, "Cannot find " + className + " are you sure this is a valid rt.jar?");
        Logger.getGlobal().log(Level.WARNING, "Continuing without instrumenting: " + className);
    }
    ClassReader cr = new ClassReader(classStream);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
    ClassVisitor cv = createShuffler.apply(cw);

    cr.accept(cv, 0);
    byte[] arr = cw.toByteArray();

    cr = new ClassReader(arr);
    cr.accept(new CheckClassAdapter(new ClassWriter(0)), 0);

    ZipEntry zipEntry = new ZipEntry(className);
    outZip.putNextEntry(zipEntry);
    outZip.write(arr, 0, arr.length);
    outZip.closeEntry();
}
 
开发者ID:TestingResearchIllinois,项目名称:NonDex,代码行数:26,代码来源:Instrumenter.java

示例9: createFunction

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
public static MethodHandle createFunction(Supplier<byte[]> generator, MethodType methodType) {
  byte[] array = generator.get();
  ClassReader reader = new ClassReader(array);
  CheckClassAdapter.verify(reader, true, new PrintWriter(System.out));
  
  Class<?> type = new ClassLoader() {
    Class<?> createClass() {
      return defineClass("Foo", array, 0, array.length);
    }
  }.createClass();
  try {
    return MethodHandles.publicLookup().findStatic(type, "foo", methodType);
  } catch (NoSuchMethodException | IllegalAccessException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:forax,项目名称:vmboiler,代码行数:17,代码来源:Example.java

示例10: validateClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
public void validateClass(ClassReader reader) {
	StringWriter writer = new StringWriter();
	PrintWriter printWriter = new PrintWriter(writer);

	Exception error = null;
	try {
		CheckClassAdapter.verify(reader, this, false, printWriter);
	} catch (Exception e) {
		error = e;
	}

	String contents = writer.toString();
	if (error != null || contents.length() > 0) {
		reader.accept(new TraceClassVisitor(printWriter), 0);
		throw new RuntimeException("Generation error\nDump for " + reader.getClassName() + "\n" + writer.toString(), error);
	}
}
 
开发者ID:SquidDev,项目名称:Patcher,代码行数:18,代码来源:RewriteClassLoader.java

示例11: loadClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
@Override
public Class<?> loadClass(String fullyQualifiedTargetClass) throws ClassNotFoundException {
	if (!testClass.equals(fullyQualifiedTargetClass)) {
		return super.loadClass(fullyQualifiedTargetClass);
	}
	String className = fullyQualifiedTargetClass.replace('.', '/');
	InputStream is = java.lang.ClassLoader.getSystemResourceAsStream(className + ".class");
	if (is == null) {
		throw new ClassNotFoundException("Class " + fullyQualifiedTargetClass + "could not be found!");
	}
	ClassReader reader = null;
	try {
		reader = new ClassReader(is);
	} catch (IOException exc) {
		throw new ClassNotFoundException();
	}
	ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
	ClassVisitor cv = new TestValuesDeterminerClassVisitor(fullyQualifiedTargetClass, writer);
	CheckClassAdapter checkClassAdapter = new CheckClassAdapter(cv);
	reader.accept(checkClassAdapter, ClassReader.SKIP_FRAMES);
	byte[] byteBuffer = writer.toByteArray();
	Class<?> result = defineClass(fullyQualifiedTargetClass, byteBuffer, 0, byteBuffer.length);
	return result;
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:25,代码来源:TestRuntimeValuesDeterminer.java

示例12: validateClass

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
/**
 * Validate a generated class
 *
 * @param reader The class to read
 * @param loader The appropriate class loader
 * @throws RuntimeException On bad validation
 */
public static void validateClass(ClassReader reader, ClassLoader loader) {
	StringWriter writer = new StringWriter();
	PrintWriter printWriter = new PrintWriter(writer);

	Exception error = null;
	try {
		CheckClassAdapter.verify(reader, loader, false, printWriter);
	} catch (Exception e) {
		error = e;
	}

	String contents = writer.toString();
	if (error != null || contents.length() > 0) {
		throw new ValidationException(reader, writer.toString(), error);
	}
}
 
开发者ID:SquidDev,项目名称:luaj.luajc,代码行数:24,代码来源:AsmUtils.java

示例13: transform

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
@Override
public byte[] transform(String s, String s2, byte[] bytes) {
    if (bytes == null) {
        return bytes;
    }
    try {
        ClassReader cr = new ClassReader(bytes);
        ClassNode classNode = new ClassNode();
        cr.accept(classNode, ClassReader.EXPAND_FRAMES);
        if (transform(s, s2, classNode)) {
            ClassWriter cw = new ClassWriter(cr, COMPUTE_MAXS);
            classNode.accept(new CheckClassAdapter(cw));
            bytes = cw.toByteArray();
        }
    } catch (Throwable t) {
        t.printStackTrace();
    }
    return bytes;
}
 
开发者ID:thomas15v,项目名称:TurtleFix,代码行数:20,代码来源:Transformer.java

示例14: SoyClassWriter

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
private SoyClassWriter(Writer writer, Builder builder) {
  super(writer.api(), Flags.DEBUG ? new CheckClassAdapter(writer, false) : writer);
  this.writer = writer;
  this.typeInfo = builder.type;
  super.visit(
      Opcodes.V1_7,
      builder.access,
      builder.type.internalName(),
      null /* not generic */,
      builder.baseClass.internalName(),
      builder.interfaces.toArray(new String[builder.interfaces.size()]));
  if (builder.fileName != null) {
    super.visitSource(
        builder.fileName,
        // No JSR-45 style source maps, instead we write the line numbers in the normal locations.
        null);
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:19,代码来源:SoyClassWriter.java

示例15: dump

import org.objectweb.asm.util.CheckClassAdapter; //导入依赖的package包/类
public static byte[] dump() throws Exception {

    ClassWriter cw = new ClassWriter(0);

    ClassVisitor cv = new CheckClassAdapter(cw);
    cv.visit(52, ACC_PUBLIC + ACC_SUPER, "json/BeanJsonifier2",
      "Ljava/lang/Object;Ljson/Jsonifier<Ljson/Bean;>;", "java/lang/Object",
      new String[] { "json/Jsonifier" });

    cv.visitSource("BeanJsonifier2.java", null);

    generateConstructor(cv);
    generateMarshal(cv);
    generateBridge(cv);
    cv.visitEnd();

    return cw.toByteArray();
  }
 
开发者ID:irobertson,项目名称:invokedynamic-talk-code,代码行数:19,代码来源:BeanJsonifierIndyDump.java


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