Errors in code

This is a discussion on Errors in code within the C++ Programming forums, part of the General Programming Boards category; Hi, i found this code somewhere on google, but it won`t compile . This is the code: Code: /* MSNMessenger ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    4

    Errors in code

    Hi, i found this code somewhere on google, but it won`t compile . This is the code:

    Code:
    /* MSNMessenger DPAPI 
    * 
    * tombkeeper[0x40]nsfocus[0x2e]com 
    * tombkeeper[0x40]xfocus[0x2e]net 
    * 2004.08.11 
    */ 
    
    #include <Windows.h> 
    #include <Stdio.h> 
    
    
    #pragma comment(lib, "Advapi32.lib") 
    
    #define FCHK(a) if (!(a)) {printf(#a " failed\n"); return 0;} 
    
    typedef struct _CRYPTOAPI_BLOB { 
       DWORD cbData; 
       BYTE* pbData; 
    } DATA_BLOB; 
    
    typedef struct _CRYPTPROTECT_PROMPTSTRUCT { 
       DWORD cbSize; 
       DWORD dwPromptFlags; 
       HWND hwndApp; 
       LPCWSTR szPrompt; 
    } CRYPTPROTECT_PROMPTSTRUCT, *PCRYPTPROTECT_PROMPTSTRUCT; 
    
    typedef BOOL (WINAPI *PCryptUnprotectData)( 
       DATA_BLOB* pDataIn, 
       LPWSTR* ppszDataDescr, 
       DATA_BLOB* pOptionalEntropy, 
       PVOID pvReserved, 
       CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct, 
       DWORD dwFlags, 
       DATA_BLOB* pDataOut 
    ); 
    
    PCryptUnprotectData CryptUnprotectData = NULL; 
    
    
    int main(void) 
    { 
       int ret; 
       HMODULE hNtdll; 
    
       HKEY hKey; 
       DWORD dwType; 
       char Data[0x100] = {0}; 
       DWORD dwSize; 
    
       DATA_BLOB DataIn; 
       DATA_BLOB DataOut; 
    
       ret = RegOpenKeyEx 
       ( 
           HKEY_CURRENT_USER, 
           "Software\Microsoft\MSNMessenger", 
           0, 
           KEY_READ, 
           &hKey 
       ); 
       if( ret != ERROR_SUCCESS ) return 1; 
    
       ret = RegQueryValueEx 
       ( 
           hKey, 
           "Password.NET Messenger Service", 
           NULL, 
           &dwType, 
           Data, 
           &dwSize 
       ); 
       if( ret != ERROR_SUCCESS ) return 1; 
    
       FCHK ((hNtdll = LoadLibrary ("Crypt32.dll")) != NULL); 
       FCHK ((CryptUnprotectData = (PCryptUnprotectData) 
              GetProcAddress (hNtdll, "CryptUnprotectData")) != NULL); 
    
       DataIn.pbData = Data + 2; // 
       DataIn.cbData = dwSize-2; 
    
       CryptUnprotectData 
       ( 
           &DataIn, 
           NULL, 
           NULL, 
           NULL, 
           NULL, 
           1, 
           &DataOut 
       ); 
    
       base64_decode (DataOut.pbData, Data, strlen(DataOut.pbData)); 
       printf ( "MSN Password: %s\n", Data); 
       return 0; 
    } 
    
    //copied from GNU libc - libc/resolv/base64.c 
    int base64_decode (char const *src, char *target, size_t targsize) 
    { 
       static const char Base64[] = 
           " ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmn
    opqrstuvwxyz0123456789+/"; 
       static const char Pad64 = '='; 
    
       int tarindex, state, ch; 
       char *pos; 
    
       state = 0; 
       tarindex = 0; 
    
       while ((ch = *src++) != '') 
       { 
           if (isspace (ch)) /* Skip whitespace anywhere. */ 
               continue; 
    
           if (ch == Pad64) 
               break; 
    
           pos = strchr (Base64, ch); 
           if (pos == 0) /* A non-base64 character. */ 
               return (-1); 
    
           switch (state) 
           { 
               case 0: 
               if (target) 
               { 
                   if ((size_t) tarindex >= targsize) 
                       return (-1); 
                   target[tarindex] = (pos - Base64) << 2; 
               } 
               state = 1; 
               break; 
               case 1: 
               if (target) 
               { 
                   if ((size_t) tarindex + 1 >= targsize) 
                       return (-1); 
                   target[tarindex] |= (pos - Base64) >> 4; 
                   target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4; 
               } 
               tarindex++; 
               state = 2; 
               break; 
               case 2: 
               if (target) 
               { 
                  ;if ((size_t) tarindex + 1 >= targsize) 
                       return (-1); 
                   target[tarindex] |= (pos - Base64) >> 2; 
                   target[tarindex + 1] = ((pos - Base64) & 0x03) << 6; 
               } 
               tarindex++; 
               state = 3; 
               break; 
               case 3: 
               if (target) 
               { 
                   if ((size_t) tarindex >= targsize) 
                       return (-1); 
                   target[tarindex] |= (pos - Base64); 
               } 
               tarindex++; 
               state = 0; 
               break; 
               default: 
               abort (); 
           } 
       } 
    
    /* 
      * We are done decoding Base-64 chars. Let's see if we ended 
      * on a byte boundary, and/or with erroneous trailing characters. 
      */ 
    
       if (ch == Pad64) 
       { /* We got a pad char. */ 
           ch = *src++; /* Skip it, get next. */ 
           switch (state) 
           { 
               case 0: /* Invalid = in first position */ 
               case 1: /* Invalid = in second position */ 
                   return (-1); 
    
               case 2: /* Valid, means one byte of info */ 
                /* Skip any number of spaces. */ 
               for ((void) NULL; ch != ''; ch = *src++) 
                   if (!isspace (ch)) 
                       break; 
                /* Make sure there is another trailing = sign. */ 
               if (ch != Pad64) 
                   return (-1); 
               ch = *src++; /* Skip the = */ 
               /* Fall through to "single trailing =" case. */ 
               /* FALLTHROUGH */ 
    
               case 3: /* Valid, means two bytes of info */ 
               /* 
                * We know this char is an =. Is there anything but 
                * whitespace after it? 
               */ 
               for ((void) NULL; ch != ''; ch = *src++) 
                   if (!isspace (ch)) 
                       return (-1); 
    
               /* 
                * Now make sure for cases 2 and 3 that the "extra" 
                * bits that slopped past the last full byte were 
                * zeros. If we don't check them, they become a 
                * subliminal channel. 
                */ 
               if (target && target[tarindex] != 0) 
                   return (-1); 
           } 
       } 
       else 
       { 
           /* 
            * We ended by seeing the end of the string. Make sure we 
            * have no partial bytes lying around. 
            */ 
           if (state != 0) 
               return (-1); 
       } 
    
       return (tarindex); 
    }
    This are the errors:

    Code:
    --------------------Configuration: Cpp1 - Win32 Debug-------------------- 
    Compiling... 
    Cpp1.cpp 
    C:msnCpp1.cpp(72) : error C2664: 'RegQueryValueExA' : cannot convert parameter 5 from 'char [256]' to 'unsigned char *' 
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 
    C:msnCpp1.cpp(79) : error C2440: '=' : cannot convert from 'char *' to 'unsigned char *' 
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 
    C:msnCpp1.cpp(93) : error C2065: 'base64_decode' : undeclared identifier 
    C:msnCpp1.cpp(93) : error C2664: 'strlen' : cannot convert parameter 1 from 'unsigned char *' to 'const char *' 
            Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast 
    C:msnCpp1.cpp(100) : error C2373: 'base64_decode' : redefinition; different type modifiers 
    Error executing cl.exe. 
    
    Cpp1.exe - 5 error(s), 0 warning(s)
    Itzme

  2. #2
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Well good for you I should post code that I find on the internet that doesn't compile too.
    Even better let's make a new forum for code on the internet that doesn't compile.
    Woop?

  3. #3
    yes, I'm registered!!! algi's Avatar
    Join Date
    Nov 2004
    Location
    Ipswich
    Posts
    161
    if it's your first code, go for something simpler, if it isn't well many bits of code doesn't work that you find online. Or it could be old code
    I started out with nothing and I still have most of it left.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    My guess is you're compiling C code with a C++ compiler.

    Try naming your program prog.c
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    It won`t work, i get 21 errors and 4 warnings then

  6. #6
    Arggggh DeepFyre's Avatar
    Join Date
    Sep 2004
    Posts
    227
    its the frickin net dude ... it could be ANYTHING, thats one thing you have to learn, just cuz its there doesnt mean it will work ... your gonna find a lot of code on the net that doesnt work
    Keyboard Not Found! Press any key to continue. . .

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    Yes i know, i have it from a forum. That guys could compile the code with no problem, but it seems i can`t register there...

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    the first thing i saw when i opned the page was this

    #include <Windows.h>
    #include <Stdio.h>

    try lowercase letters
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    > It won`t work, i get 21 errors and 4 warnings then
    Yes, and keeping all the errors to yourself is so much better than posting them to the board where we can see them

    > #include <Stdio.h>
    It's
    #include <stdio.h>
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    Still the same errors... But thanks for your help! And the code is not old, i got it from securityteam.com and is only a few months old.
    Last edited by itzme; 01-07-2005 at 03:09 AM.

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    Case 1
    > Cpp1.exe - 5 error(s), 0 warning(s)

    Case 2
    > It won`t work, i get 21 errors and 4 warnings then

    Perhaps lessons in basic maths are in order....
    Cos I'm sure 21 != 5
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,399
    After adding a few type-casts and a function declaration for base64_decode, it compiled fine for me.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  13. #13
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    Code from the net... in general...

    If the code is pure ANSI/ISO standard C++, and if it's a complete program without errors, you should be OK.

    You need to know how to use and configure your compiler for that particular type of program... i.e. Win32 console, Win32 GUI, DLL, etc.

    If there are multiple source files, you must know how to use and configure your compiler for multiple files. You might need a makefile.

    If the code is non-standard, it may not work with your particular compiler. Most real-world programs do contain some non-standard code. The author/poster should document this stuff, but like DeepFrye said, "its the frickin net dude".

    You can usually tell if the code in non-standard by checking the headers: In this case, <stdio> is standard. <windows> is not standard, but it's psudo-standard, so you can probably compile it using any Windows compiler.

    If you see something like <graphics>, or <sound>, it's non-standard code. Even if your compiler has <graphics> or <sound> headers, they won't be compatible with a different compiler.

    The code may require a special, or 3rd-party library.

    "Porting" non-standard code to a different compiler can be a MAJOR TASK.

    A lot of code on the net is incomplete... It could be a code fragment or snippet not intended to be compiled or run.

    Finally, posting that Password Decrypter code may be have been a violation of the Forum Guidelines. (?)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 03:17 PM
  2. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Linux Programming
    Replies: 0
    Last Post: 10-14-2002, 01:30 PM
  3. RAM/Swap Memory Code Errors
    By ghe1 in forum Linux Programming
    Replies: 2
    Last Post: 04-01-2002, 06:37 AM
  4. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 11:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21