• Welcome to Valhalla Legends Archive.
 

[VB] BNET FTP

Started by Don Cullen, September 18, 2005, 08:43 PM

Previous topic - Next topic

Don Cullen

What exactly is Protocol Version? Banner ID? Banner extension? And how do I get the remote filetime? The reason why I'm trying to do this is because I want to be able to download icons.bni...

After reading the BNETFTP docs on BNETDocs, I'm still confused... Is this the proper sequence:

C -> S 0x02
C -> S:

(WORD)      Length of this message
(WORD)      Protocol Version
(DWORD)      Platform ID
(DWORD)      Product ID
(DWORD)      Banner ID
(DWORD)      BannerExtension

S -> C:

(DWORD)      Server Token

C -> S:

(DWORD)      Starting position (facilitates resuming)
(FILETIME)    Local filetime
(DWORD)      Client Token
(DWORD)      Key Length
(DWORD)      Key's product value
(DWORD)      Key's public value
(DWORD)      Unknown (Always 0)
(DWORD[5])   CD key data
(STRING)   Filename

If invalid key, server disconnects. If valid, then:

S -> C:

(DWORD)      Length of this message (not including file data)
(DWORD)      File size
(DWORD)      Banner ID
(DWORD)      Banner Extension
(FILETIME)   Remote Filetime
(STRING)   Filename

(VOID)      File data

-------------------------------------------

Thanks in advance for any assistance, and for reading this!
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

UserLoser.

banner id and extension come from SID_CHECKAD, protocol version = 2, iirc it says that on the page

Don Cullen

Ah alright, I don't want to download the banners, just want to download icons.bni... How would this be done?
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

UserLoser.

Quote from: Kyro on September 18, 2005, 09:00 PM
Ah alright, I don't want to download the banners, just want to download icons.bni... How would this be done?

First, try using the other protocol because using this one isn't necessary for icons.bni

Don Cullen

#4
I decided to just take a wild guess, and try experimenting to see if I could figure it out. Still couldn't. Could you guys be so kind as to take a gander at my code, and point out any errors?

The following code is in my bnetftp module. The bnetftp socket passes along events and data to this module. This stuff is mainly for just downloading icons.bni.


Public Sub FTPDownload(Data As String, Optional Completed As Boolean = False)
    Static DownloadBuffer As String
    Dim HeaderLen As Long
    Dim Unknown As Long
    Dim FileSize As Long
    Dim RemoteFileTime As Long
    Dim FileName As String
    Dim FileData As String
    Dim Trash As Long, Trash2 As String
    If Completed = False Then
        AddC vbWhite, "Downloading..."
        DownloadBuffer = DownloadBuffer & Data
    Else
        AddC vbWhite, "Download Complete. Extracting file..."
        FTPDeBuf.SetData DownloadBuffer
        HeaderLen = FTPDeBuf.rWORD
        Unknown = FTPDeBuf.rWORD
        FileSize = FTPDeBuf.rDWORD
        Trash = FTPDeBuf.rDWORD     'Banners ID
        Trash = FTPDeBuf.rDWORD     'Banners File Extension
        Trash2 = FTPDeBuf.rFILETIME 'Remote filetime
        FileName = FTPDeBuf.rNTString
        Open FileName For Output As #1
            Print #1, FTPDeBuf.GetData
        Close
        If FileLen(FileName) = FileSize Then
            AddC vbGreen, "Extract Success!"
        Else
            Kill FileName
            AddC vbRed, "Extract Failure!"
            AddC vbRed, "Data Dump: "
            AddC vbRed, "-----------"
            AddC vbRed, "FileName: " & FileName
            AddC vbRed, "Downloaded File size is " & FileLen(File) & " bytes."
            AddC vbRed, "Server stated the file size would be " & FileSize & "."
        End If
    End If
End Sub

Public Sub FTPConnected()
    AddC vbWhite, "Connected to FTP! Sending request..."
    DMBot.bftp.SendData &H2     'Protocol: bnFTP
    With FTPBuf
        .Clear
        .InsertDWORD &H1
        .InsertDWORD CLng("&H" & Replace(StrToHex("IX86"), " ", vbNullString)) 'IX86
        .InsertDWORD CLng("&H" & Replace(StrToHex(BNETClient), " ", vbNullString)) 'SEXP
        .InsertDWORD &H0    'Banners ID
        .InsertDWORD &H0    'Bannkers File Extension
        .InsertDWORD &H0    'Start position in file (for resuming)
        .InsertDWORD &H0    'Filetime of local file
        .InsertNTString "icons.bni"
        .SendPacket DMBot.bftp, , 2
    End With
End Sub

Public Sub FTPConnect()
    AddC vbWhite, "Connecting to BNET FTP..."
    DMBot.bftp.RemoteHost = BNETServer
    DMBot.bftp.RemotePort = BNETPort
    If DMBot.bftp.State = sckConnected Then
        DMBot.bftp.Close
    End If
    DMBot.bftp.Connect
End Sub


Thanks in advance for any tips!
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Don Cullen

Using a packet logger, I was able to see the differences between Arta's BNFTP program, and mine. When I compare the packet to the bnetdoc bnftp protocol, it doesn't match. I'm trying to make sense of it, but I'm having a hard time. Here's the packets I logged from both my bot and Arta's BNFTP program. Keep in mind, Arta's is working, and mine isn't working.

DMBot

02 04 05 B4 01 01 04 02          | ...'....         
02 00 28 00 01 00 00 00 36 38 58 | ..(.....68X
49 4C 54 52 44 00 00 00 00 00 00 | ILTRD......
00 00 01 00 00 00 00 00 00 00 69 | ..........i
63 6F 6E 73 2E 62 6E 69 00       | cons.bni.


BNFTP CL Prog

02 04 05 B4 01 01 04 02          | ...'....         
02 2A 00 00 01 36 38 58 49 4C 54 | .*...68XILT
52 44 00 00 00 00 00 00 00 00 00 | RD.........
00 00 00 00 00 00 00 00 00 00 00 | ...........
69 63 6F 6E 73 2E 62 6E 69 00    | icons.bni.


From what I can see, I got this bit wrong:

00 28 00 01 00 00 00

where it should be:

2A 00 00 01

What am I doing wrong? And also, what does DRTL mean? I know that part is the product id, but for which game? I'm guessing d2lod?
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Arta


Don Cullen

Already am, upon an earlier suggestion. This is my current code:

Public Sub FTPConnected()
    AddC vbWhite, "Connected to FTP! Sending request..."
    AddC vbWhite, BNETClient
    DMBot.bftp.SendData &H2     'Protocol: bnFTP
    With FTPBuf
        .Clear
        .InsertDWORD &H1
        .InsertDWORD CLng("&H" & Replace(StrToHex("IX86"), " ", vbNullString)) 'IX86
        .InsertDWORD CLng("&H" & Replace(StrToHex("DRTL"), " ", vbNullString)) 'SEXP
        .InsertDWORD &H0    'Banners ID
        .InsertDWORD &H0    'Bannkers File Extension
        .InsertDWORD &H1    'Start position in file (for resuming)
        .InsertDWORD &H0    'Filetime of local file
        .InsertNTString "icons.bni"
        .SendPacket DMBot.bftp, , 2
    End With
    AddC vbWhite, "File request sent."
End Sub


And also I noticed you used DRTL-- whereas before I used SEXP- I changed mine to DRTL, but I don't think that makes much difference since it's just product ID-- what is DRTL?
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Arta

Diablo Retail.

Your version is wrong:

Quote
Version 1 of bnFTP actually has a version of 0x100 (256). It seems likely that it was originally coded with the bytes in the wrong order (in the message, 00 10 instead of 01 00).

Also, it should be a WORD, not a DWORD. Your message length looks wrong too, but your message log is hard to read, so I didn't check. I assume '.SendPacket' is setting the length in the message?

Don Cullen

#9
Yea, using .SendPacket. Here's code for that:

Public Function SendPacket(sck As Winsock, Optional PacketID As Long, Optional mode As Integer = 1) As Boolean
    If sck.State = sckConnected Then
        If mode = 1 Then    'Game mode
            sck.SendData Chr(&HFF) & Chr(PacketID) & MakeWORD(Len(Buffer) + 4) & Buffer
        ElseIf mode = 2 Then 'bnFTP mode
            sck.SendData MakeWORD(Len(Buffer) + 2) & Buffer
            AddC vbCyan, "BNFTP Packet Sent! Packet: " & MakeWORD(Len(Buffer) + 2) & Buffer
        End If
        SendPacket = True
    End If
    Clear
End Function


And I fixed version, changed version from dword to word. Here's new code:

Public Sub FTPConnected()
    AddC vbWhite, "Connected to FTP! Sending request..."
    AddC vbWhite, BNETClient
    DMBot.bftp.SendData &H2     'Protocol: bnFTP
    With FTPBuf
        .Clear
        .InsertWORD &H100
        .InsertDWORD CLng("&H" & Replace(StrToHex("IX86"), " ", vbNullString)) 'IX86
        .InsertDWORD CLng("&H" & Replace(StrToHex("DRTL"), " ", vbNullString)) 'SEXP
        .InsertDWORD &H0    'Banners ID
        .InsertDWORD &H0    'Bannkers File Extension
        .InsertDWORD &H1    'Start position in file (for resuming)
        .InsertDWORD &H0    'Filetime of local file
        .InsertNTString "icons.bni"
        .SendPacket DMBot.bftp, , 2
    End With
    AddC vbWhite, "File request sent."
End Sub


I packet logged it to see if it was finally right-- wasn't. I think I'm messing up somewhere- most likely in the packet length, but I'm not sure.

C -> S  02 04 05 B4 01 01 04 02                 | ...'....
S -> C  02 04 05 AC 01 01 04 02                 | ...¬....
C -> S  02 00 28 00 00 01 00 00 36 38 58        | ..(.....68X
C -> S  49 4C 54 52 44 00 00 00 00 00 00        | ILTRD......
C -> S  00 00 01 00 00 00 00 00 00 00 69        | ..........i
C -> S  63 6F 6E 73 2E 62 6E 69 00              | cons.bni.


Hmmm... Definitely gotta be the packet length. But I assumed MakeWORD(Len(Buffer) + 2) & Buffer would be sufficent-- or is the packet length byte NOT included in the packet length when getting packet length? A second, let me experiment with that by changing it to MakeWORD(Len(Buffer)) & Buffer...

C -> S  02 04 05 B4 01 01 04 02                 | ...'....
S -> C  02 04 05 AC 01 01 04 02                 | ...¬....
C -> S  02 00 26 00 00 01 00 00 36 38 58        | ..&.....68X
C -> S  49 4C 54 52 44 00 00 00 00 00 00        | ILTRD......
C -> S  00 00 01 00 00 00 00 00 00 00 69        | ..........i
C -> S  63 6F 6E 73 2E 62 6E 69 00              | cons.bni.


Nope, didn't work, it's not giving the same packet as your bnftp program. Any ideas?

[Edited to have hex display correctly]
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Arta

Your length is wrong. It does include the length byte. Everything from the length byte to the end of the filename, including the null terminator.

Don Cullen

Duh me! I completely forgot to count the null terminator! In any case, it's outputting data almost exactly as your program, except it's one byte off:

  02 00 2A 00 00 01 00 00 36 38 58 | ..*.....68X
  49 4C 54 52 44 00 00 00 00 00 00 | ILTRD......
  00 00 01 00 00 00 00 00 00 00 69 | ..........i
  63 6F 6E 73 2E 62 6E 69 00 00 00 | cons.bni...


Should be 02 2A, not 02 00 2A...

I added:

DMBot.bftp.SendData &H0

to the end of the FTPConnected() sub, to act as null terminator for that packet. I also modified the line in SendPacket to send this instead:

sck.SendData MakeWORD(Len(Buffer) + 4) & Buffer

So close.......
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Arta

You have two extra 00s between the version and the platform id as well. (Are you sure " DMBot.bftp.SendData &H2" inserts a byte?)This looks weird too:

Quote
sck.SendData MakeWORD(Len(Buffer) + 4) & Buffer

Why +4?

Other than that, I can't see anything wrong. As you make your changes, you should check the message log against BnetDocs. It shouldn't be too hard to identify errors! Just look for missing or extra bytes - ones that don't conform to the message spec.

Don Cullen

Ah, I didn't notice those extra zero'es... I'll have to look into that. No, DMBot.SendData &H2 just sends that byte directly- it doesn't bother adding to the buffer. In other words, that byte is sent by itself.

The +4 is to also include the bytes of the null terminator, and the packet length. I've confirmed I've gotten the packet length down since it matches yours now. I think it has something to do with how my PacketBuffer class works with WORDs, either that, or there's something else I'm missing. When I get home, I'm gunna put in debug code to show me what exactly is going on in the buffer, maybe I can pinpoint where it's bugging.

Also I found VB source code on PSC for a packet sniffer, but I don't know if that'd be of any use to you since Etheral's already good enough? I tried using Etheral, I couldn't figure out the filter thing so I just went to PSC, downloaded the packet sniffer I found, and it pretty much serves the same purpose, for much less file space. Limited features though.
Regards,
Don
-------

Don't wonder why people suddenly are hostile when you treat them the way they shouldn't be- it's called 'Mutual Respect'.

Arta

Ethereal is better. Learn to use it.

The message length plus nullterm is 3 bytes, not 4 - might want to change that.