Memory 使用英特尔&x27;获取堆栈指针内容;s销工具 使用ObjdUp实用工具,我们可以检索变量的相对地址,例如考虑一个简单的C程序: 源代码: #include<stdio.h> void do_stuff(int my_arg){ int my_local=my_arg+2; int i; for(i=0;i<my_local;i++) printf("i=%d\n",i); } int main(){ do_stuff(2); return 0; } #包括 void do_stuff(int my_arg){ int my_local=my_arg+2; int i; 对于(i=0;i

Memory 使用英特尔&x27;获取堆栈指针内容;s销工具 使用ObjdUp实用工具,我们可以检索变量的相对地址,例如考虑一个简单的C程序: 源代码: #include<stdio.h> void do_stuff(int my_arg){ int my_local=my_arg+2; int i; for(i=0;i<my_local;i++) printf("i=%d\n",i); } int main(){ do_stuff(2); return 0; } #包括 void do_stuff(int my_arg){ int my_local=my_arg+2; int i; 对于(i=0;i,memory,architecture,dwarf,intel-pin,dynamic-analysis,Memory,Architecture,Dwarf,Intel Pin,Dynamic Analysis,您应该能够使用Pin的SafeCopy功能访问应用程序内存并将其复制到pintool内存中 但如评论中所述,不可能总是知道变量值的可靠存储位置,因此请记住这一点。您应该能够使用Pin的安全复制功能访问应用程序内存并将其复制到pintool内存中 但正如注释中所指出的,不可能总是知道变量值可靠地存储在何处,因此请记住这一点。您始终可以获取帧地址,然后计算局部变量偏移量以获取运行时地址。但是,并非所有局部变量都将保存在专用帧地址中。有时它将仅存储在优化后的寄存器。如果始终使用非优化代码,则应该能够获

您应该能够使用Pin的SafeCopy功能访问应用程序内存并将其复制到pintool内存中


但如评论中所述,不可能总是知道变量值的可靠存储位置,因此请记住这一点。

您应该能够使用Pin的安全复制功能访问应用程序内存并将其复制到pintool内存中


但正如注释中所指出的,不可能总是知道变量值可靠地存储在何处,因此请记住这一点。

您始终可以获取帧地址,然后计算局部变量偏移量以获取运行时地址。但是,并非所有局部变量都将保存在专用帧地址中。有时它将仅存储在优化后的寄存器。如果始终使用非优化代码,则应该能够获取帧中变量的地址。例如,可以获取_ubuiltin_return_address(n)在GCC中,然后计算帧地址-20以获取变量的内容。Hello Jclin感谢您的回复,我是pintool和dwarf的初学者。您能否详细说明或指定实现此目标的步骤Hello Jclin,我能够在函数级别使用pintool检索堆栈指针。如何从我尝试的偏移量计算,它只匹配对于一个变量,您只需要
my_local
变量的地址,不是吗?嘿,Jclin,我通过检索EBP寄存器内容解决了这个问题,即在.frame部分中查找EBP索引,这是ofs 16,所以my_local=EBP+16-20的地址,非常感谢它的工作,现在我需要通过集成libdwarf和pintool来自动完成这件事ermine地址自动删除您始终可以获取帧地址,然后计算局部变量偏移量以获取运行时地址。但是,并非所有局部变量都将保存在专用帧地址中。有时,它仅在优化后存储在寄存器中。如果您始终使用非优化代码,则应该能够获取变量在帧中的地址。例如,您可以获取uu内置的u返回的u地址(n)在GCC中,然后计算帧地址-20以获取变量的内容。Hello Jclin感谢您的回复,我是pintool和dwarf的初学者。您能否详细说明或指定实现此目标的步骤Hello Jclin,我能够在函数级别使用pintool检索堆栈指针。如何从我尝试的偏移量计算,它只匹配对于一个变量,您只需要
my_local
变量的地址,不是吗?嘿,Jclin,我通过检索EBP寄存器内容解决了这个问题,即在.frame部分中查找EBP索引,这是ofs 16,所以my_local=EBP+16-20的地址,非常感谢它的工作,现在我需要通过集成libdwarf和pintool来自动完成这件事ermine地址automaticallyHello Nitzanms,pintool中是否有提供函数调用跟踪的回调函数。例如,如果main()调用foo(),foo()调用bar(),我想获得类似1.main()->2.foo()-->3.bar()的信息,这里bar()是三级和main()是1级。我想在检测时跟踪此信息。没有这样的API,事实上,由于某些边缘情况,自动计算堆栈状态不是一件小事。堆栈跟踪程序的Pin套件中有一些示例。如果您想使它们适应您的需要,它们应该适用于简单情况。您好,Nitzanms,有回调函数吗pintool中提供函数调用跟踪的函数。例如,如果main()调用foo(),foo()调用bar(),我希望获得类似1.main()->2.foo()-->3.bar()的信息,这里bar()是三级和main()是1级。我想在检测时跟踪此信息。没有这样的API,事实上,由于某些边缘情况,自动计算堆栈状态并不是一件小事。堆栈跟踪程序的Pin套件中有一些示例。如果您想使它们适应您的需要,它们应该适用于简单情况。
Contents of the .debug_info section:

  Compilation Unit @ offset 0x0:
   Length:        0xd3 (32-bit)
   Version:       4
   Abbrev Offset: 0x0
   Pointer Size:  8
 <0><b>: Abbrev Number: 1 (DW_TAG_compile_unit)
    <c>   DW_AT_producer    : (indirect string, offset: 0x0): GNU C 4.8.4 -mtune=generic -march=x86-64 -g -fstack-protector 
    <10>   DW_AT_language    : 1    (ANSI C)
    <11>   DW_AT_name        : (indirect string, offset: 0xcd): sample1.c   
    <15>   DW_AT_comp_dir    : (indirect string, offset: 0x7e): /home/bernard/PhD/TEJAS/tejas_installation_kit/Tejas-Simulator/Tejas/benchmark  
    <19>   DW_AT_low_pc      : 0x40052d 
    <21>   DW_AT_high_pc     : 0x54 
    <29>   DW_AT_stmt_list   : 0x0  
 <1><2d>: Abbrev Number: 2 (DW_TAG_base_type)
    <2e>   DW_AT_byte_size   : 8    
    <2f>   DW_AT_encoding    : 7    (unsigned)
    <30>   DW_AT_name        : (indirect string, offset: 0x47): long unsigned int   
 <1><34>: Abbrev Number: 2 (DW_TAG_base_type)
    <35>   DW_AT_byte_size   : 1    
    <36>   DW_AT_encoding    : 8    (unsigned char)
    <37>   DW_AT_name        : (indirect string, offset: 0x62): unsigned char   
 <1><3b>: Abbrev Number: 2 (DW_TAG_base_type)
    <3c>   DW_AT_byte_size   : 2    
    <3d>   DW_AT_encoding    : 7    (unsigned)
    <3e>   DW_AT_name        : (indirect string, offset: 0xde): short unsigned int  
 <1><42>: Abbrev Number: 2 (DW_TAG_base_type)
    <43>   DW_AT_byte_size   : 4    
    <44>   DW_AT_encoding    : 7    (unsigned)
    <45>   DW_AT_name        : (indirect string, offset: 0x4c): unsigned int    
 <1><49>: Abbrev Number: 2 (DW_TAG_base_type)
    <4a>   DW_AT_byte_size   : 1    
    <4b>   DW_AT_encoding    : 6    (signed char)
    <4c>   DW_AT_name        : (indirect string, offset: 0x64): signed char 
 <1><50>: Abbrev Number: 2 (DW_TAG_base_type)
    <51>   DW_AT_byte_size   : 2    
    <52>   DW_AT_encoding    : 5    (signed)
    <53>   DW_AT_name        : (indirect string, offset: 0xf1): short int   
 <1><57>: Abbrev Number: 3 (DW_TAG_base_type)
    <58>   DW_AT_byte_size   : 4    
    <59>   DW_AT_encoding    : 5    (signed)
    <5a>   DW_AT_name        : int  
 <1><5e>: Abbrev Number: 2 (DW_TAG_base_type)
    <5f>   DW_AT_byte_size   : 8    
    <60>   DW_AT_encoding    : 5    (signed)
    <61>   DW_AT_name        : (indirect string, offset: 0x75): long int    
 <1><65>: Abbrev Number: 2 (DW_TAG_base_type)
    <66>   DW_AT_byte_size   : 8    
    <67>   DW_AT_encoding    : 7    (unsigned)
    <68>   DW_AT_name        : (indirect string, offset: 0xfb): sizetype    
 <1><6c>: Abbrev Number: 2 (DW_TAG_base_type)
    <6d>   DW_AT_byte_size   : 1    
    <6e>   DW_AT_encoding    : 6    (signed char)
    <6f>   DW_AT_name        : (indirect string, offset: 0x6b): char    
 <1><73>: Abbrev Number: 4 (DW_TAG_subprogram)
    <74>   DW_AT_external    : 1    
    <74>   DW_AT_name        : (indirect string, offset: 0x59): do_stuff    
    <78>   DW_AT_decl_file   : 1    
    <79>   DW_AT_decl_line   : 2    
    <7a>   DW_AT_prototyped  : 1    
    <7a>   DW_AT_low_pc      : 0x40052d 
    <82>   DW_AT_high_pc     : 0x3f 
    <8a>   DW_AT_frame_base  : 1 byte block: 9c     (DW_OP_call_frame_cfa)
    <8c>   DW_AT_GNU_all_tail_call_sites: 1 
    <8c>   DW_AT_sibling     : <0xb9>   
 <2><90>: Abbrev Number: 5 (DW_TAG_formal_parameter)
    <91>   DW_AT_name        : (indirect string, offset: 0xd7): my_arg  
    <95>   DW_AT_decl_file   : 1    
    <96>   DW_AT_decl_line   : 2    
    <97>   DW_AT_type        : <0x57>   
    <9b>   DW_AT_location    : 2 byte block: 91 5c  (DW_OP_fbreg: -36)
 <2><9e>: Abbrev Number: 6 (DW_TAG_variable)
    <9f>   DW_AT_name        : (indirect string, offset: 0x3e): my_local    
    <a3>   DW_AT_decl_file   : 1    
    <a4>   DW_AT_decl_line   : 3    
    <a5>   DW_AT_type        : <0x57>   
    <a9>   DW_AT_location    : 2 byte block: 91 6c  (DW_OP_fbreg: -20)
 <2><ac>: Abbrev Number: 7 (DW_TAG_variable)
    <ad>   DW_AT_name        : i    
    <af>   DW_AT_decl_file   : 1    
    <b0>   DW_AT_decl_line   : 4    
    <b1>   DW_AT_type        : <0x57>   
    <b5>   DW_AT_location    : 2 byte block: 91 68  (DW_OP_fbreg: -24)
 <2><b8>: Abbrev Number: 0
 <1><b9>: Abbrev Number: 8 (DW_TAG_subprogram)
    <ba>   DW_AT_external    : 1    
    <ba>   DW_AT_name        : (indirect string, offset: 0x70): main    
    <be>   DW_AT_decl_file   : 1    
    <bf>   DW_AT_decl_line   : 9    
    <c0>   DW_AT_type        : <0x57>   
    <c4>   DW_AT_low_pc      : 0x40056c 
    <cc>   DW_AT_high_pc     : 0x15 
    <d4>   DW_AT_frame_base  : 1 byte block: 9c     (DW_OP_call_frame_cfa)
    <d6>   DW_AT_GNU_all_tail_call_sites: 1 
 <1><d6>: Abbrev Number: 0