PageRenderTime 26ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 2ms app.codeStats 0ms

/bncsutil/src/bncsutil/cdkeydecoder.h

http://ghostcb.googlecode.com/
C++ Header | 113 lines | 42 code | 16 blank | 55 comment | 0 complexity | 63abc915d1e4dbed9915a9fb36c411d4 MD5 | raw file
  1/**
  2 * BNCSutil
  3 * Battle.Net Utility Library
  4 *
  5 * Copyright (C) 2004-2006 Eric Naeseth
  6 *
  7 * CD-Key Decoder Interface
  8 * September 29, 2004
  9 *
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation; either
 13 * version 2.1 of the License, or (at your option) any later version.
 14 *
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 *
 20 * A copy of the GNU Lesser General Public License is included in the BNCSutil
 21 * distribution in the file COPYING.  If you did not receive this copy,
 22 * write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 23 * Boston, MA  02111-1307  USA
 24 */
 25
 26#ifndef BNCSUTIL_CDKEYDECODER_H
 27#define BNCSUTIL_CDKEYDECODER_H
 28
 29#include <bncsutil/mutil.h>
 30 
 31/**
 32 * Internal key type constants.
 33 */
 34#define KEY_STARCRAFT   1
 35#define KEY_DIABLO2     2
 36#define KEY_WARCRAFT2   2 /* [sic] */
 37#define KEY_WARCRAFT3   3
 38
 39MCEXP(CDKeyDecoder) {
 40protected:
 41    char* cdkey;
 42    int initialized;
 43    int keyOK;
 44    size_t keyLen;
 45    char* keyHash;
 46    size_t hashLen;
 47    int keyType;
 48    unsigned long value1;
 49    unsigned long value2;
 50    unsigned long product;
 51    char* w3value2;
 52    
 53    int processStarCraftKey();
 54    int processWarCraft2Key();
 55    int processWarCraft3Key();
 56    
 57    void decodeKeyTable(int* keyTable);
 58    
 59    inline char getHexValue(int v);
 60    inline int getNumValue(char v);
 61    
 62    inline void mult(const int r, const int x, int* a, int dcByte);
 63    
 64public:
 65    /**
 66     * Creates a new CD-key decoder object.
 67     * Not really useful unless subclassed.
 68     */
 69    CDKeyDecoder();
 70
 71	CDKeyDecoder(const char* cd_key);
 72    
 73    /**
 74     * Creates a new CD-key decoder object, using the specified key.
 75     * keyLength should be the length of the key, NOT INCLUDING the
 76     * null-terminator.  Applications should use isKeyValid after using
 77     * this constructor to check the validity of the provided key.
 78     */
 79    CDKeyDecoder(const char* cdKey, size_t keyLength);
 80    
 81    virtual ~CDKeyDecoder();
 82    
 83    int isKeyValid();
 84    int getVal2Length();
 85    uint32_t getProduct();
 86    uint32_t getVal1();
 87    uint32_t getVal2();
 88    int getLongVal2(char* out);
 89    
 90    /**
 91     * Calculates the CD-Key hash for use in SID_AUTH_CHECK (0x51)
 92     * Returns the length of the generated hash; call getHash and pass
 93     * it a character array that is at least this size.  Returns 0 on failure.
 94     *
 95     * Note that clientToken and serverToken will be added to the buffer and
 96     * hashed as-is, regardless of system endianness.  It is assumed that
 97     * the program's extraction of the server token does not change its
 98     * endianness, and since the client token is generated by the client,
 99     * endianness is not a factor.
100     */
101    size_t calculateHash(uint32_t clientToken, uint32_t serverToken);
102    
103    /**
104     * Places the calculated CD-key hash in outputBuffer.  You must call
105     * calculateHash before getHash.  Returns the length of the hash
106     * that was copied to outputBuffer, or 0 on failure.  The hash is
107     * not deleted after getHash is run; subsequent calls to getHash
108     * will still function.
109     */
110    size_t getHash(char* outputBuffer);
111};
112
113#endif /* BNCSUTIL_CDKEYDECODER_H */