1 /**
2 * MicroEmulator
3 * Copyright (C) 2006-2007 Bartek Teodorczyk <barteo@barteo.net>
4 * Copyright (C) 2006-2007 Vlad Skarzhevskyy
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * @version $Id: ClassPreprocessor.java 1243 2007-05-09 15:25:44Z vlads $
21 */
22 package org.microemu.app.classloader;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26
27 import org.microemu.log.Logger;
28 import org.objectweb.asm.ClassReader;
29 import org.objectweb.asm.ClassVisitor;
30 import org.objectweb.asm.ClassWriter;
31
32 /**
33 * @author vlads
34 *
35 */
36 public class ClassPreprocessor {
37
38 public static byte[] instrument(final InputStream classInputStream, InstrumentationConfig config) {
39 try {
40 ClassReader cr = new ClassReader(classInputStream);
41 ClassWriter cw = new ClassWriter(0);
42 ClassVisitor cv = new ChangeCallsClassVisitor(cw, config);
43 cr.accept(cv, 0);
44 return cw.toByteArray();
45 } catch (IOException e) {
46 Logger.error("Error loading MIDlet class", e);
47 return null;
48 }
49 }
50
51 }