首页 > 其他分享 >Android 代码混淆proguard技术介绍

Android 代码混淆proguard技术介绍

时间:2023-05-19 12:32:48浏览次数:34  
标签:混淆 properties public proguard file Android class android


由于各种反编译工具的泛滥,作为Android程序员在2.3版本以前只能通过手动添加proguard来实现代码混淆

proguard这个工具是一个java代码混淆的工具

在2.3版本的sdk中 我们可以看到在android-sdk-windows/tools/下面多了一个proguard文件夹
google已经把proguard技术放在了android sdk里面 可以通过正常的编译方式也能实现代码混淆了
[img]http://dl2.iteye.com/upload/attachment/0091/0331/0d3bd7d7-cab5-30c4-b902-0daad7a5eb9d.gif[/img]
可以看见新建一个工程里面有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 public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class com.android.vending.licensing.ILicensingService
-keepclasseswithmembernames class * {
    native <methods>;
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembernames class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}


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



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



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


[quote]To enable ProGuard so that it runs as part of an Ant or Eclipse build, set the proguard.config property in the <project_root>/default.properties file. The path can be an absolute path or a path relative to the project's root.[/quote]


所以我们修改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即可


[img]http://dl2.iteye.com/upload/attachment/0091/0333/3eb8d8f9-507c-343a-9994-579bc337b4bb.gif[/img]


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


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


[img]http://dl2.iteye.com/upload/attachment/0091/0335/c09065b0-39b7-3d4b-8bbd-fa688379ce3a.gif[/img]


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


标签:混淆,properties,public,proguard,file,Android,class,android
From: https://blog.51cto.com/u_15955464/6310232

相关文章

  • Android Fragment完全解析,关于碎片你所需知道的一切
    我们都知道,Android上的界面展示都是通过Activity实现的,Activity实在是太常用了,我相信大家都已经非常熟悉了,这里就不再赘述。但是Activity也有它的局限性,同样的界面在手机上显示可能很好看,在平板上就未必了,因为平板的屏幕非常大,手机的界面放在平板上可能会有......
  • Android系统联系人全特效实现(下),字母表快速滚动
    其实ListView本身是有一个快速滚动属性的,可以通过在XML中设置android:fastScrollEnabled="true"来启用。包括以前老版本的Android联系人中都是使用这种方式来进行快速滚动的。效果如下图所示:[img]http://dl2.iteye.com/upload/attachment/0088/8223/48aec4c5......
  • Android 百度地图GPS获取定位经纬度
    首先进入百度地图官网,点击开发文档-->Android定位SDK-->获取密匙,进入应用创建界面,创建新的应用。准备好后,在“产品下载”栏目下载Android定位的包,将其打包放入项目中的libs文件目录。之后就需要在AndroidManifest.xml中添加APK,在Application标签中添加:<meta-dataand......
  • android vulkan
    VulkanAPIversionsandcapabilitiesThefollowingtablelistsVulkanAPIversionsforseveralAndroidreleases.AndroidVersionVulkanVersionAndroid13Vulkan1.3Android9Vulkan1.1Android7Vulkan1.0Vulkan1.3FunctionalityOverviewV......
  • Android 动态改变 navigation 的 startDestination, 使得已登录的用户直接跳过 LoginF
    需求:未登录用户打开App,会展示登录页面LoginFragment已登录用户打开App,直接展示MainFragmentnav_graph.xml结构如下:MainActivity.java:@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);......
  • 用这些C#代码混淆器保护你的代码安全
    最近有群友问,怎么保护发布的C#代码不被别人反编译,这就需要C#代码混淆组件。C#是一种强大的编程语言,可以用于开发各种类型的应用程序,包括桌面应用程序、Web应用程序和移动应用程序等。但是,由于C#程序易于反编译,使得代码的安全性和保护性受到了威胁。为了保护C#代码,开发人员可以使用......
  • 如何将抓包工具证书(cer,crt, pem)写入到Android系统内置根证书目录中实现 HTTPS 抓包
    0x01前言:在Android6之前,手机系统既信任系统内置的证书,也信任用户自己安装的证书,但是在Android7之后,却发生了变化,手机系统只信任系统内置的根证书。当然了,这是为了手机系统更安全,但是这样一来,我们就无法使用burpsuite,charles,fidder抓包app的HTTPS请......
  • 直播商城源码,Android实现监听Settings值变化的功能
    直播商城源码,Android实现监听Settings值变化的功能先创建一个内部类继承自ContentObserver   classSettingsContentObserverextendsContentObserver{    publicSettingsContentObserver(){      super(newHandler());    }    ......
  • 直播软件开发,Android实现根据进程名杀死特定进程
    直播软件开发,Android实现根据进程名杀死特定进程首先你实现功能的进程必须是系统进程,在AndroidManifest里面加入如下标签。 android:sharedUserId="android.uid.system"​调用ActivityManager的forceStopPackageAsUser方法 ActivityManagermActivityManager=(Activity......
  • Android 获取 USB设备列表
    获取usb列表UsbManagerusbManager=(UsbManager)getSystemService(Context.USB_SERVICE);intsize=usbManager.getDeviceList().size();HashMap<String,UsbDevice>deviceList=usbManager.getDeviceList();for(Map.Entry<String,Us......