本文介绍了ltrace()如何显示rand()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当ltrace命中一个rand函数时,它会显示4个参数,如下所示:rand(0,0x5649bd4e6010,0x7f0955490760,0x7f09551cf7b0)= 0x17382962

When ltrace hits a rand function, it shows it with 4 paramters, like this:rand(0, 0x5649bd4e6010, 0x7f0955490760, 0x7f09551cf7b0) = 0x17382962

rand不接受任何参数.ltrace在这里显示什么?

rand doesn't take any arguments. What is ltrace showing here?

编辑后添加示例:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    srand((unsigned int)time(NULL));
    int r = (rand() % 4096);
    printf("The number is: %d\n", r);
}

编译并使用ltrace运行:

Compile and run with ltrace:

$ ltrace ./demo
__libc_start_main(0x4005f6, 1, 0x7ffe1e719fa8, 0x400650 <unfinished ...>
time(0)                                                                                                      = 1515331941
srand(0x5a522165, 0x7ffe1e719fa8, 0x7ffe1e719fb8, 0)                                                         = 0
rand(0x7f75b1a4b620, 0x7ffe1e719e7c, 0x7f75b1a4b0a4, 0x7f75b1a4b11c)                                         = 0x354b8023
printf("The number is: %d\n", 35The number is: 35
)                                                                            = 18
+++ exited (status 0) +++

$ ltrace ./demo
__libc_start_main(0x4005f6, 1, 0x7fffa0bf3a18, 0x400650 <unfinished ...>
time(0)                                                                                                      = 1515331963
srand(0x5a52217b, 0x7fffa0bf3a18, 0x7fffa0bf3a28, 0)                                                         = 0
rand(0x7f6e22884620, 0x7fffa0bf38ec, 0x7f6e228840a4, 0x7f6e2288411c)                                         = 0x6667c0f4
printf("The number is: %d\n", 244The number is: 244
)                                                                           = 19
+++ exited (status 0) +++

兰德显示哪些参数?

rand(0x7f6e22884620, 0x7fffa0bf38ec, 0x7f6e228840a4, 0x7f6e2288411c)                                         = 0x6667c0f4

什么是0x7f6e22884620、0x7fffa0bf38ec,0x7f6e228840a4、0x7f6e2288411c?

What are 0x7f6e22884620, 0x7fffa0bf38ec, 0x7f6e228840a4, 0x7f6e2288411c?

推荐答案

ltrace 显示了根据x86-64 ABI约定传递参数的少数寄存器的内容.

ltrace shows the content of the few registers passing arguments, according to x86-64 ABI conventions.

对于其他功能, ltrace 知道它们的API(即它们的签名),因此可以更巧妙地显示参数.

For other functions, ltrace knows their API (i.e. their signature) so show arguments more cleverly.

请参见 ltrace(1)原型库发现部分.

这篇关于ltrace()如何显示rand()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 02:32