Created
October 15, 2011 12:44
-
-
Save anonymous/1289515 to your computer and use it in GitHub Desktop.
Problem z GG
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
-module (erlgg). | |
-export ([start/0]). | |
-define (PRINT (What), io:format("~p\n", [What])). | |
start() -> | |
Addr = "http://appmsg.gadu-gadu.pl/appsvc/appmsg_ver8.asp?fmnumber=8&version=10.0.0.10450", | |
{ok, {_, _, Content}} = httpc:request(Addr), | |
[_, _, Server, _] = string:tokens(Content, " "), | |
[Ip, Port] = string:tokens(Server, ":"), | |
{ok, Sock} = gen_tcp:connect(Ip, list_to_integer(Port), [binary]), | |
receive | |
{tcp, Sock, <<Type:32/little-integer, Size:32/little-integer, Seed:32/little-integer>>} -> | |
io:format("IP: ~s:~s\n", [Ip, Port]), | |
io:format("Type: ~.16X Size: ~B Seed: ~p\n", [Type, "0x", Size, Seed]), | |
Seed | |
end, | |
Number = 123456789, % tu wpisac nr, na ktory chce sie zalogowac | |
Hash = hash(Seed), | |
GGLogin = <<Number:32/little-integer, % gg number | |
"pl"/little, % language | |
2/little, % hash type - SHA1 | |
Hash/little-binary, % hash string - 20 bytes | |
0:44/little-integer-unit:8, % filling to 64 bytes with 0 | |
2:32/little-integer, % status - available | |
0:32/little-integer, % flag | |
7:32/little-integer, % features - minimum (0x00000007) | |
0:12/little-integer-unit:8, % unused options, filling with 0 | |
0/little, % max accepted image size (in kBytes) | |
16#64/little, % unknown | |
35:32/little-integer, % version string length | |
"Gadu-Gadu Client build 10.0.0.10450"/little, | |
0:32/little-integer>>, % description string size | |
GGLoginSize = size(GGLogin), | |
GGSendLogin = <<16#31:32/little-integer, GGLoginSize:32/little-integer, GGLogin/little-binary>>, | |
ok = gen_tcp:send(Sock, GGSendLogin), | |
receive | |
%% login successful | |
{tcp, Sock, <<16#35:32/little-integer, Unknown/little-binary>>} -> | |
io:format("Udalo sie zalogowac, unknown: ~p\n", [Unknown]); | |
%% login failed - modern client | |
{tcp, Sock, <<16#42:32/little-integer, Unknown/little-binary>>} -> | |
io:format("Blad logowania, unknown: ~p\n", [Unknown]); | |
%% login failed - old client | |
{tcp, Sock, <<9:32/little-integer, Unknown/little-binary>>} -> | |
io:format("Blad logowania - starszy klient, unknown: ~p\n", [Unknown]); | |
{tcp_closed, Sock} -> | |
io:format("Zamknieto socket: ~p\n", [Sock]) | |
end, | |
%% client has logged in, sending test message | |
Recipent = 38632087, | |
TimeStamp = unix_timestamp(), | |
Msg = <<"Hello from Erlang !\0">>, | |
MsgSize = size(Msg), | |
GGSendMsg = <<Recipent:32/little-integer, % message recipent number | |
TimeStamp:32/little-integer, % UNIX timestamp | |
16#8:32/little-integer, % message class (default 0x8) | |
5:32/little-integer, % plain msg offset | |
1:32/little-integer, % html msg offset | |
"\0"/little, % html msg (empty string) | |
Msg/little-binary, % plain msg string | |
"\0\0\0">>, % attributes | |
GGSendMsgSize = size(GGSendMsg), | |
GGSend = <<16#2d:32/little-integer, GGSendMsgSize:32/little-integer, GGSendMsg/little-binary>>, | |
ok = gen_tcp:send(Sock, GGSend), | |
ok = gen_tcp:send(Sock, <<8:32/little-integer, 0:32/little-integer>>), | |
receive | |
{tcp, Sock, Cos} -> Cos; | |
Chuj -> Chuj | |
end. | |
hash(Seed) -> | |
Pass = <<"haslo">>, % tu wpisac haslo | |
BinString = <<Pass/little-binary, Seed:32/little-integer>>, | |
String = binary_to_list(BinString), | |
sha1:binstring(String). % funkcja do liczenia SHA1, z biblioteki | |
unix_timestamp() -> | |
{MegaSecs, Secs, _} = now(), | |
MegaSecs * 1000000 + Secs. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment