V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
withlqs
V2EX  ›  问与答

修改 dex2oat 来执行外部程序,出现了一个奇怪的问题

  •  
  •   withlqs · 2017-02-13 17:46:45 +08:00 · 811 次点击
    这是一个创建于 2633 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我修改了AOSP/art/dex2oat.cc,来做到当 dex2oat 运行时,能够运行别的程序。部分代码段是这样的:

    int tester() {
      pid_t pid;
      int status;
      if ((pid = fork()) < 0) {
        status = -1;
      } else if (pid == 0) {
        execl("/system/xbin/busybox", "busybox", "wget", "www.google.com", "-O", "/cache/g.html", (char *) 0);
        _exit(127);
      } else {
        while (waitpid(pid, &status, 0) < 0) {
          if (errno != EINTR) {
            status = -1;
            break;
          }
        }
      }
      return status;
    }
    
    int main(int argc, char **argv) {
      int status = tester();
      return art::dex2oat(argc, argv);
    }
    

    当我安装一个 apk 的时候, pm 会自动调用dex2oat,并且上文中的tester函数会被调用。但是会返回256(转化成一个字节就是1,也就是返回的值是 1), 并且在 cache 目录下也找不到g.html

    但是,当我在 adb shell 中运行/system/bin/dex2oat时, wget就能被正常的调用, 并且返回0 ,同时,也能在 cache 目录下找到g.html。(看上去是一切正常的)

    SELinux 是 permissive 的, Android 版本是 5.1.1 。

    问题究竟出在哪?同时我也发在了 stackoverflow 上了,暂时还没有人解答: http://stackoverflow.com/questions/42200112/modify-aosp-art-dex2oat-cc-to-run-another-program-but-return-value-256

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2227 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 05:30 · PVG 13:30 · LAX 22:30 · JFK 01:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.