Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Friends
CIEPatcherDlg Class Reference

#include <IEPatcherDlg.h>

Collaboration diagram for CIEPatcherDlg:
Collaboration graph
[legend]

List of all members.

Public Types

enum  { IDD = IDD_IEPATCHER_DIALOG }

Public Member Functions

void AddFileToList (const CString &sFile)
BOOL GetPendingFileToScan (CString &sFileToScan)
BOOL GetPendingFileToPatch (CString &sFileToPatch)
void UpdateFileStatus (const CString &sFile, PatchStatus ps)
void UpdateFileStatus (int nFileIndex, const CString &sFile, PatchStatus ps)
 CIEPatcherDlg (CWnd *pParent=NULL)
virtual ~CIEPatcherDlg ()

Static Public Member Functions

static PatchStatus ScanFile (const CString &sFileName)
static PatchStatus ScanBuffer (char *pszBuffer, long nBufferSize, BOOL bApplyPatches)
static BOOL PatchFile (const CString &sFileFrom, const CString &sFileTo, PatchStatus *pPatchStatus)
static BOOL WriteBufferToFile (const CString &sFileName, char *pszBuffer, long nBufferSize)
static BOOL ReadFileToBuffer (const CString &sFileName, char **ppszBuffer, long *pnBufferSize)
static void TraceProgress (const CString &sProgress)

Public Attributes

CImageList m_cImageList
CArray< QueuedFileData
*, QueuedFileData * > 
m_cQueuedFileDataList
CCriticalSection m_csQueuedFileDataList
CButton m_btnPatch
CListCtrl m_cFileList

Protected Member Functions

virtual void DoDataExchange (CDataExchange *pDX)
BOOL CanExit ()
virtual BOOL OnInitDialog ()
afx_msg void OnPaint ()
afx_msg HCURSOR OnQueryDragIcon ()
afx_msg void OnClose ()
afx_msg void OnScan ()
afx_msg void OnClickFilelist (NMHDR *pNMHDR, LRESULT *pResult)
afx_msg void OnPatch ()
afx_msg LONG OnUpdateFileStatus (WPARAM, LPARAM)

Protected Attributes

CIEPatcherDlgAutoProxym_pAutoProxy
HICON m_hIcon

Private Member Functions

 DECLARE_DYNAMIC (CIEPatcherDlg)

Friends

class CIEPatcherDlgAutoProxy

Detailed Description

Definition at line 36 of file IEPatcherDlg.h.


Member Enumeration Documentation

anonymous enum
Enumerator:
IDD 

Definition at line 69 of file IEPatcherDlg.h.


Constructor & Destructor Documentation

CIEPatcherDlg::CIEPatcherDlg ( CWnd *  pParent = NULL)

Definition at line 41 of file IEPatcherDlg.cpp.

       : CDialog(CIEPatcherDlg::IDD, pParent)
{
       //{{AFX_DATA_INIT(CIEPatcherDlg)
       //}}AFX_DATA_INIT
       // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
       m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
       m_pAutoProxy = NULL;
}

Definition at line 52 of file IEPatcherDlg.cpp.

{
       // If there is an automation proxy for this dialog, set
       //  its back pointer to this dialog to NULL, so it knows
       //  the dialog has been deleted.
       if (m_pAutoProxy != NULL)
              m_pAutoProxy->m_pDialog = NULL;
}

Member Function Documentation

void CIEPatcherDlg::AddFileToList ( const CString &  sFile)

Definition at line 507 of file IEPatcherDlg.cpp.

{
       CSingleLock sl(&m_csQueuedFileDataList, TRUE);

       int nIndex = m_cFileList.GetItemCount();
       m_cFileList.InsertItem(nIndex, sFile, IMG_UNKNOWNSTATUS);

       QueuedFileData *pData = new QueuedFileData;
       pData->ps = psUnknownStatus;
       pData->sFileName = sFile;
       pData->sPatchedFileName = sFile;
       m_cQueuedFileDataList.Add(pData);

       UpdateFileStatus(nIndex, pData->ps);
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CIEPatcherDlg::CanExit ( ) [protected]

Definition at line 268 of file IEPatcherDlg.cpp.

{
       // If the proxy object is still around, then the automation
       //  controller is still holding on to this application.  Leave
       //  the dialog around, but hide its UI.
       if (m_pAutoProxy != NULL)
       {
              ShowWindow(SW_HIDE);
              return FALSE;
       }

       return TRUE;
}

Here is the caller graph for this function:

void CIEPatcherDlg::DoDataExchange ( CDataExchange *  pDX) [protected, virtual]

Definition at line 62 of file IEPatcherDlg.cpp.

{
       CDialog::DoDataExchange(pDX);
       //{{AFX_DATA_MAP(CIEPatcherDlg)
       DDX_Control(pDX, IDC_PATCH, m_btnPatch);
       DDX_Control(pDX, IDC_FILELIST, m_cFileList);
       //}}AFX_DATA_MAP
}
BOOL CIEPatcherDlg::GetPendingFileToPatch ( CString &  sFileToPatch)

Definition at line 609 of file IEPatcherDlg.cpp.

{
       CSingleLock sl(&m_csQueuedFileDataList, TRUE);

       for (int n = 0; n < m_cQueuedFileDataList.GetSize(); n++)
       {
              if (m_cQueuedFileDataList[n]->ps == psPatchPending)
              {
                     sFileToPatch = m_cQueuedFileDataList[n]->sFileName;
                     return TRUE;
              }
       }
       return FALSE;
}

Here is the caller graph for this function:

BOOL CIEPatcherDlg::GetPendingFileToScan ( CString &  sFileToScan)

Definition at line 593 of file IEPatcherDlg.cpp.

{
       CSingleLock sl(&m_csQueuedFileDataList, TRUE);

       for (int n = 0; n < m_cQueuedFileDataList.GetSize(); n++)
       {
              if (m_cQueuedFileDataList[n]->ps == psUnknownStatus)
              {
                     sFileToScan = m_cQueuedFileDataList[n]->sFileName;
                     return TRUE;
              }
       }
       return FALSE;
}

Here is the caller graph for this function:

void CIEPatcherDlg::OnClickFilelist ( NMHDR *  pNMHDR,
LRESULT pResult 
) [protected]

Definition at line 257 of file IEPatcherDlg.cpp.

{
       // Check if files are selected     

       *pResult = 0;
}
void CIEPatcherDlg::OnClose ( void  ) [protected]

Definition at line 203 of file IEPatcherDlg.cpp.

{
       if (CanExit())
              CDialog::OnClose();
}

Here is the call graph for this function:

BOOL CIEPatcherDlg::OnInitDialog ( ) [protected, virtual]

Definition at line 88 of file IEPatcherDlg.cpp.

{
       CDialog::OnInitDialog();

       // Start the scanner thread
       AfxBeginThread(RUNTIME_CLASS(CScannerThread), 0);

       // Set the icon for this dialog.  The framework does this automatically
       //  when the application's main window is not a dialog
       SetIcon(m_hIcon, TRUE);                   // Set big icon
       SetIcon(m_hIcon, FALSE);           // Set small icon

       // Add icons to image list
       m_cImageList.Create(16, 16, ILC_MASK, 0, 5);
       m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_DOESNTCONTAINIE));
       m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_CONTAINSIE));
       m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_CONTAINSMOZILLA));
       m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_UNKNOWNSTATUS));

       // Associate image list with file list
       m_cFileList.SetImageList(&m_cImageList, LVSIL_SMALL);

       struct ColumnData
       {
              TCHAR *sColumnTitle;
              int nPercentageWidth;
              int nFormat;
       };

       ColumnData aColData[] =
       {
              { _T("File"),               70, LVCFMT_LEFT },
              { _T("Patch Status"),       30, LVCFMT_LEFT }
       };

       // Get the size of the file list control and neatly
       // divide it into columns

       CRect rcFileList;
       m_cFileList.GetClientRect(&rcFileList);

       int nColTotal = sizeof(aColData) / sizeof(aColData[0]);
       int nWidthRemaining = rcFileList.Width();
       
       for (int nCol = 0; nCol < nColTotal; nCol++)
       {
              ColumnData *pData = &aColData[nCol];

              int nColWidth = (rcFileList.Width() * pData->nPercentageWidth) / 100;
              if (nCol == nColTotal - 1)
              {
                     nColWidth = nWidthRemaining;
              }
              else if (nColWidth > nWidthRemaining)
              {
                     nColWidth = nWidthRemaining;
              }

              m_cFileList.InsertColumn(nCol, pData->sColumnTitle, pData->nFormat, nColWidth);

              nWidthRemaining -= nColWidth;
              if (nColWidth <= 0)
              {
                     break;
              }
       }

       return TRUE;  // return TRUE  unless you set the focus to a control
}
void CIEPatcherDlg::OnPaint ( ) [protected]

Definition at line 163 of file IEPatcherDlg.cpp.

{
       if (IsIconic())
       {
              CPaintDC dc(this); // device context for painting

              SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

              // Center icon in client rectangle
              int cxIcon = GetSystemMetrics(SM_CXICON);
              int cyIcon = GetSystemMetrics(SM_CYICON);
              CRect rect;
              GetClientRect(&rect);
              int x = (rect.Width() - cxIcon + 1) / 2;
              int y = (rect.Height() - cyIcon + 1) / 2;

              // Draw the icon
              dc.DrawIcon(x, y, m_hIcon);
       }
       else
       {
              CDialog::OnPaint();
       }
}
void CIEPatcherDlg::OnPatch ( ) [protected]

Definition at line 243 of file IEPatcherDlg.cpp.

{
       int nItem = -1;
       do {
              nItem = m_cFileList.GetNextItem(nItem, LVNI_ALL | LVNI_SELECTED);
              if (nItem != -1)
              {
                     m_cQueuedFileDataList[nItem]->ps = psPatchPending;
                     UpdateFileStatus(nItem, m_cQueuedFileDataList[nItem]->sFileName, m_cQueuedFileDataList[nItem]->ps);
              }
       } while (nItem != -1);
}

Here is the call graph for this function:

HCURSOR CIEPatcherDlg::OnQueryDragIcon ( ) [protected]

Definition at line 191 of file IEPatcherDlg.cpp.

{
       return (HCURSOR) m_hIcon;
}
void CIEPatcherDlg::OnScan ( ) [protected]

Definition at line 219 of file IEPatcherDlg.cpp.

{
       CScanForFilesDlg dlg;
       
       if (dlg.DoModal() == IDOK)
       {
              CWaitCursor wc;

              CFileFind op;
              if (op.FindFile(dlg.m_sFilePattern))
              {
                     op.FindNextFile();
                     do {
                            if (!op.IsDirectory())
                            {
                                   AddFileToList(op.GetFilePath());
                            }
                     } while (op.FindNextFile());
                     op.Close();
              }
       }
}

Here is the call graph for this function:

LONG CIEPatcherDlg::OnUpdateFileStatus ( WPARAM  wParam,
LPARAM  lParam 
) [protected]

Definition at line 210 of file IEPatcherDlg.cpp.

{
       PatchStatus ps = (PatchStatus) wParam;
       TCHAR *pszFile = (TCHAR *) lParam;
       UpdateFileStatus(pszFile, ps);
       return 0;
}

Here is the call graph for this function:

BOOL CIEPatcherDlg::PatchFile ( const CString &  sFileFrom,
const CString &  sFileTo,
PatchStatus pPatchStatus 
) [static]

Definition at line 464 of file IEPatcherDlg.cpp.

{
       if (sFileTo.IsEmpty())
       {
              return FALSE;
       }
       if (sFileTo == sFileFrom)
       {
              TraceProgress("Warning: Patching disabled for safety reasons, source and destination names must differ");
              return FALSE;
       }
       
       char *pszBuffer = NULL;
       long nBufferSize = 0;

       if (!ReadFileToBuffer(sFileFrom, &pszBuffer, &nBufferSize))
       {
              return FALSE;
       }

       // Scan and patch the buffer
       *pPatchStatus = ScanBuffer(pszBuffer, nBufferSize, TRUE);
       if (*pPatchStatus == psNotPatchable)
       {
              TraceProgress("Error: Nothing was found to patch");
       }
       else
       {
              // Write out the patch file
              WriteBufferToFile(sFileTo, pszBuffer, nBufferSize);
       }

       delete []pszBuffer;
       return FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL CIEPatcherDlg::ReadFileToBuffer ( const CString &  sFileName,
char **  ppszBuffer,
long pnBufferSize 
) [static]

Definition at line 319 of file IEPatcherDlg.cpp.

{
       CString sProcessing;
       sProcessing.Format("Processing file \"%s\"", sFileName);
       TraceProgress(sProcessing);

       // Allocate a memory buffer to slurp up the whole file
       struct _stat srcStat;
       _stat(sFileName, &srcStat);

       char *pszBuffer = new char[srcStat.st_size / sizeof(char)];
       if (pszBuffer == NULL)
       {
              TraceProgress("Error: Could not allocate buffer for file");
              return FALSE;
       }
       FILE *fSrc = fopen(sFileName, "rb");
       if (fSrc == NULL)
       {
              TraceProgress("Error: Could not open file");
              delete []pszBuffer;
              return FALSE;
       }
       size_t sizeSrc = srcStat.st_size;
       size_t sizeRead = 0;

       // Dumb but effective
       sizeRead = fread(pszBuffer, 1, sizeSrc, fSrc);
       fclose(fSrc);

       if (sizeRead != sizeSrc)
       {
              TraceProgress("Error: Could not read all of file");
              delete []pszBuffer;
              return FALSE;
       }

       *ppszBuffer = pszBuffer;
       *pnBufferSize = sizeRead;

       return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PatchStatus CIEPatcherDlg::ScanBuffer ( char *  pszBuffer,
long  nBufferSize,
BOOL  bApplyPatches 
) [static]

Definition at line 363 of file IEPatcherDlg.cpp.

{
       if (nBufferSize < sizeof(CLSID))
       {
              return psNotPatchable;
       }
              
       TraceProgress("Scanning for IE...");

       BOOL bPatchApplied = FALSE;
       PatchStatus ps = psUnknownStatus;

       // Scan through buffer, one byte at a time doing a memcmp
       for (size_t i = 0; i < nBufferSize - sizeof(CLSID); i++)
       {
              if (memcmp(&pszBuffer[i], &CLSID_MozillaBrowser, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found CLSID_MozillaBrowser");
                     if (ps == psUnknownStatus)
                     {
                            ps = psAlreadyPatched;
                     }
              }
              else if (memcmp(&pszBuffer[i], &CLSID_WebBrowser_V1, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found CLSID_WebBrowser_V1");
                     if (ps == psUnknownStatus)
                     {
                            ps = psPatchable;
                     }
                     if (bApplyPatch)
                     {
                            TraceProgress("Patching with CLSID_MozillaBrowser");
                            memcpy(&pszBuffer[i], &CLSID_MozillaBrowser, sizeof(CLSID));
                            bPatchApplied = TRUE;
                     }
              }
              else if (memcmp(&pszBuffer[i], &CLSID_WebBrowser, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found CLSID_WebBrowser");
                     if (ps == psUnknownStatus)
                     {
                            ps = psPatchable;
                     }
                     if (bApplyPatch)
                     {
                            TraceProgress("Patching with CLSID_MozillaBrowser");
                            memcpy(&pszBuffer[i], &CLSID_MozillaBrowser, sizeof(CLSID));
                            TraceProgress("Patching with CLSID_MozillaBrowser");
                            bPatchApplied = TRUE;
                     }
              }
              else if (memcmp(&pszBuffer[i], &IID_IWebBrowser, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found IID_IWebBrowser");
                     if (ps == psUnknownStatus)
                     {
                            ps = psPatchable;
                     }
              }
              else if (memcmp(&pszBuffer[i], &CLSID_InternetExplorer, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Warning: Found CLSID_InternetExplorer, patching might not work");
                     if (ps == psUnknownStatus)
                     {
                            ps = psMayBePatchable;
                     }
              }
              else if (memcmp(&pszBuffer[i], &IID_IWebBrowser2, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found IID_IWebBrowser2");
                     if (ps == psUnknownStatus)
                     {
                            ps = psPatchable;
                     }
              }
              else if (memcmp(&pszBuffer[i], &IID_IWebBrowserApp, sizeof(CLSID)) == 0)
              {
                     TraceProgress("Found IID_IWebBrowserApp");
                     if (ps == psUnknownStatus)
                     {
                            ps = psPatchable;
                     }
              }
       }

       if (ps == psUnknownStatus)
       {
              ps = psNotPatchable;
       }
       if (bApplyPatch)
       {
              ps = (bPatchApplied) ? psAlreadyPatched : psNotPatchable;
       }

       TraceProgress("Scan completed");

       return ps;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PatchStatus CIEPatcherDlg::ScanFile ( const CString &  sFileName) [static]

Definition at line 283 of file IEPatcherDlg.cpp.

{
       char *pszBuffer = NULL;
       long nBufferSize = 0;
       if (!ReadFileToBuffer(sFileName, &pszBuffer, &nBufferSize))
       {
              return psFileError;
       }

       PatchStatus ps = ScanBuffer(pszBuffer, nBufferSize, FALSE);
       delete []pszBuffer;
       return ps;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CIEPatcherDlg::TraceProgress ( const CString &  sProgress) [static]

Definition at line 501 of file IEPatcherDlg.cpp.

{
       // TODO
}

Here is the caller graph for this function:

void CIEPatcherDlg::UpdateFileStatus ( const CString &  sFile,
PatchStatus  ps 
)

Definition at line 577 of file IEPatcherDlg.cpp.

{
       CSingleLock sl(&m_csQueuedFileDataList, TRUE);

       for (int n = 0; n < m_cQueuedFileDataList.GetSize(); n++)
       {
              if (m_cQueuedFileDataList[n]->sFileName == sFile)
              {
                     UpdateFileStatus(n, sFile, ps);
                     m_cQueuedFileDataList[n]->ps = ps;
                     return;
              }
       }
}

Here is the caller graph for this function:

void CIEPatcherDlg::UpdateFileStatus ( int  nFileIndex,
const CString &  sFile,
PatchStatus  ps 
)

Definition at line 524 of file IEPatcherDlg.cpp.

{
       CString sStatus;
       int nIconStatus = -1;

       switch (ps)
       {
       case psFileError:
              sStatus = _T("File error");
              break;

       case psNotPatchable:
              sStatus = _T("Nothing to patch");
              nIconStatus = IMG_DOESNTCONTAINIE;
              break;

       case psPatchable:
              sStatus = _T("Patchable");
              nIconStatus = IMG_CONTAINSIE;
              break;

       case psMayBePatchable:
              sStatus = _T("Maybe patchable");
              nIconStatus = IMG_CONTAINSIE;
              break;

       case psAlreadyPatched:
              sStatus = _T("Already patched");
              nIconStatus = IMG_CONTAINSMOZILLA;
              break;

       case psUnknownStatus:
              sStatus = _T("Status pending");
              nIconStatus = IMG_UNKNOWNSTATUS;
              break;

       case psPatchPending:
              sStatus = _T("Patch pending");
              break;

       default:
              sStatus = _T("*** ERROR ***");
              break;
       }

       if (nIconStatus != -1)
       {
              m_cFileList.SetItem(nFileIndex, -1, LVIF_IMAGE, NULL, nIconStatus, 0, 0, 0);
       }
       m_cFileList.SetItemText(nFileIndex, ITEM_PATCHSTATUS, sStatus);
}
BOOL CIEPatcherDlg::WriteBufferToFile ( const CString &  sFileName,
char *  pszBuffer,
long  nBufferSize 
) [static]

Definition at line 298 of file IEPatcherDlg.cpp.

{
       CString sMessage;
       sMessage.Format("Saving patched file \"%s\"", sFileName);
       TraceProgress(sMessage);

       FILE *fDest = fopen(sFileName, "wb");
       if (fDest == NULL)
       {
              TraceProgress("Error: Could not open destination file");
              return FALSE;
       }

       fwrite(pszBuffer, 1, nBufferSize, fDest);
       fclose(fDest);
       TraceProgress("File saved");

       return TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class CIEPatcherDlgAutoProxy [friend]

Definition at line 39 of file IEPatcherDlg.h.


Member Data Documentation

Definition at line 70 of file IEPatcherDlg.h.

Definition at line 71 of file IEPatcherDlg.h.

Definition at line 62 of file IEPatcherDlg.h.

Definition at line 64 of file IEPatcherDlg.h.

Definition at line 65 of file IEPatcherDlg.h.

HICON CIEPatcherDlg::m_hIcon [protected]

Definition at line 83 of file IEPatcherDlg.h.

Definition at line 82 of file IEPatcherDlg.h.


The documentation for this class was generated from the following files: