@Override protected Class<?> findClass(String name) throws ClassNotFoundException { ClassGen cg = new ClassGen(name, Object.class.getName(), "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, new String[] {Serializable.class.getName()}); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }
/** * <pre> * public class SerializableImpl implements Serializable { * * public SerializableImpl() {} * * } * </pre> */ private Class<?> generateSerializableImpl() throws ClassNotFoundException { ClassGen cg = new ClassGen(CLASS_NAME_SERIALIZABLE_IMPL, Object.class.getName(), GENERATED, Constants.ACC_PUBLIC | Constants.ACC_SUPER, new String[] {Serializable.class.getName()}); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }
JavaClass clazz = Repository.lookupClass("foo.bar.YourClass"); byte[] bytes = clazz.getBytes();
byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length);
public void dumpJar(String path) { FileOutputStream os; try { os = new FileOutputStream(new File(path)); } catch (FileNotFoundException fnfe) { throw new RuntimeException("could not create file \"" + path + "\": " + fnfe); } JarOutputStream jos; try { jos = new JarOutputStream(os); for (JarEntry jbe : NonClassEntries.entries) { JarEntry destEntry = new JarEntry(jbe.getName()); byte[] bite = IOUtils.toByteArray(NonClassEntries.ins.get(jbe)); jos.putNextEntry(destEntry); jos.write(bite); jos.closeEntry(); } for (ClassGen classIt : cgs.values()) { jos.putNextEntry(new JarEntry(classIt.getClassName().replace('.', '/') + ".class")); jos.write(classIt.getJavaClass().getBytes()); jos.closeEntry(); jos.flush(); } jos.closeEntry(); jos.close(); } catch (IOException ioe) { } }
public static void dumpJar(String path, Collection<ClassGen> cgs) { FileOutputStream os; path = path.replace(".jar", "") + "-deob.jar"; try { os = new FileOutputStream(new File(path)); } catch (FileNotFoundException fnfe) { throw new RuntimeException("could not create file \"" + path + "\": " + fnfe); } JarOutputStream jos; try { jos = new JarOutputStream(os); for (JarEntry jbe : NonClassEntries.entries) { JarEntry destEntry = new JarEntry(jbe.getName()); byte[] bite = IOUtils.toByteArray(NonClassEntries.ins.get(jbe)); jos.putNextEntry(destEntry); jos.write(bite); jos.closeEntry(); } for (ClassGen classIt : cgs) { JarEntry classEntry = new JarEntry(classIt.getClassName().replace('.', '/') + ".class"); jos.putNextEntry(classEntry); jos.write(classIt.getJavaClass().getBytes()); jos.closeEntry(); } jos.closeEntry(); jos.close(); } catch (IOException ignored) { } }
public void dumpJar(String path) { FileOutputStream os; try { os = new FileOutputStream(new File(path)); } catch (FileNotFoundException fnfe) { throw new RuntimeException("could not create file \"" + path + "\": " + fnfe); } JarOutputStream jos; try { jos = new JarOutputStream(os); for (ClassGen classIt : cgs.values()) { jos.putNextEntry(new JarEntry(classIt.getClassName().replace('.', '/') + ".class")); jos.write(classIt.getJavaClass().getBytes()); jos.closeEntry(); jos.flush(); } for (JarEntry jbe : NonClassEntries.entries) { JarEntry destEntry = new JarEntry(jbe.getName()); byte[] bite = IOUtils.toByteArray(NonClassEntries.ins.get(jbe)); jos.putNextEntry(destEntry); jos.write(bite); jos.closeEntry(); } jos.closeEntry(); jos.close(); } catch (IOException ioe) { } }
public void dumpJar(String path) { FileOutputStream os; try { os = new FileOutputStream(new File(path)); } catch (FileNotFoundException fnfe) { throw new RuntimeException("could not create file \"" + path + "\": " + fnfe); } JarOutputStream jos; try { jos = new JarOutputStream(os); for (ClassGen classIt : cgs.values()) { jos.putNextEntry(new JarEntry(classIt.getClassName().replace('.', '/') + ".class")); jos.write(classIt.getJavaClass().getBytes()); jos.closeEntry(); jos.flush(); } for (JarEntry jbe : NonClassEntries.entries) { if (!jbe.isDirectory()) { JarEntry destEntry = new JarEntry(jbe.getName()); byte[] bite = IOUtils.toByteArray(NonClassEntries.ins.get(jbe)); jos.putNextEntry(destEntry); jos.write(bite); jos.closeEntry(); } } jos.closeEntry(); jos.close(); } catch (IOException ioe) { } }
byte[] bytes = clazz.getBytes(); cl = defineClass(class_name, bytes, 0, bytes.length); } else // Fourth try: Use default class loader
final byte[] bytes = clazz.getBytes(); cl = defineClass(class_name, bytes, 0, bytes.length); } else {
OutputFile outputFile= new OutputFile(classGen.getJavaClass().getBytes()); outputFile.setFileName(className + ClassFile.CLASS_ENDING); outputFile.setLocation(path + File.separatorChar + packageName);
@Override protected Class<?> findClass(String name) throws ClassNotFoundException { ClassGen cg = new ClassGen(name, "java.lang.Object", "<generated>", Constants.ACC_PUBLIC | Constants.ACC_SUPER, null); cg.addEmptyConstructor(Constants.ACC_PUBLIC); JavaClass jClazz = cg.getJavaClass(); byte[] bytes = jClazz.getBytes(); return defineClass(jClazz.getClassName(), bytes, 0, bytes.length); }
return jclass.getBytes();
byte[] classData = javaClass.getBytes();
byte[] classData = javaClass.getBytes();
/** * Generates the wrapper byte code for a given interface. * * @param interfacesToImplement The interfaces we want to generate wrapper * byte code for * @return byte[] The generated byte code */ private byte[] buildWrapper( final JavaClass[] interfacesToImplement ) throws Exception { // Create field for the wrapped class m_classGenerator.addField( m_codeGenerator.createWrappedClassField() ); // Create default constructor m_classGenerator.addMethod( m_codeGenerator.createDefaultConstructor() ); //Create field accessor for wrapped class instance m_classGenerator.addMethod( m_codeGenerator.createWrappedClassAccessor() ); // Implement interfaces Method[] interfaceMethods = m_codeGenerator.createImplementation( interfacesToImplement ); for ( int j = 0; j < interfaceMethods.length; ++j ) { m_classGenerator.addMethod( interfaceMethods[j] ); } return m_classGenerator.getJavaClass().getBytes(); } }
cg.getJavaClass().getBytes(); serTime.stop();
ClassGen ourCz = cgs.get(methodCallClass); if (ourCz != null && ourCz.containsMethod(methodCallMethod, methodCallSig) != null) { byte[] bit = ourCz.getJavaClass().getBytes(); logger.debug(methodCallClass + " " + methodCallSig); logger.debug(ourCz.getClassName());
private byte[] getBytesFromClass(final String className) throws ClassNotFoundException, IOException { final JavaClass clazz = getTestClass(className); final ConstantPoolGen cp = new ConstantPoolGen(clazz.getConstantPool()); final Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { final Method method = methods[i]; if (!method.isNative() && !method.isAbstract()) { methods[i] = injection(clazz, method, cp, findFirstStringLocalVariableOffset(method)); } } clazz.setConstantPool(cp.getFinalConstantPool()); return clazz.getBytes(); }