Search in sources :

Example 16 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class JaxWSHookProxy method doInstallDProxy.

public void doInstallDProxy(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * install proxy to javax.xml.ws.Service
     */
    dpInstall.installProxy("javax.xml.ws.Service", new String[] { "com.creditease.uav.hook.jaxws.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("getPort".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", JaxWSHookIT.class);
                m.insertBefore("{mObj=new JaxWSHookIT(\"" + appid + "\");}");
                m.insertAfter("{$_=mObj.getPort($_,this,$args);}");
            }
            if ("createDispatch".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", JaxWSHookIT.class);
                m.insertBefore("{mObj=new JaxWSHookIT(\"" + appid + "\");}");
                m.insertAfter("{$_=mObj.createDispatch($_,this,$args);}");
            }
        }
    }, false);
    /**
     * adapts: 实现对JDKProxyInvokeHandler封装的Proxy对象的替换,替换为原来的对象,因为在有些场景下对方原来的对象有一些非接口的方法需要调用
     * 比如CXF中ClientProxy.getClient(Object o), 需要原来的对象才能使用
     */
    dpInstall.doAdapts(this.getAdapts());
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) JaxWSHookIT(com.creditease.uav.hook.jaxws.interceptors.JaxWSHookIT) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 17 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class JedisHookProxy method doProxyInstall.

public void doProxyInstall(ClassLoader webapploader, final String appid) {
    /**
     * set the webapploader is the target classloader
     */
    dpInstaller.setTargetClassLoader(webapploader);
    dpInstaller.installProxy("redis.clients.jedis.Connection", new String[] { "com.creditease.uav.hook.redis.jedis.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("sendCommand".equals(m.getName())) {
                DPClass[] ccs = m.getParameterTypes();
                if (ccs.length == 2 && "byte[][]".equals(ccs[1].getName())) {
                    m.insertBefore("{JedisConnectionIT.start(\"" + appid + "\", new Object[]{$1, $2, getHost(), new Integer(getPort())});}");
                    m.insertAfter("{JedisConnectionIT.end(new Object[]{$_});}");
                    dpInstaller.addCatch(m, "JedisConnectionIT.end(new Object[]{$e});");
                }
            }
        }
    }, false);
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Example 18 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class DBCPHookProxy method InsertInterceptToClients.

/**
 * InsertInterceptToClients
 *
 * @param ic
 */
private void InsertInterceptToClients(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("InsertInterceptToClients")) {
        return;
    }
    InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
    String contextPath = (String) ic.get(InterceptConstants.CONTEXTPATH);
    String basePath = (String) ic.get(InterceptConstants.BASEPATH);
    appid = MonitorServerUtil.getApplicationId(contextPath, basePath);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * DBCP 1.x
     */
    dpInstall.installProxy("org.apache.commons.dbcp.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    /**
     * DBCP 2.x
     */
    dpInstall.installProxy("org.apache.commons.dbcp2.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    /**
     * Tomcat DBCP 2.x after 8
     */
    dpInstall.installProxy("org.apache.tomcat.dbcp.dbcp2.BasicDataSource", new String[] { "com.creditease.uav.hook.jdbc.pools.dbcp.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("setUrl".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", DBCPIT.class);
                m.insertBefore("{mObj=new DBCPIT(\"" + id + "\",this);}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) InterceptContext(com.creditease.monitor.interceptframework.spi.InterceptContext) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) DBCPIT(com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)

Example 19 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class JdbcHookProxy method injectDruid.

/**
 * injectDruid
 *
 * @param webapploader
 * @param appid
 */
private void injectDruid(ClassLoader webapploader, InterceptContext ic) {
    /**
     * check if there is druid, god, so sad we are in china, we have to support alibaba druid
     */
    try {
        webapploader.loadClass("com.alibaba.druid.Constants");
    } catch (ClassNotFoundException e) {
        return;
    }
    if (isHookEventDone("isInjectDruid")) {
        return;
    }
    final String appid = this.getAppID(ic);
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    /**
     * inject DruidDriver
     */
    dpInstall.installProxy("com.alibaba.druid.proxy.jdbc.DataSourceProxyImpl", new String[] { "com.creditease.uav.hook.jdbc.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("connect".equals(m.getName())) {
                dpInstall.defineLocalVal(m, "mObj", JdbcDriverIT.class);
                m.insertBefore("{mObj=new JdbcDriverIT(\"" + appid + "\");}");
                m.insertAfter("{$_=mObj.doProxyConnection($_);}");
            }
        }
    }, false);
    /**
     * inject DruidDataSource
     */
    dpInstall.installProxy("com.alibaba.druid.util.JdbcUtils", new String[] { "com.creditease.uav.hook.jdbc.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("createDriver".equals(m.getName()) && m.getParameterTypes().length == 2) {
                dpInstall.defineLocalVal(m, "mObj", JdbcDriverIT.class);
                m.insertBefore("{mObj=new JdbcDriverIT(\"" + appid + "\");}");
                m.insertAfter("{$_=mObj.doRegisterDriver($_,false);}");
            }
        }
    }, false);
    /**
     * adapts:<br>
     * 1) FIX simulate the behaviour of Druid before injected: <br>
     * validateConnection use given Connection to ping DB, <br>
     * and throw exception if our $Proxy is given.<br>
     * <br>
     * 2) FIX simulate the behaviour of Druid before injected: <br>
     * these 'init' methods will new a Object to specified DB type
     */
    dpInstall.doAdapts(getAdapts());
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor) JdbcDriverIT(com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)

Example 20 with DPMethod

use of com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod in project uavstack by uavorg.

the class Log4jHookProxy method InsertIntercept.

private void InsertIntercept(HookContext context, ClassLoader webapploader) {
    if (isHookEventDone("insertLog4jIntercepter")) {
        return;
    }
    ServerVendor vendor = (ServerVendor) UAVServer.instance().getServerInfo(CaptureConstants.INFO_APPSERVER_VENDOR);
    if (vendor == ServerVendor.SPRINGBOOT) {
        return;
    }
    /**
     * set the webapploader is the target classloader
     */
    dpInstall.setTargetClassLoader(webapploader);
    // 定义一个类里面的hook变量并初始化,防止每次拦截write时都初始化对象
    dpInstall.defineField("uavLogHook", LogIT.class, "org.apache.log4j.helpers.QuietWriter", "new LogIT()");
    // 定义换行符变量(与log4j中保持一致)
    dpInstall.defineField("uavLogHookLineSep", String.class, "org.apache.log4j.helpers.QuietWriter", "System.getProperty(\"line.separator\")");
    dpInstall.installProxy("org.apache.log4j.helpers.QuietWriter", new String[] { "com.creditease.uav.log.hook.interceptors" }, new DynamicProxyProcessor() {

        @Override
        public void process(DPMethod m) throws Exception {
            if ("write".equals(m.getName())) {
                m.insertBefore("{if(!$1.equals(uavLogHookLineSep)){$1=uavLogHook.formatLog($1);}}");
            }
        }
    }, false);
    // release loader
    dpInstall.releaseTargetClassLoader();
}
Also used : DPMethod(com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod) ServerVendor(com.creditease.monitor.UAVServer.ServerVendor) DynamicProxyProcessor(com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)

Aggregations

DPMethod (com.creditease.uav.monitorframework.dproxy.bytecode.DPMethod)21 DynamicProxyProcessor (com.creditease.uav.monitorframework.dproxy.DynamicProxyProcessor)20 JdbcDriverIT (com.creditease.uav.hook.jdbc.interceptors.JdbcDriverIT)4 InterceptContext (com.creditease.monitor.interceptframework.spi.InterceptContext)3 ServerVendor (com.creditease.monitor.UAVServer.ServerVendor)2 DubboIT (com.creditease.uav.hook.dubbo.interceptors.DubboIT)1 ApacheAsyncHttpClientIT (com.creditease.uav.hook.httpclients.async.interceptors.ApacheAsyncHttpClientIT)1 JaxWSHookIT (com.creditease.uav.hook.jaxws.interceptors.JaxWSHookIT)1 DBCPIT (com.creditease.uav.hook.jdbc.pools.dbcp.interceptors.DBCPIT)1 MybatisIT (com.creditease.uav.hook.jdbc.pools.mybatis.interceptors.MybatisIT)1 MongoClientIT (com.creditease.uav.hook.mongoclients.interceptors.MongoClientIT)1 RabbitmqIT (com.creditease.uav.hook.rabbitmq.interceptors.RabbitmqIT)1 AredisCommandObjectIT (com.creditease.uav.hook.redis.aredis.interceptors.AredisCommandObjectIT)1 DPClass (com.creditease.uav.monitorframework.dproxy.bytecode.DPClass)1 WebServiceListenerIT (com.creditease.uav.monitorframework.webservice.interceptors.WebServiceListenerIT)1 FastClasspathScanner (io.github.lukehutch.fastclasspathscanner.FastClasspathScanner)1