• Welcome to Valhalla Legends Archive.
 

[C#] StarCraft CD Key decoding.

Started by shout, January 10, 2005, 05:24 PM

Previous topic - Next topic

shout

I have written a C# implementation of code from JavaOp to decode a starcraft CD key, and a small program to compare it to the values received from BNLS. I used BNLS_CDKEY_EX for comparisons so I could specify a client token.

BNLS:

[0x0] 0x11
[0x1] 0x1
[0x2] 0x32574d
[0x3] 0x0
[0x4] 0xd290f3f0
[0x5] 0x543abffb
[0x6] 0xb1fc491a
[0x7] 0xccf10928
[0x8] 0x96ede672

Mine:

[0x0] 0xD
[0x1] 0x16
[0x2] 0x2c8c5f
[0x3] 0x0
[0x4] 0xe31a5e7
[0x5] 0xde016aac
[0x6] 0x185b7e7
[0x7] 0x44016d14
[0x8] 0xd171bc53


The [0x0] should be 13 for a StarCraft key right? But BNLS sends me 17...

Here is my code...

static int[] DecodeSCKey(string key)
{
key = shuffle(key);
key = final(key);

int[] values = new int[3];
values[0] = int.Parse(key.Substring(0, 2));
values[1] = int.Parse(key.Substring(2, 7));
values[2] = int.Parse(key.Substring(9, 3));

return values;
}

static string swap(string s, int a, int b)
{
char[] tmpstr = s.ToCharArray();

char tmp = tmpstr[a];
tmpstr[a] = tmpstr[b];
tmpstr[b] = tmp;

return new string(tmpstr);
}

static string shuffle(string Key)
{
int pos = 0x0B;
string key = Key;

for (int i = 0xC2; i >= 0x07; i -= 0x11)
key = swap(key, pos--, i % 0x0C);

return key;
}

static string final(string Key)
{
int hashKey = 0x13AC9741;

string sKey = Key.ToUpper();

byte[] key = Encoding.ASCII.GetBytes(sKey);
           
for (int i = (key.Length - 2); i >= 0; i--)
{
byte b = (byte)Char.ToUpper((char)key[i]);
byte c = b;
if (b <= '7')
{
b = (byte)((byte)hashKey & (byte)0xFF);
b &= 7;
b ^= c;
hashKey >>= 3;
key[i] = b;
}
else if (b < 'A')
{
b = (byte)i;
b &= 1;
b ^= c;
key[i] = b;
}
}

           
return Encoding.ASCII.GetString(key);
}


static byte[] GetSCKeyData(string Key, int ClientToken, int ServerToken)
{
int[] keyVals = CDKeyDecoder.DecodeSCKey(Key);
FIFOByteBuffer hashbuff = new FIFOByteBuffer();
FIFOByteBuffer buff = new FIFOByteBuffer();

hashbuff.InsertDword(ClientToken);
hashbuff.InsertDword(ServerToken);
hashbuff.InsertDword(keyVals[0]);
hashbuff.InsertDword(keyVals[1]);
hashbuff.InsertDword(0);
hashbuff.InsertDword(keyVals[2]);

buff.InsertDword(Key.Length);
buff.InsertDword(keyVals[0]);
buff.InsertDword(keyVals[1]);
buff.InsertDword(0);
buff.InsertByteArray(Hashing.HashData(hashbuff));

return buff;

}


Thanks in advance.

UserLoser.

Final is broken


if((unsigned char)A <= '7') {
CDKey[I] = ((unsigned char)SomeValue & 7 ^ (unsigned char)A);
SomeValue >>= 3;
} else if((unsigned char)A < 'A') {
CDKey[I] = ((unsigned char)I & 1 ^ (unsigned char)A);
}

shout

Thanks for that UserLoser.

But why is BNLS sending me a key length of 17 for the StarCraft key? I made sure I was sending the correct data, and for Diablo it reports the correct length...
Quote from: shout on January 10, 2005, 05:24 PM
BNLS:

[0x0] 0x11
[0x1] 0x1
[0x2] 0x32574d
[0x3] 0x0
[0x4] 0xd290f3f0
[0x5] 0x543abffb
[0x6] 0xb1fc491a
[0x7] 0xccf10928
[0x8] 0x96ede672


dxoigmn

Quote from: shout on January 11, 2005, 06:16 PM
Thanks for that UserLoser.

But why is BNLS sending me a key length of 17 for the StarCraft key? I made sure I was sending the correct data, and for Diablo it reports the correct length...

Are you sure the cdkey your sending doesn't have dashes "-" or spaces  " " in it?

shout

#4
I am sure.
Everything except the key length is now matches.

EDIT: Modified first post to new code.

EDIT #2
I was sending an extra DWORD to BNLS and it included it with the key length but not the key...

mentalCo.

what the hell is a 'FIFOByteBuffer'?

shout

First-in-first-out byte buffer.

Thank you for renewing a dead topic.