例如:

#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <linux/user.h> /* For constants
ORIG_EAX etc */
int main()
{ pid_t child;
long orig_eax;
child = fork();
if(child == ) {
ptrace(PTRACE_TRACEME, , NULL, NULL);
execl("/bin/ls", "ls", NULL);
}
else {
wait(NULL);
orig_eax = ptrace(PTRACE_PEEKUSER,
child, * ORIG_EAX,
NULL);
printf("The child made a "
"system call %ld\n", orig_eax);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return ;
}

在linux的某些版本是运行不了,报错:找不到某个头文件或者某个宏。(上面的代码是基于i386,我试过了好几个linux的版本,还是运行出问题)

最后发现问题了。解决如下:

linux如何查找一个宏或者函数定义的位置:

以宏定义ORIG_EAX为例:

在终端输入

第一种方法:

find /usr/include/ -name *.h | xargs grep 'ORIG_EAX'

结果:

/usr/include/i386-linux-gnu/asm/ptrace-abi.h:#define ORIG_EAX 11

/usr/include/i386-linux-gnu/sys/reg.h:# define ORIG_EAX 

第二种方法:

grep -nr ORIG_EAX /usr/include/

这种方法可以知道在第几行定义宏

结果:

/usr/include/i386-linux-gnu/asm/ptrace-abi.h::#define ORIG_EAX 11

/usr/include/i386-linux-gnu/sys/reg.h::# define ORIG_EAX 
最后修改后,成功运行:
#include <stdio.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/reg.h> /* For constants
ORIG_EAX etc */
int main()
{ pid_t child;
long orig_eax;
child = fork();
if(child == ) {
ptrace(PTRACE_TRACEME, , NULL, NULL);
execl("/bin/ls", "ls", NULL);
}
else {
wait(NULL);
orig_eax = ptrace(PTRACE_PEEKUSER,
child, * ORIG_EAX,
NULL);
printf("The child made a "
"system call %ld\n", orig_eax);
ptrace(PTRACE_CONT, child, NULL, NULL);
}
return ;
}

运行结果:

The child made a system call 

后面还有ls命令出现的目录清单

linux 使用ptrace函数时找不到头文件 .h 或者找不到某个宏的解决方法的更多相关文章

  1. Xshell连接linux(deepin)时提示ssh服务器拒绝了密码,请再试一次解决方法

    用Xshell root连接时显示ssh服务器拒绝了密码,应该是应该是sshd的设置不允许root用户用密码远程登录 修改 /etc/ssh/sshd_config文件,注意,安装了openssh才会 ...

  2. IAR 编译时找不到头文件的解决方法

    Fatal Error[Pe1696]: cannot open source file "x.h" 那是因为头文件路径没有找对 到报错的.c源文件 选中右键 选择options ...

  3. Cocoapods - pod install 成功后找不到头文件解决

    问题描述:使用Cocoapods时,import 找不到头文件. 问题原因:这是因为还没设置头文件的目录. 解决办法:在项目的Target的里设置一下,添加cocoapods头文件目录:目录路径直接写 ...

  4. 编译C++,找不到头文件(fatal error: string: No such file or directory)

    在androidproject中编译C++时,找不到头文件,报错例如以下: fatal error: string: No such file or directory 解决该问题须要在Android ...

  5. CodeBlocks "no such file or directory" 错误解决方案(创建类找不到头文件)

    在CodeBlocks下,有时候需要自己定义类,当然就要添加相应的头文件,但添加进去的头文件明明包含在项目中了, 但编译时还是会报错:no such file or directory;这是为什么呢? ...

  6. #include &lt;sys/socket.h&gt;找不到头文件

    ubuntu下socket编程涉及到头文件sys/socket.h 和sys/types.h.我是用的codeblocks编辑器,当我想查看socket,h头文件时编辑器提示找不到头文件. 我就想可能 ...

  7. 当Android工程中提示你找不到头文件,但你已经设置头文件路径了

    虽然在Android.mk文件中,配置了LOCAL_C_INCLUDES路径,但是工程中的红色叉号一直提示找不到头文件 这时,你在工程树目录中展开Includes项,捣鼓捣鼓,重新build下,或许就 ...

  8. pod JONSKit.h MBProgress.h 找不到头文件,怎么办?

    这时你看项目pod部分,多了JSONKit库.好了,第三方库就这么神奇的加进来. 头文件路径 那试试看使用JONSKit.h,在ViewController.m里引用下.找不到头文件,怎么办?还没设置 ...

  9. windows下vscode修复c++找不到头文件

    因为原博客太长将部分内容分开 vscode找不到头文件的问题是由于windows下vscode默认的编译器是微软的MSVC(vs使用的编译器)的头文件路径 如果你没有安装vs肯定会因为找不到头文件而报 ...

随机推荐

  1. CentOS 6.5上安装Python 2.7.9

    CentOS 6.6自带的是Python 2.6.6,而编译llvm需要Python 2.7以上. checking for python... /usr/bin/python checking fo ...

  2. CentOS 7 之几个新特性(转)

    上篇我们讲到默认没有ifconfig是centos7的新特性,所以我特意上网搜索了一下其新特性,找到一篇文章,现转过来. centos最小好化安装没有ifconfig命令 刚安装了centos7.0, ...

  3. phpcms v9教程 联动搜索在房地产网站开发中的应用

    开发简述:使用phpcms v9系统,修改源文件5个,创建模型:楼盘.出售.出租.中介.小区,增加联动菜单:楼盘,增加用户组:房产中介.实现功能:游客发布信息.会员申请中介.楼盘全方位展示.报名团购. ...

  4. jQuery制作go to top按钮

    转自:http://www.w3cplus.com/jquery/scrolling-to-the-top-with-jquery 每每看到网友Blog的页面底部或中间有一个按钮回到页面顶部,羡慕死人 ...

  5. oldboy第十三天学习

    1.现在给我的感觉是,python终于入门了开始越学越简单了.变得更好理解了. 一.memcached Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它 ...

  6. 使用hexo创建github博客

    前言 前面说过,之前用wordpress辛辛苦苦搭建的博客,因为服务器和域名的问题挂掉了.后来发现github也能够搭建自己的博客,不需要去关心主机域名的问题,而且还能使用Markdown来写博客,就 ...

  7. 转:A10/A20 Bootloader加载过程分析

    来自:http://blog.csdn.net/allen6268198/article/details/12905425 A10/A20 Bootloader加载过程分析 注:由于全志A10和A20 ...

  8. The 500 Most Commonly Used Words in the English Language

    Based on the combined results of British English, American English and Australian English surveys of ...

  9. Android中的webview的进度条

    <application android:icon="@drawable/hunqin" android:label="@string/app_name" ...

  10. LeetCode_Decode Ways

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...