2016年3月

使用javassist修改idea mybatis插件

反编译查看源码

# cd ~/Library/Application Support/IntelliJIdea15/mybatis_plus/lib/
# cd ~/Library/Application Support/IntelliJIdea2016.2/mybatis_plus/lib/
# cd ~/Library/Application Support/IntelliJIdea2016.3/mybatis_plus/lib/
cd ~/Library/Application Support/IntelliJIdea2017.1/mybatis_plus/lib/

使用 JD-GUI 打开 mybatis_plus.jar,查看源码:

Screenshot 2016-03-05 at 12.19.56.png
Screenshot 2016-03-05 at 12.19.53.png

修改验证逻辑

使用javassist修改字节码

import javassist.*;

class MyBatisPlusCrack {

    public static void main(String[] args) throws Exception {
        ClassPool pool = ClassPool.getDefault();
        CtClass c = pool.get("com.seventh7.mybatis.util.JavaUtils");
        CtMethod m = c.getDeclaredMethod("refValid");
        m.setBody("{ validated = true; valid = true; return valid; }");
        c.writeFile();

        CtClass cc = pool.get("com.seventh7.mybatis.service.JavaService");
        CtMethod mm = cc.getDeclaredMethod("stop");
        mm.setBody("{ return; }");
        cc.writeFile();
    }

}
# 运行
javac -classpath ".:javassist.jar:mybatis_plus.jar" MyBatisPlusCrack.java
java -classpath ".:javassist.jar:mybatis_plus.jar" MyBatisPlusCrack

此时会在当前目录下生成修改过的两个类文件,使用压缩软件替换jar包中的这两个文件;重启idea。

jar uvf mybatis_plus.jar \
    com/seventh7/mybatis/service/JavaService.class \
    com/seventh7/mybatis/util/JavaUtils.class