proguard 加密代码

proguard 调通了

com.pyx4me 的 proguard-maven-plugin 总是失败,com.github.wvengen调通,这工具暂时也不想去深究,调通就先用着。

<plugin>
	<groupId>com.github.wvengen</groupId>
	<artifactId>proguard-maven-plugin</artifactId>
	<version>2.0.6</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>proguard</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<source>1.7</source>
		<target>1.7</target>
		<encoding>UTF-8</encoding>
		<libs>
			<lib>${java.home}/lib/rt.jar</lib>
			<lib>${java.home}/lib/jsse.jar</lib>
		</libs> 
	</configuration>
				
	<dependencies>
		<dependency>
			<groupId>net.sf.proguard</groupId>
			<artifactId>proguard-base</artifactId>
			<version>4.9</version>
			<scope>runtime</scope>
		</dependency>
	</dependencies>
</plugin>

执行clean package

INFO] --- proguard-maven-plugin:2.0.6:proguard (default) @ Common ---
[INFO] execute ProGuard [-injars, 'F:\JavaCode\Code\xxx-common_proguard_base.jar'(!META-INF/maven/**), -outjars, 'F:\JavaCode\Code\xxx-common.jar', -libraryjars, 'xxxx', -libraryjars, 'xxx', -libraryjars, 'F:\JavaCode\res\m2\repository\log4j\log4j\1.2.16\log4j-1.2.16.jar', -libraryjars, 'xxx', -libraryjars, 'C:\Java\JDK7\jdk1.7.0_13\jre/lib/rt.jar', -libraryjars, 'C:\Java\JDK7\jdk1.7.0_13\jre/lib/jsse.jar', -printmapping, 'F:\JavaCode\xxxproguard_map.txt', -printseeds, 'F:\JavaCode\xxxx\Common\target\proguard_seeds.txt']
[INFO] proguard jar: F:\JavaCode\res\m2\repository\net\sf\proguard\proguard-base\4.9\proguard-base-4.9.jar
 [proguard] ProGuard, version 4.9
 [proguard] Reading library jar [C:\Java\JDK7\jdk1.7.0_13\jre\lib\rt.jar]
 [proguard] Reading library jar [C:\Java\JDK7\jdk1.7.0_13\jre\lib\jsse.jar]
 [proguard] Error: You have to specify '-keep' options for the shrinking step.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE

 

proguard/InputReader.java  78行 readInput("Reading program ",    100 行的     readInput("Reading library ",
程序码里写的较为清楚,需要一些keep commands
// Check if we have at least some keep commands.
if (configuration.keep == null)
{
    throw new IOException("You have to specify '-keep' options for the shrinking step.");
}
官网上找到一个配置

<configuration>
    <options>
        <option>-allowaccessmodification</option>
        <option>-keep public class * extends java.applet.Applet { *; }</option>
    </options>
</configuration>

 添加一个keep

-keep  class com.util.time.** {*;}  

 [proguard]   Copying resources from program jar [F:\JavaCode\xxx-common_proguard_base.jar] (filtered)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

这时就已经好了,但是包结构都变了,成了a,b,c,d ....的了

虽然是混淆加密了,但是外部也不能再直接使用类来...地去引用了,皱眉

 

部分参考了:http://blog.csdn.net/zhangjianying/article/details/7939593

下面的配置先留着:

 

# ----------------------------------
#  通过指定数量的优化能执行
#  -optimizationpasses n
# ----------------------------------
-optimizationpasses 3

# ----------------------------------
#   混淆时不会产生形形色色的类名 
#   -dontusemixedcaseclassnames
# ----------------------------------
-dontusemixedcaseclassnames
# ----------------------------------
#      指定不去忽略非公共的库类
#  -dontskipnonpubliclibraryclasses
# ----------------------------------
#-dontskipnonpubliclibraryclasses

# ----------------------------------
#       不预校验
#    -dontpreverify
# ----------------------------------
# -dontpreverify

# ----------------------------------
#      输出生成信息
#       -verbose
# ----------------------------------
-verbose

#混淆时应用侵入式重载 
-overloadaggressively 
 
#优化时允许访问并修改有修饰符的类和类的成员 
-allowaccessmodification
#确定统一的混淆类的成员名称来增加混淆 
-useuniqueclassmembernames



#这里添加你不需要混淆的类

-keep  class org.** {*;} 
#-keep  class com.zsoftware.common.constant.** {*;} 
#-keep  class com.zsoftware.common.dwr.** {*;} 
#-keep  class com.zsoftware.common.servelt.** {*;} 
#-keep  class com.zsoftware.common.util.** {*;} 
#-keep  class com.zsoftware.Component.** {*;} 
#-keep  class com.zsoftware.interfacepkg.** {*;} 
#-keep  class com.zsoftware.model.** {*;} 
#-keep  class com.zsoftware.view.** {*;} 
#-keep  class com.zsoftware.webResource.** {*;} 

-keep public class * extends  javax.servlet.Servlet
 
-keepdirectories  **
-keepattributes **
 

#-keepnames class * implements java.io.Serializable
# ---------保护所有实体中的字段名称----------
-keepclassmembers class * implements java.io.Serializable {
    <fields>;
}

# --------- 保护类中的所有方法名 ------------
-keepclassmembers class * {
	public <methods>;
}
 

 

寻找一个,外部可引用其中的类,但是类又不轻易被外面的程序所反编译的方法…………

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值