Question

Alright so I'm trying to write a generic string deobfuscator (Similar to what .NET has with Simple Assembly Explorer)

What I want to do is grab a method's instructions via BCEL and execute them with arguments I provide and have access to the output of that method. Is this possible to do with any existing libraries? If so, can I get some help?

Thanks

Was it helpful?

Solution

A combination of BCEL and reflection/invocation could do the job. Use BCEL to get the names of the classes and methods (your LDC, invokestatic trick or something similiar) and invoke the method right after. You can do this if you put your "test classes" on the classpath. To me, there's no need to execute byte code.


If you have a class and a method name, it goes like this:

Class clazz = Class.forName(yourClassName);
// either (for public methods)
Method method = clazz.getMethod(yourMethodName);
// or for protected / private methods:
Method method = clazz.getDeclaredMethod(yourMethodName, yourArgumentTypes);
method.setAccessible(true); 

// assuming the method is static
Object result = method.invoke(null, yourMethodArgs);
// otherwise: pass a object reference instead of null
// to call the method "on" that object
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top