Valhalla Legends Forums Archive | Visual Basic Programming | PowerBasic DLL, VB6, and odd variable issues

AuthorMessageTime
Barabajagal
I've been working on writing my own CDKey and Password hashing system for a little while, and decided to turn it into a PowerBasic DLL for speed, efficiency, and 64 bit integers. Unfortunately, this has given me a very odd problem with hashing Starcraft CD Keys.

I have a little tester program which displays the values and final hash for a key, using fake client and server tokens (0x12345678 client, 0x87654321 server). The problem is, variable values get switched around. The DLL's API call looks like this:
[code]Private Declare Function HashAuthCDKey Lib "RRBSHA.dll" (ByVal CDKey As String, ByVal ClientToken As Long, ByVal ServerToken As Long, ByRef Product As Long, ByRef PublicVal As Long, ByRef PrivateVal As Long) As String[/code]

I send it everything just fine, and it returns the correct values, except that one variable is always wrong. Right now, it's setting ClientToken to the same value as ServerToken on the first run, then randomly selects other variables. It also sometimes sets the Product value to other values. I made the DLL display the data in its own function:
[code]Function HashKeyAuth Alias "HashAuthCDKey" (ByVal CDKey As String, ByVal ClientToken As Long, ByVal ServerToken As Long, ByRef Product As Long, ByRef PublicVal As Long, ByRef PrivateVal As Long) Export As String
Dim Ret As String
Dim RetVal As Byte
    RetVal = DecodeKey(CDKey, Product, PublicVal, PrivateVal)
    If RetVal = 0 Then
        Ret = MakeDWORD(ClientToken)
        Ret = Ret & MakeDWORD(ServerToken)
        Ret = Ret & MakeDWORD(Product)
        Ret = Ret & MakeDWORD(PublicVal)
        Ret = Ret & MakeDWORD(0)
        Ret = Ret & MakeDWORD(PrivateVal)
        Function = BrokenSHA1(Ret)
        MsgBox Hex$(ClientToken) & " " & Hex$(ServerToken) & " " & Hex$(Product) & " " & Hex$(PublicVal) & " " & Hex$(PrivateVal)
    Else
        Function = Str$(RetVal)
    End If
End Function[/code]
That returns all correct values, but as soon as it gets to VB, it screws up one of the variables. I can't tell what the hell's going on with it.
Edit: It's not my MakeDWORD function. I replaced CopyMemory with the built in Poke statement, and if anything was wrong with it, I'd get a General Protection Fault error.

Anyone got any ideas on how to get this mess straightened out?
May 22, 2007, 8:18 PM
l2k-Shadow
I'd have to blame powerbasic for that, it has to be sending the return values back incorrectly, VB usually doesn't screw up while working with C++ dlls. If you're going to have a dll to do those functions for you anyway, I don't understand why you don't just use C++ instead.
May 22, 2007, 11:01 PM
Barabajagal
Because I know PB better, and it's just as fast and efficient. It doesn't make sense, though. It only happens with Starcraft Keys ( because it's an odd length string or something maybe?). Everything else works perfectly. The same Exported function is used for Starcraft and D2/W2 keys, and it works fine for d2. It didn't used to do this either, but something changed somewhere along the line.
May 22, 2007, 11:17 PM
tumeria
Because PowerBasic and Visual Basic are crap, thats why
May 23, 2007, 12:16 AM
Quarantine
[quote author=tumeria link=topic=16726.msg169361#msg169361 date=1179879366]
Because PowerBasic and Visual Basic are crap, thats why
[/quote]

Smartest thing you've said in your 33 posts :)
May 23, 2007, 12:27 AM
Barabajagal
How is PowerBasic crap? It supports all useful variable types, runs just as fast as C, compiles into very small files, and uses no runtimes or framework of any type. It's the best BASIC language I've seen for Windows. Also, insulting VB is against this forum's rules.

Edit: noticed another odd occurance. If I call the function using a variable for CDKey, it has the problem, but if I send it a string directly, it seems to work fine. I can use HashAuthCDKey(Trim$(Str$(CDKey)), ClientToken, ServerToken, KeyProd, KeyVal1, KeyVal2) and it works fine as well. I guess it has something to do with how string variables are stored in VB. How very odd.
May 23, 2007, 12:47 AM
tumeria
I would like to see these toted benchmarks against C


Besides that, BASIC is terrible. Ok if you're running on a commodore in 1985, but not good for much else
May 23, 2007, 1:16 AM
tumeria
It could also be that, you know, you've got to pay for it
May 23, 2007, 1:20 AM
Barabajagal
Shh. You don't have to pay for anything.
[img]http://www.kopimi.se/kopimi/kopimi_amerika_america_us_u.gif[/img]
May 23, 2007, 1:30 AM
Quarantine
So you otherwise pirate a language which you praise? Wow.

And yea..there is no way a BASIC language will provide anyone with the low level flexbility of C.
Obviously it isn't so great if you can't get this to work.
May 23, 2007, 3:19 AM
Barabajagal
I did get it to work. The problem is VB sets a string variable with all numeric values as a numeric string. Example:
[code]Dim strVal As String
Dim strStr As String
    strVal = "1234567890"
    strStr = "ABCDEFGHIJ"
    Debug.Print Str$(strVal)
    Debug.Print Str$(strStr)
[/code]
The second debug will error, because strStr is already a string, but strVal is a numeric string. Apparently they're different in VB, and that screws up PB's return. All I have to do now is figure out how to do NLS in PB and I'll have myself a new DLL for hashing.

What flexibility are you interested in? I'll see if I can find something similar in PB. I'd be interested to see how it ranks.
May 23, 2007, 3:38 AM
l2k-Shadow
[quote author=Sachen link=topic=16726.msg169370#msg169370 date=1179891514]
I did get it to work. The problem is VB sets a string variable with all numeric values as a numeric string. Example:
[code]Dim strVal As String
Dim strStr As String
    strVal = "1234567890"
    strStr = "ABCDEFGHIJ"
    Debug.Print Str$(strVal)
    Debug.Print Str$(strStr)
[/code]
The second debug will error, because strStr is already a string, but strVal is a numeric string. Apparently they're different in VB, and that screws up PB's return. All I have to do now is figure out how to do NLS in PB and I'll have myself a new DLL for hashing.

What flexibility are you interested in? I'll see if I can find something similar in PB. I'd be interested to see how it ranks.
[/quote]

Do you also have the checkrevision for ver-IX86-x.mpq?
May 23, 2007, 6:06 AM
Barabajagal
I have no interest in game hashing. I'm only doing CDKey and Password hashing. I do ver-ix86-x hashing using BNLib.dll still.
May 23, 2007, 6:44 AM

Search