Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- // this can take a long time
- void doOneThing() {
- // ...
- }
- // this can take a long time too
- void doAnotherThing () {
- //...
- }
- int main(int argc, char** argv) {
- string mycool_str = "im a cool str\n"; // stl uses a smart pointers?
- doOneThing();
- doAnotherThing();
- return 0;
- } // here the mycool_str will be deleted??
- // compiled with g++
- // decompiled with Radare2
- /*
- [0x000010b0]> pdf @ main
- ┌ 129: int main (int argc, char **argv, char **envp);
- │ ; var char **var_60h @ rbp-0x60
- │ ; var int64_t var_54h @ rbp-0x54
- │ ; var int64_t var_41h @ rbp-0x41
- │ ; var int64_t var_40h @ rbp-0x40
- │ ; var int64_t var_18h @ rbp-0x18
- │ ; arg int argc @ rdi
- │ ; arg char **argv @ rsi
- │ ; DATA XREF from entry0 @ 0x10d1
- │ 0x000011b7 55 push rbp
- │ 0x000011b8 4889e5 mov rbp, rsp
- │ 0x000011bb 53 push rbx
- │ 0x000011bc 4883ec58 sub rsp, 0x58
- │ 0x000011c0 897dac mov dword [var_54h], edi ; argc
- │ 0x000011c3 488975a0 mov qword [var_60h], rsi ; argv
- │ 0x000011c7 64488b042528. mov rax, qword fs:[0x28]
- │ 0x000011d0 488945e8 mov qword [var_18h], rax
- │ 0x000011d4 31c0 xor eax, eax
- │ 0x000011d6 488d45bf lea rax, [var_41h]
- │ 0x000011da 4889c7 mov rdi, rax
- │ 0x000011dd e8befeffff call sym std::allocator<char>::allocator() ; sym.std::allocator_char_::allocator
- │ 0x000011e2 488d55bf lea rdx, [var_41h]
- │ 0x000011e6 488d45c0 lea rax, [var_40h]
- │ 0x000011ea 488d35140e00. lea rsi, str.im_a_cool_str ; 0x2005 ; "im a cool str\n"
- │ 0x000011f1 4889c7 mov rdi, rax
- │ 0x000011f4 e877feffff call sym std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) ; sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::basic_string_char_const___std::allocator_char__const
- │ 0x000011f9 488d45bf lea rax, [var_41h]
- │ 0x000011fd 4889c7 mov rdi, rax
- │ 0x00001200 e84bfeffff call sym std::allocator<char>::~allocator() ; sym.std::allocator_char_::_allocator
- │ 0x00001205 e89fffffff call sym doOneThing() ; sym.doOneThing
- │ 0x0000120a e8a1ffffff call sym doAnotherThing() ; sym.doAnotherThing
- │ 0x0000120f bb00000000 mov ebx, 0
- │ 0x00001214 488d45c0 lea rax, [var_40h]
- │ 0x00001218 4889c7 mov rdi, rax
- │ 0x0000121b e810feffff call sym std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ; sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::_basic_string
- │ 0x00001220 89d8 mov eax, ebx
- │ 0x00001222 488b4de8 mov rcx, qword [var_18h]
- │ 0x00001226 6448330c2528. xor rcx, qword fs:[0x28]
- │ ┌─< 0x0000122f 7421 je 0x1252
- └ ┌──< 0x00001231 eb1a jmp loc.0000124d
- */
- #include <iostream>
- #include <string>
- void doOneThing() {
- // ...
- }
- void doAnotherThing () {
- //...
- }
- int main(int argc, char** argv) {
- string* mycool_str = new std::string("im a cool str\n"); // needs manual delete, write?
- delete mycool_str; // delete the mycool_str
- doOneThing();
- doAnotherThing();
- return 0;
- }
- // compiled with g++
- // decompiled with Radare2
- /*
- [0x000010d0]> pdf @ main
- ┌ 172: int main (int argc, char **argv, char **envp);
- │ ; var char **var_40h @ rbp-0x40
- │ ; var int64_t var_34h @ rbp-0x34
- │ ; var int64_t var_21h @ rbp-0x21
- │ ; var int64_t var_20h @ rbp-0x20
- │ ; var int64_t canary @ rbp-0x18
- │ ; arg int argc @ rdi
- │ ; arg char **argv @ rsi
- │ ; DATA XREF from entry0 @ 0x10f1
- │ 0x000011d7 55 push rbp
- │ 0x000011d8 4889e5 mov rbp, rsp
- │ 0x000011db 4154 push r12
- │ 0x000011dd 53 push rbx
- │ 0x000011de 4883ec30 sub rsp, 0x30
- │ 0x000011e2 897dcc mov dword [var_34h], edi ; argc
- │ 0x000011e5 488975c0 mov qword [var_40h], rsi ; argv
- │ 0x000011e9 64488b042528. mov rax, qword fs:[0x28]
- │ 0x000011f2 488945e8 mov qword [canary], rax
- │ 0x000011f6 31c0 xor eax, eax
- │ 0x000011f8 488d45df lea rax, [var_21h]
- │ 0x000011fc 4889c7 mov rdi, rax
- │ 0x000011ff e8bcfeffff call sym std::allocator<char>::allocator() ; sym.std::allocator_char_::allocator
- │ 0x00001204 4c8d65df lea r12, [var_21h]
- │ 0x00001208 bf20000000 mov edi, 0x20 ; "@"
- │ 0x0000120d e83efeffff call sym operator new(unsigned long) ; sym.operator_new_unsigned_long
- │ 0x00001212 4889c3 mov rbx, rax
- │ 0x00001215 4c89e2 mov rdx, r12
- │ 0x00001218 488d35e60d00. lea rsi, str.im_a_cool_str ; 0x2005 ; "im a cool str\n"
- │ 0x0000121f 4889df mov rdi, rbx
- │ 0x00001222 e869feffff call sym std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) ; sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::basic_string_char_const___std::allocator_char__const
- │ 0x00001227 48895de0 mov qword [var_20h], rbx
- │ 0x0000122b 488d45df lea rax, [var_21h]
- │ 0x0000122f 4889c7 mov rdi, rax
- │ 0x00001232 e839feffff call sym std::allocator<char>::~allocator() ; sym.std::allocator_char_::_allocator
- │ 0x00001237 488b5de0 mov rbx, qword [var_20h]
- │ 0x0000123b 4885db test rbx, rbx
- │ ┌─< 0x0000123e 7415 je 0x1255
- │ │ 0x00001240 4889df mov rdi, rbx
- │ │ 0x00001243 e8e8fdffff call sym std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string() ; sym.std::__cxx11::basic_string_char__std::char_traits_char___std::allocator_char___::_basic_string
- │ │ 0x00001248 be20000000 mov esi, 0x20 ; "@"
- │ │ 0x0000124d 4889df mov rdi, rbx
- │ │ 0x00001250 e80bfeffff call sym operator delete(void*, unsigned long) ; sym.operator_delete_void___unsigned_long
- │ │ ; CODE XREF from main @ 0x123e
- │ └─> 0x00001255 e86fffffff call sym doOneThing() ; sym.doOneThing
- │ 0x0000125a e871ffffff call sym doAnotherThing() ; sym.doAnotherThing
- │ 0x0000125f b800000000 mov eax, 0
- │ 0x00001264 488b4de8 mov rcx, qword [canary]
- │ 0x00001268 6448330c2528. xor rcx, qword fs:[0x28]
- │ ┌─< 0x00001271 7436 je 0x12a9
- │ ┌──< 0x00001273 eb2f jmp 0x12a4
- ..
- │ ││ ; CODE XREF from main @ 0x1273
- │ └──> 0x000012a4 e8d7fdffff call sym.imp.__stack_chk_fail ; void __stack_chk_fail(void)
- │ │ ; CODE XREF from main @ 0x1271
- │ └─> 0x000012a9 4883c430 add rsp, 0x30
- │ 0x000012ad 5b pop rbx
- │ 0x000012ae 415c pop r12
- │ 0x000012b0 5d pop rbp
- └ 0x000012b1 c3 ret
- [0x000010d0]>
- */
Advertisement
Add Comment
Please, Sign In to add comment