/*
							Super Simple Login - Version 1.0
									Created By
										-	FTProtocol
*/

#include <iostream>
#include "connect.h"
using namespace std;

char* cookies;

int exec_gunz()
{
	char* buffer = (char*)malloc(120000);
	char *path = (char*)malloc(256); 

	initialize_winsock();	
	
	memset(path,0,256);
	strcpy(path,"/common/prelaunch.nhn?gameId=u_gunz&subId=");

	connection conn = connect_to_server("gunz.ijji.com",80);
	http_get(conn,"gunz.ijji.com",path,NULL,NULL);
	
	memset(buffer,0,120000);
	rrecv(conn,buffer,120000);

    cookies = http_getcookies(buffer);

	endconnection(conn);
	free(buffer);

  return 0;
}

int login()
{
	char username[256]={0};
	char password[256]={0};
	int game;
	char *login = (char*)malloc(256); 
	char* buffer = (char*)malloc(120000);

	printf("\n Enter your username: ");
		gets(username);
	printf("\n Enter your password: ");
		gets(password);

	initialize_winsock();	

	memset(login,0,256);
	strcpy(login,"/login.nhn?m=login");
	strcat(login,"&memberid=");
	strcat(login,username);
	strcat(login,"&password=");
	strcat(login,password);

	connection conn = connect_to_server("login.ijji.com",80);
	http_get(conn,"login.ijji.com",login,NULL,NULL);

	memset(buffer,0,120000);
	rrecv(conn,buffer,120000);

    cookies = http_getcookies(buffer);

	endconnection(conn);
	free(login);
	free(buffer);

	system("cls");
	printf("\n Please select your game");
	printf("\n -------------------------");
	printf("\n Games:");
	printf("\n\n 1. Gunz");
	printf("\n\n Select a game: ");
	scanf("%i",&game);

		switch(game)
		{
		case 1 :
			exec_gunz();
			break;
		default :
			printf("\n Invalid Game!");
			break;
		}

	return 0;
}

int main()
{
	printf("\n NOTATROJAN - Version 1.0");
	printf("\n   -  By FTProtocol");

	system("cls");
	login();

	return 0;
}

ok after speaking to a friend who is very advanced in c++ he gave me his own socket file and im currently using that ( just improved version of winsock )

Now the problem is, it wont launch the game if the cookie from the login doesnt match the cookie from the launch game request. And i think thats whats doing on so please help!

Recommended Answers

All 11 Replies

1. what's wrong with winsock, that you need some secret socket library? and i doubt VERY SERIOUSLY that it's "improved" in any way. At best, it will be equivalent. more likely it will be a level of abstraction from winsock that just adds overhead, and probably unintended bugs.

2. system("cls") --- that's just horrid practice.

3. gets ... who taught you to do that? don't listen to that person any more.


2 and 3 are evidence of sloppy, poor programming, but #1 is a big deal. you're not going to get very far with having people help you debug as long as you're doing sketchy stuff like that. lf you're going to be "FTP protocol" then you better learn how to use winsock for yourself and not rely on some suspicious secret library. i don't care if your friend is a genius.


.

1. what's wrong with winsock, that you need some secret socket library? and i doubt VERY SERIOUSLY that it's "improved" in any way. At best, it will be equivalent. more likely it will be a level of abstraction from winsock that just adds overhead, and probably unintended bugs.

2. system("cls") --- that's just horrid practice.

3. gets ... who taught you to do that? don't listen to that person any more.


2 and 3 are evidence of sloppy, poor programming, but #1 is a big deal. you're not going to get very far with having people help you debug as long as you're doing sketchy stuff like that. lf you're going to be "FTP protocol" then you better learn how to use winsock for yourself and not rely on some suspicious secret library. i don't care if your friend is a genius.


.

everything i've learnt, ive learnt myself.

/*
	socket.h - coded in C
	by: Robotnik / 12ob0t

	www.b0ts.org

	functions:
	connect_to_server() - connects to a server
	connect_with_proxy() - connects to a server with a specified proxy
	ssend() - faster version of send
	rrecv() - faster version of recv
	endconnection() - end a connection
	
	http_get() - GET request in HTTP protocol
	http_post() - POST request in HTTP protocol
	http_getcookies() - gets the cookie from a recieved buffer
*/

#include <winsock2.h>
#include <stdio.h>

#pragma comment(lib,"ws2_32.lib")
#define skt SOCKET

typedef struct connection
{
	sockaddr_in address;
	skt socket;
	struct hostent *host;
	bool isconnected;
}connection;

	
WSADATA wsa_data;

int initialize_winsock()
{
	int data = 1;

#ifdef WIN32
	data = WSAStartup(MAKEWORD(2,2),&wsa_data);
#endif
	if(data != 0)
		return 0;

	return 1;
}

connection connect_to_server(char* ip,int port)
{
	connection conn;
	sockaddr_in address;
	hostent *host;
	skt sock;
	int i = 0;

	host = gethostbyname(ip);
	address.sin_family = AF_INET;	
	address.sin_addr = *(struct in_addr *)host->h_addr;
	address.sin_port = htons(port);
	sock = socket(AF_INET,SOCK_STREAM,0);
	i = connect(sock,(SOCKADDR *)&address,sizeof(address));

	if(i != 0)
	{
		conn.isconnected = false;
		conn.socket = NULL;
		conn.address = address;
		conn.host = NULL;
	}
	else
	{
		conn.isconnected = true;
		conn.socket = sock;
		conn.address = address;
		conn.host = host;
	}

	return conn;
}

connection connect_with_proxy(char* ip, int port, char* proxyip, int proxyport)
{
	connection conn;
	char* proxbuffer = (char*)malloc(1024);
	int i = 0;

	conn = connect_to_server(proxyip,proxyport);

	if(conn.isconnected == false)
		return conn;

	memset(proxbuffer,0,1024);
	sprintf(proxbuffer,"CONNECT %s:%d HTTP/1.1\r\n\r\n",ip,port);
	send(conn.socket,proxbuffer,strlen(proxbuffer),0);

	i = recv(conn.socket,proxbuffer,1024,0);

	free(proxbuffer);

	if(i <= 0)
	{
		conn.isconnected = false;
		return conn;
	}

	return conn;
}

int ssend(connection conn,char* buffer)
{
	return send(conn.socket,buffer,strlen(buffer),0);
}

int rrecv(connection conn, char* buffer, int len)
{
	return recv(conn.socket,buffer,len,0);
}

void endconnection(connection conn)
{
	closesocket(conn.socket);
}

int http_get(connection conn,char* host,char* path,char* cookies,char* referer)
{
	int i = 0;
	char* string = (char*)malloc(1024);
	memset(string,0,1024);

	sprintf(string,
			"GET %s " 
			"HTTP/1.1\r\n"
			"Host: %s\r\n"
			"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3\r\n"
			"Keep-Alive: 300\r\n"
			"Connection: keep-alive\r\n"
			,path
			,host
		);

	if (referer)
	{
		strcat(string,"Referer: ");
		strcat(string,referer);
		strcat(string,"\r\n");
	}

	if (cookies)
	{
		strcat(string,"Cookie: ");
		strcat(string,cookies);
		strcat(string,"\r\n");
	}

	strcat(string,"\r\n");

	i = ssend(conn,string);

	free(string);

	return i;
}

int http_post(connection conn,char* host,char* path,char* data,char* cookies,char* referer)
{
	int i = 0;
	char* string = (char*)malloc(1024);
	memset(string,0,1024);

	sprintf(string,
			"POST %s "
			"HTTP/1.1\r\n"
			"Host: %s\r\n"
			"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3\r\n"
			"Referer: %s\r\n"
			"Keep-Alive: 300\r\n"
			"Connection: keep-alive\r\n",path,host,referer);

	if(cookies)
	{
		strcat(string,"Cookie: ");
		strcat(string,cookies);
		strcat(string,"\r\n");
	}

	char *s1 = "Content-Type: application/x-www-form-urlencoded\r\n";
	char *s2 = (char*)malloc(128);

	memset(s2,0,128);
	sprintf(s2,"Content-Length: %i\r\n\r\n",strlen(data));

	if(conn.socket)
	{
		ssend(conn,string);
		ssend(conn,s1);
		ssend(conn,s2);
		ssend(conn,data);
		free(s2);
		free(string);
		return 1;
	}

	free(s2);
	free(string);

	return 0;
}

char* http_getcookies(char* buffer)
{
	char* cookies = strstr(buffer,"Set-Cookie:");

	if(cookies)
	{
		char* cookie = (char*)malloc(2024);
		memset(cookie,0,2024);
		
		while(strstr(cookies,"Set-Cookie:"))
		{
			cookies = strstr(cookies,"Set-Cookie:");
			cookies += strlen("Set-Cookie:");
			*cookies++;
			
			strncat(cookie,cookies,strstr(cookies,";")-cookies);

			if(strstr(cookies,"Set-Cookie:"))
				strcat(cookie,"; ");
		}

		return cookie;
	}
	else
	{
		return NULL;
	}

	return NULL;
}

i believe it better than winsock so i really dont care.
So can you help or not?

>>i believe it better than winsock so i really dont care.
No it isn't -- the code you posted IS using winsock, it does not replace it. There is nothing wrong with using libraries that make your life a little easier, all programmers do that.

>>everything i've learnt, ive learnt myself.
Admiral achievement, but it will take you years to unlearn all the terrible code examples that you find on the net and in many very old books.

Here are a few links you should read. Scroll down and you will find links to other very helpful pages.

>>So can you help or not?
No.

ok, i've re-thought this whole plan.

I've been trying to use CreateProcess() and hide the window, ive manage to get it to open calc.exe now is there a way to hide this window?

because when using shellexecute it doesnt hide the firefox window, why is this?

>>now is there a way to hide this window
Yes -- CreateProcess() has a parameter that does that. See the STARTUPINFO structure.

PROCESS_INFORMATION info;
	STARTUPINFO startup;
	memset(&startup, 0, sizeof(startup)) ;
	memset(&info, 0, sizeof(info)) ;
	startup.cb = sizeof(startup);
	startup.wShowWindow = SW_HIDE;

/*	printf("\n Enter your username: ");
		gets(username);
	printf("\n Enter your password: ");
		gets(password);*/

	sprintf(buffer,"calc.exe",NULL,NULL);	
		
	CreateProcess(NULL,buffer, NULL, NULL, FALSE, 0, NULL, NULL, &startup, &info);

Im really not sure why but it doesn't hide the window, i checked everything i could see but i think i've still done something wrong.

any ideas? :(

Sorry if im being a pain and asking too many questions :(

Im really not sure why but it doesn't hide the window, i checked everything i could see but i think i've still done something wrong.
any ideas? :(

Use the STARTF_USESHOWWINDOW flag ...

PROCESS_INFORMATION info;
	STARTUPINFO startup;
	memset(&startup, 0, sizeof(startup)) ;
	memset(&info, 0, sizeof(info)) ;
	startup.cb = sizeof(startup);
	startup.wShowWindow = SW_HIDE;
        [B]startup.dwFlags |= STARTF_USESHOWWINDOW;[/B]
        // ...

that still doesn't hide the calculator window. I really dont understand this lol xD

you also have to specify dwFlags member of that structure startup.dwFlags = STARTF_USESHOWWINDOW; Read the description in MSDN instead of blindly trying to use something you know nothing about.

thats what i did read lol, i must have missed it :(

Sometimes you have to read MSDN a million times before fully comprehending it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.