/hitcon-2017-luaky-main.c Secret
Created
November 6, 2017 16:08
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int __cdecl main(int argc, const char **argv, const char **envp) | |
{ | |
unsigned int v3; // eax | |
signed int v4; // ebx | |
unsigned int v5; // eax | |
bool v6; // bp | |
signed int v7; // ebx | |
unsigned int v8; // eax | |
unsigned __int64 v9; // rcx | |
bool v10; // r12 | |
int result; // eax | |
int v12; // ebx | |
signed __int64 v13; // rcx | |
bool v14; // al | |
unsigned int v15; // eax | |
unsigned int v16; // ecx | |
unsigned int v17; // eax | |
unsigned int v18; // eax | |
unsigned int v19; // eax | |
_QWORD *v20; // rax | |
__int64 v21; // [rsp+0h] [rbp-B8h] | |
char v22; // [rsp+8h] [rbp-B0h] | |
int v23; // [rsp+10h] [rbp-A8h] | |
char v24; // [rsp+14h] [rbp-A4h] | |
int v25; // [rsp+1Ch] [rbp-9Ch] | |
char v26; // [rsp+20h] [rbp-98h] | |
int v27; // [rsp+28h] [rbp-90h] | |
char v28; // [rsp+2Ch] [rbp-8Ch] | |
int v29; // [rsp+34h] [rbp-84h] | |
char v30; // [rsp+38h] [rbp-80h] | |
int v31; // [rsp+40h] [rbp-78h] | |
char v32; // [rsp+44h] [rbp-74h] | |
int v33; // [rsp+4Ch] [rbp-6Ch] | |
void *v34; // [rsp+50h] [rbp-68h] | |
__int64 v35; // [rsp+60h] [rbp-58h] | |
unsigned __int64 v36; // [rsp+78h] [rbp-40h] | |
v36 = __readfsqword(0x28u); | |
signal(14, (__sighandler_t)TLE_handler); | |
setbuf(stdout, 0LL); | |
puts("Welcome to luaky arena! Show us your AI:"); | |
ZN9LuaPlayer9read_codeB5cxx11Ev(&v34, 0LL); | |
LuaPlayer::LuaPlayer(&v21, &v34); | |
if ( v34 != &v35 ) | |
operator delete(v34); | |
__printf_chk(1LL, "Fighting with Slime..."); | |
v3 = urnd(); | |
battle<LuaPlayer,Slime>((std::chrono::_V2::steady_clock *)&v22, 100000, v21, v3 % 3, 1); | |
if ( (double)v23 < 90000.0 ) | |
goto LABEL_34; | |
puts("\x1B[1;32m\nNice! Let's try something serious :)\n\x1B[0m"); | |
v4 = 0; | |
do | |
{ | |
__printf_chk(1LL, "Fighting with Alpaca-%d..."); | |
v5 = urnd(); | |
battle<LuaPlayer,Alpaca>((std::chrono::_V2::steady_clock *)&v24, 100000, v21, v5, 1); | |
v6 = (double)v25 >= 90000.0; | |
++v4; | |
} | |
while ( v4 <= 9 && (double)v25 >= 90000.0 ); | |
puts(&byte_2CD1); | |
v7 = 0; | |
do | |
{ | |
__printf_chk(1LL, "Fighting with Nozomi-%d..."); | |
v8 = urnd(); | |
v9 = v8 | |
- 0x7FFFFFFF | |
* ((unsigned __int64)((0x200000005LL * (unsigned __int128)v8 >> 64) | |
+ ((unsigned __int64)(v8 - (0x200000005LL * (unsigned __int128)v8 >> 64)) >> 1)) >> 30); | |
if ( v8 == 0x7FFFFFFF | |
* ((unsigned __int64)((0x200000005LL * (unsigned __int128)v8 >> 64) | |
+ ((unsigned __int64)(v8 - (0x200000005LL * (unsigned __int128)v8 >> 64)) >> 1)) >> 30) ) | |
v9 = 1LL; | |
battle<LuaPlayer,Nozomi>((std::chrono::_V2::steady_clock *)&v26, 100000, v21, v9, 1); | |
v10 = (double)v27 >= 90000.0; | |
++v7; | |
} | |
while ( v7 <= 9 && (double)v27 >= 90000.0 ); | |
if ( v6 || (double)v27 >= 90000.0 ) | |
{ | |
getenv("FLAG_LUAKY"); | |
__printf_chk(1LL, "\x1B[1;32m\nYou are luaky! %s\n\x1B[0m\n"); | |
if ( v6 && v10 ) | |
{ | |
puts("Can you beat all of them...?"); | |
v12 = 0; | |
while ( 1 ) | |
{ | |
__printf_chk(1LL, "\rFighting with [HIDDEN]-%d..."); | |
v15 = urnd(); | |
v16 = v15; | |
v17 = 3 * (v15 / 3); | |
if ( v16 == v17 ) | |
{ | |
v18 = urnd(); | |
battle<LuaPlayer,Slime>((std::chrono::_V2::steady_clock *)&v28, 100000, v21, v18 % 3, 0); | |
v14 = (double)v29 >= 90000.0; | |
if ( ++v12 > 99 ) | |
goto LABEL_27; | |
} | |
else | |
{ | |
if ( v16 - v17 == 1 ) | |
{ | |
v19 = urnd(); | |
battle<LuaPlayer,Alpaca>((std::chrono::_V2::steady_clock *)&v30, 100000, v21, v19, 0); | |
v14 = (double)v31 >= 90000.0; | |
} | |
else | |
{ | |
v13 = (unsigned int)urnd() % 0x7FFFFFFFuLL; | |
if ( !v13 ) | |
v13 = 1LL; | |
battle<LuaPlayer,Nozomi>((std::chrono::_V2::steady_clock *)&v32, 100000, v21, v13, 0); | |
v14 = (double)v33 >= 90000.0; | |
} | |
if ( ++v12 > 99 ) | |
{ | |
LABEL_27: | |
if ( v14 ) | |
{ | |
getenv("FLAG_VERY_LUAKY"); | |
__printf_chk(1LL, "\x1B[1;32m\n\nWow... You are VERY LUAKY!! %s\x1B[0m\n"); | |
} | |
break; | |
} | |
} | |
if ( !v14 ) | |
goto LABEL_27; | |
} | |
} | |
} | |
result = 0; | |
if ( __readfsqword(0x28u) != v36 ) | |
{ | |
LABEL_34: | |
v20 = (_QWORD *)__cxa_allocate_exception(8LL); | |
*v20 = "Too weak, even Slime can beat you :("; | |
__cxa_throw(v20, &`typeinfo for'char const*, 0LL); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment