首页
社区
课程
招聘
Nexus6P 7.1.2 内核编译修改 TracerPid
发表于: 2018-8-18 16:48 19682

Nexus6P 7.1.2 内核编译修改 TracerPid

2018-8-18 16:48
19682
参考网上文章,自己修改过程整理一下。

环境
    虚拟机:VMware Workstation Pro 14
    主机OS:Ubuntu16.04 LTS
    终端:Huawei Nexus6P 64G 国际版
    源码:Android N (版本N2G48C)

Ubuntu16.4 配置环境

    中科大的AOSP镜像
    AOSP官方教程——准备

下载源码

    首先下载 repo 工具:

# mkdir ~/bin
# PATH=~/bin:$PATH
# curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
// 如果上述 URL 不可访问,可以用下面的:
// curl -sSL  'https://gerrit-googlesource.proxy.ustclug.org/git-repo/+/master/repo?format=TEXT' |base64 -d > ~/bin/repo
# chmod a+x ~/bin/repo


    下载每月更新初始化包:

# wget https://mirrors.tuna.tsinghua.edu.cn/aosp-monthly/aosp-latest.tar  // 下载初始化包
# tar xf aosp-latest.tar  // 解压
# cd aosp   // 解压得到的 AOSP 工程目录
// 这时 ls 的话什么也看不到,因为只有一个隐藏的 .repo 目录

     初始化仓库(Android指定版本): 
# repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest
// 如果提示无法连接到 gerrit.googlesource.com,可以编辑 ~/bin/repo,把 REPO_URL 一行替换成下面的:
// REPO_URL = 'https://gerrit-googlesource.proxy.ustclug.org/git-repo'
// 如果需要指定版本
// N2G48C  android-7.1.2_r28
# repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-7.1.2_r28

     同步源码树(以后只需执行这条命令来同步):
# repo sync

    创建一个空目录来存放您的内核工作文件:
# mkdir WORKING_DIRECTORY
# cd WORKING_DIRECTORY

    使用git下载内核源码:
// 清华
# git clone https://aosp.tuna.tsinghua.edu.cn/android/kernel/msm.git
// 谷歌
# git clone https://android.googlesource.com/kernel/msm.git

# cd msm    //进入msm工程目录

    查看版本列表建议利用grep过滤自己需要内容
# git branch -a | grep angler

这么多版本怎么选择 可以直接查看 关于手机 内核版本 3.10.73-g5547b00553a 或者
# cat /proc/version
Linux version 3.10.73-g5547b00553a (android-build@vped9.mtv.corp.google.com) (gcc version 4.9.x-google 20140827 (prerelease) (GCC) ) #1 SMP PREEMPT Fri May 19 23:01:51 UTC 2017

    可以直接git同步分支
# git checkout 3.10.73-g5547b00553a
// 也可以选择这个版本 同步分支
# git checkout -b android-msm-angler-3.10-nougat-mr2 origin/android-msm-angler-3.10-nougat-mr2

修改内核代码, 使TracerPid始终为0

    

    要修改的文件涉及到两个

    msm/fs/proc/base.c    (278行)

static int proc_pid_wchan(struct task_struct *task, char *buffer)
{
    unsigned long wchan;
    char symname[KSYM_NAME_LEN];

    wchan = get_wchan(task);

    if (lookup_symbol_name(wchan, symname) < 0)
        if (!ptrace_may_access(task, PTRACE_MODE_READ))
            return 0;
        else
            return sprintf(buffer, "%lu", wchan);
     // else
               // return sprintf(buffer, "%s", symname);
    else
           {
       if (strstr(symname, "trace")) { 
            return sprintf(buffer, "%s", "sys_epoll_wait"); 
       } 
       return sprintf(buffer, "%s", symname); 
    }
}



    msm/fs/proc/array.c    (140行)
static const char * const task_state_array[] = {
	"R (running)",		/*   0 */
	"S (sleeping)",		/*   1 */
	"D (disk sleep)",	/*   2 */
	"T (stopped)",		/*   4 */
//	"t (tracing stop)", 	/*   8 */
	"S (sleeping)",		/*   8 */
	"Z (zombie)",		/*  16 */
	"X (dead)",		/*  32 */
	"x (dead)",		/*  64 */
	"K (wakekill)",		/* 128 */
	"W (waking)",		/* 256 */
	"P (parked)",		/* 512 */
};



    msm/fs/proc/array.c    (195行)
seq_printf(m,
		"State:\t%s\n"
		"Tgid:\t%d\n"
		"Pid:\t%d\n"
		"PPid:\t%d\n"
		"TracerPid:\t%d\n"
		"Uid:\t%d\t%d\t%d\t%d\n"
		"Gid:\t%d\t%d\t%d\t%d\n",
		get_task_state(p),
		leader ? task_pid_nr_ns(leader, ns) : 0,
		pid_nr_ns(pid, ns),
		ppid,/*tpid*/0,


编译内核
    修改完成后开始编译内核

// 将工具集加入到路径中
# export PATH=$PATH:~/aosp/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/bin
// 设置目标架构
# export ARCH=arm64
// 设置编联合编译方式,不要漏了最后边的“-”
# CROSS_COMPILE=aarch64-linux-android-
// 编译
# make angler_defconfig
# make



    编译过程中出现问题


// 换
# ARCH=arm64 CROSS_COMPILE=aarch64-linux-android- make

    内核编译完成后
    编译成功后内核镜像就存放在./arch/arm64/boot/目录下。

// 进入Android 源码目录
# cd ~/asop/
// 设置刚刚编译完成 Image.gz-dtb 文件变量
# export TARGET_PREBUILT_KERNEL=~/aosp/k/msm/arch/arm64/boot/Image.gz-dtb
# . build/envsetup.sh
# lunch <angler>



// 开始编译内核
# make bootimage



这样就编译内核编译完成。
文件输出在 out/target/product/angler/boot.img

刷机
// 手机进入fastboot模式
# fastboot.exe flash boot boot.img


完成后内存版本显示

测试


到这里就结束了。



[课程]Linux pwn 探索篇!

最后于 2018-8-18 16:50 被小琦编辑 ,原因:
收藏
免费 2
支持
分享
打赏 + 2.00雪花
打赏次数 1 雪花 + 2.00
 
赞赏  junkboy   +2.00 2018/08/18
最新回复 (7)
雪    币: 11716
活跃值: (133)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
支持                
2018-8-18 16:55
0
雪    币: 1694
活跃值: (253)
能力值: ( LV8,RANK:130 )
在线值:
发帖
回帖
粉丝
3
不错,正好打算搞个调试机
2018-8-22 17:54
0
雪    币: 2166
活跃值: (11)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
不知道能否修改源码,允许ptrace第二次。。
最后于 2018-8-22 20:26 被lofrank编辑 ,原因:
2018-8-22 20:23
0
雪    币: 30
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
5
编译后。刷入开机不了一直卡在 Google 什么原因
2019-8-26 18:53
0
雪    币: 574
活跃值: (364)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
mark
2019-8-27 09:46
0
雪    币: 758
活跃值: (78)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
2020-4-17 16:17
0
雪    币: 112
活跃值: (408)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
ma
2021-12-1 14:41
0
游客
登录 | 注册 方可回帖
返回
//