Android 逆向】Android 进程注入工具开发 ( 系统调用 | Android NDK 中的系统调用示例 )

网友投稿 711 2022-05-28

文章目录

一、系统调用

二、Android NDK 中的系统调用示例

一、系统调用

在 " 用户层 " , 运行的都是用户应用程序 ;

用户层 下面 是 驱动层 , 驱动层 下面是 系统层 , 最底层是 BIOS ; 系统层 包含 系统内核 ;

层级从上到下 : 用户层 | 驱动层 | 系统层 | BIOS ;

上述 4 4 4 层之间 , 不可以直接跨越 , 应用想要读取 驱动 / 内核 的数据是不被允许的 , 强行访问会导致崩溃 ;

应用的功能 需要借助 驱动实现 , 如文件读写 , 肯定要借助 硬盘驱动 实现 文件 在硬盘上的读写操作 ;

使用 " 软中断 " 实现跨层访问 , 软中断是由软件发起的 , 不是由错误导致 ;

调用 read 方法 , 读取文件 , 触发了软中断 , 以 arm 为例 , 执行 SVC 指令 , 参数 0 , 在 R0 中可以设置另外的参数 , 该 R0 参数指定调用什么功能 ;

整个应用进程的控制权此时就交给了 驱动层 / 系统层 , 在这些底层具体执行了哪些操作 , 应用层是不知道的 ;

arm 架构的 CPU 中软中断指令是 SVC ;

x86 架构的 CPU 中软中断指令是 int ;

与 软中断 相对应的是 硬中断 ; 硬中断 是由 硬件产生 ;

二、Android NDK 中的系统调用示例

系统调用相关的头文件定义在 D:\Microsoft\AndroidNDK64\android-ndk-r16b\sysroot\usr\include\asm-generic\unistd.h 文件中 ; 在该文件中定义了所有的系统调用 ;

#include #ifndef __SYSCALL #define __SYSCALL(x,y) #endif #if __BITS_PER_LONG == 32 || defined(__SYSCALL_COMPAT) #define __SC_3264(_nr,_32,_64) __SYSCALL(_nr, _32) #else #define __SC_3264(_nr,_32,_64) __SYSCALL(_nr, _64) #endif #ifdef __SYSCALL_COMPAT #define __SC_COMP(_nr,_sys,_comp) __SYSCALL(_nr, _comp) #define __SC_COMP_3264(_nr,_32,_64,_comp) __SYSCALL(_nr, _comp) #else #define __SC_COMP(_nr,_sys,_comp) __SYSCALL(_nr, _sys) #define __SC_COMP_3264(_nr,_32,_64,_comp) __SC_3264(_nr, _32, _64) #endif #define __NR_io_setup 0 #define __NR_io_destroy 1 #define __NR_io_submit 2 #define __NR_io_cancel 3 #define __NR_io_getevents 4 #define __NR_setxattr 5 #define __NR_lsetxattr 6 #define __NR_fsetxattr 7 #define __NR_getxattr 8 #define __NR_lgetxattr 9 #define __NR_fgetxattr 10 #define __NR_listxattr 11 #define __NR_llistxattr 12 #define __NR_flistxattr 13 #define __NR_removexattr 14 #define __NR_lremovexattr 15 #define __NR_fremovexattr 16 #define __NR_getcwd 17 #define __NR_lookup_dcookie 18 #define __NR_eventfd2 19 #define __NR_epoll_create1 20

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

以 #define __NR_getuid 174 系统调用为例 , 174 对应的 16 进制数为 0xAE ;

进行软中断时 , 执行如下汇编执指令时 ,

MOV R0, 0xAE SVC 0

【Android 逆向】Android 进程注入工具开发 ( 系统调用 | Android NDK 中的系统调用示例 )

1

2

会自动执行 #define __NR_getuid 174 对应的系统调用 ;

Android 任务调度

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:能让你的Intellij IDEA 起飞的几个设置(设置背景 字体 快捷键 鼠标悬停提示 提示忽略大小写 取消单行显示)
下一篇:鲲鹏云服务器安装puppeteer
相关文章