Results 1 to 9 of 9

Thread: Code for my DLL not working PLZ HELP

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110

    Code for my DLL not working PLZ HELP

    Having problems with the code below!
    If you help me fix it, I'll give you money.
    Right now it compiles into the DLL without any errors or warnings, but....it crashes when being used.

    Code:
    #include <windows.h>
    #include <stdio.h>
    
    const BYTE KeyTable[256] = { 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0x00, 0xFF, 0x01, 0xFF, 0x02, 0x03, 0x04, 0x05, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0xFF, 0x0D, 0x0E, 0xFF, 0x0F, 0x10, 0xFF, 
    0x11, 0xFF, 0x12, 0xFF, 0x13, 0xFF, 0x14, 0x15, 0x16, 0x17, 0x18, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0xFF, 0x0D, 0x0E, 0xFF, 0x0F, 0x10, 0xFF, 
    0x11, 0xFF, 0x12, 0xFF, 0x13, 0xFF, 0x14, 0x15, 0x16, 0x17, 0x18, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 
    0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xF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, 0x03, 0x09, 0x00, 0x01, 0x0F, 0x07, 0x0C, 0x0A, 0x06, 0x04, 0x08,
    0x06, 0x02, 0x04, 0x05, 0x0B, 0x08, 0x0C, 0x0E, 0x0D, 0x0F, 0x07, 0x01, 0x0A, 0x00, 0x03, 0x09,
    0x05, 0x04, 0x0E, 0x0C, 0x07, 0x06, 0x0D, 0x0A, 0x0F, 0x02, 0x09, 0x01, 0x00, 0x0B, 0x08, 0x03,
    0x0C, 0x07, 0x08, 0x0F, 0x0B, 0x00, 0x05, 0x09, 0x0D, 0x0A, 0x06, 0x0E, 0x02, 0x04, 0x03, 0x01,
    0x03, 0x0A, 0x0E, 0x08, 0x01, 0x0B, 0x05, 0x04, 0x02, 0x0F, 0x0D, 0x0C, 0x06, 0x07, 0x09, 0x00,
    0x0C, 0x0D, 0x01, 0x0F, 0x08, 0x0E, 0x05, 0x0B, 0x03, 0x0A, 0x09, 0x00, 0x07, 0x02, 0x04, 0x06,
    0x0D, 0x0A, 0x07, 0x0E, 0x01, 0x06, 0x0B, 0x08, 0x0F, 0x0C, 0x05, 0x02, 0x03, 0x00, 0x04, 0x09,
    0x03, 0x0E, 0x07, 0x05, 0x0B, 0x0F, 0x08, 0x0C, 0x01, 0x0A, 0x04, 0x0D, 0x00, 0x06, 0x09, 0x02,
    0x0B, 0x06, 0x09, 0x04, 0x01, 0x08, 0x0A, 0x0D, 0x07, 0x0E, 0x00, 0x0C, 0x0F, 0x02, 0x03, 0x05,
    0x0C, 0x07, 0x08, 0x0D, 0x03, 0x0B, 0x00, 0x0E, 0x06, 0x0F, 0x09, 0x04, 0x0A, 0x01, 0x05, 0x02,
    0x0C, 0x06, 0x0D, 0x09, 0x0B, 0x00, 0x01, 0x02, 0x0F, 0x07, 0x03, 0x04, 0x0A, 0x0E, 0x08, 0x05,
    0x03, 0x06, 0x01, 0x05, 0x0B, 0x0C, 0x08, 0x00, 0x0F, 0x0E, 0x09, 0x04, 0x07, 0x0A, 0x0D, 0x02,
    0x0A, 0x07, 0x0B, 0x0F, 0x02, 0x08, 0x00, 0x0D, 0x0E, 0x0C, 0x01, 0x06, 0x09, 0x03, 0x05, 0x04,
    0x0A, 0x0B, 0x0D, 0x04, 0x03, 0x08, 0x05, 0x09, 0x01, 0x00, 0x0F, 0x0C, 0x07, 0x0E, 0x02, 0x06,
    0x0B, 0x04, 0x0D, 0x0F, 0x01, 0x06, 0x03, 0x0E, 0x07, 0x0A, 0x0C, 0x08, 0x09, 0x02, 0x05, 0x00,
    0x09, 0x06, 0x07, 0x00, 0x01, 0x0A, 0x0D, 0x02, 0x03, 0x0E, 0x0F, 0x0C, 0x05, 0x0B, 0x04, 0x08,
    0x0D, 0x0E, 0x05, 0x06, 0x01, 0x09, 0x08, 0x0C, 0x02, 0x0F, 0x03, 0x07, 0x0B, 0x04, 0x00, 0x0A,
    0x09, 0x0F, 0x04, 0x00, 0x01, 0x06, 0x0A, 0x0E, 0x02, 0x03, 0x07, 0x0D, 0x05, 0x0B, 0x08, 0x0C,
    0x03, 0x0E, 0x01, 0x0A, 0x02, 0x0C, 0x08, 0x04, 0x0B, 0x07, 0x0D, 0x00, 0x0F, 0x06, 0x09, 0x05,
    0x07, 0x02, 0x0C, 0x06, 0x0A, 0x08, 0x0B, 0x00, 0x0F, 0x04, 0x03, 0x0E, 0x09, 0x01, 0x0D, 0x05,
    0x0C, 0x04, 0x05, 0x09, 0x0A, 0x02, 0x08, 0x0D, 0x03, 0x0F, 0x01, 0x0E, 0x06, 0x07, 0x0B, 0x00,
    0x0A, 0x08, 0x0E, 0x0D, 0x09, 0x0F, 0x03, 0x00, 0x04, 0x06, 0x01, 0x0C, 0x07, 0x0B, 0x02, 0x05,
    0x03, 0x0C, 0x04, 0x0A, 0x02, 0x0F, 0x0D, 0x0E, 0x07, 0x00, 0x05, 0x08, 0x01, 0x06, 0x0B, 0x09,
    0x0A, 0x0C, 0x01, 0x00, 0x09, 0x0E, 0x0D, 0x0B, 0x03, 0x07, 0x0F, 0x08, 0x05, 0x02, 0x04, 0x06,
    0x0E, 0x0A, 0x01, 0x08, 0x07, 0x06, 0x05, 0x0C, 0x02, 0x0F, 0x00, 0x0D, 0x03, 0x0B, 0x04, 0x09,
    0x03, 0x08, 0x0E, 0x00, 0x07, 0x09, 0x0F, 0x0C, 0x01, 0x06, 0x0D, 0x02, 0x05, 0x0A, 0x0B, 0x04,
    0x03, 0x0A, 0x0C, 0x04, 0x0D, 0x0B, 0x09, 0x0E, 0x0F, 0x06, 0x01, 0x07, 0x02, 0x00, 0x05, 0x08
    };
    
    #define W3_KEYLEN 26
    #define W3_BUFLEN (W3_KEYLEN*2)
        
    void tableLookup(char *key, BYTE buf[]);
    void Mult(int rounds, int mulx, int bufA[], int bufB[], int decodedBYTE);
    void decodeKeyTablePass1(int keyTable[]);
    void decodeKeyTablePass2(int keyTable[]);
    
    int val1;
    BYTE val2[10];
    int product;
    
        /** Creates a new instance of War3Decode */
        void __stdcall DecodeWar3CDKey(char *cdkey)
        {
            BYTE table[W3_BUFLEN];
            int values[4];
            tableLookup(cdkey, table); 
            
            for(int i = W3_BUFLEN; i > 0; i--) 
                Mult(4, 5, values, values, table[i - 1]); 
    
            // -------------
    
            decodeKeyTablePass1(values); 
            
            
            decodeKeyTablePass2(values); 
    
            
            product = values[0] >> 0x0a; 
            //val1 = ((values[0] & 0x03FF) << 0x10) | (values[1] >> 0x10); 
            //val1 = IntFromBYTEArray.LITTLEENDIAN.getInteger(values, 0);
            val1 = ((values[0] & 0x03FF) << 0x10) | (values[1] >> 0x10); 
    
            val2[0] = (BYTE)((values[1] & 0x00FF) >> 0);
            val2[1] = (BYTE)((values[1] & 0xFF00) >> 8);
            
    	    *(DWORD *)(val2 + 2) = values[2];
    	    *(DWORD *)(val2 + 6) = values[3];
            
        }
    
    
        void tableLookup(char *key, BYTE buf[]) 
        { 
            int a;
            int b = 0x21;
            BYTE decode;
    
            for(int i = 0; i < W3_KEYLEN; i++) 
            { 
                a = (b + 0x07B5) % W3_BUFLEN; 
                b = (a + 0x07B5) % W3_BUFLEN; 
                decode = KeyTable[ key[i] ];; 
                buf[a] = (BYTE)(decode / 5); 
                buf[b] = (BYTE)(decode % 5); 
            } 
        } 
    
        void Mult(int rounds, int mulx, int bufA[], int bufB[], int decodedBYTE) 
        { 
            int posA = rounds - 1;
            int posB = rounds - 1;
    
            while(rounds-- > 0) 
            { 
                __int64 param1 = bufA[posA--];
                param1 &= 0x00000000FFFFFFFFl;
                
                __int64 param2 = mulx;
                param2 &= 0x00000000FFFFFFFFl;
                
                __int64 edxeax = param1 * param2;
    
                //ULONGLONG edxeax = UInt32x32To64(*BufA--, Mulx); 
                bufB[posB--] = decodedBYTE + (int)edxeax; 
                decodedBYTE = (int)(edxeax >> 32); 
            } 
    
        } 
    
        void decodeKeyTablePass1(int keyTable[]) 
        { 
            int ebx, ecx, esi, ebp; 
            int var_C, var_4; 
            int var_8 = 29; 
    
            for(int i = 464; i >= 0; i -= 16) 
            { 
                esi = (var_8 & 7) << 2; 
                var_4 = var_8 >> 3; 
                var_C = (keyTable[3 - var_4] & (0x0F << esi)) >> esi; 
    
                if(i < 464) 
                { 
                    for(int j = 29; j > var_8; j--) 
                    { 
                        ecx = (j & 7) << 2; 
                        ebp = (keyTable[0x03 - (j >> 3)] & (0x0F << ecx)) >> ecx; 
                        var_C = TranslateTable[ebp^TranslateTable[var_C + i] + i]; 
                    } 
                } 
    
                for(int j = --var_8; j >= 0; j--) 
                { 
                    ecx = (j & 7) << 2; 
                    ebp = (keyTable[0x03 - (j >> 3)] & (0x0F << ecx)) >> ecx; 
                    var_C = TranslateTable[ebp^TranslateTable[var_C + i] + i]; 
                } 
    
                int index = 3 - var_4; 
                ebx = (TranslateTable[var_C + i] & 0x0F) << esi;     
                keyTable[index] =(ebx | ~(0x0F << esi) & ((int)keyTable[index])); 
            } 
        } 
    
        void decodeKeyTablePass2(int keyTable[]) 
        { 
            int eax, edx, ecx, edi, esi, ebp; 
            BYTE Copy[4];
    	    Copy[0] = keyTable[3];
    		Copy[1] = keyTable[2];
    		Copy[2] = keyTable[1];
    		Copy[3] = keyTable[0];
            esi = 0; 
    
            for(edi = 0; edi < 120; edi++) 
            { 
                eax = edi & 0x1F; 
                ecx = esi & 0x1F; 
                edx = 3 - (edi >> 5); 
                
                ebp = *(DWORD *)((BYTE *)(Copy+3) - ((esi >> 5) << 2));  //<-- original c++ code
                
                //System.out.print(PadString.padHex(ebp, 8) + " ");
                
                
                ebp = (ebp & (1 << ecx)) >> ecx; 
                keyTable[edx] = ((ebp & 1) << eax) | (~(1 << eax) & keyTable[edx]); 
                esi += 0x0B; 
                if(esi >= 120) 
                    esi -= 120; 
            } 
        }
    Last edited by ChR0NiC; Sep 26th, 2004 at 11:45 PM.

  2. #2
    Lively Member
    Join Date
    Sep 2004
    Posts
    74
    where are the DLL standard init routine's?
    The load / unload etc etc

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110
    Originally posted by Calibra
    where are the DLL standard init routine's?
    The load / unload etc etc
    Huh?

  4. #4
    Lively Member
    Join Date
    Sep 2004
    Posts
    74
    Originally posted by ChR0NiC
    Huh?
    Where is youre DllMain routine?

    even if it isn't implemented, it needs to be declared, or am i mistaken?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110
    Well I don't have one, but all my other functions work without crash and produce output, just this one crashes it

    I am getting "Access Violation" and it point to the line

    Code:
    ebp = KeyTable[0x03 - (j >> 0x03)];
    Which makes no sense -.-
    Last edited by ChR0NiC; Sep 26th, 2004 at 02:59 PM.

  6. #6
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    I've seen this code before, but I'll refrain from making the comments that always seem to come up when someone mentions it


    Anyway, make sure you're passing the key in the form the function wants it; this code does not check for spaces or dashes in the string, so if they are present it could possibly cause an access violation when it tries to calculate the location in the table from these characters. This is my bet.

    Other than that, I know this code works as advertised, so it's definently a problem with the way you're calling it or passing data.
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2004
    Posts
    110
    There was an include I missed that is

    Code:
    #include "stdafx.h"
    Which means it was in the local folder, I don't seem to have it. Does anyone know what that usually is?

  8. #8
    PowerPoster sunburnt's Avatar
    Join Date
    Feb 2001
    Location
    Boulder, Colorado
    Posts
    1,403
    stdafx.h is a header automatically generated by visual studio when you select to use pre compiled headers (indeed, stdafx is the precompiled header). In this case, if you aren't using precompiled headers, you can safely delete all references to stdafx.h
    Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.

  9. #9
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    And deactivate "precompiled headers" in the project options.

    But you know, with a function name like "DecodeWar3CDKey", it's pretty obvious that this DLL isn't quite legal...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width