v10 = __readfsqword(0x28u); megaInit(); global_argc = argc; global_argv = (__int64)argv; global_envp = (__int64)envp; print_art(); puts( "Welcome, human, to the 42nd centennial dolphin acrobatics show! Better get to it.\n" "These dolphins aren't going to train themselves..."); v6 = getppid(); snprintf(s, 0x14uLL, "/proc/%d/comm", v6); stream = fopen(s, "r"); fgets(s2, 32, stream); for ( i = 0; i <= 31; ++i ) { if ( s2[i] == 10 ) { s2[i] = 0; break; } } if ( !strncmp("fish", s2, 4uLL) ) { puts("\nThe dolphins aren't in the mood for fish right now."); result = 0; } elseif ( !strncmp("bash", s2, 4uLL) ) { puts("\nThe dolphins don't appreciate your threats of violence."); result = 0; } elseif ( !strncmp("tidbits", s2, 7uLL) ) { puts("\nUpon seeing the tidbits, the dolphins begin their performance."); puts( "\n" "As you give them the signal, you are amazed by the dolphins' uncanny ability to\n" "perform a double-backwards-somersault through a hoop whilst whistling \"The Star\n" "Spangled Banner.\" You can't help but wonder if there's some hidden meaning behind\n" "their actions."); if ( !(unsignedint)tricks() ) sub_21960(); result = 0; } else { puts("\nThe dolphins are hungry..."); result = 0; } return result; }
看起来代码很长,让我们来分段看看它做了些什么吧。
1 2 3 4 5 6 7 8 9 10 11 12
v6 = getppid(); snprintf(s, 0x14uLL, "/proc/%d/comm", v6); stream = fopen(s, "r"); fgets(s2, 32, stream); for ( i = 0; i <= 31; ++i ) { if ( s2[i] == 10 ) { s2[i] = 0; break; } }
if ( !strncmp("fish", s2, 4uLL) ) { puts("\nThe dolphins aren't in the mood for fish right now."); result = 0; } elseif ( !strncmp("bash", s2, 4uLL) ) { puts("\nThe dolphins don't appreciate your threats of violence."); result = 0; } elseif ( !strncmp("tidbits", s2, 7uLL) ) { puts("\nUpon seeing the tidbits, the dolphins begin their performance."); puts( "\n" "As you give them the signal, you are amazed by the dolphins' uncanny ability to\n" "perform a double-backwards-somersault through a hoop whilst whistling \"The Star\n" "Spangled Banner.\" You can't help but wonder if there's some hidden meaning behind\n" "their actions.");
v4 = __readfsqword(0x28u); stream = popen("/bin/grep tidbits /proc/*/comm", "r"); if ( !stream ) { puts("ERROR: This challenge depends on grep."); exit(1); } putchar(10); for ( i = 0; fgets(s, 1024, stream) && i <= 5; ++i ) printf("Performed trick %c...\n", (unsigned int)(i + 65)); if ( i <= 5 ) { if ( i > 4 ) return 0LL; puts("\nYou ran out of treats. The dolphins are no longer following your lead."); } else { puts("\nYou overfed the dolphins and they decided to take a nap."); } return 1LL; }