使用 Ptrace 检索系统调用,在第一次调用后停止
Retrieving system calls with Ptrace, stopping after first one
我正在尝试检索所有系统调用的数量,并最终检索使用 ptrace 的 give 程序调用的系统调用的名称。 我在 64 位系统上,所以我使用 ORIG_RAX * 8 使用 ptrace 查找系统调用。我目前只能检索第一个系统调用,示例运行的输出如下。有什么想法吗?
谢谢!
输出: griffinm@well $ g++ mystrace.cc
~/cs153/assn2
griffinm@well $ a.out ls
Please wait
The child made a system call 59
a.out mystrace.cc mystrace.cc~
Number of machine instructions : 252376
~/cs153/assn2
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/ptrace.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <errno.h>
#define ORIG_RAX 120
int main( int argc, char* argv[])
{
long long counter = 0; /* machine instruction counter */
int wait_val; /* child's return value */
int pid;
long orig_eax; /* child's process id */
puts("Please wait");
switch (pid = fork()) {
case -1:
perror("fork");
break;
case 0:
ptrace(PTRACE_TRACEME, 0, 0, 0);
execvp(argv[1], NULL);
break;
default:
wait(&wait_val);
orig_eax = ptrace(PTRACE_PEEKUSER,
pid, ORIG_RAX,
NULL);
printf("The child made a "
"system call %ldn", orig_eax);
while (wait_val == 1407 ) {
counter++;
if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
perror("ptrace");
wait(&wait_val);
}
}
printf("Number of machine instructions : %lldn", counter);
return 0;
}
Update Default Case:
Default:
wait(&wait_val);
while (wait_val == 1407 ) {
counter++;
if (ptrace(PTRACE_SYSCALL, pid, 0, 0) != 0)
perror("ptrace");
orig_eax = ptrace(PTRACE_PEEKUSER,
pid, 8*ORIG_RAX,
NULL);
cout<<orig_eax<<endl;
wait(&wait_val);
}
}
编辑:
Output:
griffinm@well $ a.out pwd
Please wait
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
/home/csmajs/griffinm/cs153/assn2
-1
-1
-1
-1
-1
-1
我认为 8*Orig_RAX 是问题所在,机器就像我说的一样是 64 位。有什么想法吗?
您可能希望使用PTRACE_SYSCALL
而不是PTRACE_SINGLESTEP
来运行子项到下一个系统调用,而不仅仅是单个指令。 然后,您可以再次使用该PTRACE_PEEKUSER
来查看它是什么系统调用。
相关文章:
- QLibrary 函数在第一次调用时工作缓慢
- EGL 在第一次 opengl 函数调用时崩溃
- Lib Caffe (C++): input_blobs()[0] 在第一次调用后会导致底部形状错误
- boost::async_connect 上的 ASIO 完成处理程序在第一次失败后再也没有调用过
- C++uniform_int_distribution在第一次调用时总是返回min()
- 如果我对async_read进行两次调用,那么只有在处理完第一次调用之后,才会处理第二次调用,这是否安全
- 如何在递归模板函数的第一次调用时执行函数
- SFML在使用代码::块的第一次调用时崩溃
- 使用openCV从网络摄像头捕获图像的函数仅在第一次调用时起作用
- C++ 笛卡尔乘积迭代器在第一次迭代时调用基类函数
- posix_memalign / malloc 在第一次调用免费后分配较低的地址
- 为什么第一次工作后对 LoadLibrary 的调用会失败并显示"找不到指定的模块"
- 使用 Ptrace 检索系统调用,在第一次调用后停止
- 第一次制作了一个跨越几个类的程序,但我在函数调用方面遇到了问题
- 为什么第一次调用readline()会减慢随后所有对fnmatch()的调用
- 删除第一次循环时未调用析构函数的保留字
- 为什么我得到第一次机会异常,如果没有人调用该函数
- CryptoAPI RSA: CryptDecrypt只在第一次解密,其他调用返回NTE_BAD_DATA
- 一种测试您是否第一次运行多个递归调用 C++ 的方法
- 是在第一次调用静态成员函数之前初始化的静态类变量