本文整理汇总了Java中org.objectweb.asm.util.CheckClassAdapter.verify方法的典型用法代码示例。如果您正苦于以下问题:Java CheckClassAdapter.verify方法的具体用法?Java CheckClassAdapter.verify怎么用?Java CheckClassAdapter.verify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.objectweb.asm.util.CheckClassAdapter
的用法示例。
在下文中一共展示了CheckClassAdapter.verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: dumpVerify
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
public String dumpVerify(byte[] bytecode, ClassLoader classLoader) {
if (bytecode == null) {
throw new NullPointerException("bytecode must not be null");
}
if (classLoader == null) {
throw new NullPointerException("classLoader must not be null");
}
final StringWriter out = new StringWriter();
final PrintWriter writer = new PrintWriter(out);
final ClassReader cr = new ClassReader(bytecode);
CheckClassAdapter.verify(cr, classLoader, true, writer);
return out.toString();
}
示例7: verify
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
/**
* See {@link org.objectweb.asm.util.CheckClassAdapter#verify(ClassReader, boolean, PrintWriter)}.
*/
public static void verify(final ClassReader cr, final boolean dump,
final PrintWriter pw) {
/*
* For plain verification, we don't need to restore the original access
* bytes the way we do when the check adapter is used as part of a chain, so
* we can just strip it and use the ASM version directly.
*/
final ClassWriter classWriter = new ClassWriter(0);
cr.accept(new InnerClassAccessStripper(CompilationConfig.ASM_API_VERSION,
classWriter), ClassReader.SKIP_DEBUG);
final ClassReader strippedCr = new ClassReader(classWriter.toByteArray());
CheckClassAdapter.verify(strippedCr, dump, pw);
}
示例8: verifyClass
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
public static void verifyClass(byte[] bytes) {
StringWriter sw = new StringWriter();
PrintWriter printer = new PrintWriter(sw);
CheckClassAdapter.verify(new ClassReader(bytes), false, printer);
String result = sw.toString();
if (result.length() > 0) {
throw new RuntimeException(result);
}
}
示例9: loadClass
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
public Class<?> loadClass(ClassCompilationContext ctx) {
// generate bytecode
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
ctx.getClazz().accept(cw);
// load class
Class<?> cls;
byte[] bb = cw.toByteArray();
String className = Type.getObjectType(ctx.getClazz().name).getClassName();
// try {
// Files.write(bb, new File("target/compiledRecipes/" + ctx.clazz.name
// + ".class"));
// } catch (IOException e2) {
// throw new SaltaException("Error while writing generated class", e2);
// }
try {
cls = getLoader().defineClass(className, bb);
ctx.initFields(cls);
} catch (Throwable e) {
System.out.println("Error while loading compiled recipe class");
ClassReader cr = new ClassReader(bb);
cr.accept(new TraceClassVisitor(null, new ASMifier(), new PrintWriter(System.out)), 0);
CheckClassAdapter.verify(cr, false, new PrintWriter(System.err));
throw new SaltaException("Error while loading compiled recipe", e);
}
// return result
return cls;
}
示例10: verifyClassBytes
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
private boolean verifyClassBytes(final byte[] bytes) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
CheckClassAdapter.verify(new ClassReader(bytes), false, pw);
final String result = sw.toString();
if (result.length() > 0)
logger.error(result);
return result.length() == 0;
}
示例11: checkAsmBytes
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
public final static void checkAsmBytes(byte[] bytes, PrintWriter pw)
{
try
{
ClassReader cr = new ClassReader(bytes);
CheckClassAdapter.verify(cr, true, pw);
}
catch (Exception e)
{
e.printStackTrace();
}
}
示例12: implementInterface
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
private static void implementInterface(ClassNode cn) throws Exception
{
// MethodNode fromMethod = new MethodNode(ACC_PUBLIC, "fromData",
// "(Ljava/io/DataInput;)V", null, new String[] {
// "java/io/IOException",
// "java/lang/ClassNotFoundException" });
// mv = cw.visitMethod(ACC_PUBLIC, "toData", "(Ljava/io/DataOutput;)V",
// null, new String[] { "java/io/IOException" });
MethodNode toMethod = new MethodNode(ACC_PUBLIC, "toData", "(Ljava/io/DataOutput;)V", null,
new String[] { "java/io/IOException" });
InsnList instToMethod = toMethod.instructions;
for (int i = 0; i < cn.fields.size(); i++)
{
FieldNode fn = (FieldNode) cn.fields.get(i);
toMethod(cn.name, fn, instToMethod);
}
instToMethod.add(new InsnNode(RETURN));
cn.methods.add(toMethod);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
byte[] bt = cw.toByteArray();
ClassReader cr = new ClassReader(bt);
CheckClassAdapter ca = new CheckClassAdapter(cw);
FileOutputStream fo = new FileOutputStream("d:/x1.log");
PrintWriter pw = new PrintWriter(fo);
ca.verify(cr, true, pw);
ByteArrayClassLoader bacl = new ByteArrayClassLoader(bt);
Class cls = bacl.loadClass("ynd.test.Ac01");
DataSerializable di = (DataSerializable) cls.newInstance();
di.toData(null);
}
示例13: assertValidClass
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
private byte[] assertValidClass(final Class<?> clazz)
throws IllegalClassFormatException {
final byte[] bs = transform(clazz);
// printClass(bs);
final StringWriter sw = new StringWriter();
CheckClassAdapter.verify(new ClassReader(bs), false, new PrintWriter(sw));
assertTrue(sw.toString(), sw.toString().length() == 0);
return bs;
}
示例14: getInstrumentedBytes
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
private byte[] getInstrumentedBytes(String className, ClassNode classNode, boolean containsStubs) throws ClassNotFoundException {
new ClassInstrumentor(classNode, containsStubs).instrument();
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS) {
@Override
public int newNameType(String name, String desc) {
return super.newNameType(name, desc.charAt(0) == ')' ? remapParams(desc) : remapParamType(desc));
}
@Override
public int newClass(String value) {
value = remapType(value);
return super.newClass(value);
}
};
classNode.accept(classWriter);
byte[] classBytes = classWriter.toByteArray();
if (debug) {
try {
FileOutputStream fileOutputStream = new FileOutputStream("tmp/" + className + ".class");
fileOutputStream.write(classBytes);
fileOutputStream.close();
CheckClassAdapter.verify(new ClassReader(classBytes), true, new PrintWriter(new FileWriter("tmp/" + className + ".analysis", false)));
new ClassReader(classBytes).accept(new TraceClassVisitor(new PrintWriter(new FileWriter("tmp/" + className + ".dis", false))), 0);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return classBytes;
}
示例15: checkClassData
import org.objectweb.asm.util.CheckClassAdapter; //导入方法依赖的package包/类
/**
* Utility to run the {@link CheckClassAdapter} on the class and print it to a string. for
* debugging.
*/
private static void checkClassData(ClassData clazz) {
StringWriter sw = new StringWriter();
CheckClassAdapter.verify(
new ClassReader(clazz.data()),
ExpressionTester.class.getClassLoader(),
false,
new PrintWriter(sw));
String result = sw.toString();
if (!result.isEmpty()) {
throw new IllegalStateException(result);
}
}