2013-05-14 115 views
3

我想使用java混淆器來混淆我的源代碼。我使用了proguard,因爲它是建議最多的一個。我配置了我的build.xml如下使用proguard混淆源代碼

<target name="-post-jar"> 
    <property name="proguard.jar.path" value="D:/pro/proguard.jar" /> 
    <taskdef resource="proguard/ant/task.properties" 
      classpath="${proguard.jar.path}" /> 
    <echo message="Obfuscating ${dist.jar}..."/> 
    <mkdir dir="${build.dir}/obfuscated"/> 
    <proguard printmapping="${build.dir}/obfuscated/${application.title}.map" 
       renamesourcefileattribute="SourceFile" ignorewarnings="true"> 

     <injar file="${dist.jar}" /> 
     <outjar file="${build.dir}/obfuscated/${application.title}.jar" /> 

     <libraryjar path="${javac.classpath}" />   
     <libraryjar file="${java.home}/lib/rt.jar" /> 
     <libraryjar file="${java.home}/lib/jce.jar" /> 

     <keepattribute name="InnerClasses" /> 
     <keepattribute name="SourceFile" /> 
     <keepattribute name="LineNumberTable" /> 
     <keepattribute name="Deprecated" /> 
     <keepattribute name="*Annotation*" /> 
     <keepattribute name="Signature" /> 
     <keepattribute name="Exceptions" /> 

     <keep access="public"> 
      <field access="public protected" /> 
      <method access="public protected" /> 
     </keep> 

     <keepclassmembernames access="public"> 
      <method type  ="java.lang.Class" 
        name  ="class$" 
        parameters="java.lang.String" /> 
      <method type  ="java.lang.Class" 
        name  ="class$" 
        parameters="java.lang.String,boolean" /> 
     </keepclassmembernames> 

     <keepclasseswithmembernames> 
      <method access="native" /> 
     </keepclasseswithmembernames> 

     <keepclassmembers extends="java.lang.Enum"> 
      <method access="public static" 
        type="**[]" 
        name="values" 
        parameters="" /> 
      <method access="public static" 
        type="**" 
        name="valueOf" 
        parameters="java.lang.String" /> 
     </keepclassmembers> 

     <keepnames implements="java.io.Serializable"/> 
     <keepclassmembers implements="java.io.Serializable"> 
      <field access ="final" 
        type  ="long" 
        name  ="serialVersionUID" /> 
      <field access ="!static !transient" 
        name  ="**"/> 
      <field access ="!private" 
        name  ="**"/> 
      <method access ="!private" 
        name  ="**"/> 
      <method access ="private" 
        type  ="void" 
        name  ="writeObject" 
        parameters="java.io.ObjectOutputStream" /> 
      <method access ="private" 
        type  ="void" 
        name  ="readObject" 
        parameters="java.io.ObjectOutputStream" /> 
      <method type  ="java.lang.Object" 
        name  ="writeReplace" 
        parameters="" /> 
      <method type  ="java.lang.Object" 
        name  ="readResolve" 
        parameters="" /> 
     </keepclassmembers> 

    </proguard> 
    <copy file="${build.dir}/obfuscated/${application.title}.jar" tofile="${dist.jar}" overwrite="true"/> 
    <delete dir="${build.dir}/obfuscated"/> 
</target> 

但它會導致以下錯誤:

java.lang.UnsupportedOperationException: Method must be overridden in [proguard.optimize.peephole.ClassMerger] if ever called 
    at proguard.classfile.util.SimplifiedVisitor.visitAnyClass(SimplifiedVisitor.java:47) 
    at proguard.classfile.util.SimplifiedVisitor.visitLibraryClass(SimplifiedVisitor.java:59) 
    at proguard.classfile.LibraryClass.accept(LibraryClass.java:301) 
    at proguard.classfile.ProgramClass.subclassesAccept(ProgramClass.java:433) 
    at proguard.optimize.peephole.VerticalClassMerger.visitProgramClass(VerticalClassMerger.java:83) 
    at proguard.classfile.ProgramClass.accept(ProgramClass.java:346) 
    at proguard.classfile.ClassPool.classesAccept(ClassPool.java:125) 
    at proguard.optimize.Optimizer.execute(Optimizer.java:565) 
    at proguard.ProGuard.optimize(ProGuard.java:307) 
    at proguard.ProGuard.execute(ProGuard.java:116) 
    at proguard.ant.ProGuardTask.execute(ProGuardTask.java:316) 
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) 
    at sun.reflect.GeneratedMethodAccessor137.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) 
    at org.apache.tools.ant.Task.perform(Task.java:348) 
    at org.apache.tools.ant.Target.execute(Target.java:392) 
    at org.apache.tools.ant.Target.performTasks(Target.java:413) 
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) 
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368) 
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) 
    at org.apache.tools.ant.Project.executeTargets(Project.java:1251) 
    at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:285) 
    at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539) 
    at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153) 
+0

@AndrewThompson這是一個選擇,爲什麼不呢? – 2013-05-14 07:14:13

+0

看看這個鏈接是否可以幫助你:http://sourceforge.net/p/proguard/bugs/384/ – 2013-05-14 07:17:11

+0

@Andrew Thompson:在我的情況下必須至少保護它免於反編譯。 – Deeps 2013-05-14 07:31:14

回答

2

而不是使用選項-ignorewarnings的,你應該嘗試解決您獲得的警告。你沒有在你的問題中提到警告,但可能是你已經指定了依賴於程序類(帶有-injars)的庫類(帶有-libraryjars),這是不允許的。 (CFR)。 ProGuard手冊>簡介。