2015-08-27 11:36:14 +00:00
|
|
|
package bcelifier;
|
|
|
|
|
2015-09-02 15:11:32 +00:00
|
|
|
import org.apache.commons.bcel6.generic.*;
|
|
|
|
import org.apache.commons.bcel6.classfile.*;
|
|
|
|
import org.apache.commons.bcel6.*;
|
2015-08-27 11:36:14 +00:00
|
|
|
import java.io.*;
|
|
|
|
|
|
|
|
public class ThisCreator implements Constants {
|
|
|
|
private InstructionFactory _factory;
|
|
|
|
private ConstantPoolGen _cp;
|
|
|
|
private ClassGen _cg;
|
|
|
|
|
|
|
|
public ThisCreator() {
|
2015-10-31 17:48:46 +00:00
|
|
|
_cg = new ClassGen("bcelifier.This", "java.lang.Object", "This.java", ACC_PUBLIC | ACC_SUPER, new String[] { });
|
2015-08-27 11:36:14 +00:00
|
|
|
|
|
|
|
_cp = _cg.getConstantPool();
|
|
|
|
_factory = new InstructionFactory(_cg, _cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void create(OutputStream out) throws IOException {
|
|
|
|
createMethod_0();
|
|
|
|
createMethod_1();
|
|
|
|
_cg.getJavaClass().dump(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createMethod_0() {
|
|
|
|
InstructionList il = new InstructionList();
|
|
|
|
MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { }, "<init>", "bcelifier.This", il, _cp);
|
|
|
|
|
|
|
|
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
|
|
|
il.append(_factory.createInvoke("java.lang.Object", "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
|
|
|
|
InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
|
|
|
|
method.setMaxStack();
|
|
|
|
method.setMaxLocals();
|
|
|
|
_cg.addMethod(method.getMethod());
|
|
|
|
il.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void createMethod_1() {
|
|
|
|
InstructionList il = new InstructionList();
|
|
|
|
MethodGen method = new MethodGen(0, new ObjectType("bcelifier.This"), Type.NO_ARGS, new String[] { }, "methode", "bcelifier.This", il, _cp);
|
|
|
|
|
|
|
|
InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
|
|
|
|
InstructionHandle ih_1 = il.append(_factory.createReturn(Type.OBJECT));
|
|
|
|
method.setMaxStack();
|
|
|
|
method.setMaxLocals();
|
|
|
|
_cg.addMethod(method.getMethod());
|
|
|
|
il.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
bcelifier.ThisCreator creator = new bcelifier.ThisCreator();
|
|
|
|
creator.create(new FileOutputStream("bcelifier.This.class"));
|
|
|
|
}
|
|
|
|
}
|