Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Obscured Obfuscation

Similar Questions: Here and Here

I guess the situation is pretty uncommon to begin with, and so I admit it is probably too localized for SO.

The Problem

public class bqf implements azj
{
    ...

    public static float b = 0.0F;

    ...

    public void b(...)
    {
        ...

        /* b, in both references below,
         * is meant to be a class (in the
         * default package)
         *
         * It is being obscured by field
         * b on the right side of the
         * expression.
         */
        b var13 = b.a(var9, var2, new br());

        ...
    }
}

The error is: cannot invoke a(aji, String, br) on primitive type float.

Compromisable limitations:

  • Field b cannot be renamed.
  • Class b cannot be renamed or refactored.

Why

I am modifying an obfuscated program. For irrelevant[?], unknown (to me), and uncompromisable reasons the modification must be done via patching the original jar with .class files. Hence, renaming the public field b or class b would require modifying much of the program. Because all of the classes are in the default package, refactoring class b would require me to modify every class which references b (much of the program). Nevertheless there is a substantial amount of modification I do intend on doing, and it is a pain to do it at the bytecode level; just not enough to warrant renaming/refactoring.

Possible Solutions

  • The most obvious one is to rename/refactor. There are thousands of classes, and every single one is in the default package. It seems like every java program I want to modify has that sort of obfuscation. : (

    Anyways sometimes I do take the time to just go about manually renaming/refactoring the program. But when when there's too many errors (I once did 18,000), this is not a viable option.

  • The second obvious option is to do it in bytecode (via ASM). Sometimes this is ok, when the modifications are small or simple enough. Unfortunately doing bytecode modifications on only the files which I can't compile through java (which is most of them, but this is what I usually try to do) is painfully slow by comparison.

  • Sometimes I can extend class b, and use that in my modified class. Obviously this won't always work, for example when b is an enum. Unfortunately this means a lot of extra classes.

  • It may be possible to create a class with static wrapper methods to avoid obscurity. I just thought of this.

  • A tool which remaps all of the names (not deobfuscate, just unique names), then unmaps them after you make modifications. That would be sweet. I should make one if it doesn't exist.

  • The problem would also be solved with a way to force the java compiler to require the keyword "this".

like image 364
Max Avatar asked Oct 20 '22 01:10

Max


1 Answers

b.a(var9, var2, new br());

can easily be rewritten using reflection:

Class.forName("b").getMethod("a", argTypes...).invoke(null, var9, var2, new br());

The problem would also be solved with a way to force the java compiler to require the keyword "this".

I don't think how this would help you for a static member. Compiler would have to require us to qualify everything—basically, disallow simple names altogether except for locals.

like image 103
Marko Topolnik Avatar answered Oct 22 '22 17:10

Marko Topolnik