Question

I am trying to replace a certain class file with my own in an obfuscated jar. The original class file has methods named "new" and "null" so a quick decompile + compile doesn't work. I tried compiling and using jbe to add new methods named "new" that relayed everything to "new_symbol" functions (with new_symbol beeing the decompiled version of the original "new" function). This did not work. ("code segment has wrong length in class file")

Does anyone know of a way to refractor method names in class files? And if that isn't possible, a way to reliably create those "proxy functions"? From google I learned that there are about 1000+ different backend library's but only jbe as fronted for bytecode editing?

EDIT: Let me try to illustrate it. Let's say that there is a jar file with a class that provides a function that logs everything you give it to a database. I'd like to replace that class file with my own, and it should not only log everything to a database, but also print whatever data it gets to the command line.

The problem is, that class file was obfuscated and the obfuscator gave it public method names like "new" or "null". If you try:

public class replacement{
public void new (string data){
...
}
}

And compile that, you get compilation errors.

My idea was to create this :

public class replacement{
public void newsymbol (string data){
...
}
}

And use a bytecode editor to create a function named "new" that calls "newsymbol" with the same arguments. (but I get "code segment wrong length" and other errors going down this route.

My question therefore could be better frased as "give me a way to intercept calls to a class file who's public methods are named "new" "null" "weird_unicode_symbols""....

Was it helpful?

Solution 2

So, what turned out to be the best solution for me was to use a hex editor (as suggested by user60561).

Apparantly, the name of every function and field is only saved once in the class file so if you use names with the same amount of bytes you can hexedit your way to victory. For me it came down to replacing "new" by "abc" and every strange unicode character with a two-char sequence.

Thanks for all the suggestions.

OTHER TIPS

Scala allows you to use identifiers in names if you surround them by `.

class f{
    def `new`():Int = {
        return 3
    }
}

jd-gui output

import scala.reflect.ScalaSignature;

@ScalaSignature(bytes=/* snip */)
public class f
{
    public int jdMethod_new()
    {
        return 3;
    }
}

I assume that jdMethod_ is prefixed in order to make the identifier valid. There is no jdMethod_ when looking at the class file using a hex editor.

However, this does have a flaw when you need to use public fields; scalac never generates public fields, it always makes them private and creates accessors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top