android程序反编译与二次打包

前言

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

注意路劲不要有中文不然会执行失败。执行成功以后能够看到在文件夹下生成了与apk同名的文件夹,打开能够看到目录结构以下:
是否是很熟悉?是的这里面和咱们android代码结果相似,只是java源码看不到,以另一种形式smali的形式存在,这个下面再说。到这里反编译结束。

篡改

咱们首先修改资源文件试下,经过查看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,执行过程以下图:工具

能够看到在当前文件夹下面生成了 demofake.apk,咱们看看能不能正常使用,结果悲剧了,忘了签名,效果以下:

签名以后把原来的卸载从新安装,效果如图:

接下来咱们继续搞事情,尝试串改布局文件,加上本身的内容。,一样经过查看AndroidManifest.xml,咱们知道当贝市场的入口activity是decompile.lsj.com.decompile.MainActivity,这个时候咱们就要祭出咱们的另外一个法宝Smali2Java,这个工具不但支持带个smali文件装成java代码,还支持将apk转换为java代码,咱们用Smali2Java打开测试demo apk,找到MainActivity,以下图:

啥子都没有,这个咋整?根据咱们的经验既然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>
复制代码

而后在从新打包签名,安装效果图以下:

证实是有效果的。
相关文章
相关标签/搜索