代码混淆技术android,Android 源码混淆技术初试; 混淆内部类

在使用keep 保留混淆模块的时候,如果预计activity里面的内部类需要这样去keep:

-keep public class

com.xx.XXXOuterClassActivity$* {

*;

}

下方的方式只能对一个文件进行混淆,如果需要批量处理的话,例如打各个渠道包的混淆apk,那么就要使用ant 或maven了;

转自:http://blog.csdn.net/Zengyangtech/article/details/6127600

a4c26d1e5885305701be709a3d33442f.png

可以看见新建一个工程里面有default.properties和proguard.cfg

默认的default.properties代码如下

# This file is automatically generated by Android Tools.

# Do not modify this file -- YOUR CHANGES WILL BE ERASED!

#

# This file must be checked in Version Control Systems.

#

# To customize properties used by the Ant build system use,

# "build.properties", and override values to adapt the script to your

# project structure.

# Project target.

target=android-9

我们可以看到proguard.cfg已经帮我们写好了优化代码脚本

-optimizationpasses 5

-dontusemixedcaseclassnames

-dontskipnonpubliclibraryclasses

-dontpreverify

-verbose

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-keep publicclass* extends android.app.Activity

-keep publicclass* extends android.app.Application

-keep publicclass* extends android.app.Service

-keep publicclass* extends android.content.BroadcastReceiver

-keep publicclass* extends android.content.ContentProvider

-keep publicclasscom.android.vending.licensing.ILicensingService

-keepclasseswithmembernames class* {

native ;

}

-keepclasseswithmembernames class* {

public(android.content.Context, android.util.AttributeSet);

}

-keepclasseswithmembernames class* {

public(android.content.Context, android.util.AttributeSet,int);

}

-keepclassmembers enum* {

publicstatic**[] values();

publicstatic** valueOf(java.lang.String);

}

-keep class* implements android.os.Parcelable {

publicstaticfinal android.os.Parcelable$Creator *;

}

从脚本中可以看到,混淆中保留了继承自Activity、Service、Application、BroadcastReceiver、ContentProvider等基本组件以及com.android.vending.licensing.ILicensingService

并保留了所有的Native变量名及类名,所有类中部分以设定了固定参数格式的构造函数,枚举等等。(详细信息请参考/examples中的例子及注释。)

接下来 按照google帮助文档里说的

To enable ProGuard so that it runsaspart of an Ant or Eclipse build,setthe proguard.config propertyinthe /default.properties file. The path can be an absolute path or a path relative to the project's root.

所以我们修改default.properties file

加上一句

proguard.config=proguard.cfg

如下

# This file is automatically generated by Android Tools.

# Do not modify this file -- YOUR CHANGES WILL BE ERASED!

#

# This file must be checked in Version Control Systems.

#

# To customize properties used by the Ant build system use,

# "build.properties", and override values to adapt the script to your

# project structure.

# Project target.

target=android-9

proguard.config=proguard.cfg

然后正常的编译签名即可

然后用Android Tools生成一个发布的apk即可

a4c26d1e5885305701be709a3d33442f.png

然后用反编译工具查看dex文件

最后导出反编译之后的混淆代码如下图

a4c26d1e5885305701be709a3d33442f.png

是不是很轻松加愉快!希望各位程序员都能保护好自己的Android代码!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值