Android逆向(三)修改资源文件

        前两篇博客总结了Android常用逆向工具的使用,掌握了逆向工具的基本使用后,我们可以做一些有趣的事情。例如:某一款app的背景是红色的,我们觉得不好看,那么我们可以在反编译后给它换成其他颜色的。例如:某一款app的某个字符串叫“hello world”,我们觉得不好听,那么我们可以修改为自己想要的内容,例如“hello android”。例如:某一款app的名字叫“123”,我们觉得不好听,可以给它改成“456”。再例如:某一款app的某个界面的图片我们不喜欢,我们甚至可以替换为自己的照片。这篇博客讲的就是,逆向后最基本的修改—修改资源文件。

        第一、获取一个用于逆向和修改的apk

        首先,我们得有一个用于逆向和修改的apk。修改资源是逆向后最基本的一种修改,因此,我们自己创建一个Android项目,用于接下来所有的逆向和修改。到后面,我们会通过一款app进行实战,先从最基础的开始。我们先创建一个用于修改的项目,命名为“MyReverseDemo”。

        很简单的一个布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorTest"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/btn_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/btn1_name"/>
    <TextView
        android:id="@+id/tv_1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:text="@string/tv_name"/>
    <Button
        android:id="@+id/btn_2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="20sp"
        android:text="@string/btn2_name"/>
    <ImageView
        android:id="@+id/img_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>

</LinearLayout>

        strings.xml文件:

<resources>
    <string name="app_name">mReverseDemo</string>
    <string name="btn1_name">按钮1</string>
    <string name="btn2_name">按钮2</string>
    <string name="tv_name">文本文本文本</string>
</resources>

        colors.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
    <color name="colorTest">#ff0f0f</color>
</resources>

        打包,编译成apk,安装到模拟器。在这里,不介绍如何打包和签名app,可自行百度“Android Studio如何打包apk”。我们运行一下,看一下效果,基本就是长这么个样子(很丑):

        第二、将我们自己创建的apk反编译

        打开Android Killer,将我们的apk拖进去,反编译。

        第三、修改apk的资源文件

        反编译后,我们找到布局文件,打开,如下所示。这跟我们的布局文件源代码基本是一样的。因此,接下来修改资源文件并不是太难的事情。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="vertical" android:background="@color/colorTest" android:layout_width="fill_parent" android:layout_height="fill_parent"
  xmlns:android="http://schemas.android.com/apk/res/android">
    <Button android:textSize="20.0sp" android:id="@id/btn_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btn1_name" />
    <TextView android:textSize="25.0sp" android:id="@id/tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_name" />
    <Button android:textSize="20.0sp" android:id="@id/btn_2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/btn2_name" />
    <ImageView android:id="@id/img_1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher" />
</LinearLayout>

        1、修改背景颜色:

        我们的apk,现在的背景颜色是很鲜艳的红色。我们想修改为其他颜色,如何修改?看一下上面我们反编译后的布局文件源码,里面有这么一句很熟悉代码:

android:background="@color/colorTest"

其实,这就是声明背景颜色的代码。我们去colors.xml中查一下colorTest的颜色值。打开后,我们发现这里有很多的颜色,为了方便查找,我们直接使用搜索功能,搜索关键字“colorTest”,定位到colorTest所在的位置,我们修改为:

<color name="colorTest">#ff444444</color>

        这里有一点需要注意,修改后,我们一定要保存现有的修改:

        然后,去Android里选择编译,编译完成后,点击log里面最后的apk路径,拿到新生成的apk:

        我们卸载原来的app,安装我们反编译和修改背景后的app,看一下效果。我们原有的鲜艳的背景,已经变成如下图的暗色背景。由于本人有点色弱,因此,就不说下面是个什么颜色了。总之,我们达到了我们的目的:把鲜艳的颜色,变成了如下图的暗色。

2、修改按钮上的文本

        按钮一上的文本是“按钮1”,我们不想叫它“按钮1”了,想给他换个名字“Button1”。我们仍然去查看反编译后的布局文件。发现有下面这么一句,这个跟我们在布局文件中去引用字符串其实是有一点不同的,没有“+”。

android:text="@string/btn1_name"

        我们尝试去搜索“btn1_name”,找到了btn1_name的值,如下所示。

        我们修改一下,把“按钮1”修改为“Button1”,并且保存。编译后,卸载原来的app,安装新的apk,运行效果如下:

        3、修改TextView的内容、字体大小以及颜色

        仍然是跟上面一样的操作,修改布局文件中的内容和字体大小:例如,我修改内容为“哈哈,你的apk被我反编译啦!”,字体大小为“30sp”,并且我把字体颜色给它改成其他颜色,例如自带的colorAccent。

        修改字符串的内容不是什么难事,跟我们修改Button的内容一样。修改字体大小,也不难,只需要修改25为30即可。而为原本没有指定颜色的TextView添加字体颜色,需要我们在TextView声明的最后手动添加一行代码(这跟我们写布局文件时是一样的),如下所示:

    <TextView android:textSize="30.0sp" android:id="@id/tv_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/tv_name" android:textColor="@color/colorAccent"/>
<string name="tv_name">哈哈,你的apk被我反编译啦!</string>

        一定记得保存所有的修改后,编译生成apk。卸载原来的,安装xinde apk,运行效果如下所示:

        4、修改图片

        在我们布局的最下面一层,有个图片,也就是app默认的图标。我觉得很难看,我想替换一个好看的图片。我们也是查看反编译后的布局文件,我们看到了这么一句代码:

android:src="@mipmap/ic_launcher"

       (1) 我们打开mipmap文件夹,点击右键,选择打开方式,打开文件路径:

        (2)复制粘贴一张新的图片到文件夹下,例如我的图片叫“qmusic”:

        (3)修改引用图片资源的代码:

android:src="@mipmap/qmusic"

        (4)保存代码,编译,卸载旧的apk,安装新的并且运行,如下图所示:

        5、修改app的名字

        (1)我们找到AndroidManifest.xml文件,如下:

<?xml version="1.0" encoding="utf-8" standalone="no"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="tudu.mreversedemo">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme">
        <activity android:name="tudu.mreversedemo.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

        其中,里面有这么一句熟悉的代码:

android:label="@string/app_name"

        (2)查找app_name字符串,找到后修改为“破解”:

        (3)保存,编译,卸载旧的apk,安装新的apk并查看,我们的app名字已经修改为“破解”:

  

        最后,总结一下,这篇博客我总结了反编译apk后如何修改资源文件,包括修改文字内容,字体大小和颜色、图片资源、应用名称等。这只是最基本的修改,不会涉及到原有的java代码的修改,比较简单。在后面的博客中,我会逐渐的总结如何修改逻辑代码,比起修改资源文件,会稍微复杂一些,敬请期待。

猜你喜欢

转载自blog.csdn.net/qq_21154101/article/details/88856889