Skip to content

Commit

Permalink
fix: jvm fault injection problem,className not match and javassist no…
Browse files Browse the repository at this point in the history
…t found exception.
  • Loading branch information
liqixin committed May 16, 2024
1 parent 2b1da1d commit 2d2d064
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion chaosmetad/tools/jvm/ChaosMetaClassFileTransformer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ private void doInject(CtMethod ctMethod, ChaosMetaJVMMethodRule methodRule) thro
}
}

private static String normalizeClass(String className) {
return className.replace("/", ".");
}

public String getMessage() {
return message;
Expand All @@ -80,11 +83,16 @@ public byte[] transform(ClassLoader loader, String className, Class<?> classBein
System.out.printf("transform class: %s, targetClassName: %s, status: %s, loader: %s, \n", className, targetClassName, status, loader.toString());

try {
if (!targetClassName.equals(className) || (status.equals("recovered"))) {
//fix className not match
String normalizeClassName = normalizeClass(className);
if (!targetClassName.equals(normalizeClassName) || (status.equals("recovered"))) {
return null;
}

ClassPool pool = ClassPool.getDefault();
//fix javassist not found exception
ClassClassPath classPath = new ClassClassPath(loader.loadClass(targetClassName));
pool.insertClassPath(classPath);
CtClass ctClass = pool.get(targetClassName);
if (status.equals("success") || status.equals("fail")) {
// TODO: Need to consider how to clean up the added packages when restoring?
Expand Down

0 comments on commit 2d2d064

Please sign in to comment.