#include <windows.h>
#include <defs.h>
//-------------------------------------------------------------------------
// Data declarations
extern char a127_0_0_1[10]; // weak
extern char aRequest_method[]; // idb
extern char aRequest_uri[12]; // weak
extern char aHttp_host[10]; // weak
extern char aHttp_cookie[12]; // weak
extern char aHttp_referer[13]; // weak
extern char aHttp_user_agen[16]; // weak
extern char aContent_length[15]; // weak
extern char aPost[5]; // weak
extern void *_progname; // weak
extern void *off_8049008; // weak
extern char aSAugustSHttp1_[90]; // weak
extern _UNKNOWN unk_804907C; // weak
extern int dword_8049180; // weak
extern int dword_8049190; // weak
extern char byte_80491E0; // weak
extern _UNKNOWN unk_80491E4; // weak
extern _UNKNOWN unk_8049200; // weak
extern int environ; // weak
//-------------------------------------------------------------------------
// Function declarations
int __cdecl init_proc();
int __stdcall connect(SOCKET s, const struct sockaddr *name, int namelen); // idb
int snprintf(_DWORD, _DWORD, const char *, ...); // weak
char *__cdecl getenv(const char *); // idb
int __cdecl __inet_addr(_DWORD); // weak
SOCKET __stdcall socket(int af, int type, int protocol); // idb
int __cdecl write(int, const void *, unsigned int); // idb
int __cdecl __deregister_frame_info(_DWORD); // weak
int __error(void); // weak
int __cdecl read(int, void *, unsigned int); // idb
int _init_tls(void); // weak
int __stdcall shutdown(SOCKET s, int how); // idb
int __cdecl atexit(void (__cdecl *)()); // idb
void __cdecl exit(int); // idb
int __cdecl __register_frame_info(_DWORD, _DWORD); // weak
int __cdecl close(int); // idb
void __fastcall start(int a1, void (__cdecl *a2)(), int a3); // idb
void __cdecl sub_80486E8();
int (__cdecl *__cdecl sub_804873C())(_DWORD, _DWORD);
int __cdecl sub_8048788(int a1);
signed int __cdecl sub_80487D4();
int __cdecl sub_8048A3C();
void __cdecl term_proc(); // idb
//----- (0804853C) --------------------------------------------------------
int __cdecl init_proc()
{
sub_804873C();
return sub_8048A3C();
}
//----- (08048658) --------------------------------------------------------
void __fastcall start(int a1, void (__cdecl *a2)(), int a3)
{
void (__cdecl *v3)(); // ecx@1
int i; // edx@3
int v5; // eax@10
int r; // [sp+1Ch] [bp+4h]@1
v3 = a2;
environ = (int)((char *)&a3 + r + 4);
if ( r > 0 )
{
if ( a3 )
{
_progname = (void *)a3;
for ( i = a3; *(_BYTE *)i; ++i )
{
if ( *(_BYTE *)i == 47 )
_progname = (void *)(i + 1);
}
}
}
atexit(v3);
atexit(term_proc);
init_proc();
v5 = sub_80487D4();
exit(v5);
}
//----- (080486E8) --------------------------------------------------------
void __cdecl sub_80486E8()
{
int (*i)(void); // eax@2
if ( !byte_80491E0 )
{
for ( i = *(int (**)(void))off_8049008; *(_DWORD *)off_8049008; i = *(int (**)(void))off_8049008 )
{
off_8049008 = (char *)off_8049008 + 4;
i();
}
if ( __deregister_frame_info )
__deregister_frame_info(&unk_804907C);
byte_80491E0 = 1;
}
}
//----- (0804873C) --------------------------------------------------------
int (__cdecl *__cdecl sub_804873C())(_DWORD, _DWORD)
{
int (__cdecl *result)(_DWORD, _DWORD); // eax@1
result = __register_frame_info;
if ( __register_frame_info )
result = (int (__cdecl *)(_DWORD, _DWORD))__register_frame_info(&unk_804907C, &unk_80491E4);
if ( dword_8049190 )
result = 0;
return result;
}
//----- (08048788) --------------------------------------------------------
int __cdecl sub_8048788(int a1)
{
int result; // eax@1
unsigned __int8 v2; // al@2
int v3; // edx@2
signed int v4; // ebx@2
char v5; // al@4
int i; // ecx@4
unsigned __int8 v7; // al@5
result = 0;
if ( !a1 )
return result;
v2 = *(_BYTE *)a1;
v3 = 0;
v4 = 0;
if ( *(_BYTE *)a1 == 45 )
{
v4 = -1;
goto LABEL_10;
}
if ( v2 == 43 )
{
LABEL_10:
i = a1 + 1;
v7 = *(_BYTE *)(a1 + 1);
goto LABEL_6;
}
v5 = v2 ^ 0x30;
for ( i = a1 + 1; v5 <= 9; ++i )
{
v3 = v5 + 10 * v3;
v7 = *(_BYTE *)i;
LABEL_6:
v5 = v7 ^ 0x30;
}
return (v4 ^ v3) - v4;
}
//----- (080487D4) --------------------------------------------------------
signed int __cdecl sub_80487D4()
{
signed int v0; // edx@1
unsigned int v1; // ebx@1
char *v2; // eax@3
char *v3; // edi@3
char *v4; // esi@3
signed int v5; // eax@4
char *v6; // ST24_4@4
signed int v7; // eax@5
signed int v8; // ST1C_4@5
char v9; // cf@6
unsigned __int8 v10; // zf@6
signed int v11; // ecx@6
char *v12; // edi@6
char *v13; // esi@6
void *v14; // edi@10
int v15; // ecx@11
int v16; // eax@12
int v17; // edx@12
int v19; // ST30_4@18
unsigned int v20; // esi@19
SOCKET v21; // eax@1
int v22; // eax@2
int v23; // eax@6
int v24; // eax@18
int v25; // eax@19
struct sockaddr name; // [sp+418h] [bp-28h]@2
char *v27; // [sp+24h] [bp-41Ch]@3
char *v28; // [sp+20h] [bp-420h]@3
char *v29; // [sp+1Ch] [bp-424h]@3
char *v30; // [sp+18h] [bp-428h]@3
int v31; // [sp+14h] [bp-42Ch]@3
char v32; // [sp+28h] [bp-418h]@10
v21 = socket(2, 1, 0);
v1 = v21;
v0 = 1;
if ( (signed int)v21 >= 0 )
{
memset(&name, 0, sizeof(name));
HIBYTE(name.sa_family) = 2;
*(_WORD *)&name.sa_data[0] = -28641;
*(_DWORD *)&name.sa_data[2] = __inet_addr("127.0.0.1");
v22 = connect(v1, &name, 16);
v0 = 1;
if ( v22 >= 0 )
{
v27 = getenv("REQUEST_METHOD");
v28 = getenv("REQUEST_URI");
v29 = getenv("HTTP_HOST");
v30 = getenv("HTTP_COOKIE");
v3 = getenv("HTTP_REFERER");
v4 = getenv("HTTP_USER_AGENT");
v2 = getenv("CONTENT_LENGTH");
v31 = (int)v2;
if ( !v2 )
v2 = "127.0.0.1" + 9;
v6 = v2;
v5 = (signed int)v3;
if ( !v3 )
v5 = 134515392;
v8 = v5;
v7 = (signed int)v30;
if ( !v30 )
v7 = 134515392;
v23 = snprintf(
&unk_8049200,
10000,
"%s /august%s HTTP/1.1\nHost: %s\nCookie: %s\nReferer: %s\nUser-Agent: %s\nContent-Length: %s\n\n",
v27,
v28 + 19,
v29,
v7,
v8,
v4,
v6);
write(v1, &unk_8049200, v23);
v12 = "POST";
v11 = 5;
v13 = v27;
do
{
if ( !v11 )
break;
v9 = *v13 < (unsigned __int8)*v12;
v10 = *v13++ == *v12++;
--v11;
}
while ( v10 );
v14 = &v32;
if ( !(v9 | v10) == v9 )
{
v24 = sub_8048788(v31);
v19 = v24;
if ( v24 > 0 )
{
while ( 1 )
{
v25 = read(0, &v32, 0x3E8u);
v20 = v25;
if ( v25 <= 0 )
{
if ( *(_DWORD *)__error() != 4 )
return 1;
}
else
{
while ( write(v1, &v32, v20) < 0 )
{
if ( *(_DWORD *)__error() != 4 )
return 1;
}
v19 -= v20;
}
if ( v19 <= 0 )
goto LABEL_11;
}
}
v14 = &v32;
}
LABEL_11:
shutdown(v1, 1);
do
{
while ( 1 )
{
v31 = v15;
v16 = read(v1, v14, 0x3E8u);
if ( v16 <= 0 )
break;
v31 = v17;
write(1, v14, v16);
}
}
while ( v16 && *(_DWORD *)__error() == 4 );
close(v1);
v0 = 0;
}
}
return v0;
}
//----- (08048A3C) --------------------------------------------------------
int __cdecl sub_8048A3C()
{
int *v0; // ebx@1
int result; // eax@2
v0 = &dword_8049180;
if ( dword_8049180 != -1 )
{
do
{
result = ((int (*)(void))*v0)();
--v0;
}
while ( *v0 != -1 );
}
return result;
}
//----- (08048A64) --------------------------------------------------------
void __cdecl term_proc()
{
sub_80486E8();
}