Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - problema con le char
Forum - C/C++ - problema con le char

Avatar
davidsf (Normal User)
Newbie


Messaggi: 19
Iscritto: 05/08/2008

Segnala al moderatore
Postato alle 11:06
Lunedì, 11/08/2008
dunque il mio problema consiste in questo:

io ho tre file: main.cpp; GetMsnPassword.h e GetMsnPassword.cpp

in GetMsnPassword.h ho dichiarato questa struttura:

Codice sorgente - presumibilmente C++

  1. #ifndef _GETMSNPASS_
  2. #define _GETMSNPASS_
  3. #define WIN32_LEAN_AND_MEAN
  4.  
  5. #include <windows.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <tchar.h>
  9.  
  10. typedef struct ACCESSDATA
  11. {
  12.     char *Username;
  13.     char *Password;
  14. } ACCESSDATA;
  15.  
  16. //Following definitions taken from wincred.h
  17. //[available only in Oct 2002 MS Platform SDK / LCC-Win32 Includes]
  18.  
  19. typedef struct _CREDENTIAL_ATTRIBUTEA {
  20.     LPSTR Keyword;
  21.     DWORD Flags;
  22.     DWORD ValueSize;
  23.     LPBYTE Value;
  24. }
  25. CREDENTIAL_ATTRIBUTEA,*PCREDENTIAL_ATTRIBUTEA;
  26.  
  27. typedef struct _CREDENTIALA {
  28.     DWORD Flags;
  29.     DWORD Type;
  30.     LPSTR TargetName;
  31.     LPSTR Comment;
  32.     FILETIME LastWritten;
  33.     DWORD CredentialBlobSize;
  34.     LPBYTE CredentialBlob;
  35.     DWORD Persist;
  36.     DWORD AttributeCount;
  37.     PCREDENTIAL_ATTRIBUTEA Attributes;
  38.     LPSTR TargetAlias;
  39.     LPSTR UserName;
  40. } CREDENTIALA,*PCREDENTIALA;
  41.  
  42. typedef CREDENTIALA CREDENTIAL;
  43. typedef PCREDENTIALA PCREDENTIAL;
  44.  
  45.  
  46. ////////////////////////////////////////////////////////////////////
  47.  
  48. typedef BOOL (WINAPI *typeCredEnumerate)(LPCTSTR, DWORD, DWORD *,
  49. PCREDENTIAL **);
  50. typedef VOID (WINAPI *typeCredFree)(PVOID);
  51.  
  52. class MSNPassword
  53. {
  54.     public:
  55.         MSNPassword();
  56.         ~MSNPassword() {};
  57.  
  58.         ACCESSDATA * GetPasswords();
  59.  
  60.     private:
  61.         typeCredEnumerate pfCredEnumerate;
  62.         typeCredFree pfCredFree;
  63. };
  64.  
  65. #endif



in GetMsnPassword.cpp

Codice sorgente - presumibilmente C++

  1. #include "GetMsnPassword.h"
  2.  
  3. MSNPassword::MSNPassword()
  4. {
  5.     typeCredEnumerate pfCredEnumerate = NULL;
  6.     typeCredFree pfCredFree = NULL;
  7. }
  8.  
  9. ACCESSDATA * MSNPassword::GetPasswords()
  10. {
  11.     PCREDENTIAL *CredentialCollection = NULL;
  12.     HMODULE hAdvapi32DLL = NULL;
  13.     DWORD dwCount = 0;
  14.     DWORD dwTempIndex = 0;
  15.     BOOL bOK = FALSE;
  16.  
  17.     hAdvapi32DLL = LoadLibrary(_T("advapi32.dll"));
  18.  
  19. #ifdef _UNICODE
  20.     pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateW");
  21. #else
  22.     pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateA");
  23. #endif
  24.  
  25.     pfCredFree = (typeCredFree)GetProcAddress(hAdvapi32DLL,"CredFree");
  26.  
  27.     //Get an array of 'credential', satisfying the filter
  28.     bOK = pfCredEnumerate(_T("WindowsLive:name=*"),0,&dwCount,&CredentialCollection);
  29.  
  30.     ACCESSDATA D[dwCount];
  31.     for(dwTempIndex=0; dwTempIndex<dwCount; dwTempIndex++)
  32.     {
  33.         D[dwTempIndex].Username =  CredentialCollection[dwTempIndex]->UserName;
  34.         if (CredentialCollection[dwTempIndex]->CredentialBlob != NULL)
  35.         {
  36.             D[dwTempIndex].Password = new char[CredentialCollection[dwTempIndex]->CredentialBlobSize / 2];
  37.             for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
  38.                 D[dwTempIndex].Password[W] = ' ';
  39.  
  40.             for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
  41.                 D[dwTempIndex].Password[W] = (char) CredentialCollection[dwTempIndex]->CredentialBlob[W * 2];
  42.         }
  43.         else
  44.         {
  45.             D[dwTempIndex].Password = "(NULL)";
  46.         }
  47.     }
  48.  
  49.     //Free credential collection
  50.     pfCredFree(CredentialCollection);
  51.  
  52.  
  53.  
  54.     //Free lib
  55.     if(NULL != hAdvapi32DLL)
  56.     {
  57.         FreeLibrary(hAdvapi32DLL);
  58.     }
  59.     return D;
  60. }



e in main.cpp

Codice sorgente - presumibilmente C++

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <tchar.h>
  4. #include "GetMsnPassword.h"
  5.  
  6. int main()
  7. {
  8.         MSNPassword T;
  9.         ACCESSDATA *R = T.GetPasswords();
  10.         printf(R[0].Username);
  11.     printf(R[0].Password);
  12.         system("PAUSE");
  13.     return TRUE;
  14. }



ah, uso dev c++

il programma arriva a scrivermi sulla console l'username (indirizzo) corretto, ma la password viene una roba assurda

perchè?
come posso risolvere?

(ho aggiunto anche i file del progetto)


davidsf ha allegato un file: Hacking passwords.zip (3807 bytes)
Clicca qui per scaricare il file
PM Quote