下载地址:http://proguard.sourceforge.net
以下面的Test.java文件为例:
import
java.util.
*
;
import java.io. * ;
public class Test {
public static void main(String[] args) throws Exception {
BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
String s = stdin.readLine();
if (s.length() % 2 == 0 )
System.out.println(showMsg1());
else
System.out.println(showMsg2());
Flight a = new Flight();
a.setName(s);
System.out.println(a.output());
Bomber b = new Bomber();
b.setName(s);
System.out.println(b.output());
s = stdin.readLine();
StringTokenizer st = new StringTokenizer(s);
int n = Integer.parseInt(st.nextToken());
System.out.println(compute(n));
}
public static String showMsg1() {
return " You are my sun1 " ;
}
public static String showMsg2() {
return " You are my sun2 " ;
}
public static int compute( int n) {
if (n > 1 )
return n * compute(n - 1 );
else
return 1 ;
}
public static class Flight {
public Flight() {
}
public String output() {
return this .name;
}
public void setName(String name) {
this .name = " Flight: " + name;
}
private String name;
}
public static class Bomber {
public Bomber() {
}
public String output() {
return this .name;
}
public void setName(String name) {
this .name = " Bomber: " + name;
}
private String name;
}
}
import java.io. * ;
public class Test {
public static void main(String[] args) throws Exception {
BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in));
String s = stdin.readLine();
if (s.length() % 2 == 0 )
System.out.println(showMsg1());
else
System.out.println(showMsg2());
Flight a = new Flight();
a.setName(s);
System.out.println(a.output());
Bomber b = new Bomber();
b.setName(s);
System.out.println(b.output());
s = stdin.readLine();
StringTokenizer st = new StringTokenizer(s);
int n = Integer.parseInt(st.nextToken());
System.out.println(compute(n));
}
public static String showMsg1() {
return " You are my sun1 " ;
}
public static String showMsg2() {
return " You are my sun2 " ;
}
public static int compute( int n) {
if (n > 1 )
return n * compute(n - 1 );
else
return 1 ;
}
public static class Flight {
public Flight() {
}
public String output() {
return this .name;
}
public void setName(String name) {
this .name = " Flight: " + name;
}
private String name;
}
public static class Bomber {
public Bomber() {
}
public String output() {
return this .name;
}
public void setName(String name) {
this .name = " Bomber: " + name;
}
private String name;
}
}
首先jar cvf a.jar *.class打包程序,然后jad -d d:/ -r -s java d:/*.class反编译程序,生成Test.java文件,通过对比可以发现,它和原来文件的内容基本是相同的。
//
Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Test.java
import java.io. * ;
import java.util.StringTokenizer;
public class Test
{
public static class Bomber
{
public String output()
{
return name;
}
public void setName(String s)
{
name = ( new StringBuilder()).append( " Bomber: " ).append(s).toString();
}
private String name;
public Bomber()
{
}
}
public static class Flight
{
public String output()
{
return name;
}
public void setName(String s)
{
name = ( new StringBuilder()).append( " Flight: " ).append(s).toString();
}
private String name;
public Flight()
{
}
}
public Test()
{
}
public static void main(String args[])
throws Exception
{
BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(System.in));
String s = bufferedreader.readLine();
if (s.length() % 2 == 0 )
System.out.println(showMsg1());
else
System.out.println(showMsg2());
Flight flight = new Flight();
flight.setName(s);
System.out.println(flight.output());
Bomber bomber = new Bomber();
bomber.setName(s);
System.out.println(bomber.output());
s = bufferedreader.readLine();
StringTokenizer stringtokenizer = new StringTokenizer(s);
int i = Integer.parseInt(stringtokenizer.nextToken());
System.out.println(compute(i));
}
public static String showMsg1()
{
return " You are my sun1 " ;
}
public static String showMsg2()
{
return " You are my sun2 " ;
}
public static int compute( int i)
{
if (i > 1 )
return i * compute(i - 1 );
else
return 1 ;
}
}
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
// Source File Name: Test.java
import java.io. * ;
import java.util.StringTokenizer;
public class Test
{
public static class Bomber
{
public String output()
{
return name;
}
public void setName(String s)
{
name = ( new StringBuilder()).append( " Bomber: " ).append(s).toString();
}
private String name;
public Bomber()
{
}
}
public static class Flight
{
public String output()
{
return name;
}
public void setName(String s)
{
name = ( new StringBuilder()).append( " Flight: " ).append(s).toString();
}
private String name;
public Flight()
{
}
}
public Test()
{
}
public static void main(String args[])
throws Exception
{
BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(System.in));
String s = bufferedreader.readLine();
if (s.length() % 2 == 0 )
System.out.println(showMsg1());
else
System.out.println(showMsg2());
Flight flight = new Flight();
flight.setName(s);
System.out.println(flight.output());
Bomber bomber = new Bomber();
bomber.setName(s);
System.out.println(bomber.output());
s = bufferedreader.readLine();
StringTokenizer stringtokenizer = new StringTokenizer(s);
int i = Integer.parseInt(stringtokenizer.nextToken());
System.out.println(compute(i));
}
public static String showMsg1()
{
return " You are my sun1 " ;
}
public static String showMsg2()
{
return " You are my sun2 " ;
}
public static int compute( int i)
{
if (i > 1 )
return i * compute(i - 1 );
else
return 1 ;
}
}
进入Proguard的lib目录,用JDK打开proguardgui.jar,点选Input/Output标签,选择要混淆的JAR包(注意是JAR包),输出JAR包,以及用到的所有类库。
点选Obfuscation标签,选中不需要混淆的类(要被反射的类绝对不能被混淆),一般是1,4,5,9,10,11
,12这几个选项。
a.txt的文件内容为:(混淆函数名)
Gcd
b.txt的文件内容为:(混淆类名)
A
B
点选Process标签,Process按钮,生产b.jar
解压b.jar后,这时的3个class文件分别为A.class、B.class、Test.class;
重新反编译程序jad -d d:/b/ -r -s java d:/b/*.class,生成3个java文件:A.java、B.java、Test.java,具体内容如下:
A.java
//
Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
public final class A
{
public A()
{
}
public final String Gcd()
{
return Gcd;
}
public final void Gcd(String s)
{
Gcd = ( new StringBuilder()).append( " Bomber: " ).append(s).toString();
}
private String Gcd;
}
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
public final class A
{
public A()
{
}
public final String Gcd()
{
return Gcd;
}
public final void Gcd(String s)
{
Gcd = ( new StringBuilder()).append( " Bomber: " ).append(s).toString();
}
private String Gcd;
}
B.java
//
Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
public final class B
{
public B()
{
}
public final String Gcd()
{
return Gcd;
}
public final void Gcd(String s)
{
Gcd = ( new StringBuilder()).append( " Flight: " ).append(s).toString();
}
private String Gcd;
}
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
public final class B
{
public B()
{
}
public final String Gcd()
{
return Gcd;
}
public final void Gcd(String s)
{
Gcd = ( new StringBuilder()).append( " Flight: " ).append(s).toString();
}
private String Gcd;
}
Test.java
//
Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
import java.io. * ;
import java.util.StringTokenizer;
public class Test
{
public Test()
{
}
public static void main(String args[])
{
String s;
if ((s = (args = new BufferedReader( new InputStreamReader(System.in))).readLine()).length() % 2 == 0 )
System.out.println( " You are my sun1 " );
else
System.out.println( " You are my sun2 " );
Object obj;
((B) (obj = new B())).Gcd(s);
System.out.println(((B) (obj)).Gcd());
((A) (obj = new A())).Gcd(s);
System.out.println(((A) (obj)).Gcd());
s = args.readLine();
args = Integer.parseInt((args = new StringTokenizer(s)).nextToken());
System.out.println(Gcd(args));
}
private static int Gcd( int i)
{
if (i > 1 )
return i * Gcd(i - 1 );
else
return 1 ;
}
}
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3)
import java.io. * ;
import java.util.StringTokenizer;
public class Test
{
public Test()
{
}
public static void main(String args[])
{
String s;
if ((s = (args = new BufferedReader( new InputStreamReader(System.in))).readLine()).length() % 2 == 0 )
System.out.println( " You are my sun1 " );
else
System.out.println( " You are my sun2 " );
Object obj;
((B) (obj = new B())).Gcd(s);
System.out.println(((B) (obj)).Gcd());
((A) (obj = new A())).Gcd(s);
System.out.println(((A) (obj)).Gcd());
s = args.readLine();
args = Integer.parseInt((args = new StringTokenizer(s)).nextToken());
System.out.println(Gcd(args));
}
private static int Gcd( int i)
{
if (i > 1 )
return i * Gcd(i - 1 );
else
return 1 ;
}
}