#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Long Beach, California
    Posts
    86
    Rep Power
    14

    Manipulating Files


    I'm trying to make a program in eather C or C++ that finds a certain cookie. My problem is that cookies are named different depending on there login name, and they are held in differen locations depending on what operating system. I would be greatly appreceative if you somebody could tell me how I could do this. Not program it for me, but just tell me what I would have to do. Maby in the future I will port it to something other than Windows, but for now it's just going to be Windows.

    Thanks a bunch
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    Just to verify something here... are you trying to get to the cookie files that are cached by Internet Explorer in the hard drive?
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2001
    Location
    Long Beach, California
    Posts
    86
    Rep Power
    14
    Yeah
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,638
    Rep Power
    4247
    You probably want to use FindFirstUrlCacheEntry(), FindNextUrlCacheEntry() and FindCloseUrlCache(). Check MSDN for the documentation of these functions. The code below should work for you. You'll need to put whatever you need to do to the cache files in the section commented with "**** PUT YOUR CODE HERE *****". Hope this helps!

    Code:
    #include <wininet.h>
    
    BOOL ParseCache() {
        BOOL bResult = FALSE;
        BOOL bDone = FALSE;
        LPINTERNET_CACHE_ENTRY_INFO lpCacheEntry = NULL;  
        DWORD  dwTrySize, dwEntrySize = 4096; // start buffer size    
        HANDLE hCacheDir = NULL;    
        DWORD  dwError = ERROR_INSUFFICIENT_BUFFER;
        
        do 
        {                               
            switch (dwError)
            {
                // need a bigger buffer
                case ERROR_INSUFFICIENT_BUFFER: 
                    delete [] lpCacheEntry;            
                    lpCacheEntry = (LPINTERNET_CACHE_ENTRY_INFO) new char[dwEntrySize];
                    lpCacheEntry->dwStructSize = dwEntrySize;
                    dwTrySize = dwEntrySize;
                    BOOL bSuccess;
                    if (hCacheDir == NULL)                
                      
                        bSuccess = (hCacheDir 
                          = FindFirstUrlCacheEntry("cookie:", lpCacheEntry,
                          &dwTrySize)) != NULL;
                    else
                        bSuccess = FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize);
    
                    if (bSuccess)
                        dwError = ERROR_SUCCESS;    
                    else
                    {
                        dwError = GetLastError();
                        dwEntrySize = dwTrySize; // use new size returned
                    }
                    break;
    
                 // we are done
                case ERROR_NO_MORE_ITEMS:
                    bDone = TRUE;
                    bResult = TRUE;                
                    break;
    
                 // we have got an entry
                case ERROR_SUCCESS:
    		if (lpCacheEntry->CacheEntryType & COOKIE_CACHE_ENTRY) {
    		// ***************************
    		// **** PUT YOUR CODE HERE *****
    		// ***************************
    		}				
                        
                    // get ready for next entry
                    dwTrySize = dwEntrySize;
                    if (FindNextUrlCacheEntry(hCacheDir, lpCacheEntry, &dwTrySize))
                        dwError = ERROR_SUCCESS;          
         
                    else
                    {
                        dwError = GetLastError();
                        dwEntrySize = dwTrySize; // use new size returned
                    }                    
                    break;
    
                // unknown error
                default:
                    bDone = TRUE;                
                    break;
            }
    
            if (bDone)
            {   
                delete [] lpCacheEntry; 
                if (hCacheDir)
                    FindCloseUrlCache(hCacheDir);         
                                      
            }
        } while (!bDone);
        return bResult;
    }

IMN logo majestic logo threadwatch logo seochat tools logo