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>
複製代碼
而後在從新打包簽名,安裝效果圖以下: