/lightweight-instrumentation

a lightweight java bytecode instrumentation (not safe)

Primary LanguageC++

Simple-Instrumentation


features

  • classTransform
  • redefineClass
  • retransformClass

Usage

@Test
public void test(){
    SClassTransformer.list.add(new CustomTransfomer());
}

package com.utils;

import com.utils.Transformer;

public class SClassTransformer {
    /* add your custom Transfomer here*/
    public static ArrayList<Transformer> list = new ArrayList();

    public native static void redefineClass(Class<?> clazz,byte[] bytes);
    
    public native static void retransformClass(Class<?> clazz); 

    public static byte[] tansform(String name,byte[] orignalBytes){
       for(Transformer transfomer : SClassTransformer.list)
       {
           return transfomer.tansform(name,orignalBytes);
       } 
       return orignalBytes;
    }

    static{
        // ur lib load
        System.load("path/library.dll");
    }

}

package com.utils;

public abstract class Transformer {
    public abstract byte[] tansform(String name,byte[] orignalBytes);
}