繁体   English   中英

使用asm完成字节码检测后,将引发java.lang.reflect.InvocationTargetException。

[英]java.lang.reflect.InvocationTargetException gets thrown when bytecode instrumentation is finished with asm.

我想用Java检测一些方法/类。 为此,我编写了一个Java代理,该代理仅提供我选择的几个类。

我使用以下代码来获取已加载的类并过滤其中的一些类:

 instrumentation.addTransformer(myTransformer,true);

 Class[] loadedClasses=instrumentation.getAllLoadedClasses();

 Class[] modifiableClasses=ModifiableClasses(loadedClasses,instrumentation);

Class[] filteredClasses=filterClasses(modifiableClasses);

if(instrumentation.isRetransformClassesSupported()){
        System.out.println("retransformation is Supported");
        instrumentation.retransformClasses(filteredClasses);
     }

这不会造成任何问题filterClasses返回一些我想正常检测的类,我想检测这些类:

  • Ljava / nio / Buffer;
  • Ljava / util / HashMap $ Entry;
  • Ljava / nio / HeapCharBuffer;
  • Ljava / nio / CharBuffer;
  • Ljava / lang / ClassLoader;
  • Ljava / lang / Class;
  • Ljava / util / HashMap;
  • Ljava / nio / ByteBuffer;
  • Ljava / lang / System;
  • Ljava / io / BufferedWriter;
  • Ljava / lang / String;
  • Ljava / io / OutputStreamWriter;
  • Ljava / io / BufferedOutputStream;
  • Ljava / nio / charset / CoderResult;
  • Ljava / io / Writer;
  • Ljava / util / HashSet;
  • Ljava / nio / charset / CharsetEncoder;
  • Ljava / io / FileOutputStream;
  • Ljava / io / PrintStream;

一切正常我在特定的文件夹中打印已检测和未检测的类以进行调试。 我使用asm CoreAPI在方法的开头和结尾添加一些指令,而我没有使用它们来构造,本地方法,抽象方法和静态变量。 当我只是检测正在加载的新类时,一切正常。 我想我不了解ClassLoader的某些知识,或者在控制台上得到的具体信息:

    Exception in thread "main" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(Unknown Source)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(Unknown Source)
     Caused by: java.lang.InternalError
    at sun.instrument.InstrumentationImpl.retransformClasses0(Native Method)
    at sun.instrument.InstrumentationImpl.retransformClasses(Unknown Source)
    at my.Agent.Watcher.premain(Watcher.java:88)
    ... 6 more
    FATAL ERROR in native method: processing of -javaagent failed

我非常感谢您提供的任何帮助,甚至可以为正确的方向提供链接或提示。

抱歉,我的错误是在检测类中更加精确地发现之后,我发现了一些错误,如果我希望这种错误能够解决的话。 admin / mod可以关闭该线程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM