Proguard 混淆之乱谈 2

2023-10-13 15:10
文章标签 混淆 proguard 之乱

本文主要是介绍Proguard 混淆之乱谈 2,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

之前说了产品不进行安全措施的后果,没看的童鞋可以看下。

《Proguard 混淆之乱谈1》

接下来欢迎Proguard闪亮登场!

1.什么是Proguard?

 

ProGuard is a Java class file shrinker, optimizer, obfuscator, and preverifier. The shrinking step detects and removes unused classes, fields, methods and attributes. The optimization step analyzes and optimizes the bytecode of the methods. The obfuscation step renames the remaining classes, fields, and methods using short meaningless names. These first steps make the code base smaller, more efficient, and harder to reverse-engineer. The final preverification step adds preverification information to the classes, which is required for Java Micro Edition and for Java 6 and higher.

Each of these steps is optional. For instance, ProGuard can also be used to just list dead code in an application, or to preverify class files for efficient use in Java 6.

Proguard是用来对java文件进行压缩,优化,混淆和预校验的工具,压缩阶段检测并移除没有用的class,field,method,attribute,优化阶段分析并优化字节编码,混淆阶段用较短的名称重命名剩下的class,field,method,第一阶段可以使代码量更少,更有效,也更难被反编译,最后阶段是预校验,在上面三完成后,JVM,Java6或者更高版本运行前进行校验。

注意:每步都是可选的,并不是说1234挨个要都执行,你可以选择你需要的使用,下面插入来自官网的各阶段图,证明咱是一本正经的在胡谈,不是乱说。

2.Proguard如何工作的?

首先在介绍Proguard如何工作前,先了解下EntryPoint,这是认识Proguard工作的基本,不会爬就想飞,小心摔得疼呀。

照例,我们看看官方是怎么说的,咱好对应胡谈。

 

In order to determine which code has to be preserved and which code can be discarded or obfuscated, you have to specify one or more entry points to your code. These entry points are typically classes with main methods, applets, midlets, activities, etc.In the shrinking step, ProGuard starts from these seeds and recursively determines which classes and class members  are used. All other classes and class members are discarded.The preverification step is the only step that doesn't have to know the entry points.In the optimization step, ProGuard further optimizes the code. Among other optimizations, classes and methods that are not entry points can be made private, static, or final, unused parameters can be removed, and some methods may be inlined.In the obfuscation step, ProGuard renames classes and class members that are not entry points. In this entire process, keeping the entry points ensures that they can still be accessed by their original names.

看,官方老爷说了,entrypoint就是为了标记哪些code在各个阶段是否要做哪个操作。压缩阶段,ProGuard会从上述的EntryPoint中开始遍历搜索出哪些类和类的成员在使用(虽然标记了,但不代表会被用到,切记!),对于那些没有被使用的类和成员,就会在此阶段阶段被丢弃。优化阶段,没有被标记的的类和方法都会被设置为private,static或者final,而且不使用的参数都会被移除。混淆阶段,ProGuard对没标记的类和方法进行重命名。预校验阶段,对代码进行预检测,以便保证稳定性。

 

3.Proguard 使用语法

官方文档在这里,可以查看,接下来对其中部分做下介绍

3.1 Input/Output Options

@filename
-inlude filename
从filename文件中读取配置信息
-basedirectory 基本路径,之后可以作为相对路径根路径使用
-injars,-outjars 输入输出包
-libraryjars 作为库文件处理不会在outjar中包含
-skipnonpubliclibraryclasses    指定忽略非公共的库类。 
-dontskipnonpubliclibraryclasses    指定不去忽略非公共的库类。 
-dontskipnonpubliclibraryclassmembers    指定不去忽略包非公共的库类的成员。 
-keepdirectories  保留outjar中的路径,可能导致资源获取异常
-target
-version

-keepprocessing

3.2 Keep Options

-keep {Modifier} {class_specification} 保护指定的类文件和类的成员

-keepclassmembers {modifier} {class_specification} 保护指定类的成员,如果此类受到保护他们会保护的更好
-keepclassmembernames {class_specification} 保护指定的类的成员的名称(如果他们不会压缩步骤中删除)
-printseeds {filename} 列出类和类的成员-keep选项的清单,标准输出到给定的文件

-keepclasseswithmembers {class_specification} 保护指定的类和类的成员,但条件是所有指定的类和类成员是要存在。

-keepnames {class_specification} 保护指定的类和类的成员的名称(如果他们不会压缩步骤中删除)

-keepclasseswithmembernames {class_specification} 保护指定的类和类的成员的名称,如果所有指定的类成员出席(在压缩步骤之后)

 

 

 

 

 

  • 3.3 Shrinking Options

 

 

  •  -dontshrink 不压缩输入的类文件
  •  -printusage {filename} 输出未被压缩的文件列表到usage.txt中
  •  -whyareyoukeeping {class_specification} 打印为何保留指定class的原因

 

 

  • 3.4 Optimization Options

-dontoptimize 不优化输入的类文件

-optimizations 高手使用,进行部分优化

-assumenosideeffects {class_specification} 优化时假设指定的方法,没有任何副作用

-allowaccessmodification 优化时允许访问并修改有修饰符的类和类的成员

-mergeinterfaceaggressively

 

 

  • 3.5 Obfuscation Options

 

 

  •    -dontobfuscate 不混淆输入的类文件
  • -printmapping 输出映射关系
  • -applymapping 复用映射关系表
  • -obfuscationdictionary {filename} 使用给定文件中的关键字作为要混淆方法的名称
  • -classofuscationdictionary {filename}使用给定文件中的关键字作为要混淆类的名称
  • -packageofuscationdictionary {filename}使用给定文件中的关键字作为要混淆包的名称
  • -overloadaggressively 混淆时应用侵入式重载
  • -useuniqueclassmembernames 确定统一的混淆类的成员名称来增加混淆
  • -keeppackagenames 保留包名
  • -flattenpackagehierarchy {package_name} 重新包装所有重命名的包并放在给定的单一包中
  • -repackageclass {package_name} 重新包装所有重命名的类文件中放在给定的单一包中
  • -dontusemixedcaseclassnames 混淆时不会产生形形色色的类名
  • -keepattributes {attribute_name,...} 保护给定的可选属性,例如LineNumberTable, LocalVariableTable, SourceFile, Deprecated, Synthetic, Signature, and InnerClasses.
  • -keepparameters 保留方法的参数名称和类型
  • -renamesourcefileattribute {string} 设置源文件中给定的字符串常量
  • -adaptclassstring
  • -adaptresourcesfilenames
  • -adaptresourcefilecontents

 

 

  •  

 

  • 3.6 Preverification Options

 

 

  • -dontpreverify 不进行预校验
  • -microedtion

 

 

 

  • 3.7 General Options

 

 

  • -verbose
  • -dontwarn 不警告
  • -dontnote 不提醒可能存在的错误
  • -ignorewarning 忽略warning
  • -printconfiguration 打印配置信息
  • -dump 输出文件结构

 

 

 

  • 3.8 Class Paths

 

 

  • 路径,可以加过滤条件

 

 

 

  • 3.9 File Names

 

 

  • 可带上相对路径或者绝对路径

 

 

 

  • 3.10 File Filters

 

?matches any single character in a file name.
*matches any part of a filename not containing the directory separator.
**matches any part of a filename, possibly containing any number of directory separators.

 

 

  • 3.11 Filters

 

 

  • 同上

 

 

 

  • 3.12 Keep Option Modifiers

 

 

  • -includdescriptorclass 输出文件包括描述类
  • -allowshrunk
  • -allowoptimization
  • -allowobfuscation

 

 

 

  • 3.13 Class Specifications
  •  

这篇关于Proguard 混淆之乱谈 2的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/204066

相关文章

LLVM IR指令VM混淆分析

未混淆编译  编写一个最简单的测试代码,对 test_add函数用于对两个数相加: int __attribute((__annotate__("vm"))) test_add(int a, int b) {int c = a + b;return c;}int main(void) {int c = test_add(1, 2);return c;} 编译成中间代码:  未加

有关混淆的问题解决

第一部分:(对齐) 简单优化:Zipalign Android SDK中包含一个“zipalign”的工具,它能够对打包的应用程序进行优化。在你的应用程序上运行zipalign,使得在运行时Android与应用程序间的交互更加有效率。因此,这种方式能够让应用程序和整个系统运行得更快。我们强烈推荐在新的和已经发布的程序上使用zipalign工具来得到优化后的版本——即使你的程序是在老版本的A

js混淆保护在线工具开源项目大全

具体前往:js代码混淆加密保护工具&开源项目大全

Android编程之解决android-support-v4打包混淆编译的问题

转载自:http://blog.csdn.net/a348163124/article/details/19545909 如果工程引入了android-support-v4的jar类库,那么在工程打包混淆时,就会出现报错提示。例如提示你:You may need to specify additional library jars (using ‘-libraryjars’)。 这里先给出解决

Android App代码混淆解决方案

转载自:http://blog.csdn.net/u013718120/article/details/51777242 App虽然没有那么的高大上,但是代码的混淆是代表了程序员对App的责任心, 也是对App安全的一点点保证。今天我会将自己做Android混淆的过程和体会分享给大家,也避免大家少走弯路,少跳坑。 本篇博客混淆基于Android Studio的IDE开发环境。 其实在Andr

ambari与hortonworks、apache易混淆关系

百度百科上ambari写的是apache的,并在网页后面附上了apache官网url,但是hortonworks官网上也挂着个ambari,初学者容易混淆;其实两者是差不多的,据我观察: apache ambari是原始版本,发行的最新版本会高于hortonworks官网里面的最新发行版本; 但ambari2.7.1.0在hortonworks官网中已经有Ubuntu18的安装教程了,而apa

proguaid 混淆代码

注意:这里有一个坑。就是-ignorewarnings 他老是混淆不了,告诉你不行。其实加上这句话,就可以了。 下面贴一下代码: -injars c:/ceb_lib.jar-outjars c:/proguard_out.jar-optimizationpasses 5-dontusemixedcaseclassnames-dontskipnonpubliclibrarycla

混淆导致Crash

崩溃log Caused by: java.lang.NoSuchFieldError: no "J" field "peer" in class "Lnet/sourceforge/zbar/ImageScanner;" or its superclassesat net.sourceforge.zbar.ImageScanner.init(Native Method)2020-0

minifyEnabled属性 和ProGuard配置文件

在Android的build.gradle文件中,release配置块主要用于配置应用程序的发布版本。你提供的两个release配置块中,主要区别在于minifyEnabled的值和使用的ProGuard配置文件。 1. minifyEnabled属性 minifyEnabled false: 当minifyEnabled设置为false时,代码压缩和混淆不会被启用。这意味着在构建发布版本时

代码混淆总结

#指定代码的压缩级别     -optimizationpasses 5          #包明不混合大小写     -dontusemixedcaseclassnames          #不去忽略非公共的库类     -dontskipnonpubliclibraryclasses          # 指定不去忽略包可见的库类的成员    -don