Reverse Engineering for Beginners

(avery) #1

CHAPTER 51. C++ CHAPTER 51. C++


call puts
mov esi, [esp+14h]
mov [esp], esi
call _ZNSt8__detail15_List_node_base9_M_unhookEv ; std::__detail::_List_node_base::⤦
Ç_M_unhook(void)
mov [esp], esi ; void
call _ZdlPv ; operator delete(void
)
mov [esp], ebx
call _Z13dump_List_valPj ; dump_List_val(uint *)
mov [esp], ebx
call _ZNSt10_List_baseI1aSaIS0_EE8_M_clearEv ; std::_List_base<a,std::allocator>::⤦
Ç_M_clear(void)
lea esp, [ebp-8]
xor eax, eax
pop ebx
pop esi
pop ebp
retn
main endp


Listing 51.30: The whole output


  • empty list:
    ptr=0x0028fe90 _Next=0x0028fe90 _Prev=0x0028fe90 x=3 y=0

  • 3-elements list:
    ptr=0x000349a0 _Next=0x00034988 _Prev=0x0028fe90 x=3 y=4
    ptr=0x00034988 _Next=0x00034b40 _Prev=0x000349a0 x=1 y=2
    ptr=0x00034b40 _Next=0x0028fe90 _Prev=0x00034988 x=5 y=6
    ptr=0x0028fe90 _Next=0x000349a0 _Prev=0x00034b40 x=5 y=6
    node at .begin:
    ptr=0x000349a0 _Next=0x00034988 _Prev=0x0028fe90 x=3 y=4
    node at .end:
    ptr=0x0028fe90 _Next=0x000349a0 _Prev=0x00034b40 x=5 y=6

  • let's count from the begin:
    1st element: 3 4
    2nd element: 1 2
    3rd element: 5 6
    element at .end(): 5 6

  • let's count from the end:
    element at .end(): 5 6
    3rd element: 5 6
    2nd element: 1 2
    1st element: 3 4
    removing last element...
    ptr=0x000349a0 _Next=0x00034988 _Prev=0x0028fe90 x=3 y=4
    ptr=0x00034988 _Next=0x0028fe90 _Prev=0x000349a0 x=1 y=2
    ptr=0x0028fe90 _Next=0x000349a0 _Prev=0x00034988 x=5 y=6


MSVC


MSVC’s implementation (2012) is just the same, but it also stores the current size of the list. This implies that the .size()
method is very fast (O(1)): it just reads one value from memory. On the other hand, the size variable must be updated at
each insertion/deletion.


MSVC’s implementation is also slightly different in the way it arranges the nodes:

← Previous
Free download pdf