I have a very creative solution to allow my unsigned code all access through my signed library. Although bad practice, I fear I have no other solution (except rewriting a lot of code, that then needs to be rewrited back).
I have the following class:
public abstract class full {
public static <T,S,P> S access(final T object, final String function, final P parameter) {
AccessController.doPrivileged(new PrivilegedAction<S>() {
@Override
public S run() {
try {
if (parameter == null) {
Class[] argTypes = { };
Object passedArgv[] = { };
return (S)object.getClass().getMethod(function, argTypes).invoke(object, passedArgv);
} else {
Class[] argTypes = { parameter.getClass() };
Object passedArgv[] = { parameter };
return (S)object.getClass().getMethod(function, argTypes).invoke(object, passedArgv);
}
} catch (NoSuchMethodException ex) {
Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(full.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
});
return null;
}
}
It works great for functions that return Objects, but not for primitives. Boolean bool = full.access(..); will result in a nullpointer, because generic methods can't handle primitives.
Any ideas about how to take the right approach?
To test:
public static Boolean test() {
return true;
}
public Main() {
System.out.println(((Boolean)redirect.full.access(this, "test", null)));
}
Booleantype is not a primitive (which is why it can be null) but rather a wrapper class around abool. Thebooltype is a primitive -- thus, the NPE lies elsewhere.