Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Binary Bomb phase 4 Dump of assembler code for function phase_4: > 0x00000000004

ID: 3751147 • Letter: B

Question

Binary Bomb phase 4

Dump of assembler code for function phase_4:
> 0x0000000000400fe7 <+0>:     sub    $0x18,%rsp
   0x0000000000400feb <+4>:     lea    0x8(%rsp),%rcx
   0x0000000000400ff0 <+9>:     lea    0xc(%rsp),%rdx
   0x0000000000400ff5 <+14>:    mov    $0x40290d,%esi
   0x0000000000400ffa <+19>:    mov    $0x0,%eax
   0x0000000000400fff <+24>:    callq 0x400c00 <__isoc99_sscanf@plt>
   0x0000000000401004 <+29>:    cmp    $0x2,%eax
   0x0000000000401007 <+32>:    jne    0x401010 <phase_4+41>
   0x0000000000401009 <+34>:    cmpl   $0xe,0xc(%rsp)
   0x000000000040100e <+39>:    jbe    0x401015 <phase_4+46>
   0x0000000000401010 <+41>:    callq 0x401662 <explode_bomb>
   0x0000000000401015 <+46>:    mov    $0xe,%edx
   0x000000000040101a <+51>:    mov    $0x0,%esi
   0x000000000040101f <+56>:    mov    0xc(%rsp),%edi
   0x0000000000401023 <+60>:    callq 0x400fb4 <func4>
   0x0000000000401028 <+65>:    cmp    $0x12,%eax
   0x000000000040102b <+68>:    jne    0x401034 <phase_4+77>
   0x000000000040102d <+70>:    cmpl   $0x12,0x8(%rsp)
   0x0000000000401032 <+75>:    je     0x401039 <phase_4+82>
   0x0000000000401034 <+77>:    callq 0x401662 <explode_bomb>
   0x0000000000401039 <+82>:    add    $0x18,%rsp
   0x000000000040103d <+86>:    retq
   End of assembler dump.
(gdb) disassemble /m func4

Dump of assembler code for function func4:
   0x0000000000400fb4 <+0>:     push   %rbx
   0x0000000000400fb5 <+1>:     mov    %edx,%eax
   0x0000000000400fb7 <+3>:     sub    %esi,%eax
   0x0000000000400fb9 <+5>:     mov    %eax,%ebx
   0x0000000000400fbb <+7>:     shr    $0x1f,%ebx
   0x0000000000400fbe <+10>:    add    %ebx,%eax
   0x0000000000400fc0 <+12>:    sar    %eax
   0x0000000000400fc2 <+14>:    lea    (%rax,%rsi,1),%ebx
   0x0000000000400fc5 <+17>:    cmp    %edi,%ebx
   0x0000000000400fc7 <+19>:    jle    0x400fd5 <func4+33>
   0x0000000000400fc9 <+21>:    lea    -0x1(%rbx),%edx
   0x0000000000400fcc <+24>:    callq 0x400fb4 <func4>
   0x0000000000400fd1 <+29>:    add    %ebx,%eax
   0x0000000000400fd3 <+31>:    jmp    0x400fe5 <func4+49>
   0x0000000000400fd5 <+33>:    mov    %ebx,%eax
   0x0000000000400fd7 <+35>:    cmp    %edi,%ebx
   0x0000000000400fd9 <+37>:    jge    0x400fe5 <func4+49>
   0x0000000000400fdb <+39>:    lea    0x1(%rbx),%esi
   0x0000000000400fde <+42>:    callq 0x400fb4 <func4>
   0x0000000000400fe3 <+47>:    add    %ebx,%eax
   0x0000000000400fe5 <+49>:    pop    %rbx
   0x0000000000400fe6 <+50>:    retq
End of assembler dump.

So what is the answer for bomb 4. Is it 0 7 ?

Explanation / Answer

#include "trim.h"

namespace generic {

std::string trim_right(const std::string& s) {

std::string::size_type e = s.find_last_not_of(" ");

return std::string(s, 0, e == std::string::npos ? 0 : e + 1);

}

std::string trim_left(const std::string& s) {

std::string::size_type b = s.find_first_not_of(" ");

return std::string(s, b == std::string::npos ? 0 : b, std::string::npos);

}

std::string trim(const std::string& s) {

const char* ws = " ";

std::string::size_type e = s.find_last_not_of(ws);

std::string::size_type b = s.find_first_not_of(ws);

if (b == std::string::npos) { b = 0; }

return std::string(s, b, e == std::string::npos ? 0 : e - b + 1);

}

}