Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: Archangel on May 18, 2006, 10:05 PM

Title: 0x51 Help using BNCSUtil
Post by: Archangel on May 18, 2006, 10:05 PM
Since, i always get the same response and i havnt programmed a bot since 05 i need some help, i know.. i have tried.

Edit: Response i got "0x200: Invalid CD key" and yes its a valid cd-key.


Private Sub BNCS_SID_Auth_Check(lngLogonType As Long, strMPQNumber As String, lngServerToken As Long, strChecksumFormula As String)
    AddChat frmMain.rtbChat, vbYellow, "Sending Sid_Auth_Check (0x51)."
   
    Dim lngNewMPQNumber As Long
    Dim HashFiles(2) As String
    Dim lngChecksum As Long
    Dim lngEXEVersion As Long
    Dim lngDecoder As Long
    Dim strKeyHash As String
    Dim lngHashLength As Long
    Dim strExeInfo As String
   
    lngNewMPQNumber = extractMPQNumber(strMPQNumber)
   
    If (lngNewMPQNumber < 0) Then
        DisconnectBNCS
        AddChat frmMain.rtbChat, vbRed, "Unrecognized MPQ number."
        Exit Sub
    End If
   
    GetHashFiles HashFiles
   
    If (checkRevision(strChecksumFormula, HashFiles(0), HashFiles(1), _
    HashFiles(2), lngNewMPQNumber, lngChecksum) = False) Then
        DisconnectBNCS
        AddChat frmMain.rtbChat, vbRed, "Error: CheckRevision failed."
        Exit Sub
    End If
   
    lngEXEVersion = getExeInfo(HashFiles(0), strExeInfo)
    If (lngEXEVersion = 0) Then
        DisconnectBNCS
        AddChat frmMain.rtbChat, vbRed, "Error: Failed to get executable hash file information."
        Exit Sub
    End If
   
    Dim Buffer As New clsPacketBuffer
    Set Buffer = New clsPacketBuffer
       
        With Buffer
            .iDWORD Cfg.lngClientToken     'Client token
            .iDWORD lngEXEVersion          'EXE Version
            .iDWORD lngChecksum            'EXE Hash
            .iDWORD &H1                    'Number of keys
            .iDWORD &H0                    'Boolean Spawn Cd-Key
           
        lngDecoder = kd_create(Cfg.strCdKey, Len(Cfg.strCdKey))
        If (lngDecoder = -1) Then
            DisconnectBNCS
            AddChat frmMain.rtbChat, vbRed, "Error: Failed to decode your CD-key."
            Exit Sub
        End If
       
        lngHashLength = kd_calculateHash(lngDecoder, Cfg.lngClientToken, lngServerToken)
        If (lngHashLength = 0) Then
            DisconnectBNCS
            AddChat frmMain.rtbChat, vbRed, "Error: Failed to hash your CD-key."
            Exit Sub
        End If
       
        strKeyHash = String$(lngHashLength, vbNullChar) ' Initialize buffer.
        Call kd_getHash(lngDecoder, strKeyHash)
       
            .iDWORD Len(Cfg.strCdKey)      'Cd-Key Length
            .iDWORD kd_product(lngDecoder) 'Cd-Key Product Value
            .iDWORD kd_val1(lngDecoder)    'Cd-Key Public Value
            .iDWORD &H0                    'Unknown (0)
            .iNonNTString strKeyHash       'Hashed Key Data
           
            .iNTString strExeInfo          'Exe Information
            .iNTString "BNCE"              'Cd-Key Owner
           
            .sPacket SID_Auth_Check        'Send SID_Auth_Info
        End With
       
    Set Buffer = Nothing
End Sub
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 19, 2006, 01:14 AM
Ok, i dont know if this might help but when i send the packet strExeInfo it starts with "(null)... " and not with "Starcraft.exe... ", i don't really know if that affects in something.

Here is the packet logging.


4  Hide  Hide  98  Send 
0000  FF 51 62 00 6B 10 05 02 0B 03 01 01 C6 E5 B0 C3    .Qb.k...........
0010  01 00 00 00 00 00 00 00 0D 00 00 00 01 00 00 00    ................
0020  43 98 58 00 00 00 00 00 EF 43 16 82 C9 DE 00 60    C.X......C.....`
0030  B9 E1 1F D6 75 67 37 E6 A9 04 43 30 28 6E 75 6C    ....ug7...C0(nul
0040  6C 29 20 30 35 2F 31 39 2F 30 36 20 30 32 3A 33    l) 05/19/06 02:3
0050  32 3A 30 35 20 31 31 34 36 39 33 39 00 42 4E 43    2:05 1146939.BNC
0060  45 00                                              E.

5  Hide  Hide  9  Recv 
0000  FF 51 09 00 00 02 00 00 00                         .Q.......
Title: Re: 0x51 Help using BNCSUtil
Post by: pianka on May 19, 2006, 06:06 AM
You may want to double check your value of HashFiles(0)--and probably the others--before passing it to checkRevision().
Title: Re: 0x51 Help using BNCSUtil
Post by: MysT_DooM on May 19, 2006, 08:21 AM
Maybe when your sending the

.iDWORD kd_product(lngDecoder) 'Cd-Key Product Value
            .iDWORD kd_val1(lngDecoder)    'Cd-Key Public Value


its not getting the right values; like try doin

.iDWORD Mid$(kd_product(lngDecoder), 1, 2) 'product
.iDWORD Mid$(kd_val1(lngDecoder),  3, 7) 'public


i think that might be the problem
Title: Re: 0x51 Help using BNCSUtil
Post by: warz on May 19, 2006, 08:33 AM
You may also want to note that it's not starting with a null byte.

Quote
0030  B9 E1 1F D6 75 67 37 E6 A9 04 43 30 28 6E 75 6C    ....ug7...C0(nul
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 19, 2006, 01:27 PM
Quote from: MysT_DooM on May 19, 2006, 08:21 AM
Maybe when your sending the

.iDWORD kd_product(lngDecoder) 'Cd-Key Product Value
            .iDWORD kd_val1(lngDecoder)    'Cd-Key Public Value


its not getting the right values; like try doin

.iDWORD Mid$(kd_product(lngDecoder), 1, 2) 'product
.iDWORD Mid$(kd_val1(lngDecoder),  3, 7) 'public


i think that might be the problem


Tried is not this.

Quote from: warz on May 19, 2006, 08:33 AM
You may also want to note that it's not starting with a null byte.

Quote
0030 B9 E1 1F D6 75 67 37 E6 A9 04 43 30 28 6E 75 6C ....ug7...C0(nul

I dont understand what u mean by is not starting with a null byte? what is not starting with a null byte?

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


[13:41:37] Disconnected.
[13:41:37] Connecting...
[13:41:37] Connected!
[13:41:37] Sending protocol byte: Game (0x01).
[13:41:37] Sending Sid_Auth_Info (0x50).
[13:41:38] Handeling packet: Sid_Auth_Info (0x50)
[13:41:38] Sending Sid_Auth_Check (0x51).
[13:41:38] MPQNumber: IX86ver3.mpq
[13:41:38] ServerToken: -7284
[13:41:38] Checksum Formula: A=502971062 B=688582030 C=933114557 4 A=A^S B=B^C C=C+A A=A-B
[13:41:38] NewMPQNumber: 3
[13:41:38] HashFile(0): C:\Documents and Settings\Naruto.KONOHA-48E3F658\Escritorio\DaN\Visual Basic\BNCE\STAR\Starcraft.exe
[13:41:38] HashFile(1): C:\Documents and Settings\Naruto.KONOHA-48E3F658\Escritorio\DaN\Visual Basic\BNCE\STAR\Storm.dll
[13:41:38] HashFile(2): C:\Documents and Settings\Naruto.KONOHA-48E3F658\Escritorio\DaN\Visual Basic\BNCE\STAR\Battle.snp
[13:41:38] Checksum: -2099924186
[13:41:38] ExeVersion: 16843531
[13:41:38] ExeInfo: (null) 05/19/06 02:32:05 1146939
[13:41:38] Decoder: 0
[13:41:38] Hash Length: 20
Title: Re: 0x51 Help using BNCSUtil
Post by: Ringo on May 19, 2006, 02:05 PM
Quote from: Archangel on May 19, 2006, 01:27 PM
[13:41:38] ServerToken: -7284
hi, that seems abit small for an average server token, could you be reading it as a WORD rather than a DWORD?
Title: Re: 0x51 Help using BNCSUtil
Post by: l2k-Shadow on May 19, 2006, 02:25 PM
Seems like the function is fine, perhaps post your GetHashFiles() function and the function from which you call this so we can have a better understanding about your issues with incorrect values for the variables.
Title: Re: 0x51 Help using BNCSUtil
Post by: warz on May 19, 2006, 02:42 PM
Oh, does it literally have "(null)" in the packet log / file information string, or did you put that in there telling us that it's a 0x00 byte? If it's literally in there, I think I remember while looking at the BNCSutil source code one time, it does supply a string with "(null)" in it if there's an error in one of the functions. Maybe not, though, this is just a faint memory that this thread triggered.
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 19, 2006, 04:17 PM
Yah im using BNCSUtil and (null) should be starcraft, here is my gethashfile funtion:


Public Sub GetHashFiles(Files() As String)
    Select Case Cfg.strProduct
        Case "STAR", "SEXP"
            Files(0) = App.Path & "\STAR\Starcraft.exe"
            Files(1) = App.Path & "\STAR\Storm.dll"
            Files(2) = App.Path & "\STAR\Battle.snp"
    End Select
End Sub


Since i cant get this done im trying to use example code to see if i can fix it, but im not doing any good.
Title: Re: 0x51 Help using BNCSUtil
Post by: l2k-Shadow on May 19, 2006, 05:32 PM
Post the function from which you call BNCS_SID_Auth_Check().
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 20, 2006, 02:31 AM
Quote from: l2k-Shadow on May 19, 2006, 05:32 PM
Post the function from which you call BNCS_SID_Auth_Check().


Private Sub Handle_BNCS_Sid_Auth_Info(strBuffer As clsPacketBuffer)
    AddChat frmMain.rtbChat, vbYellow, "Handleling packet: Sid_Auth_Info (0x50)"
   
    Dim lngLogonType As Long
    Dim lngServerToken As Long
    Dim lngUDPValue As Long
    'FILETIME 8 BYTES SKIP :P
    Dim strMPQNumber As String
    Dim strChecksumFormula As String
   
    lngLogonType = strBuffer.gDWORD()
    lngServerToken = strBuffer.gDWORD()
    lngUDPValue = strBuffer.gDWORD()
    strBuffer.sBytes 8
    strMPQNumber = strBuffer.gString()
    strChecksumFormula = strBuffer.gString()
   
    BNCS_SID_Auth_Check lngLogonType, strMPQNumber, lngServerToken, strChecksumFormula
End Sub
Title: Re: 0x51 Help using BNCSUtil
Post by: pianka on May 20, 2006, 09:34 AM
First: LOL@strBuffer.gString

Second: you are calling kd_init() at the beginning of your program, correct?
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 20, 2006, 12:12 PM
Quote from: PiaNKA on May 20, 2006, 09:34 AM
First: LOL@strBuffer.gString

Second: you are calling kd_init() at the beginning of your program, correct?

im using example bot code for calling kd_init()

    On Error GoTo Startup_Error
    If (kd_init() = 0) Then
        MsgBox "The BNCSutil CD-key decoder could not be initialized, " & _
            "and the bot must close.", vbCritical, "Example Bot"
        End
    End If
Title: Re: 0x51 Help using BNCSUtil
Post by: l)ragon on May 20, 2006, 12:48 PM
Public Function CheckRev(ByVal FileExe As String, ByVal FileStormDll As String, ByVal FileBnetDll As String, ByVal HashText As String, ByRef Version As Long, ByRef Checksum As Long, ByRef exeinfo As String, ByVal mpqName As String, ByVal MyClient As String)
Dim MpqNumber As Long
Dim CRev As Boolean
    MpqNumber = extractMPQNumber(mpqName)
    CRev = (checkRevision_Raw(HashText, FileExe, FileStormDll, FileBnetDll, MpqNumber, Checksum) > 0)
    Version = getExeInfo(FileExe, exeinfo)
    If InStr(1, exeinfo, "(null)") <> 0 Then
        exeinfo = Replace(exeinfo, "(null)", GetExe(MyClient))
    End If
    Debug.Print exeinfo
End Function

Private Function GetExe(ByVal MyClient As String) As String
    Select Case MyClient
        Case "RATS", "PXES", "RHSS"
            GetExe = "Starcraft.exe"
        Case "VD2D", "PX2D"
            GetExe = "Game.exe"
        Case "3RAW", "PX3W"
            GetExe = "WAR3.exe"
        Case "RHSD"
            GetExe = "Diablo_s.exe"
        Case "RTSJ"
            GetExe = "StarcraftJ.exe"
        Case "LTRD"
            GetExe = "Diablo.exe"
        Case "NB3W"
            GetExe = "Warcraft II BNE.exe"
        Case "MD3W"
            GetExe = "War3Demo.exe"
        Case Else
            GetExe = MyClient
    End Select
End Function


here.
Title: Re: 0x51 Help using BNCSUtil
Post by: Archangel on May 20, 2006, 01:28 PM
Ok, all the problem i had was in my buffer, i resovled it with the help of Pianka, i got a last question, should i take care about the (null)?
Title: Re: 0x51 Help using BNCSUtil
Post by: raylu on May 21, 2006, 11:40 AM
Didn't we determine somewhere a long time ago about how that was one of the optional fields?

Pianka is still online?!
Title: Re: 0x51 Help using BNCSUtil
Post by: l)ragon on May 21, 2006, 01:27 PM
Quote from: raylu on May 21, 2006, 11:40 AM
Didn't we determine somewhere a long time ago about how that was one of the optional fields?

Pianka is still online?!
Believe I posted that it was optional June of 05, the exeinfo and cdkey user name is both optional. Would still rather see people do things the way the game does it but hey it is your cdkey lol.

Public Function p0x51(sck As Winsock, _
                       typ As String, _
                       cKey As Long, _
                       sKey As Long, _
                       CDK1 As String, _
                       CDK2 As String, _
                       Spawn As Long, _
                       CDKeyUsername As String, _
                       Version As Long, _
                       Checksum As Long, _
                       exeinfo As String)
Dim pb As New clsPacketBuffer
Dim NumberOfCDKeys As Long
Dim CDKeyOneBuf As String
Dim CDKeyTwoBuf As String
Dim CDKeyHashDat As String

    NumberOfCDKeys = GetNumberOfKeys(typ)

    Select Case NumberOfCDKeys
        Case 0
            'LTRD, RHSD, RHSS, W3DM can also use this function.
        Case 1
            CDKeyOneBuf = DoCDKeyOne(CDK1, sKey, cKey) 'CDKEY ONE
        Case 2
            CDKeyOneBuf = DoCDKeyOne(CDK1, sKey, cKey) 'CDKEY ONE
            CDKeyTwoBuf = DoCDKeyTwo(CDK2, sKey, cKey) 'CDKEY TWO
        Case Else
            'There are no products that have more then 2
            'cdkeys as of yet, But.. since the packet
            'could take more then 2, possibly they might
            'set up for some expansion to an expansion
            'games?
    End Select
    CDKeyHashDat = CDKeyOneBuf & CDKeyTwoBuf
   
    With pb
        .InsertDWORD cKey
        .InsertDWORD Version
        .InsertDWORD Checksum
        .InsertDWORD NumberOfCDKeys
        .InsertDWORD Spawn
        .InsertNonNTString CDKeyHashDat                             'W3DM, RHSS, RHSD, LTRD this field is empty, so haveing it here still wont have an effect
        .InsertNTString exeinfo                                     'Optional string <- Discovered to be Optional by me, l)ragon June 1, 2005.
        .InsertNTString IIf(NumberOfCDKeys > 0, CDKeyUsername, "")  'Optional string <- Discovered to be Optional by me, l)ragon June 1, 2005.
        .SendBuffer sck, Bnet, SID_AUTH_CHECK
    End With
   
    Set pb = Nothing
End Function

Private Function GetNumberOfKeys(typ As String) As Long
    Select Case typ
        Case "LTRD", "RHSD", "RHSS", "MD3W":
            GetNumberOfKeys = &H0
        Case "PX2D", "PX3W":
            GetNumberOfKeys = &H2
        Case Else:
            GetNumberOfKeys = &H1
    End Select
End Function


I'm sure you can figure out rest thats missing.