Author | Message | Time |
---|---|---|
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: [code] [0x0] 0x11 [0x1] 0x1 [0x2] 0x32574d [0x3] 0x0 [0x4] 0xd290f3f0 [0x5] 0x543abffb [0x6] 0xb1fc491a [0x7] 0xccf10928 [0x8] 0x96ede672 [/code] Mine: [code] [0x0] 0xD [0x1] 0x16 [0x2] 0x2c8c5f [0x3] 0x0 [0x4] 0xe31a5e7 [0x5] 0xde016aac [0x6] 0x185b7e7 [0x7] 0x44016d14 [0x8] 0xd171bc53 [/code] The [0x0] should be 13 for a StarCraft key right? But BNLS sends me 17... Here is my code... [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; } [/code] Thanks in advance. | January 10, 2005, 11:24 PM |
UserLoser. | Final is broken [code] 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); } [/code] | January 10, 2005, 11:42 PM |
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 author=shout link=topic=10162.msg94812#msg94812 date=1105399479] BNLS: [code] [0x0] 0x11 [0x1] 0x1 [0x2] 0x32574d [0x3] 0x0 [0x4] 0xd290f3f0 [0x5] 0x543abffb [0x6] 0xb1fc491a [0x7] 0xccf10928 [0x8] 0x96ede672 [/code] [/quote] | January 12, 2005, 12:16 AM |
kamakazie | [quote author=shout link=topic=10162.msg94918#msg94918 date=1105488962] 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] Are you sure the cdkey your sending doesn't have dashes "-" or spaces " " in it? | January 12, 2005, 12:31 AM |
shout | 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... | January 12, 2005, 12:44 AM |
mentalCo. | what the hell is a 'FIFOByteBuffer'? | February 7, 2005, 6:01 PM |
shout | First-in-first-out byte buffer. Thank you for renewing a dead topic. | February 7, 2005, 8:51 PM |