JBuilder 有“加密”的选项,叫 "Obfuscate",在 Project properties | Build 里面。
不过,要效果好还是要用专门的“加扰器”- Java Obfuscator。
cheka 讲的 “改变量和方法名”,也就是“名称加扰”- Name Obfuscation,
是被称为第一代加密器所做的事情。而所谓的第二代加密器则可以做“流程加扰”-
Flow Obfuscation 以及“字符串加密”- String Encryption。效果大大不同。
下面的例子资料来自: http://www.zelix.com/klassmaster/features.html
原始代码:
package test;
import java.util.*;
class Demo {
private Vector buffer = new Vector();
/**
* Return the position of the specified String in the
* buffer. Remove the String once if it has been found.
* Return -1 if the String isn't found. */
int getStringPos(String string) {
for(int counter=0;
counter < buffer.size();
counter++) {
String curString = (String)buffer.elementAt(counter);
if (curString.equals(string)) {
buffer.remove(counter);
return counter;
}
}
return -1;
}
}
经过“名称加扰”,再反编译:
package a;
import java.util.Vector;
class a {
private Vector a new Vector();
int a(String s) {
for(int i = 0;
i < a.size();
i++) {
String s1 = (String)a.elementAt(i);
if(s1.equals(s)) {
a.remove(i);
return i;
}
}
return -1;
}
}
经过“流程加扰”,再反编译:
package a;
import java.util.Vector;
class a {
private Vector a;
public static int b;
a() {
a = new Vector();
}
int a(String s) {
int i;
int j;
j = b;
i = 0;
if(j == 0) goto _L2;
else
goto _L1
_L1:
String s1 = (String)a.elementAt(i);
s1.equals(s);
if(j != 0) goto _L4;
else
goto _L3
_L3:
JVM INSTR ifeq 48;
goto _L5 _L6
_L5:
break MISSING_BLOCK_LABEL_37;
_L6:
continue;
a.remove(i);
i;
_L4:
return;
_L2:
if(i >= a.size())
return -1;
if(true) goto _L1;
else
goto _L7
_L7:
}
}
这么一搞的话,源程序是恢复不出来了。