android因为平台的缘由,未经加固的app是比较容易反编译进行二次打包,好比加入广告、植入木马、去掉开发者加入的一些商业化的东西等等,这就致使了市面上出现了各类apk的破解版或者纯净版,做为开发者,固然不但愿本身的app脱离控制,这就有了所谓的app加固,正所谓知己知彼,百战不殆。要想知道如何受,啊呸是守,咱们应该先要知道如何攻,攻主要分三步:反编译、修改代码或者资源文件、二次打包,下面以测试demo为例,一步步演示。 先运行下demo,demo的名称叫测试Demo,只是简单的显示了下Hello World! 以下图:java
工欲善其事必先利其器,准备的工具以下:apktool.jar、apktool.bat。官网地址:ibotpeaches.github.io/Apktool/android
将上面的文件以及测试demo的apk放在同一文件夹下面,cmd到文件夹下执行以下命令:git
apktool d com.lsj.decompile_v.1.0.apk,执行过程以下图:github
咱们首先修改资源文件试下,经过查看AndroidManifest.xm以下:bash
<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" android:compileSdkVersion="28" android:compileSdkVersionCodename="9" package="com.lsj.decompile" platformBuildVersionCode="1" platformBuildVersionName="1.0">
<application android:allowBackup="true" android:appComponentFactory="android.support.v4.app.CoreComponentFactory" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:name="android.support.multidex.MultiDexApplication" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
<activity android:name="decompile.lsj.com.decompile.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
复制代码
咱们知道app的的名称是@string/app_name,接下来咱们先尝试把app的名称改掉,分别在上面反编译产生的文件夹里面找到对应的资源进行修改,好比咱们找到app_name这个字符串,改为“反编译测试Demo”。app
执行以下命令ide
apktool b com.lsj.decompile_v.1.0 -o demofake.apk,执行过程以下图:工具
啥子都没有,这个咋整?根据咱们的经验既然layout通常和Activity有必定的关联,咱们直接去layout文件夹里面找,找到activity_main.xml,打开:布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
复制代码
看到只有一个TextView,而且内容是“Hello World!”,应该就是它,接下来咱们作一个操做,在这个TextView上面盖上另外一个TextView,显示这是一个广告,修改以下以下:测试
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="这是一个广告"
android:background="#ffff00"
android:gravity="center"/>
</android.support.constraint.ConstraintLayout>
复制代码
而后在从新打包签名,安装效果图以下: