Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#9 String hiding

open
nobody
None
5
2014-08-15
2001-12-17
Anonymous
No

Not a feature request, just some code if anyone wants
it. Didn't know where to put it.

It's a very simple string hider, but it works pretty
well, combined with StrongRenamer:

pre = new StringMangler { decoder="test.Obj" }
renamer = new StrongRenamer { charset = "_" }

.. gives ..

public void run() {
_._._(_._._(__._("uk\u007f~eu", 8) + __ + __._
("u", 25) + ___ + __._("u", 42)), ____);
}

Code below.. to use it you'll have to cut-n-paste the
_mangle() part (at the bottom) into one of the classes
you're obfuscating, and name that class in the config
file.
<hr>

package jode.obfuscator.modules;
import jode.obfuscator.*;
import jode.bytecode.*;
import java.util.*;

public class StringMangler implements
CodeTransformer,Opcodes,OptionHandler {
int numC;
Reference mangler;

public void setOption(String opt, Collection
val) {
if(opt.startsWith("decoder")) {
String s = (String)
val.iterator().next();
mangler =
Reference.getReference(

"L"+s+";", // <-- the class where you
put the _mangle function

"_mangle",

"(Ljava/lang/String;I)Ljava/lang/String;");
}
}
public void transformCode(BytecodeInfo bc) {
if(mangler==null) throw new Error("You
need to set the decoder parameter.");
ListIterator lit = bc.getInstructions
().listIterator();
while(lit.hasNext()) {
Instruction ldc =
(Instruction) lit.next();

int op = ldc.getOpcode();
// ldc?
if(op!=opc_ldc) continue;

Object obj = ldc.getConstant();
if(obj instanceof String) {

String s = (String)obj;

int ofs = (numC++)*17
% _maxStr;
if(numC>=_maxStr)
throw new Error("Out of buffer space");

ldc.setConstant(_mangle
(s,ofs));

Instruction loadInt =
new Instruction(opc_ldc);
loadInt.setConstant
(new Integer(ofs));
lit.add(loadInt);

Instruction call = new
Instruction(opc_invokestatic);
call.setReference
(mangler);
lit.add(call);
}
}
}

// -- snip
static final int _maxStr = 200;
static String[] _cache = new String[_maxStr];
public static String _mangle(String s0,int i) {
String s;
if((s=_cache[i])!=null) return s;
char[] c = s0.toCharArray();
for(int j=c.length;j-->0;) c[j]^=42;
return _cache[i] = new String(c);
}
// -- snip

}

Discussion

  • Logged In: NO

    package jode.obfuscator.modules;
    import jode.obfuscator.*;
    import jode.bytecode.*;
    import java.util.*;

    public class StringMangler implements
    CodeTransformer,Opcodes,OptionHandler {
    int numC;
    Reference mangler;

    public void setOption(String opt, Collection val) {
    if(opt.startsWith("decoder")) {
    String s = (String) val.iterator
    ().next();
    mangler = Reference.getReference(
    "L"+s+";",
    // <-- the class where you put the _mangle function
    "_mangle",

    "(Ljava/lang/String;I)Ljava/lang/String;");
    }
    }
    public void transformCode(BytecodeInfo bc) {
    if(mangler==null) throw new Error("You need
    to set the decoder parameter.");
    ListIterator lit = bc.getInstructions
    ().listIterator();
    while(lit.hasNext()) {
    Instruction ldc = (Instruction)
    lit.next();

    int op = ldc.getOpcode();
    // ldc?
    if(op!=opc_ldc) continue;

    Object obj = ldc.getConstant();
    if(obj instanceof String) {

    String s = (String)obj;

    int ofs = (numC++)*17 %
    _maxStr;
    if(numC>=_maxStr) throw new
    Error("Out of buffer space");

    ldc.setConstant(_mangle
    (s,ofs));

    Instruction loadInt = new
    Instruction(opc_ldc);
    loadInt.setConstant(new
    Integer(ofs));
    lit.add(loadInt);

    Instruction call = new
    Instruction(opc_invokestatic);
    call.setReference(mangler);
    lit.add(call);
    }
    }
    }

    // -- snip
    static final int _maxStr = 200;
    static String[] _cache = new String[_maxStr];
    public static String _mangle(String s0,int i) {
    String s;
    if((s=_cache[i])!=null) return s;
    char[] c = s0.toCharArray();
    for(int j=c.length;j-->0;) c[j]^=42;
    return _cache[i] = new String(c);
    }
    // -- snip

    }