一步一坑定制Android虚拟机1·引子

背景

作为一名网络安全研究员,我深谙网络安全学习起来的不易。前些年自己一直都很懒,没能养成一个总结的好习惯。所以这次就趁着自己业余时间想要搞事情的前提下,把学习定制化Android内核和功能的这一过程弄成一个系列文章。

在我的学习过程中,我发现不管国内外,在互联网上提供的资料还是很有限的,而且每个人的理解都相对片面,而且也是重操作而轻理论,让人觉得云里雾里的。再加上编译器、内核源码、操作系统的不断更新,以及各种各样不同的需求,很多文章反而会起到一个误导的作用。因此笔者将会尽可能的把自己填过的坑在这个系列文章中详细记录下来,希望可以帮助能够看到这些文章的读者。

由于现在移动互联网的高速发展,很多和我们生活、娱乐、工作息息相关的事情也都搬到了手机这个平台中。作为开放、占有率最高的手机操作系统,Android平台上出现的应用层出不穷。而遗憾的是,通常手机是基于ARM处理器的,其能够执行的指令也为ARM指令集。这也就意味着通常意义上,常规的电脑端不能安装Android操作系统或者无法流畅运行装有该操作系统的虚拟机。

不过Android系统的开发人员很早都意识到了这个问题,并随之提出了Android x86的系统镜像,也就是说上面提到的那个问题随着Android x86的问世似乎已经得到了解决。可是事实并非如此,否则网上也不会涌出大量的Android虚拟机解决方案提供给广大手游用户。

现如今运行Android x86的方案通常有四种:

  • 使用VirtualBox或者VMware等虚拟化软件安装运行
  • 使用Google提供的AVD(Android Virtual Device)直接运行系统镜像
  • 安装到操作系统中
  • 使用Android x86适配的硬件设备,如部分手机和平板

可以看到这四种解决方案都不怎么友好。首先是Virtualbox等虚拟机软件,首先它们无法虚拟Android运行时需要的各种传感器,如GPS、距离、运动等,也无法对硬件进行很好的处理;其次如果在内核编译阶段不加入虚拟化模块,那么会直接对使用起来不友好,具体体现在鼠标独占、无法自定义DNS且无线网络模块无法使用等。其次是安装到操作系统,这个成本太高,而且不实用,也没有解决各种传感器问题。再说使用适配的硬件,那还不如直接买一个手机或使用ARM的平板来的方便。

所以如今似乎最靠谱的解决方案是谷歌官方提供的AVD,毕竟是官方的东西。它能够模拟各种传感器,而且运行起来速度非常快!但是安装AVD对普通用户还是不友好的,而且如果想要增加内核功能还是得修改内核,或者至少拥有一个内核的编译环境——这也就是本系列文章的由来。

我的需求:在保证兼容性的前提下,即不破坏谷歌官方提供的(其实是Intel提供的)Android x86模拟器对arm指令的仿真处理,增加一个虚拟音频的内核模块。

概念

所以终归还是要修改内核的,而修改内核的前提是先能够编译一个可用的内核。这里先熟悉几个概念:

  • Android源码:包含了Android Framework层的所有源代码和同内核层通信的HAL层的部分源代码。但是不包含Linux内核代码
  • Android x86源码:包含了Android x86整个项目组所有的代码,并且内置了很多预设的编译环境。
  • Goldfish:在Android仿真环境中使用的,能够虚拟的ARM指令处理的Linux内核,Android x86中的Linux内核源码由此而来。

注意:Intel提供的基于AVD的Android x86仿真镜像在Android 5.0以后取消了内核对模块的支持,所以如果要在仿真环境中开发调试内核驱动程序的话,建议选择5.0以下版本的系统。


环境准备

在笔者的实际测试中,某图像上传处理的软件EABI=ARMv7,lib目录下只有armv7的so,Android 6.0的镜像对于该APP不能支持,甚至在安装中就失败,对于其他EABI=ARMv7的APP则能够部分支持。而这些APP在Android 4.4中都能安装成功,但是部分不能运行。也就是Android x86中对于ARM指令的仿真处理还是存在盲区的(可能主要集中在图像处理这快,笔者当时只是初步测试,其中原理现在尚未弄明白,待清楚后补充)。

而现在很多APP已经要求最低的Android sdk API版本为17(Android 4.2)了,所以笔者不推荐使用Android 4.2以下的源码来修改和定制功能。因此,这里笔者就选择Android 4.4(API 19)版本作为定制内核的小目标。

因为笔者初始时在这方面也没有经验,理论上来讲反正都是要改内核,那么用最新版本的也没问题。而笔者的最初的考量是,即便修改内核出了什么幺蛾子,那么也可以用内核的编译环境直接编译模块来进行安装,同样能达到目的。抱着学习的态度,所以在一开始对于那些能够预见的坑能避免就尽量避免。

Android虚拟机Dalvik完整源码,宝贵资源,欢迎下载! This directory contains the Dalvik virtual machine and core class library, as well as related tools, libraries, and tests. A note about the licenses and header comments --------------------------------------------- Much of the code under this directory originally came from the Apache Harmony project, and as such contains the standard Apache header comment. Some of the code was written originally for the Android project, and as such contains the standard Android header comment. Some files contain code from both projects. In these cases, the header comment is a combination of the other two, and the portions of the code from Harmony are identified as indicated in the comment. Here is the combined header comment: /* * Copyright (C) The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * ---------- * * Portions of the code surrounded by "// BEGIN Harmony code" and * "// END Harmony code" are copyrighted and licensed separately, as * follows: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Native SH call bridge --------------------- Native SH call bridge is written by Shin-ichiro KAWASAKI and Contributed to Android by Hitachi, Ltd. and Renesas Solutions Corp.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值