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


Java CheckClassAdapter.verify方法代码示例

本文整理汇总了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;
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:23,代码来源:Validate.java

示例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);
	}
}
 
开发者ID:SquidDev-CC,项目名称:CCTweaks-Lua,代码行数:24,代码来源:AsmUtils.java

示例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);
  }
}
 
开发者ID:forax,项目名称:vmboiler,代码行数:17,代码来源:Example.java

示例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);
	}
}
 
开发者ID:SquidDev,项目名称:Patcher,代码行数:18,代码来源:RewriteClassLoader.java

示例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);
	}
}
 
开发者ID:SquidDev,项目名称:luaj.luajc,代码行数:24,代码来源:AsmUtils.java

示例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();
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:17,代码来源:ASMBytecodeDisassembler.java

示例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);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:17,代码来源:DrillCheckClassAdapter.java

示例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);
	}
}
 
开发者ID:junkdog,项目名称:constexpr-java,代码行数:11,代码来源:TestUtil.java

示例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;
}
 
开发者ID:ruediste,项目名称:salta,代码行数:33,代码来源:RecipeCompiler.java

示例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;
}
 
开发者ID:OreCruncher,项目名称:Jiffy,代码行数:10,代码来源:Transformer.java

示例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();
  }
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:13,代码来源:GemliteHelper.java

示例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);
}
 
开发者ID:iisi-nj,项目名称:GemFireLite,代码行数:37,代码来源:Test1.java

示例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;

}
 
开发者ID:ncredinburgh,项目名称:QuickTheories,代码行数:11,代码来源:CoverageTransformerTest.java

示例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;
}
 
开发者ID:qx,项目名称:FullRobolectricTestSample,代码行数:34,代码来源:AsmInstrumentingClassLoader.java

示例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);
  }
}
 
开发者ID:google,项目名称:closure-templates,代码行数:17,代码来源:ExpressionTester.java


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