Valhalla Legends Forums Archive | Battle.net Bot Development | A few basic questions from a beginner. Split from my introduction thread.

AuthorMessageTime
option
Hey guys. I had a few questions I asked in my intro thread, but I guess that wasn't really the appropriate place to ask them. Before answering them I urge you to read that thread found here: https://davnit.net/bnet/vL/index.php?topic=16870.0 to get a handle on where I am currently at.

Anyways, the questions:

When performing local hashing, which library is best used SOLELY for CheckRevision? BNCSutil or MBNCSutil? I couldn't find any documentation for BNCSutil, the site is down due to a bad apache configuration.

Why and where is Broken SHA-1 used in a BNET bot? And am I supposed to understand all of these math functions? I saw some sample source code from a bot, and there was all this math I had trouble following. I am hoping all the math was simply libraries that I can import instead of having to write on my own, because if that's not the case, It will be a lot longer than I anticipated before I can connect to BNET with my own client.

Alright lastly, I understand that in order to create a packet (using Byes, Words, and DWORDS), the data must be in Hexadecimal form. I.e., DWORD: 3f 2a D0 3x. Well, what is the data before you convert it to hex? What data do you use to convert to hex to send as a packet? Kind of a general question but it's got me so confused heh

That's all for now. Thanks in advance, look forward to hearing some replies. I've been hunting around and these questions are kind of like a mental block, once I have some more insight I think I can move further in my quest to make a bot lol.

-option
July 12, 2007, 6:57 PM
Barabajagal
BNCSutil for VB and VC++ 6. MBNCSutil for .NET languages. I'll get you some documentation some time or other if you want.
BSHA is used for hashing SC, D2, and War2 CD Keys, passwords, and all that good stuff (regular SHA-1 for War3 cd keys). The functions are built into BNCSutil, so you don't need to know it at all.
Data is actually all raw data, which can either be viewed as hex or text (strings). The best thing to do is use a packet debuffer, which is basically a class module that has a lot of nifty functions to read the packet data and store it in usable variables correctly.
July 12, 2007, 9:26 PM
option
Alright, cool. Helpful reply. If you could get me the documentation for BNCSutil.dll I would *greatly* appreciate it, as I am using VB 6.0 enterprise. I've got BNCSutil already but have no clue how to implement it as I don't have the documentation.

Thanks for the response.
July 12, 2007, 10:07 PM
Barabajagal
Here's the basic layout for the BNCSutil.bas Module:
[code]Option Explicit
Private Type sockaddr_in
    sin_family  As Integer
    sin_port    As Integer
    sin_addr    As Long
    sin_zero    As String * 8
End Type
Private Declare Function getpeername Lib "ws2_32.dll" (ByVal s As Long, Name As sockaddr_in, namelen As Long) As Long
Private Declare Function bncsutil_getVersionString Lib "bncsutil.dll" (ByVal OutBuf As String) As Long
Private Declare Sub hashPassword Lib "bncsutil.dll" (ByVal Password As String, ByVal outBuffer As String)
Private Declare Sub doubleHashPassword Lib "bncsutil.dll"
  (ByVal Password As String, ByVal ClientToken As Long, ByVal ServerToken As Long, ByVal outBuffer As String)
Public Declare Sub nls_free Lib "bncsutil.dll" (ByVal NLS As Long)
Public Declare Sub nls_get_A Lib "bncsutil.dll" (ByVal NLS As Long, ByVal Out As String)
Public Declare Sub nls_get_M1 Lib "bncsutil.dll" (ByVal NLS As Long, ByVal Out As String, ByVal B As String, ByVal Salt As String)
Public Declare Sub calcHashBuf Lib "bncsutil.dll" (ByVal Data As String, ByVal Length As Long, ByVal Hash As String)
Public Declare Function kd_init Lib "bncsutil.dll" () As Long
Public Declare Function kd_free Lib "bncsutil.dll" (ByVal decoder As Long) As Long
Public Declare Function kd_val1 Lib "bncsutil.dll" (ByVal decoder As Long) As Long
Public Declare Function kd_val2 Lib "bncsutil.dll" (ByVal decoder As Long) As Long
Public Declare Function kd_product Lib "bncsutil.dll" (ByVal decoder As Long) As Long
Public Declare Function kd_isValid Lib "bncsutil.dll" (ByVal decoder As Long) As Long
Public Declare Function kd_getHash Lib "bncsutil.dll" (ByVal decoder As Long, ByVal Out As String) As Long
Public Declare Function kd_create Lib "bncsutil.dll" (ByVal CDKey As String, ByVal keyLength As Long) As Long
Public Declare Function kd_calculateHash Lib "bncsutil.dll" (ByVal decoder As Long, ByVal ClientToken As Long, ByVal ServerToken As Long) As Long
Public Declare Function nls_init Lib "bncsutil.dll" (ByVal Username As String, ByVal Password As String) As Long
Public Declare Function nls_check_signature Lib "bncsutil.dll" (ByVal Address As Long, ByVal Signature As String) As Long
Public Declare Function nls_account_create Lib "bncsutil.dll" (ByVal NLS As Long, ByVal Buffer As String, ByVal buflen As Long) As Long
Public Declare Function nls_check_M2 Lib "bncsutil.dll" (ByVal NLS As Long, ByVal M2 As String, ByVal B As String, ByVal Salt As String) As Long
Public Declare Function nls_account_change_proof Lib "bncsutil.dll"
  (ByVal NLS As Long, ByVal Buffer As String, ByVal NewPassword As String,
  ByVal B As String, ByVal Salt As String) As Long
Public Function bncsutil_getVersion() As String
Dim s As String * 12
Dim Length As Long
    Length = bncsutil_getVersionString(s)
    bncsutil_getVersion = Left$(s, Length)
End Function
Public Function bncsutil_doubleHashPassword(ByVal Password As String, ByVal ClientToken As Long, ByVal ServerToken As Long) As String
Dim Hash As String * 20
    doubleHashPassword Password, ClientToken, ServerToken, Hash
    bncsutil_doubleHashPassword = Hash
End Function
Public Function bncsutil_hashPassword(ByVal Password As String) As String
Dim Hash As String * 20
    hashPassword Password, Hash
    bncsutil_hashPassword = Hash
End Function
Public Function nls_check_wsBNCS_signature(ByVal wsBNCSHandle As Long, ByVal ServerSignature As String) As Boolean
Dim addr    As sockaddr_in
Dim addrlen As Long
    addrlen = 16
    If (getpeername(wsBNCSHandle, addr, addrlen) = -1) Then
        nls_check_wsBNCS_signature = False
    Else
        nls_check_wsBNCS_signature = (nls_check_signature(addr.sin_addr, ServerSignature))
    End If
End Function[/code]

Hashing passwords is pretty easy. As is checking NLS Signatures (look up what to do in the BnetDocs mirror). For hashing CDKeys, here's a SID_CDKEY2 example (used for warcraft II logins):
[code]Private Sub SID_Send_CDKEY2()
Dim KeyDecoder      As Long
Dim KeyHash        As String
Dim HashLength      As Long
Dim strCDKey        As String
Dim KeyVal1        As Long
Dim KeyVal2        As Long
Dim KeyProd        As Long
Dim HashData        As String
    strCDKey = Config.CDKey
    kd_init
    KeyDecoder = kd_create(strCDKey, Len(strCDKey))
    If (KeyDecoder = -1) Then
        DisconnectBNCS
        'Display Error: "Failed to decode your CD Key."
        Exit Sub
    End If
    HashLength = kd_calculateHash(KeyDecoder, ClientToken, ServerToken)
    If (HashLength = 0) Then
        DisconnectBNCS
        'Display Error: "Failed to calculate your CD Key hash."
        Exit Sub
    End If
    If (kd_isValid(KeyDecoder) = 0) Then
        DisconnectBNCS
        'Display Error: "The product installer algorithm rejected your CD Key."
        Exit Sub
    End If
    KeyHash = String$(HashLength, vbNullChar)
    KeyProd = kd_product(KeyDecoder)
    KeyVal1 = kd_val1(KeyDecoder)
    KeyVal2 = kd_val2(KeyDecoder)
    HashData = Packet.CreateDWORD(ClientToken)
    HashData = HashData & Packet.CreateDWORD(ServerToken)
    HashData = HashData & Packet.CreateDWORD(KeyProd)
    HashData = HashData & Packet.CreateDWORD(KeyVal1)
    HashData = HashData & Packet.CreateDWORD(KeyVal2)
    calcHashBuf HashData, HashLength, KeyHash
    If Len(KeyHash) <> 20 Then
        DisconnectBNCS
        'Display Error: "Failed to hash your CD Key."
        Exit Sub
    End If
    kd_free KeyDecoder
    Packet.ClearOutbound
    If Config.Spawn Then
        Packet.InsertDWORD &H1
    Else
        Packet.InsertDWORD &H0
    End If
    Packet.InsertDWORD Len(strCDKey)
    Packet.InsertDWORD KeyProd
    Packet.InsertDWORD KeyVal1
    Packet.InsertDWORD ServerToken
    Packet.InsertDWORD ClientToken
    Packet.InsertString KeyHash
    Packet.InsertNTString Config.Username
    wsBNCS.SendPacket Packet.SendBNCSPacket(SID_CDKEY2)
End Sub[/code]
Hope that sort of explains things for ya.

Edit: I'm working on my own CDKey and Password hashing DLL (written in PowerBasic), but it's currently causing the occasional 3 week IP Ban, so I have more work to do on it before it's released. (I think it has something to do with converting longs to DWords... and negative value issues.)

[Edit: broke up some definitions that were wrecking the tables.]
July 12, 2007, 10:36 PM
option
Nice stuff. I saved it. Got anything regarding Crevs?
July 12, 2007, 11:39 PM
Barabajagal
CheckRevision... heh. I wrote a big ol Database of values, which you can view at http://rcb.realityripple.com/crev/ . There's a few ways to do CheckRevision... First off, use BNLS or a BNLS clone (packet 1A). JBLS doesn't support CRev yet, but Blake (HDX) is working on it. I've got a system that sometimes works for some people (my ISP is a dirty wh0re), ls.realityripple.com. The values are usually correct, it's whether or not you can connect to it. Then there's the original BNLS, which has (nearly) always worked. There's also Rob's CRev DLL (which I would recommend you use if you want to do all local stuff), and iago's source.
Edit: I'll be back on tomorrow, until then, hopefully another member can answer your questions and/or dispute everything I say.
July 13, 2007, 12:38 AM
DDA-TriCk-E
[quote author=現のさざ波 link=topic=16871.msg170942#msg170942 date=1184275589]
BNCSutil for VB and VC++ 6. MBNCSutil for .NET languages. I'll get you some documentation some time or other if you want.
BSHA is used for hashing SC, D2, and War2 CD Keys, passwords, and all that good stuff (regular SHA-1 for War3 cd keys). The functions are built into BNCSutil, so you don't need to know it at all.
Data is actually all raw data, which can either be viewed as hex or text (strings). The best thing to do is use a packet debuffer, which is basically a class module that has a lot of nifty functions to read the packet data and store it in usable variables correctly.
[/quote]
You can use MBNCSutil for non .NET languages, I find it to be a lot nicer as well, since the code is managed.
July 13, 2007, 3:46 AM
HdxBmx27
[quote author=現のさざ波 link=topic=16871.msg170950#msg170950 date=1184287139]
CheckRevision... heh. I wrote a big ol Database of values, which you can view at http://rcb.realityripple.com/crev/ . There's a few ways to do CheckRevision... First off, use BNLS or a BNLS clone (packet 1A). JBLS doesn't support CRev yet, but Blake (HDX) is working on it. I've got a system that sometimes works for some people (my ISP is a dirty wh0re), ls.realityripple.com. The values are usually correct, it's whether or not you can connect to it. Then there's the original BNLS, which has (nearly) always worked. There's also Rob's CRev DLL (which I would recommend you use if you want to do all local stuff), and iago's source.
Edit: I'll be back on tomorrow, until then, hopefully another member can answer your questions and/or dispute everything I say.
[/quote]Yes it does. I finished porting lockdown last week.
Also, EDIT you last port! You're breaking tables with the api declarations.

@ The Questions:
Check Revision:
Either use BNLS (Currently doesn't work for Wc3), JBLS (Works foe all standard BNLS clients), Or BNCSUtil.dll (Doesn't work for Starcraft or Wc2)
There is no current library thats ONLY for check revision, aside form CheckRevision.dll.. but thats old, and outdated. (Oh and of coarse the real CheckRevison librarys.. but I doubt you know how to mod them to make them work.)

X-SHA1/Other Encryptions:
You really don't need to understand what/show the encryptions work. As there are tons of alternate methods that you can use. BNLS/JBLS, BNCSutil.dll, other libraries, etc..
As for when it's used. In almost every Login packet, The Passwords and CDKeys are the main point.
Passwords are 'Double Hashes' with the client and server tokens.
  encoded = H(ServerToken & ClientToken & H(Password)); (Where H is the x-SHA1 algorithm)
CDKeys are 'decoded', using a function that splits them into three values 'Public', 'Private', and 'Product'
And then that info is sent into the x-SHA1 algo!
  encoded = H(ServerToken & ClientToken & Product & Public & 0x00000000 & Private)

As for how data should be sent, raw bytes. Whenever you see something like:
01 00 01 00
That equates to the value &H00010001
So you wouldn't do:
WinSock.Send "01 00 01 00"
You'd do:
WinSock.Seind Char(&H01) & Char(&H00) & Char(&H01) & Char(00)
As you can see, this is when a Buffer class comes in handy, (Look at Andy's code) 

I suggest you read the following pages off Bnet Docs:
Notational Conventions
Sizes and Types
Protocol Headers
Login Sequences
Along with almost anything in the Bot Dev repository subforum here.

Besides that. Get crackin the best way to learn is to do.
First thing though, so you don't get IPed for a bijillion years for stupid things.
Packet log another bot connecting to see what your data should look like after being sent though DebugOutput() (I couldn't find a link, You'll have to search for it. it's a function that turns the binary date into the Hex you see in packet logs)
If you get stuck, read BnetDocs and packet logs. If all else fails, post here with AS MUCH DETAIL AS POSSIBLE. (Code segments and Packet logs are  MUST)
~Hdx
July 13, 2007, 4:29 AM
option
Alright I am saving code and bookmarking replies, this is surely helpful stuff. The only thing I can ask now (before my hands are completely full) is if you guys can supply some links that teach what exactly a checkrevision is, how to use it, etc, relating to D2. I have already decided I want my bot to do local hashing instead of relying on BNLS or JBLS even though they sound like great sytems.
July 13, 2007, 5:03 PM
Barabajagal
Diablo 2 uses the old CheckRevision system, which can be used entirely through BNCSutil's local hashing.
July 13, 2007, 8:09 PM
option
Alright, and what are the parameters for local hashing with BNCSutil? What's the function name, what files are needed for my product, D2XP, and is there any available documentation?
July 13, 2007, 8:31 PM
Barabajagal
Heh... completely forgot I removed that from my code.

You need the following stuff added to the API calls:
[code]Public Declare Function extractMPQNumber Lib "bncsutil.dll" (ByVal mpqName As String) As Long
Public Declare Function checkRevision_Raw Lib "bncsutil.dll" Alias "checkRevisionFlat"
  (ByVal ValueString As String, ByVal File1 As String, ByVal File2 As String, ByVal File3 As String,
  ByVal mpqNumber As Long, ByRef Checksum As Long) As Long
Public Declare Function getExeInfo_Raw Lib "bncsutil.dll" Alias "getExeInfo"
  (ByVal Filename As String, ByVal exeInfoString As String, ByVal infoBufferSize As Long,
  Version As Long, ByVal Platform As Long) As Long[/code]

And the functions to use them:
[code]
Public Function checkRevisionA(ValueString As String, Files() As String, mpqNumber As Long, Checksum As Long) As Boolean
    checkRevisionA = (checkRevision_Raw(ValueString, Files(0), Files(1), Files(2), mpqNumber, Checksum) > 0)
End Function

Public Function getExeInfo(EXEFile As String, InfoString As String, Optional ByVal Platform As Long = BNCSUTIL_PLATFORM_WINDOWS) As Long
    Dim Version As Long, InfoSize As Long, Result As Long
    Dim i&
    InfoSize = 256
    InfoString = String$(256, vbNullChar)
    Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
    If Result = 0 Then
        getExeInfo = 0
        Exit Function
    End If
    While Result > InfoSize
        If InfoSize > 1024 Then
            getExeInfo = 0
            Exit Function
        End If
        InfoSize = InfoSize + 256
        InfoString = String$(InfoSize, vbNullChar)
        Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
    Wend
    getExeInfo = Version
    i = InStr(InfoString, vbNullChar)
    If i = 0 Then Exit Function
    InfoString = Left$(InfoString, i - 1)
End Function[/code]

Here's the original BNCSutil.bas file:
[code]Attribute VB_Name = "BNCSutil"
Option Explicit

'------------------------------------------------------------------------------
'  BNCSutil
'  Battle.Net Utility Library
'
'  Copyright © 2004-2005 Eric Naeseth
'------------------------------------------------------------------------------
'  Visual Basic Declarations
'  November 20, 2004
'------------------------------------------------------------------------------
'  This library is free software; you can redistribute it and/or
'  modify it under the terms of the GNU Lesser General Public
'  License as published by the Free Software Foundation; either
'  version 2.1 of the License, or (at your option) any later version.
'
'  This library is distributed in the hope that it will be useful,
'  but WITHOUT ANY WARRANTY; without even the implied warranty of
'  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
'  Lesser General Public License for more details.
'
'  A copy of the GNU Lesser General Public License is included in the BNCSutil
'  distribution in the file COPYING.  If you did not receive this copy,
'  write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
'  Boston, MA  02111-1307  USA
'------------------------------------------------------------------------------

'  DLL Imports
'---------------------------

' Library Information
Public Declare Function bncsutil_getVersion Lib "bncsutil.dll" () As Long
Public Declare Function bncsutil_getVersionString_Raw Lib "bncsutil.dll" _
    Alias "bncsutil_getVersionString" (ByVal outBuf As String) As Long

' CheckRevision
Public Declare Function extractMPQNumber Lib "bncsutil.dll" _
    (ByVal mpqName As String) As Long
' [!] You should use checkRevision and getExeInfo (see below) instead of their
'    _Raw counterparts.
Public Declare Function checkRevision_Raw Lib "bncsutil.dll" Alias "checkRevisionFlat" _
    (ByVal ValueString As String, ByVal File1 As String, ByVal File2 As String, _
    ByVal File3 As String, ByVal mpqNumber As Long, ByRef Checksum As Long) As Long
Public Declare Function getExeInfo_Raw Lib "bncsutil.dll" Alias "getExeInfo" _
    (ByVal Filename As String, ByVal exeInfoString As String, _
    ByVal infoBufferSize As Long, Version As Long, ByVal Platform As Long) As Long

' Old Logon System
' [!] You should use doubleHashPassword and hashPassword instead of their
'    _Raw counterparts.  (See below for those functions.)
Public Declare Sub doubleHashPassword_Raw Lib "bncsutil.dll" Alias "doubleHashPassword" _
    (ByVal Password As String, ByVal ClientToken As Long, ByVal ServerToken As Long, _
    ByVal outBuffer As String)
Public Declare Sub hashPassword_Raw Lib "bncsutil.dll" Alias "hashPassword" _
    (ByVal Password As String, ByVal outBuffer As String)

' Broken SHA-1
Public Declare Sub calcHashBuf Lib "bncsutil.dll" _
    (ByVal Data As String, ByVal Length As Long, ByVal Hash As String)

' CD-Key Decoding

' Call kd_init() first to set up the decoding system, unless you are only using kd_quick().
' Then call kd_create() to create a key decoder "handle" each time you want to
' decode a CD-key.  It will return the handle or -1 on failure.  The handle
' should then be passed as the "decoder" argument to all the other kd_ functions.
' Call kd_free() on the handle when finished with the decoder to free the
' memory it is using.

Public Declare Function kd_quick Lib "bncsutil.dll" _
    (ByVal CDKey As String, ByVal ClientToken As Long, ByVal ServerToken As Long, _
    PublicValue As Long, Product As Long, ByVal HashBuffer As String, ByVal BufferLen As Long) As Long
Public Declare Function kd_init Lib "bncsutil.dll" () As Long
Public Declare Function kd_create Lib "bncsutil.dll" _
    (ByVal CDKey As String, ByVal keyLength As Long) As Long
Public Declare Function kd_free Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
Public Declare Function kd_val2Length Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
Public Declare Function kd_product Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
Public Declare Function kd_val1 Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
Public Declare Function kd_val2 Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
Public Declare Function kd_longVal2 Lib "bncsutil.dll" _
    (ByVal decoder As Long, ByVal Out As String) As Long
Public Declare Function kd_calculateHash Lib "bncsutil.dll" _
    (ByVal decoder As Long, ByVal ClientToken As Long, ByVal ServerToken As Long) As Long
Public Declare Function kd_getHash Lib "bncsutil.dll" _
    (ByVal decoder As Long, ByVal Out As String) As Long
Public Declare Function kd_isValid Lib "bncsutil.dll" _
    (ByVal decoder As Long) As Long
   
'New Logon System

' Call nls_init() to get a "handle" to an NLS object (nls_init will return 0
' if it encounters an error).  This "handle" should be passed as the "NLS"
' argument to all the other nls_* functions.  You do not need to change the
' username and password to upper-case as nls_init() will do this for you.
' Call nls_free() on the handle to free the memory it's using.
' nls_account_create() and nls_account_logon() generate the bodies of
' SID_AUTH_ACCOUNTCREATE and SID_AUTH_ACCOUNTLOGIN packets, respectively.

Public Declare Function nls_init Lib "bncsutil.dll" _
    (ByVal Username As String, ByVal Password As String) As Long 'really returns a POINTER!
Public Declare Function nls_init_l Lib "bncsutil.dll" _
    (ByVal Username As String, ByVal Username_Length As Long, _
    ByVal Password As String, ByVal Password_Length As Long) As Long
Public Declare Function nls_reinit Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Username As String, ByVal Password As String) As Long
Public Declare Function nls_reinit_l Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Username As String, ByVal Username_Length As Long, _
    ByVal Password As String, ByVal Password_Length As Long) As Long
Public Declare Sub nls_free Lib "bncsutil.dll" _
    (ByVal NLS As Long)
Public Declare Function nls_account_create Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Buffer As String, ByVal BufLen As Long) As Long
Public Declare Function nls_account_logon Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Buffer As String, ByVal BufLen As Long) As Long
Public Declare Sub nls_get_A Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Out As String)
Public Declare Sub nls_get_M1 Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Out As String, ByVal B As String, ByVal Salt As String)
Public Declare Function nls_check_M2 Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal M2 As String, ByVal B As String, ByVal Salt As String) As Long
Public Declare Function nls_check_signature Lib "bncsutil.dll" _
    (ByVal Address As Long, ByVal Signature As String) As Long
Public Declare Function nls_account_change_proof Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Buffer As String, ByVal NewPassword As String, _
    ByVal B As String, ByVal Salt As String) As Long 'returns a new NLS pointer for the new password
Public Declare Sub nls_get_S Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Out As String, ByVal B As String, ByVal Salt As String)
Public Declare Sub nls_get_K Lib "bncsutil.dll" _
    (ByVal NLS As Long, ByVal Out As String, ByVal S As String)
   
Private Declare Function bncsutil_debug_status Lib "bncsutil.dll" () As Long
Private Declare Function bncsutil_set_debug_status Lib "bncsutil.dll" (ByVal NewStatus As Long) As Long
Private Declare Sub bncsutil_debug_message Lib "bncsutil.dll" (ByVal Message As String)
Private Declare Sub bncsutil_debug_dump Lib "bncsutil.dll" (ByVal Message As String, ByVal Length As Long)
Private Declare Function bncsutil_internal_debug_messages Lib "bncsutil.dll" () As Long
   
'  Constants
'---------------------------
Public Const BNCSUTIL_PLATFORM_X86& = &H1
Public Const BNCSUTIL_PLATFORM_WINDOWS& = &H1
Public Const BNCSUTIL_PLATFORM_WIN& = &H1

Public Const BNCSUTIL_PLATFORM_PPC& = &H2
Public Const BNCSUTIL_PLATFORM_MAC& = &H2

Public Const BNCSUTIL_PLATFORM_OSX& = &H3

'  Winsock
'---------------------------
Private Type sockaddr_in
    Family As Integer
    Port As Integer
    Address As Long
    Filler As String * 8
End Type

Private Declare Function getsockname Lib "ws2_32.dll" (ByVal S As Long, Name As sockaddr_in, NameLen As Long) As Long


'---------------------------------------'
'  VB-Specifc Functions and Properties  '
'---------------------------------------'

Public Property Get Version() As String
    Version = bncsutil_getVersionString()
End Property

Public Property Get DebugMode() As Boolean
    DebugMode = (bncsutil_debug_status() <> 0)
End Property

Public Property Let DebugMode(ByVal NewValue As Boolean)
    If (NewValue) Then
        bncsutil_set_debug_status 1
    Else
        bncsutil_set_debug_status 0
    End If
End Property

Public Property Get InternalDebugMessages() As Boolean
    InternalDebugMessages = (bncsutil_internal_debug_messages() <> 0)
End Property

Public Sub DebugMessage(Message As String)
    bncsutil_debug_message Message
End Sub

Public Sub DebugHexDump(Data As String, Optional ByVal Length As Long = -1)
    If (Length = -1) Then
        Length = Len(Data)
    End If
   
    bncsutil_debug_dump Data, Length
End Sub


' RequiredVersion must be a version as a.b.c
' Returns True if the current BNCSutil version is sufficent, False if not.
Public Function bncsutil_checkVersion(ByVal RequiredVersion As String) As Boolean
    Dim i&, j&
    Dim Frag() As String
    Dim Req As Long, Check As Long
    bncsutil_checkVersion = False
    Frag = Split(RequiredVersion, ".")
    j = 0
    For i = UBound(Frag) To 0 Step -1
        Check = Check + (CLng(Val(Frag(i))) * (100 ^ j))
        j = j + 1
    Next i
    Check = bncsutil_getVersion()
    If (Check >= Req) Then
        bncsutil_checkVersion = True
    End If
End Function

Public Function bncsutil_getVersionString() As String
    Dim S As String * 12
    Dim Length As Long
    Length = bncsutil_getVersionString_Raw(S)
    bncsutil_getVersionString = Left$(S, Length)
End Function

'CheckRevision
Public Function checkRevision(ValueString As String, File1$, File2$, File3$, mpqNumber As Long, Checksum As Long) As Boolean
    checkRevision = (checkRevision_Raw(ValueString, File1, File2, File3, mpqNumber, Checksum) > 0)
End Function

Public Function checkRevisionA(ValueString As String, Files() As String, mpqNumber As Long, Checksum As Long) As Boolean
    checkRevisionA = (checkRevision_Raw(ValueString, Files(0), Files(1), Files(2), mpqNumber, Checksum) > 0)
End Function

'EXE Information
'Information string (file name, date, time, and size) will be placed in InfoString.
'InfoString does NOT need to be initialized (e.g. InfoString = String$(255, vbNullChar))
'Returns the file version or 0 on failure.
Public Function getExeInfo(EXEFile As String, InfoString As String, Optional ByVal Platform As Long = BNCSUTIL_PLATFORM_WINDOWS) As Long
    Dim Version As Long, InfoSize As Long, Result As Long
    Dim i&
    InfoSize = 256
    InfoString = String$(256, vbNullChar)
    Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
    If Result = 0 Then
        getExeInfo = 0
        Exit Function
    End If
    While Result > InfoSize
        If InfoSize > 1024 Then
            getExeInfo = 0
            Exit Function
        End If
        InfoSize = InfoSize + 256
        InfoString = String$(InfoSize, vbNullChar)
        Result = getExeInfo_Raw(EXEFile, InfoString, InfoSize, Version, Platform)
    Wend
    getExeInfo = Version
    i = InStr(InfoString, vbNullChar)
    If i = 0 Then Exit Function
    InfoString = Left$(InfoString, i - 1)
End Function

'OLS Password Hashing
Public Function doubleHashPassword(Password As String, ByVal ClientToken&, ByVal ServerToken&) As String
    Dim Hash As String * 20
    doubleHashPassword_Raw Password, ClientToken, ServerToken, Hash
    doubleHashPassword = Hash
End Function

Public Function hashPassword(Password As String) As String
    Dim Hash As String * 20
    hashPassword_Raw Password, Hash
    hashPassword = Hash
End Function

Public Function nls_check_socket_signature(ByVal SocketHandle As Long, Signature As String) As Boolean
    Dim NameLen As Long, Name As sockaddr_in
   
    NameLen = 16
    getsockname SocketHandle, Name, NameLen
   
    nls_check_socket_signature = (nls_check_signature(Name.Address, Signature) <> 0)
End Function[/code]

[Edit: broke up some definitions that were wrecking the tables.]
July 13, 2007, 8:43 PM
option
Alright and I am assuming the Files that go into the Files array [Files(0) Files(1) and Files(2)] are Bnclient.dll, Game.exe, and D2Client.dll?
July 14, 2007, 5:05 AM
Barabajagal
Game.exe, Bnclient.dll, D2client.dll. order matters.
July 14, 2007, 5:13 AM
option
Alright it's confusing but I'm gonna try and put something together ... T_T wish me some kind of luck
July 14, 2007, 5:52 AM
Barabajagal
Heh, maybe you should post your hashing function on here before you test it ;)
July 14, 2007, 7:50 AM
option
After checking it out, I'm not ready. I have no idea what goes on when I perform a CheckRevision, I.e., the parts the compose it .... like the getEXEinfo and extractmpq number functions. I need to hunt around and find some more things to read before I attempt this
July 15, 2007, 3:24 AM

Search