批处理混淆与 Proguard

huangapple go评论68阅读模式
英文:

Batch obfuscation with proguard

问题

我需要混淆一系列的jar文件。什么是最佳的方法来实现这个?这些jar包之间有相互依赖关系。我需要为每个jar包编写单独的proguard配置文件,并编写一个脚本来进行迭代处理吗?或者是否已经有更好的方法可用?

英文:

I need to obfuscate a list of jars files. What is the best method for doing this ?. This jars has inter dependencies. Do I need to write separate proguard conf file for each jar and to write a script to iterate through it ?. Or any better methods already available ?

答案1

得分: 0

终于我成功地通过创建一个 gradle 任务来实现这一点:<br>
* 安装最新的 gradle
* 创建一个目录并执行 `gradle init` 并选择基本设置
* 创建一个文本文件,其中指定了所有要混淆的输入 jar 包
* 创建 proguard.conf 文件
* 在 build.gradle 中更新如下任务:<br>

      buildscript {
        repositories {
          mavenCentral()
        }
        dependencies {
          classpath 'net.sf.proguard:proguard-gradle:6.0.3'
          classpath 'net.sf.proguard:proguard-base:6.0.3'
        }
      }
      task proguard(type: proguard.gradle.ProGuardTask) {
       configuration 'proguard.conf'
       new File("${System.getProperty('user.dir')}/injars.txt").eachLine { file ->
            injars "${System.getProperty('user.dir')}/inputjars/${file}"
            outjars "${System.getProperty('user.dir')}/outputjars/${file}"
       }

       libraryjars "${System.getProperty('java.home')}/lib/rt.jar"
       libraryjars "${System.getProperty('java.home')}/lib/jce.jar"
       libraryjars "${System.getProperty('user.dir')}/dependencies/"    // 所有依赖库    
      }
英文:

Finally I am able to achieve this by creating a gradle task<br>

  • Install latest gradle

  • Create a directory and execute gradle init and select basic

  • Create a text file where all the input jars specified to obfuscate

  • Create the proguard.conf

  • Update the build.gradle with the following task.<br>

    buildscript {
      repositories {
        mavenCentral()
      }
      dependencies {
        classpath &#39;net.sf.proguard:proguard-gradle:6.0.3&#39;
        classpath &#39;net.sf.proguard:proguard-base:6.0.3&#39;
      }
    }
    task proguard(type: proguard.gradle.ProGuardTask) {
     configuration &#39;proguard.conf&#39;
     new File(&quot;${System.getProperty(&#39;user.dir&#39;)}/injars.txt&quot;).eachLine { file -&gt;
          injars &quot;${System.getProperty(&#39;user.dir&#39;)}/inputjars/${file}&quot;
          outjars &quot;${System.getProperty(&#39;user.dir&#39;)}/outputjars/${file}&quot;
     }
    
     libraryjars &quot;${System.getProperty(&#39;java.home&#39;)}/lib/rt.jar&quot;
     libraryjars &quot;${System.getProperty(&#39;java.home&#39;)}/lib/jce.jar&quot;
     libraryjars &quot;${System.getProperty(&#39;user.dir&#39;)}/dependencies/&quot;    //All the dependant libraries    
    }
    

huangapple
  • 本文由 发表于 2020年10月7日 17:10:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/64240857.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定