修改dalvik虚拟机源码加载自定义BOOTCLASSPATH

修改dalvik虚拟机源码加载自定义BOOTCLASSPATH


for 代码插桩框架 或 xposed框架
在android5.0之前,使用dalvik虚拟机,之后换成了art虚拟机,这个方法对新的系统可能不好用了,作为一种思路仅供参考。

原因

在android4.x的时代,流行刷机和第三方ROM,比如MIUI、乐蛙、百度等等。
ROM的制作者要在ROM中集成Xposed或者加载MIUI的Framework,必须修改Boot分区的ramdisk/init.environ.rc来加载额外的BOOTCLASSPATH,例如添加:

/data/app/com.miui.sdk-1.apk
/data/app/com.miui.sdk-2.apk
/system/app/miui.apk
/data/app/com.miui.framework-1.apk
/data/app/com.miui.framework-2.apk
/system/app/MiuiFramework.apk

但有些手机因为BL锁的原因,就是不能改boot分区。
为了绕开这个限制,直接修改libdvm.so源码,自定义BOOTCLASSPATH变量,最终实现修改目的。

修改方法

  1. 一般手机商不会去修改虚拟机的底层代码,所以只要找到对应的android大版本源码来修改编译替换就可以了。
  2. 在dalvik初始化读取BOOTCLASSPATH变量后,插入自己要添加的class路径
  3. 源码路径dalvik/vm/Init.cpp,修改setCommandLineDefaults函数
static void setCommandLineDefaults()
{
    const char* envStr = getenv("CLASSPATH");
    if (envStr != NULL) {
        gDvm.classPathStr = strdup(envStr);
    } else {
        gDvm.classPathStr = strdup(".");
    }
    envStr = getenv("BOOTCLASSPATH");

    //add by benjaminwan
    if (envStr != NULL) {
    const char* stockenv = getenv("BOOTCLASSPATH");
    //ALOGW("BJW Stock BOOTCLASSPATH = %s",stockenv);
    const char* myaddclass = ":/data/app/com.miui.sdk-1.apk:/data/app/com.miui.sdk-2.apk:/system/app/miui.apk:/data/app/com.miui.framework-1.apk:/data/app/com.miui.framework-2.apk:/system/app/MiuiFramework.apk";
    int len=strlen(stockenv)+strlen(myaddclass)+1;
    char* result=(char *)malloc(len);
    snprintf(result, len, "%s%s", stockenv, myaddclass);
    envStr = result;
    //ALOGW("BJW OEM BOOTCLASSPATH = %s",envStr);
    }
    //add by benjaminwan

    if (envStr != NULL) {
        gDvm.bootClassPathStr = strdup(envStr);
    } else {
        gDvm.bootClassPathStr = strdup(".");
    }

修改效果图

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
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、付费专栏及课程。

余额充值