byte[] counterAdaptClass(final InputStream is, final String name) throws Exception { if (c != null) { p.removeClass(c); } c = p.loadClass(is); BCField[] fields = c.getDeclaredFields(); if (!c.isInterface()) { c.declareField("_counter", "I"); } BCMethod[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; ++i) { BCMethod m = methods[i]; if (!m.getName().equals("<init>") && !m.isStatic() && !m.isAbstract() && !m.isNative()) { Code code = m.getCode(false); if (code != null) { code.aload().setLocal(0); code.aload().setLocal(0); code.getfield().setField(name, "_counter", "I"); code.constant().setValue(1); code.iadd(); code.putfield().setField(name, "_counter", "I"); code.setMaxStack(Math.max(code.getMaxStack(), 2)); } } } return c.toByteArray(); }
byte[] nullAdaptClass(final InputStream is, final String name) throws Exception { if (c != null) { p.removeClass(c); } c = p.loadClass(is); BCField[] fields = c.getDeclaredFields(); BCMethod[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; ++i) { Code code = methods[i].getCode(false); if (code != null) { while (code.hasNext()) { Instruction ins = code.next(); } if (compute) { code.calculateMaxStack(); code.calculateMaxLocals(); } } } return c.toByteArray(); }
static BCClass nullSERPAdapt(Project p, BCClass c, final byte[] b) throws Exception { if (c != null) { p.removeClass(c); } c = p.loadClass(new ByteArrayInputStream(b)); c.getDeclaredFields(); BCMethod[] methods = c.getDeclaredMethods(); for (int i = 0; i < methods.length; ++i) { Code code = methods[i].getCode(false); if (code != null) { while (code.hasNext()) { code.next(); } if (compute) { code.calculateMaxStack(); code.calculateMaxLocals(); } } } c.toByteArray(); return c; }