public Object run() throws ClassNotFoundException { return getResourceAsStream(getClassResourceName(name)); } }, acc);
public Object run() { return findResource(name); } }, acc);
public Object run() { URL url = findResource(name); if ((url == null) && delegatingToParent && (getParent() != null)) { url = getParent().getResource(name); } return url; } }, acc);
public MIDletClassLoader(ClassLoader parent) { super(new URL[] {}, parent); noPreporcessingNames = new HashSet(); acc = AccessController.getContext(); config = new InstrumentationConfig(); config.setEnhanceCatchBlock(enhanceCatchBlock); config.setEnhanceThreadCreation(true); }
/** * Appends the Class Location URL to the list of URLs to search for classes and resources. * * @param Class * Name */ public void addClassURL(String className) throws MalformedURLException { String resource = getClassResourceName(className); URL url = getParent().getResource(resource); if (url == null) { url = this.getResource(resource); } if (url == null) { throw new MalformedURLException("Unable to find class " + className + " URL"); } String path = url.toExternalForm(); if (debug) { Logger.debug("addClassURL ", path); } addURL(new URL(path.substring(0, path.length() - resource.length()))); }
public void visitTypeInsn(final int opcode, String desc) { if ((opcode == NEW) && (config.isEnhanceThreadCreation())) { if ("java/util/Timer".equals(desc)) { desc = codeName(MIDletTimer.class); } else if ("java/util/TimerTask".equals(desc)) { desc = codeName(MIDletTimerTask.class); } else if ("java/lang/Thread".equals(desc)) { desc = codeName(MIDletThread.class); } } mv.visitTypeInsn(opcode, desc); }
public void configure(MIDletClassLoaderConfig clConfig, boolean forJad) throws MalformedURLException { for (Iterator iter = clConfig.appclasspath.iterator(); iter.hasNext();) { String path = (String) iter.next(); StringTokenizer st = new StringTokenizer(path, File.pathSeparator); while (st.hasMoreTokens()) { this.addURL(new URL(IOUtils.getCanonicalFileClassLoaderURL(new File(st.nextToken())))); } } for (Iterator iter = clConfig.appclasses.iterator(); iter.hasNext();) { this.addClassURL((String) iter.next()); } int delegationType = clConfig.getDelegationType(forJad); this.delegatingToParent = (delegationType == MIDletClassLoaderConfig.DELEGATION_DELEGATING); this.findPathInParent = (delegationType == MIDletClassLoaderConfig.DELEGATION_RELAXED); }
private MIDletClassLoader createMIDletClassLoader(boolean forJad) { MIDletClassLoader mcl = new MIDletClassLoader(getExtensionsClassLoader()); if (!Serializable.class.isAssignableFrom(Injected.class)) { Logger.error("classpath configuration error, Wrong Injected class detected. microemu-injected module should be after microemu-javase in eclipse"); } if (mIDletClassLoaderConfig != null) { try { mcl.configure(mIDletClassLoaderConfig, forJad); } catch (MalformedURLException e) { Message.error("Error", "Unable to find MIDlet classes, " + Message.getCauseMessage(e), e); } } mcl.disableClassPreporcessing(Injected.class); mcl.disableClassPreporcessing(MIDletThread.class); mcl.disableClassPreporcessing(MIDletTimer.class); mcl.disableClassPreporcessing(MIDletTimerTask.class); MIDletResourceLoader.classLoader = mcl; return mcl; }
private static ExtensionsClassLoader getExtensionsClassLoader() { if (instance.extensionsClassLoader == null) { instance.extensionsClassLoader = new ExtensionsClassLoader(new URL[] {}, instance.getClass().getClassLoader()); } return instance.extensionsClassLoader; }
public void visitTryCatchBlock(final Label start, final Label end, final Label handler, final String type) { if (config.isEnhanceCatchBlock() && type != null) { if (catchInfo == null) { catchInfo = new HashMap(); } CatchInformation newHandler = (CatchInformation)catchInfo.get(handler); if (newHandler == null) { newHandler = new CatchInformation(type); catchInfo.put(handler, newHandler); } mv.visitTryCatchBlock(start, end, newHandler.label, type); } else { mv.visitTryCatchBlock(start, end, handler, type); } }
static URL getClassURL(ClassLoader parent, String className) throws MalformedURLException { String resource = getClassResourceName(className); URL url = parent.getResource(resource); if (url == null) { throw new MalformedURLException("Unable to find class " + className + " URL"); } String path = url.toExternalForm(); return new URL(path.substring(0, path.length() - resource.length())); }
/** * Special case for classes injected to MIDlet * * @param klass */ public void disableClassPreporcessing(Class klass) { disableClassPreporcessing(klass.getName()); }
/** * Allow access to resources */ public InputStream getResourceAsStream(String name) { final URL url = getResource(name); if (url == null) { return null; } try { return (InputStream) AccessController.doPrivileged(new PrivilegedExceptionAction() { public Object run() throws IOException { return url.openStream(); } }, acc); } catch (PrivilegedActionException e) { if (debug) { Logger.debug("Unable to find resource for class " + name + " ", e); } return null; } }
public void visitLabel(Label label) { if (config.isEnhanceCatchBlock() && catchInfo != null) { CatchInformation newHandler = (CatchInformation)catchInfo.get(label); if (newHandler != null) { mv.visitLabel(newHandler.label); // no push, just use current Throwable in stack mv.visitMethodInsn(INVOKESTATIC, INJECTED_CLASS, "handleCatchThrowable", "(Ljava/lang/Throwable;)Ljava/lang/Throwable;"); // stack contains Throwable, just verify that it is right type for this handler mv.visitTypeInsn(CHECKCAST, newHandler.type); } } mv.visitLabel(label); }
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { return new ChangeCallsMethodVisitor(super.visitMethod(access, name, desc, signature, exceptions), config); }
public static byte[] instrument(final InputStream classInputStream, InstrumentationConfig config) { try { ClassReader cr = new ClassReader(classInputStream); ClassWriter cw = new ClassWriter(0); ClassVisitor cv = new ChangeCallsClassVisitor(cw, config); cr.accept(cv, 0); return cw.toByteArray(); } catch (IOException e) { Logger.error("Error loading MIDlet class", e); return null; } }
public Object run() throws ClassNotFoundException { return getResourceAsStream(getClassResourceName(name)); } }, acc);
public void visit(final int version, final int access, final String name, final String signature, String superName, final String[] interfaces) { if ((0xFF & version) >= 49) { String v = (String) javaVersion.get(new Integer(version)); Logger.warn("Loading MIDlet class " + name + " of version " + version + ((v == null) ? "" : (" " + v))); } if (config.isEnhanceThreadCreation()) { if (superName.equals("java/lang/Thread")) { superName = ChangeCallsMethodVisitor.codeName(MIDletThread.class); } else if (superName.equals("java/util/Timer")) { superName = ChangeCallsMethodVisitor.codeName(MIDletTimer.class); } else if (superName.equals("java/util/TimerTask")) { superName = ChangeCallsMethodVisitor.codeName(MIDletTimerTask.class); } } super.visit(version, access, name, signature, superName, interfaces); }
public static ClassLoader createExtensionsClassLoader(final URL[] urls) { return new ExtensionsClassLoader(urls, getExtensionsClassLoader()); }
if ((config.isEnhanceThreadCreation()) && (name.equals("<init>"))) { if (owner.equals("java/util/Timer")) { owner = codeName(MIDletTimer.class); } else if (owner.equals("java/util/TimerTask")) { owner = codeName(MIDletTimerTask.class); } else if (owner.equals("java/lang/Thread")) { owner = codeName(MIDletThread.class);