當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。