[笔记] OS X and iOS 内核开发

一、KEXT包的安全性说明

  1. KEXT 程序包及其包含的所有文件及文件夹必须属于 root 用户(用户 id 是 0)
  2. KEXT 程序包及其包含的所有文件及文件夹必须属于 wheel 组(组 id 是 0)
  3. KEXT 程序包及其包含的所有文件夹的权限掩码必须是 0755 (rwxr-xr-x)
  4. KEXT 程序包中的所有文件的权限掩码必须是 0644 (rw-r--r--)

使用 xcode 编译内核扩展时,会设置出了用户与组以外的所有要求,我们只要通过如下命令来设置用户与组即可:

sudo chown -R root:wheel xxx.kext

需要注意的是,不要在 xcode 生成的内核扩展上直接修改,这样会造成 xcode 无法删除内核扩展,最好拷贝出来修改。

二、命令行实用程序

  1. kextload:加载内核扩展, sudo kextload xxx.kext
  2. kextunload:卸载内核扩展, sudo kextunload xxx.kext
  3. kextutil:加载内核扩展,并提供诊断信息,便于分析加载失败的原因
  4. kextstat:显示所有已加载的内核扩展
  5. ioreg:show I/O Kit registry,"man ioreg"
  6. ioclasscount:内核对象的内存管理是基于引用计数,该工具可以用来打印所有已加载的内核对象的引用计数个数,便于调试内存泄露

三、查看调试输出

实用 Console 程序查看内核扩展中输出的 Log

四、IORegistryExplorer

用来查看系统系统上已经加载的驱动程序。是 xcode 的附属工具,需要单独下载:hardware_io_tools_for_xcode

五、The Wheel Group

There is a special group in BSD called the wheel group.

Membership in the wheel group confers on users the ability to become the root user by using the su utility on the command line.

Users who are not in the wheel group can’t become the root user,

even if they have the correct password.

六、

原文地址:https://www.cnblogs.com/Proteas/p/3508091.html