泰兴网站开发,自己做网站 需要哪些,中国建筑网官网企业文化,php做的网站怎么发布yGuard官方文档地址#xff1a;https://yworks.github.io/yGuard/index.html
yGuard官方文档包含了比较全面的内容#xff0c;由于文档是英文的#xff0c;而且文档翻译后的浏览效果不是特别好#xff0c;所以看文档入门有点难度。
这个系列的重点是混淆#xff0c;所以… yGuard官方文档地址https://yworks.github.io/yGuard/index.html
yGuard官方文档包含了比较全面的内容由于文档是英文的而且文档翻译后的浏览效果不是特别好所以看文档入门有点难度。
这个系列的重点是混淆所以不会涉及yGuard中的shrink用法主要是rename的用法。
本文使用的 maven-antrun-plugin 插件插件的基本配置如下
pluginartifactIdmaven-antrun-plugin/artifactIdversion1.8/versionexecutionsexecutionphasepackage/phasegoalsgoalrun/goal/goalsidobfuscate/idconfigurationtasks!-- Ant具体配置 --/tasks/configuration/execution/executions
/plugin在插件配置的 tasks 中是 Ant 的具体配置下面是一个参考官方示例修改过的配置针对单个模块的配置。
taskspropertynameproject.jarvalue${project.build.directory}/${project.build.finalName}.jar/propertynameproject.jar.unobfvalue${project.build.directory}/${project.build.finalName}_unobf.jar/movefile${project.jar}tofile${project.jar.unobf}verbosetrue/propertynameruntime_classpathrefidmaven.runtime.classpath/taskdefnameyguardclassnamecom.yworks.yguard.YGuardTaskclasspath${runtime_classpath}/yguardinoutpair in${project.jar.unobf} out${project.jar} /externalclassespathelement location${runtime_classpath}/!-- 下面配置是错误的 --pathelement location${maven.dependency.com.google.code.gson.gson.jar.path}//externalclassesrename logfile${project.build.directory}/${project.build.finalName}_renamelog.xmlkeepclass classesnone methodsnone fieldsnonepatternsetinclude nameorg.example.//patternset/class/keep/rename/yguard
/tasks在这个配置中前两个 property 定义了两个属性在ant中可以通过 ${project.build.directory} 引用Maven配置并不是所有配置都能生效可以通过下面的方式简单验证
targetecho messagebasedir: ${basedir}/echo messageproject.build.directory: ${project.build.directory}/
/target上面任务会输出以下内容和所在项目有关
main:[echo] basedir: D:\GitLab\module-parent\module-yuard[echo] project.build.directory: D:\GitLab\module-parent\module-yuard\target上面配置第三个 move 实际上给 maven 默认打包出来的 jar 改了个名字从.jar 后缀改成了 .jar.unobf。
再下面一个 property 中通过 refidmaven.runtime.classpath 指定了运行时的类路径可以用下面方式查看类路径的信息
property nameruntime_classpath refidmaven.runtime.classpath/
echo messageruntime_classpath: ${runtime_classpath}/关于 refidmaven.runtime.classpath 更多的信息可以看下面文档 https://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html 输出结果如下
main:[echo] runtime_classpath: D:\GitLab\module-parent\module-yuard\target\classes;D:\GitLab\module-parent\module-a\target\module-a-1.0-SNAPSHOT.jar;D:\GitLab\module-parent\module-b\target\module-b-1.0-SNAPSHOT.jar;D:\GitLab\module-parent\module-c\target\module-c-1.0-SNAPSHOT.jar;D:\Dev\.m2\repository\com\yworks\yguard\4.1.1-SNAPSHOT\yguard-4.1.1-SNAPSHOT.jar;D:\Dev\.m2\repository\com\yworks\annotation\4.1.1-SNAPSHOT\annotation-4.1.1-SNAPSHOT.jar;D:\Dev\.m2\repository\org\ow2\asm\asm\9.2\asm-9.2.jar;D:\Dev\.m2\repository\org\apache\ant\ant\1.10.12\ant-1.10.12.jar;D:\Dev\.m2\repository\org\apache\ant\ant-launcher\1.10.12\ant-launcher-1.10.12.jar;D:\Dev\.m2\repository\cn\hutool\hutool-all\5.7.22\hutool-all-5.7.22.jar这里正好结合下面的 externalclasses 看看通过 debug yGuard可以看到注入的实际地址 可以看到类路径最后一个是 D:\GitLab\module-parent\module-yuard\${maven.dependency.com.google.code.gson.gson.jar.path}这个明显没有对应的 jar这种写法是无法自动解析为对应jar包的使用Maven时需要注意官方示例和文档中也有类似的错误。
再下面的 taskdef 就是 ant 扩展任务的定义属于固定写法再往下的 yguard 就是 yGuard 主要的配置部分了。
yGuard部分通过inoutpair in${project.jar.unobf} out${project.jar} /定义要处理的jar包in是输入out是输出这两个名字可以一样相当于会覆盖。inoutpair可以配置多个但是maven执行的机制导致这里能被有效混淆的只能有1个后续实现的多模块混淆是利用了Maven生命周期的一些特点实现的。
externalclasses部分是外部 jar 依赖运行时用到的可以配置到这里可以一个个指定也可以像上面文档直接指定 maven 的运行时类路径。
rename是本系列的重点上面示例中使用的 keep配置具体的混淆规则混淆规则中主要使用 class配置一般情况下不需要细致的具体的方法进行配置通过 class 的属性配置一般的通用规则即可。
针对 class元素的 classesmethodsfields 三个属性遵循以下表格的规则-代表被混淆*代表保留。
Value/Visibilitypublicprotectedfriendlyprivatenone----public*---protected**--friendly***-private****
例如当配置 classespublic 时所有 public class XXX 会保持原样其他类型的会被混淆当 classesprivate 时所有类名都会保留方法和字段也是类似的上面示例中 class classesnone methodsnone fieldsnone相当于类名、方法、字段全部被混淆都不被保留。
上面配置 include nameorg.example./ 时包名最后的 . 必须包含你还可以使用 ant 中的 * 和 ** 匹配单级或多级通过 ? 匹配单个字符。
class 可以配置很多个
class classesnone methodsnone fieldsnonepatternsetinclude nameorg.example./include nameorg.example.c.util.FileUtil//patternset
/class
class classesprivate methodsprivate fieldsprivatepatternsetinclude nameorg.example.c.//patternset
/class上面相当于两部分规则第一部分是完全混淆的代码第二部分是完全保留的代码当配置多块时patternset 部分配置的类不能重叠。上面部分配置中存在重叠的部分首先 org.example. 包含了 org.example.c. 和 org.example.c.util.FileUtil上面配置想法是把 org.example. 下面的代码都混淆把 org.example.c 下面的 FileUtil 混淆。但是不混淆 org.example.c.真正执行的结果是 org.example.c. 都没有被混淆如下图但是a和b被混淆了。 如果把上面两部分 class顺序调整一下结果还是一样虽然看了yGuard源码但是没找到明确的规则目前猜测是混淆低的优先级更高。如果把上面两个 class 的 patternset 调换所有代码都不会被混淆。
因此当你有多组配置时指定的范围要尽可能的小而且所有配置要互斥不能互相包含想要实现想要的效果需要按下面的方式进行配置
class classesnone methodsnone fieldsnonepatternsetinclude nameorg.example./include nameorg.example.c.util.FileUtil//patternset
/class
class classesprivate methodsprivate fieldsprivatepatternsetinclude nameorg.example.c./exclude nameorg.example.c.util.FileUtil//patternset
/class这里在优先级更高的规则中通过 exclude nameorg.example.c.util.FileUtil/ 进行了排除如果你的混淆配置更复杂优先级无法确定时上面的配置粒度仍然不够小应该把 include nameorg.example./ 变得更具体如下
class classesnone methodsnone fieldsnonepatternsetinclude nameorg.example.a./include nameorg.example.b./include nameorg.example.c.util.FileUtil//patternset
/class
class classesprivate methodsprivate fieldsprivatepatternsetinclude nameorg.example.c./exclude nameorg.example.c.util.FileUtil//patternset
/class当你遇到更难解决的情况时有可能是指定所有具体类的规则。
了解的 yGuard 这部分配置后接下来就可以进行多模块配置了多模块配置中也会提供一个示例项目方便跟着操作研究。