Skip to content

VeroFess/JHook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JHook

A tool that can dynamically modify Java classes at runtime.

Demo

Tested on Java 1.8 - Java 17, just support JDK

package com.binklac.jhook.test;

import com.binklac.jhook.JHook;
import com.binklac.jhook.Utils;
import javassist.*;

import java.io.IOException;

class JHookTestPrinter {
    public static Boolean PrintAndGetResult(){
        System.out.println("[X] The function has not been modified. ");
        return false;
    }
}

public class JHookTest {
    public static void main(String[] args) throws NotFoundException, CannotCompileException, IOException {
        System.out.println("[#] JHook operating environment check.");

        ClassPool defaultClassPool = ClassPool.getDefault();

        defaultClassPool.appendClassPath(Utils.GetJHookJarPath());

        CtClass jndiLookupClass = defaultClassPool.get("com.binklac.jhook.test.JHookTestPrinter");
        CtMethod lookup = jndiLookupClass.getDeclaredMethod("PrintAndGetResult");
        lookup.setBody("{System.out.println(\"[#] The function was successfully modified.\"); return Boolean.TRUE;}");

        if (!JHook.Instance().ModifyClass("com.binklac.jhook.test.JHookTestPrinter", jndiLookupClass.toBytecode())) {
            System.out.println("[X] The class cannot be modified, you need to install jdk or upgrade to a version after Java SE 9 to use the program normally.!");
        }

        if (JHookTestPrinter.PrintAndGetResult()) {
            System.out.println("[#] JHook is running normally and your environment supports JHook.");
        } else {
            System.out.println("[X] JHook cannot run normally and the test fails.");
        }
    }
}

About

A tool that can dynamically modify Java classes at runtime.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages