Java again.
Using too many parameters this time
public class M
{
public static final int maxmethods=1024;
public static void main(String[]a) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
StringBuffer paramvals = new StringBuffer();
StringBuffer paramdecls = new StringBuffer();
StringBuffer paramusages = new StringBuffer();
String[] methodnames = new String[maxmethods];
String[] methods = new String[maxmethods];
int i=0;
for (; i < maxmethods-1; i++)
{
methodnames[i] = "method"+i+"(";
System.out.println(i);
if(i<253){
paramvals.append(i+",");
paramusages.append("param"+i+",");
paramdecls.append("int param"+i+",");}
}
i=maxmethods-1;
methodnames[i] = "method"+i+"(";
paramvals.append(255+"");
paramusages.append("param"+255);
paramdecls.append("int param"+255);
for (int j = 0; j < methodnames.length-1; j++)
{
methods[j] = "public static void "+methodnames[j]+paramdecls+")\n{\n"+methodnames[j+1]+paramusages+");\n}";
}
methods[maxmethods-1] = "public static void "+methodnames[maxmethods-1]+paramdecls+")\n{\nSystem.out.println(\"This shouldnt be reached\");\n}";
//fuckyou java
StringBuilder finaL = new StringBuilder();
finaL.append("public class F{\npublic static void main(String[]a){System.out.println(\"NOPPE\");}\n\nstatic{helper();}\n"+
"public static void helper(){method0("+paramvals+");\n}\n//#######################################################+\n");
for (String method : methods)
{
finaL.append(method);
}
finaL.append("}");
new FileWriter(new File("F.java")).write((finaL+"").toCharArray());//Dump of srcfile generated
EU c2 = new EU("F", finaL+"");
JavaCompiler c = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager f = c.getStandardFileManager(null,null,null);
c.getTask(null, f, null, null, null,Arrays.asList(new EU[]{c2})).call();
//System.out.print(new File("").toURI().toURL());
URLClassLoader u = new URLClassLoader(new URL[]{new File("").toURI().toURL()});
Class fc = u.loadClass("F");
fc.getMethod("helper", null).invoke(null, null);
}
public static class EU extends SimpleJavaFileObject {
final String code;
EU(String name, String code) {
super(URI.create("string:///" + name.replace('.','/') + JavaFileObject.Kind.SOURCE.extension),
JavaFileObject.Kind.SOURCE);
this.code = code;
}
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
}
}
}
generated file is dumped in workdirecotry used while running; no endless recursion inside :P
runtime compilation ftw :)
Edit: moved the method count to a constant