proguardproguard 混淆war教程包

Java类文件的混淆 - ITeye问答
使用ProGuard进行java类文件混淆时,发现效果不甚理想。
原因在于:项目是个web项目使用SSH构架,配置文件中含有绝大多数类的全路径。这样ProGuard的缩写类名机制基本无法使用。
求教:
&&& 牛人们在遇到这种情况如何解决代码混淆问题的?
&&& 是否有更好的混淆工具推荐?
Thanks& In& advance!
我们用的是金蝶公司的Jocky,虽然混淆的等级不能设置太高(太高的话在JSP中调用除问题),但那些名称想反编译过来也是比较晕的了
建议用Allatori,我们公司都是通过它来实现代码的保密性的,混的效果很好.
Allatori(非开源软件)是一个Java obfuscator属于第二代obfuscators的家庭,因此它的所有频谱的机会保护你的知识产权。 Allatori具有以下几种保护方式:命名混淆,流混淆,调试信息混淆,字符串编码,以及水印技术。对于教育和非商业项目来说这个混淆器是免费的。
2.1版本支持war和ear文件格式,并且允许对需要混淆代码的应用程序添加有效日期。
相关业务逻辑jar 不会混淆的,看你在开发工程时如何规范了。
Java EE 为什么要混淆代码啊? 一般是Java ME 才会需要混淆。
是否可以吧关键的业务逻辑单独打成jar,再混淆,其它的一般SSH的流程也没必要混淆啊.
http://www.oschina.net/project/lang/19?tag=167
已解决问题
未解决问题maven中添加proguard来混淆代码 - pyzheng - ITeye博客
博客分类:
一步步教你使用Proguard混淆Java源代码
直接使用mvn package可能直接出错,所以先用jar:jar命令得到jar文件,在使用proguard:proguard混淆。
命令在idea的Maven Projects查看。
参考:
com.pyx4me=&com.github.wvengen,版本号要变成2.0.7
&plugin&
&groupId&com.pyx4me&/groupId&
&artifactId&proguard-maven-plugin&/artifactId&
&version&2.0.6&/version&
&executions&
&execution&
&phase&package&/phase&
&goal&proguard&/goal&
&/execution&
&/executions&
&configuration&
&source&1.7&/source&
&target&1.7&/target&
&encoding&UTF-8&/encoding&
&lib&${java.home}/lib/rt.jar&/lib&
&lib&${java.home}/lib/jsse.jar&/lib&
&/configuration&
&dependencies&
&dependency&
&groupId&net.sf.proguard&/groupId&
&artifactId&proguard-base&/artifactId&
&version&4.9&/version&
&scope&runtime&/scope&
&/dependency&
&/dependencies&
proguard.conf
# ----------------------------------
#& 通过指定数量的优化能执行
#& -optimizationpasses n
# ----------------------------------
-optimizationpasses 3
# ----------------------------------
#&& 混淆时不会产生形形色色的类名
#&& -dontusemixedcaseclassnames
# ----------------------------------
-dontusemixedcaseclassnames
# ----------------------------------
#&&&&& 指定不去忽略非公共的库类
#& -dontskipnonpubliclibraryclasses
# ----------------------------------
#-dontskipnonpubliclibraryclasses
# ----------------------------------
#&&&&&& 不预校验
#&&& -dontpreverify
# ----------------------------------
# -dontpreverify
# ----------------------------------
#&&&&& 输出生成信息
#&&&&&& -verbose
# ----------------------------------
-verbose
#混淆时应用侵入式重载
-overloadaggressively
#优化时允许访问并修改有修饰符的类和类的成员
-allowaccessmodification
#确定统一的混淆类的成员名称来增加混淆
-useuniqueclassmembernames
#这里添加你不需要混淆的类
-dontwarn javax.crypto.**
-keep class javax.crypto.**
-keep& class com.rh.hasp.util.** {*;}
#-keep& class mon.constant.** {*;}
-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&;
}
执行:mvn package
输出:
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar
[INFO]
[INFO] --- proguard-maven-plugin:2.0.6:proguard (default) @ rh-hasp ---
[INFO] execute ProGuard [-injars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar'(!META-INF/maven/**), -outjars, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar', -include, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/proguard.conf', -libraryjars, '/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar', -libraryjars, '/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar', -libraryjars, '/usr/java/jdk1.7.0_51/jre/lib/rt.jar', -printmapping, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt', -printseeds, '/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_seeds.txt']
[INFO] proguard jar: /home/pandy/m2/repository/net/sf/proguard/proguard-base/4.9/proguard-base-4.9.jar
[proguard] ProGuard, version 4.9
[proguard] Reading input...
[proguard] Reading program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[proguard] Reading library jar [/home/pandy/m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar]
[proguard] Reading library jar [/home/pandy/m2/repository/commons-lang/commons-lang/2.6/commons-lang-2.6.jar]
[proguard] Reading library jar [/usr/java/jdk1.7.0_51/jre/lib/rt.jar]
[proguard] Initializing...
[proguard] Note: the configuration refers to the unknown class 'javax.servlet.Servlet'
[proguard] Note: there were 1 references to unknown classes.
[proguard]&&&&&& You should check your configuration for typos.
[proguard] Ignoring unused library classes...
[proguard]&& Original number of library classes: 19278
[proguard]&& Final number of library classes:&&& 19278
[proguard] Printing kept classes, fields, and methods...
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]&& Original number of program classes: 8
[proguard]&& Final number of program classes:&&& 8
[proguard] Inlining subroutines...
[proguard] Optimizing...
[proguard]&& Number of finalized classes:&&&&&&&&&&&&&&&& 5
[proguard]&& Number of vertically merged classes:&&&&&&&& 0
[proguard]&& Number of horizontally merged classes:&&&&&& 0
[proguard]&& Number of removed write-only fields:&&&&&&&& 3
[proguard]&& Number of privatized fields:&&&&&&&&&&&&&&&& 12
[proguard]&& Number of inlined constant fields:&&&&&&&&&& 0
[proguard]&& Number of privatized methods:&&&&&&&&&&&&&&& 0
[proguard]&& Number of staticized methods:&&&&&&&&&&&&&&& 1
[proguard]&& Number of finalized methods:&&&&&&&&&&&&&&&& 45
[proguard]&& Number of removed method parameters:&&&&&&&& 0
[proguard]&& Number of inlined constant parameters:&&&&&& 2
[proguard]&& Number of inlined constant return values:&&& 0
[proguard]&& Number of inlined short method calls:&&&&&&& 0
[proguard]&& Number of inlined unique method calls:&&&&&& 13
[proguard]&& Number of inlined tail recursion calls:&&&&& 0
[proguard]&& Number of merged code blocks:&&&&&&&&&&&&&&& 2
[proguard]&& Number of variable peephole optimizations:&& 72
[proguard]&& Number of arithmetic peephole optimizations: 0
[proguard]&& Number of cast peephole optimizations:&&&&&& 0
[proguard]&& Number of field peephole optimizations:&&&&& 1
[proguard]&& Number of branch peephole optimizations:&&&& 36
[proguard]&& Number of string peephole optimizations:&&&& 11
[proguard]&& Number of simplified instructions:&&&&&&&&&& 3
[proguard]&& Number of removed instructions:&&&&&&&&&&&&& 33
[proguard]&& Number of removed local variables:&&&&&&&&&& 2
[proguard]&& Number of removed exception blocks:&&&&&&&&& 3
[proguard]&& Number of optimized local variable frames:&& 25
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]&& Original number of program classes: 8
[proguard]&& Final number of program classes:&&& 8
[proguard] Optimizing...
[proguard]&& Number of finalized classes:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of vertically merged classes:&&&&&&&& 0
[proguard]&& Number of horizontally merged classes:&&&&&& 0
[proguard]&& Number of removed write-only fields:&&&&&&&& 0
[proguard]&& Number of privatized fields:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of inlined constant fields:&&&&&&&&&& 0
[proguard]&& Number of privatized methods:&&&&&&&&&&&&&&& 0
[proguard]&& Number of staticized methods:&&&&&&&&&&&&&&& 0
[proguard]&& Number of finalized methods:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of removed method parameters:&&&&&&&& 1
[proguard]&& Number of inlined constant parameters:&&&&&& 0
[proguard]&& Number of inlined constant return values:&&& 0
[proguard]&& Number of inlined short method calls:&&&&&&& 0
[proguard]&& Number of inlined unique method calls:&&&&&& 0
[proguard]&& Number of inlined tail recursion calls:&&&&& 0
[proguard]&& Number of merged code blocks:&&&&&&&&&&&&&&& 0
[proguard]&& Number of variable peephole optimizations:&& 4
[proguard]&& Number of arithmetic peephole optimizations: 0
[proguard]&& Number of cast peephole optimizations:&&&&&& 0
[proguard]&& Number of field peephole optimizations:&&&&& 0
[proguard]&& Number of branch peephole optimizations:&&&& 1
[proguard]&& Number of string peephole optimizations:&&&& 2
[proguard]&& Number of simplified instructions:&&&&&&&&&& 0
[proguard]&& Number of removed instructions:&&&&&&&&&&&&& 50
[proguard]&& Number of removed local variables:&&&&&&&&&& 1
[proguard]&& Number of removed exception blocks:&&&&&&&&& 0
[proguard]&& Number of optimized local variable frames:&& 1
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]&& Original number of program classes: 8
[proguard]&& Final number of program classes:&&& 8
[proguard] Optimizing...
[proguard]&& Number of finalized classes:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of vertically merged classes:&&&&&&&& 0
[proguard]&& Number of horizontally merged classes:&&&&&& 0
[proguard]&& Number of removed write-only fields:&&&&&&&& 0
[proguard]&& Number of privatized fields:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of inlined constant fields:&&&&&&&&&& 0
[proguard]&& Number of privatized methods:&&&&&&&&&&&&&&& 0
[proguard]&& Number of staticized methods:&&&&&&&&&&&&&&& 0
[proguard]&& Number of finalized methods:&&&&&&&&&&&&&&&& 0
[proguard]&& Number of removed method parameters:&&&&&&&& 0
[proguard]&& Number of inlined constant parameters:&&&&&& 0
[proguard]&& Number of inlined constant return values:&&& 0
[proguard]&& Number of inlined short method calls:&&&&&&& 0
[proguard]&& Number of inlined unique method calls:&&&&&& 0
[proguard]&& Number of inlined tail recursion calls:&&&&& 0
[proguard]&& Number of merged code blocks:&&&&&&&&&&&&&&& 0
[proguard]&& Number of variable peephole optimizations:&& 0
[proguard]&& Number of arithmetic peephole optimizations: 0
[proguard]&& Number of cast peephole optimizations:&&&&&& 0
[proguard]&& Number of field peephole optimizations:&&&&& 0
[proguard]&& Number of branch peephole optimizations:&&&& 0
[proguard]&& Number of string peephole optimizations:&&&& 2
[proguard]&& Number of simplified instructions:&&&&&&&&&& 0
[proguard]&& Number of removed instructions:&&&&&&&&&&&&& 6
[proguard]&& Number of removed local variables:&&&&&&&&&& 0
[proguard]&& Number of removed exception blocks:&&&&&&&&& 0
[proguard]&& Number of optimized local variable frames:&& 0
[proguard] Shrinking...
[proguard] Removing unused program classes and class elements...
[proguard]&& Original number of program classes: 8
[proguard]&& Final number of program classes:&&& 8
[proguard] Obfuscating...
[proguard] Printing mapping to [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/proguard_map.txt]...
[proguard] Preverifying...
[proguard] Writing output...
[proguard] Preparing output jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1.jar]
[proguard]&& Copying resources from program jar [/mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1_proguard_base.jar] (filtered)
[INFO]
[INFO] --- maven-jar-plugin:2.3.2:jar (default) @ rh-hasp ---
[INFO] Building jar: /mnt/D/work_documents/workspace_ide_linux/rh_hasp_util/target/rh-hasp-1.1-lib.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
这时就已经好了,但是包结构都变了,成了a,b,c,d ....的了
虽然是混淆加密了,但是外部也不能再直接使用类来...地去引用了
浏览: 1106699 次
来自: 珠海
很有用,谢谢
厉害,困扰了我很久
非常好,很实用啊。。
你好,你能把能讓這個程序的運行起來的代碼發我一下嗎?非常著急需 ...
可能配置有问题.
这文章我只是收藏转发而已, 并没有实 ...1082人阅读
工具:proguard&5.2
准备:web项目导出的jar包和war包,项目所需的jar包
1.proguard设置:
设置所要混淆的项目jar包,和混淆后的包名称。并添加项目所用的包。
Shrinking,不选不填
Obfuscation设置如上。
Optimization如上。
Information,其中表示版本。
Process,”save&configuration”,生成文件,该文件就是混淆配置文件。
2.设置配置文件
将上述生成的文件用打开,加入你混淆所要保留的类。
-keep&{Modifier}&{class_specification}&&&&保护指定的类文件和类的成员
-keepclassmembers&{modifier}&{class_specification}&&&&保护指定类的成员,如果此类受到保护他们会保护的更好
-keepclasseswithmembers&{class_specification}&&&&保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。
-keepnames&{class_specification}&&&&保护指定的类和类的成员的名称(如果他们不会压缩步骤中删除)
-keepclassmembernames&{class_specification}&&&&保护指定的类的成员的名称(如果他们不会压缩步骤中删除)
-keepclasseswithmembernames&{class_specification}&&&&保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后)
-printseeds&{filename}&&&&列出类和类的成员选项的清单,标准输出到给定的文件
具体怎么写可以百度,我的建议是:先把所有类都保留,或者就混淆一个类,慢慢的扩大混淆范围,这样成功率会高一些。
上述文件配置好后,然后。
可能出现的问题:
1..pro文件不能加载,肯定是你的配置写的有问题,改一下。
2.在过程中项目所需的包报错,可能是包有问题,重新下一个试一试就行了。
将你生成的混淆过后的包中的文件替换到文件中。
将包放到的下,开启检查能正常运行。若报错肯定是混淆有问题。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:4773次
排名:千里之外
原创:18篇
(2)(10)(1)(5)您的邮箱:
请将您的邮箱作为登录账号
您的昵称:
4~30个字符,可以为中文
登陆密码:
6~30个半角字符
确认密码:
请再次输入密码
验 证 码 :
开源混淆工具ProGuard配置详解及配置实例
时间:  
作者:开源吧  
出处:开源吧
ProGuard是一个免费的java类文件压缩,优化,混淆器.它探测并删除没有使用的类,字段,方法和属性.它删除没有用的说明并使用字节码得到最大优化.它使用无意义的名字来重命名类,字段和方法.
ProGuard的作用:
1.创建紧凑的代码文档是为了更快的网络传输,快速装载和更小的内存占用.
2.创建的程序和程序库很难使用反向工程.
3.所以它能删除来自源文件中的没有调用的代码
4.充分利用java6的快速加载的优点来提前检测和返回java6中存在的类文件.
-include {filename}    从给定的文件中读取配置参数
-basedirectory {directoryname}    指定基础目录为以后相对的档案名称
-injars {class_path}    指定要处理的应用程序jar,war,ear和目录
-outjars {class_path}    指定处理完后要输出的jar,war,ear和目录的名称
-libraryjars {classpath}    指定要处理的应用程序jar,war,ear和目录所需要的程序库文件
-dontskipnonpubliclibraryclasses    指定不去忽略非公共的库类。
-dontskipnonpubliclibraryclassmembers    指定不去忽略包可见的库类的成员。
-keep {Modifier} {class_specification}    保护指定的类文件和类的成员
-keepclassmembers {modifier} {class_specification}    保护指定类的成员,如果此类受到保护他们会保护的更好
-keepclasseswithmembers {class_specification}    保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。
-keepnames {class_specification}    保护指定的类和类的成员的名称(如果他们不会压缩步骤中删除)
-keepclassmembernames {class_specification}    保护指定的类的成员的名称(如果他们不会压缩步骤中删除)
-keepclasseswithmembernames {class_specification}    保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后)
-printseeds {filename}    列出类和类的成员-keep选项的清单,标准输出到给定的文件
-dontshrink    不压缩输入的类文件
-printusage {filename}
-whyareyoukeeping {class_specification}    
-dontoptimize    不优化输入的类文件
-assumenosideeffects {class_specification}    优化时假设指定的方法,没有任何副作用
-allowaccessmodification    优化时允许访问并修改有修饰符的类和类的成员
-dontobfuscate    不混淆输入的类文件
-printmapping {filename}
-applymapping {filename}    重用映射增加混淆
-obfuscationdictionary {filename}    使用给定文件中的关键字作为要混淆方法的名称
-overloadaggressively    混淆时应用侵入式重载
-useuniqueclassmembernames    确定统一的混淆类的成员名称来增加混淆
-flattenpackagehierarchy {package_name}    重新包装所有重命名的包并放在给定的单一包中
-repackageclass {package_name}    重新包装所有重命名的类文件中放在给定的单一包中
-dontusemixedcaseclassnames    混淆时不会产生形形色色的类名
-keepattributes {attribute_name,...}    保护给定的可选属性,例如LineNumberTable, LocalVariableTable, SourceFile, Deprecated, Synthetic, Signature, and InnerClasses.
-renamesourcefileattribute {string}    设置源文件中给定的字符串常量
Ant Example:
&!-- This Ant build file illustrates how to process applications,
     by including ProGuard-style configuration options.
     Usage: ant -f applications2.xml --&
&project name="Applications" default="obfuscate" basedir="../.."&
&target name="obfuscate"&
  &taskdef resource="proguard/ant/task.properties"
           classpath="lib/proguard.jar" /&
  &proguard&
    &!-- Specify the input jars, output jars, and library jars. --&
    -injars  in.jar
    -outjars out.jar
    -libraryjars ${java.home}/lib/rt.jar
    &!-- -libraryjars junit.jar    --&
    &!-- -libraryjars servlet.jar  --&
    &!-- -libraryjars jai_core.jar --&
    &!-- ...                       --&
    &!-- Save the obfuscation mapping to a file, and preserve line numbers. --&
    -printmapping out.map
    -renamesourcefileattribute SourceFile
    -keepattributes SourceFile,LineNumberTable
    &!-- Preserve all annotations. --&
    -keepattributes *Annotation*
    &!-- Preserve all public applications. --&
    -keepclasseswithmembers public class * {
        public static void main(java.lang.String[]);
    }
    &!-- Preserve all native method names and the names of their classes. --&
    -keepclasseswithmembernames class * {
        native &methods&;
    }
    &!-- Preserve the methods that are required in all enumeration classes. --&
    -keepclassmembers class * extends java.lang.Enum {
        public static **[] values();
        public static ** valueOf(java.lang.String);
    }
    &!-- Explicitly preserve all serialization members. The Serializable
         interface is only a marker interface, so it wouldn't save them.
         You can comment this out if your library doesn't use serialization.
         If your code contains serializable classes that have to be backward
         compatible, please refer to the manual. --&
    -keepclassmembers class * implements java.io.Serializable {
        static final long serialVersionUID;
        static final java.io.ObjectStreamField[] serialPersistentF
        private void writeObject(java.io.ObjectOutputStream);
        private void readObject(java.io.ObjectInputStream);
        java.lang.Object writeReplace();
        java.lang.Object readResolve();
    }
    &!-- Your application may contain more items that
         typically classes that are dynamically created using Class.forName --&
  &/proguard&
&/project&
我要留言/评论
CopyRight ©
 京ICP备号

我要回帖

更多关于 proguard 不混淆包名 的文章

 

随机推荐