Luigi Auriemma

aluigi.org (ARCHIVE-ONLY FORUM!)
It is currently 19 Jul 2012 19:41

All times are UTC [ DST ]





Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 40 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: 07 Jan 2008 18:34 

Joined: 21 Dec 2007 04:27
Posts: 16
Forget the "enctype2_decoder", ad the sample Luigi attached:

Code:
int enctype2_wrapper(unsigned char *key, unsigned char *data, int size) {
    unsigned char   *p;

    p = enctype2_decoder(key, data, &size);
    memmove(data, p, size);
    return(size);
}


To enctype2_decoder.c then compile the dll again, now instead of "enctype2_decoder" you use "enctype2_wrapper" the return value shall be an integer (the buffer size) like so:

Code:
[DllImport("enctype2_decoder.dll")]
public static extern int enctype2_wrapper(byte[] key, byte[] data, int size);


Now the data should be decoded and the return value for this function should be the new size of it.



Luigi, Thanks for your help, finally it works! 4377 servers correcly decoded. The problem was Chr(0) & Chr(1) that had to be replaced with " ".


Top
 Profile  
 
 
 Post subject:
PostPosted: 07 Jan 2008 20:27 

Joined: 02 Jan 2008 19:34
Posts: 12
Revolty wrote:
To enctype2_decoder.c then compile the dll again, now instead of "enctype2_decoder" you use "enctype2_wrapper" the return value shall be an integer (the buffer size) like so:


Yeah I understand that, but it seems you didn't get my problem.

The encrypted serverdata is stored in a bytearray in this C .dll. How can I read this array from my program?


Top
 Profile  
 
 Post subject:
PostPosted: 07 Jan 2008 20:48 

Joined: 21 Dec 2007 04:27
Posts: 16
Avatar wrote:
Revolty wrote:
To enctype2_decoder.c then compile the dll again, now instead of "enctype2_decoder" you use "enctype2_wrapper" the return value shall be an integer (the buffer size) like so:


Yeah I understand that, but it seems you didn't get my problem.

The encrypted serverdata is stored in a bytearray in this C .dll. How can I read this array from my program?

No.
When you call "enctype2_decoder" or "enctype2_wrapper" you need to specefie the "key" (aka gamekey or handoff), then the decoded tcp packet received by gamespy (as data array) and the length. After you run the function, the decoded packet has beeing modefied (encoded).

So there is no "new" array its the same as you used as your "byte[] data"


Top
 Profile  
 
 Post subject:
PostPosted: 07 Jan 2008 21:10 

Joined: 02 Jan 2008 19:34
Posts: 12
I am confused :)

I thought I talk to the gamespy masterserver, then I get a challenge key. I ecrypt this key using your vb.net implementation. with this new decrypted key, I can ask for the serverlist.

I want to ue the decrypt function for this encrypted serverlist from the imported .dll, but I can get the real return value. I tried byte[] and string, both doesn't work. Since it *must* be a byte array, I cant use any funtion which is returning an integer.


Top
 Profile  
 
 Post subject:
PostPosted: 07 Jan 2008 21:43 

Joined: 21 Dec 2007 04:27
Posts: 16
Avatar wrote:
I am confused :)

I thought I talk to the gamespy masterserver, then I get a challenge key. I ecrypt this key using your vb.net implementation. with this new decrypted key, I can ask for the serverlist.


Yes thats correct, but you get the server list decrypted, the encryption is beeing done at your computer.
You open connection, gamespy send you a "Secure key", you encrypt that key and get a "valid", now you send a new packet that include the valid key, the response will be a decrypted server list, at this point you send it for encryption.

Here is my full code, obviusly you cant use it in C but you might get an idea how its done, you can use the same "challange" and "gamekey".

Code:
Imports System.Text
Imports System.IO
Imports System.Net.Sockets

Public Class GameSpy

    '//Secure Key Encryption
    Dim sA As New gsmalg2

    '//Serverlist Encryption
    Declare Ansi Function Encode Lib "C:\enctype2_decoder.dll" Alias "enctype2_wrapper" _
    (ByVal gamekey() As Byte, ByVal buffer() As Byte, ByVal len As Integer) As Integer

    Private Sub cb_ReceiveServers_click(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles cb_ReceiveServers.Click

        Dim TcpClient As New TcpClient()
        Dim HandShake(22) As Byte
        Lb_Servers.Items.Clear()

        TcpClient.Connect("207.38.11.34", 28900)
        Dim Reader As New StreamReader(TcpClient.GetStream, Encoding.Default, False)

        '//Open Conection, Receive Secure key & Encode
        TcpClient.GetStream.Read(HandShake, 0, 21)
        Dim Valid As String = sA.Valid(Encoding.Default.GetString(HandShake).Substring(15, 6))

        '//Send Challange
        Dim Challange() As Byte = createPacket(Valid, "", True)
        TcpClient.GetStream.Write(Challange, 0, Challange.Length)

        '//Receive Packet
        Dim Data() As Byte = Encoding.Default.GetBytes(Reader.ReadToEnd.Replace(Chr(0), " ").Replace(Chr(1), " ").Trim)
        TcpClient.GetStream.Close()

        '//enctype2_wrapper!
        Dim Key() As Byte = Encoding.Default.GetBytes("d4kZca"), _
        Length As Integer = Encode(Key, Data, Data.Length), _
        S As String = Encoding.Default.GetChars(Data)

        '//IP & Port's to Lisbox (-7 Becouse of "\final" at end)
        For i As Integer = 0 To Length - 7 Step 6
            Lb_Servers.Items.Add( _
            Asc(S(i)) & "." & Asc(S(i + 1)) & "." & Asc(S(i + 2)) & "." & Asc(S(i + 3)) & ":" & Asc(S(i + 4)) * 256 + Asc(S(i + 5)))
        Next

        Me.Text = "Server IP:s ( " & Lb_Servers.Items.Count & " )"

    End Sub

    Public Function createPacket _
    (ByVal Valid As String, Optional ByVal Filter As String = "", Optional ByVal Compressed As Boolean = True) As Byte()

        createPacket = Encoding.Default.GetBytes( _
        "\gamename\gamespy2\gamever\20603020\enctype\2\validate" & Valid & _
        "\final\list" & IIf(Compressed = True, "cmp", "") & _
        "\gamename\battlefield2" & IIf(Len(Filter) > 0, "\where" & Filter, "") & "\final")
    End Function

End Class


Last edited by Revolty on 07 Jan 2008 22:30, edited 4 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: 07 Jan 2008 21:51 

Joined: 02 Jan 2008 19:34
Posts: 12
Thanks for the code, I gonna read it tomorrow. I could make a managed .dll and import it to my program or I convert it to C#. Let you know if it worked tomorrow.


Top
 Profile  
 
 Post subject:
PostPosted: 21 Feb 2008 18:13 

Joined: 08 Oct 2007 22:03
Posts: 11
dude, have you tried to add filters to that query? i mean, on gslist i can pu something like numplayers > 0, how can you do send that kind of info to the gamespy server so it only returns you the filtered servers?


Top
 Profile  
 
 Post subject:
PostPosted: 21 Feb 2008 18:37 

Joined: 13 Aug 2007 21:44
Posts: 4068
Location: http://aluigi.org
Add the \where\ field like in the following example:
\gamename\gamespy2\gamever\20603020\enctype\1\validate\/Px3\final\\list\cmp\gamename\wot\where\(numplayers > 0)


Top
 Profile  
 
 Post subject:
PostPosted: 21 Feb 2008 20:48 

Joined: 08 Oct 2007 22:03
Posts: 11
cool, ok now i have some C code, C# code, vb.net code, and lots of php code i have gattered from around the net, and try to make something that works with that... thanks for the help


Top
 Profile  
 
 Post subject: Re: Algorithm works, but no love from GS.
PostPosted: 31 Jul 2009 08:56 

Joined: 03 Oct 2008 00:52
Posts: 3
Edit: screw it ill jsut port enctype2


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 40 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: