β

Javassist

火星信息安全研究院 4 阅读

Javassist (Java Programming Assistant) makes Java bytecode manipulation simple. It is a class library for editing bytecodes in Java; it enables Java programs to define a new class at runtime and to modify a class file when the JVM loads it. Unlike other similar bytecode editors, Javassist provides two levels of API: source level and bytecode level. If the users use the source-level API, they can edit a class file without knowledge of the specifications of the Java bytecode. The whole API is designed with only the vocabulary of the Java language. You can even specify inserted bytecode in the form of source text; Javassist compiles it on the fly. On the other hand, the bytecode-level API allows the users to directly edit a class file as other editors.

以前没怎么写过java代码,破解java程序都是这么干的:

直接修改字节码,但是这个方法实现起来比较复杂的方法就变得比较蛋疼。直到在 这里 发现了这个东西,一切就变得简单了。照抄那边的代码同样的修改就可以直接通过代码来完成了,如下:


package obaby.mars.charles;


import javassist.*;

import java.io.IOException;

public class Main {

    public static void main(String[] args) {


        try {
            ClassPool classPool= ClassPool.getDefault();
            classPool.insertClassPath("/Users/obaby/charles_patcher/charles.jar"); //复制出来charles.jar的文件路径
            CtClass ctClass = classPool.get("com.xk72.charles.oFTR");
            CtMethod ctMethod =ctClass.getDeclaredMethod("Yuaz",null);
            System.out.print(ctMethod.toString());
            ctMethod.setBody("{return true;}");
            ctMethod = ctClass.getDeclaredMethod("lktV",null);
            ctMethod.setBody("{return \"obaby@mars\";}");
            ctClass.writeFile();
        } catch (NotFoundException e) {
            System.out.print("failed");

        } catch (CannotCompileException e){

        } catch (IOException e){

        }
    }
}

参考链接: https://blog.zzzmode.com/2017/05/16/charles-4.0.2-cracked/

原创文章,转载请注明: 转载自 obaby@mars

本文标题: 《Javassist》

本文链接地址: http://www.h4ck.org.cn/2018/01/javassist/

作者:火星信息安全研究院
Hack-Crack 信息安全 【Mars Information Serurity Institute】
原文地址:Javassist, 感谢原作者分享。

发表评论