230 # endif 231 232 /** One less thread. Decrement the counter. If it is zero we 233 terminate the entire process. */ 234 result = 0; 235 # ifdef SHARED 236 unsigned int *ptr = libc_pthread_functions.ptr_nthreads; 237 PTR_DEMANGLE (ptr); 238 # else 239 extern unsigned int nptl_nthreads attribute ((weak)); 240 unsigned int *const ptr = & nptl_nthreads; 241 # endif 242 243 if (! atomic_decrement_and_test (ptr)) 244 /** Not much left to do but to exit the thread, not the process. */
245
246 } 247 #else exit_thread (0);
248 /** Nothing fancy, just call the function. */
249 result = main (argc, argv, environ MAIN_AUXVEC_PARAM); 250 #endif 251 252 exit (result); 253 } 多个输入参数,然后开始对程序进行初始化工作,如初始化线程、安装 SSP 防护、注册 析构函数等,包括对程序结束的撤销系统资源等等。那么现在我们可以解答文件开始的问题, main 是从__libc_satart_main 函数调用的。 我们看到 libc_start_main 传入了 7 个参数,其中有 init 和 finit,在 IDA 反汇编时 时 libc_csu_init 和__libc_csu_finit.这两个函数一个是函数开始处理和一个是函数退 出处理,就是在 main 前后,我们可以看一下这两个函数都作了什么,首先我们看一下 libc_csu_init IDA 反汇编; .text:08048400 .text:08048400 ; Attributes: bp-based frame .text:08048400 .text:08048400 public libc_csu_init .text:08048400 libc_csu_init proc near ; DATA XREF: _start+10 o .text:08048400 .text:08048400 arg_0 = dword ptr 8 .text:08048400 arg_4 = dword ptr 0Ch .text:08048400 arg_8 = dword ptr 10h .text:08048400 .text:08048400 push ebp .text:08048401 mov ebp, esp .text:08048403 push edi .text:08048404 push esi .text:08048405 push ebx
.text:08048406 call i686_get_pc_thunk_bx .text:0804840B add ebx, 1BE9h .text:08048411 sub esp, 0Ch .text:08048414 call _init_proc .text:08048419 lea edi, (__CTOR_LIST - 8049FF4h)[ebx] .text:0804841F lea eax, (__CTOR_LIST - 8049FF4h)[ebx] .text:08048425 sub edi, eax
|