Skip to content

Commit

Permalink
Make proxy classes inherit protection domain of original class
Browse files Browse the repository at this point in the history
Fixes #24
  • Loading branch information
makamys committed Nov 22, 2023
1 parent afd8ddc commit 3174776
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package makamys.coretweaks.optimization.transformerproxy;

import java.lang.reflect.Method;
import java.security.ProtectionDomain;

import org.apache.commons.io.FileUtils;
import org.objectweb.asm.AnnotationVisitor;
Expand Down Expand Up @@ -28,9 +29,9 @@ public static Class<?> generate(Class<?> parent, Class<?> transClass) throws Exc
FileUtils.writeByteArrayToFile(Util.childFile(CoreTweaks.OUT_DIR, "DUMP__" + newName + ".class"), result);
}

Method defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class);
Method defineClass = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class, ProtectionDomain.class);
defineClass.setAccessible(true);
defineClass.invoke(Launch.classLoader, newName, result, 0, result.length);
defineClass.invoke(Launch.classLoader, newName, result, 0, result.length, transClass.getProtectionDomain());

return Class.forName(newName);
}
Expand Down

0 comments on commit 3174776

Please sign in to comment.