本文介绍了找不到二进制.dtors和.ctors的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读的书黑客,剥削THA艺术。在书中有解释使用.dtors和.ctors的截面。我试图重现这本书的exercices之一,但在我的可执行文件我没有这个部分。起初我以为这个问题是,我是编译64位,但我现在为编译32位和.dtors和.ctors仍然没有在节表中出现。这里是code:

I am reading the book Hacking, tha art of exploitation. In the book there is a section that explain the use of .dtors and .ctors. I'm trying to reproduce one of the exercices of the book but in my executable I do not have this sections. At first I thought the problem was that I was compiling for 64-bit, but now I'm compiling for 32-bit and .dtors and .ctors still not appearing in the section table. Here is the code:

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

static void
miConstructor(void) __attribute__ ((constructor));
static void
miDestructor(void) __attribute__ ((destructor));

int
main(void) {
printf("En main() \n");
return 0;
}

void
miConstructor(void) {
printf("En el constructor\n");
}

void
miDestructor(void) {
    printf("En el destructor\n");
}

我用编译:

 gcc -m32 -o a.out dtors_example.c

这是纳米输出:

080495f0 d _DYNAMIC
080496e4 d _GLOBAL_OFFSET_TABLE_
080484dc R _IO_stdin_used
     w _ITM_deregisterTMCloneTable
     w _ITM_registerTMCloneTable
     w _Jv_RegisterClasses
080485d8 r __FRAME_END__
080495ec d __JCR_END__
080495ec d __JCR_LIST__
08049704 D __TMC_END__
08049704 A __bss_start
080496fc D __data_start
080483c0 t __do_global_dtors_aux
080495e4 t __do_global_dtors_aux_fini_array_entry
08049700 D __dso_handle
080495dc t __frame_dummy_init_array_entry
     w __gmon_start__
080484ba T __i686.get_pc_thunk.bx
080495e4 t __init_array_end
080495dc t __init_array_start
08048450 T __libc_csu_fini
08048460 T __libc_csu_init
     U __libc_start_main@@GLIBC_2.0
08049704 A _edata
08049708 A _end
080484c0 T _fini
080484d8 R _fp_hw
080482b8 T _init
08048320 T _start
08049704 b completed.5730
080496fc W data_start
08048350 t deregister_tm_clones
080483e0 t frame_dummy
0804840c T main
08048428 t miConstructor
0804843c t miDestructor
     U puts@@GLIBC_2.0
08048380 t register_tm_clones

的输出objdump的既不显示.dtors或.ctors

The output of objdump neither show .dtors or .ctors

也许部分__init_array_end,__init_array_start或__do_global_dtors_aux与.ctors和.dtors的行为?

Maybe the sections __init_array_end, __init_array_start or __do_global_dtors_aux are related with the behavior of .ctors and .dtors?

先谢谢了。

推荐答案

这个问题可能是GCC。根据GCC 4.7版可产生.ctors节,但GCC 4.7使用.init_array代替.ctors。您可以通过执行命令,它下面列出证实了这一点。
objdump的-dr -j .ctors a.out.if没有发现的部分,尽量objdump的-dr -j .init_array的a.out
或者你可以做到这一点readelf -S a.out的列出所有部分。那么你会发现.ctors或(和).init_array。

The issue is likely gcc. under gcc 4.7 version can generate .ctors sections, but gcc 4.7 use .init_array instead of .ctors. you can confirm this by doing command which list below.objdump -dr -j .ctors a.out.if no sections found, try objdump -dr -j .init_array a.outor you can do this readelf -S a.out to list all sections. then you'll find .ctors or(and) .init_array.

这篇关于找不到二进制.dtors和.ctors的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 00:28