3

Test platform is Linux 32 bit.

I use IDA Pro to disassembly the basename from coreutils 8.5 compiled by gcc 4.6.3

Here is a code snippet generated by IDA Pro

           call    _i686_get_pc_thunk_bx                                 
           add     ebx, 292Eh
           sub     esp, 18h
           mov     eax, ds:(__dso_handle_ptr - 804DFF4h[ebx]
           test    eax, eax
           jz      short loc_804B6F8
           mov     eax, [eax]

     loc_804B6DB:
           mov     [esp+1Ch+var_14], eax
           mov     eax, [esp+1Ch+arg_0]
           mov     dword [esp+1Ch+var_18], 0
           mov     [esp+1Ch+var_1C], eax
           call    __cxa_atexit
           add     esp, 18h
           pop     ebx
           retn

     loc_804B6F8:
           xor     eax, eax
           jmp     short loc_804B6DB

I don't understand this line:

mov     eax, ds:(__dso_handle_ptr - 804DFF4h[ebx]

and after searching the code, I can only find this:

        __dso_handle    dd 0

in the .data section.

So my questions are:

  1. What is the meaning of this line..? Is it like a version checking stuff..?
  2. Can I just safely remove this line without affecting the functionality of the code..?
3
  • 1
    You should really add more context!
    – 0xC0000022L
    Commented Feb 1, 2014 at 23:49
  • Can you please post at least the whole main of basename?
    – PhoeniX
    Commented Feb 2, 2014 at 7:40
  • @ph0sec Thank you and I can modify the question later. But basically I modify my IDC scripts to directly generate nasm syntax asm, then this problem gone.... Commented Feb 2, 2014 at 15:08

1 Answer 1

8

You are looking at binary that is compiled as position-independent code. The call _i686_get_pc_thunk_bx and the following addition to ebx shows just that. If you take a look at the disassembly, you'll see that the address of the add ebx, 292Eh plus 0x292E will result in the first address of the GOT. That why in the next line, _dso_handle_ptr is addressed in such a "funny" way.

IDA however is nice enough to show you this in the disassembly as you would normally only see 0xSOMEADDR[ebx].

In terms of the second question: that line retrieves a global variable, puts it into eax and then checks if it is zero or not. So, you should not just "delete" that line since then the test eax, eax would use some old value of eax (which I am sure you will not like all that much).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.