转:Proguard使用教程

下载地址: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;
    }

}

 

首先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 ;
    }

}

 

进入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;
}

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;
}

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 ;
    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值