• Welcome to Valhalla Legends Archive.
 

PowerBasic DLL, VB6, and odd variable issues

Started by Barabajagal, May 22, 2007, 03:18 PM

Previous topic - Next topic

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:
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

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:
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

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?

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.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

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.

tumeria

Because PowerBasic and Visual Basic are crap, thats why

Warrior

Quote from: tumeria on May 22, 2007, 07:16 PM
Because PowerBasic and Visual Basic are crap, thats why

Smartest thing you've said in your 33 posts :)
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Barabajagal

#5
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.

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

tumeria

It could also be that, you know, you've got to pay for it

Barabajagal

Shh. You don't have to pay for anything.

Warrior

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.
Quote from: effect on March 09, 2006, 11:52 PM
Islam is a steaming pile of fucking dog shit. Everything about it is flawed, anybody who believes in it is a terrorist, if you disagree with me, then im sorry your wrong.

Quote from: Rule on May 07, 2006, 01:30 PM
Why don't you stop being American and start acting like a decent human?

Barabajagal

I did get it to work. The problem is VB sets a string variable with all numeric values as a numeric string. Example:
Dim strVal As String
Dim strStr As String
    strVal = "1234567890"
    strStr = "ABCDEFGHIJ"
    Debug.Print Str$(strVal)
    Debug.Print Str$(strStr)

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.

l2k-Shadow

Quote from: Sachen on May 22, 2007, 10:38 PM
I did get it to work. The problem is VB sets a string variable with all numeric values as a numeric string. Example:
Dim strVal As String
Dim strStr As String
    strVal = "1234567890"
    strStr = "ABCDEFGHIJ"
    Debug.Print Str$(strVal)
    Debug.Print Str$(strStr)

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.

Do you also have the checkrevision for ver-IX86-x.mpq?
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

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.