diff --git a/Contrib/InstallOptions/InstallerOptions.cpp b/Contrib/InstallOptions/InstallerOptions.cpp index c494ac90..1fb062a1 100644 --- a/Contrib/InstallOptions/InstallerOptions.cpp +++ b/Contrib/InstallOptions/InstallerOptions.cpp @@ -826,16 +826,7 @@ int WINAPI StaticLINKWindowProc(HWND hWin, UINT uMsg, LPARAM wParam, WPARAM lPar } #endif -int nIdx; -HWND childwnd; -int cw_vis; -int was_ok_enabled; -char old_cancel[256]; -char old_ok[256]; -char old_back[256]; -int old_cancel_enabled; int old_cancel_visible; -char old_title[1024]; int createCfgDlg() { @@ -858,8 +849,7 @@ int createCfgDlg() return 1; } - childwnd=FindWindowEx(hMainWindow,NULL,"#32770",NULL); // find window to replace - if (!childwnd || nRectId != DEFAULT_RECT) childwnd=GetDlgItem(hMainWindow,nRectId); + HWND childwnd=GetDlgItem(hMainWindow,nRectId); if (!childwnd) { popstring(NULL); @@ -867,23 +857,16 @@ int createCfgDlg() return 1; } - cw_vis=IsWindowVisible(childwnd); - if (cw_vis) ShowWindow(childwnd,SW_HIDE); - hCancelButton = GetDlgItem(hMainWindow,IDCANCEL); hNextButton = GetDlgItem(hMainWindow,IDOK); hBackButton = GetDlgItem(hMainWindow,3); - was_ok_enabled=EnableWindow(hNextButton,1); - GetWindowText(hCancelButton,old_cancel,sizeof(old_cancel)); if (pszCancelButtonText) SetWindowText(hCancelButton,pszCancelButtonText); - GetWindowText(hNextButton,old_ok,sizeof(old_ok)); if (pszNextButtonText) SetWindowText(hNextButton,pszNextButtonText); - GetWindowText(hBackButton,old_back,sizeof(old_back)); if (pszBackButtonText) SetWindowText(hBackButton,pszBackButtonText); if (bBackEnabled!=0xFFFF0000) EnableWindow(hBackButton,bBackEnabled); - if (bCancelEnabled!=0xFFFF0000) old_cancel_enabled=!EnableWindow(hCancelButton,bCancelEnabled); + if (bCancelEnabled!=0xFFFF0000) EnableWindow(hCancelButton,bCancelEnabled); if (bCancelShow!=0xFFFF0000) old_cancel_visible=ShowWindow(hCancelButton,bCancelShow?SW_SHOWNA:SW_HIDE); HFONT hFont = (HFONT)SendMessage(hMainWindow, WM_GETFONT, 0, 0); @@ -933,7 +916,7 @@ int createCfgDlg() #define DEFAULT_STYLES (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS) - for (nIdx = 0; nIdx < nNumFields; nIdx++) { + for (int nIdx = 0; nIdx < nNumFields; nIdx++) { static struct { char* pszClass; DWORD dwStyle; @@ -1217,10 +1200,7 @@ int createCfgDlg() } if (pszTitle) - { - GetWindowText(hMainWindow,old_title,sizeof(old_title)); SetWindowText(hMainWindow,pszTitle); - } pFilenameStackEntry = *g_stacktop; *g_stacktop = (*g_stacktop)->next; char tmp[32]; @@ -1254,19 +1234,10 @@ void showCfgDlg() if (lpWndProcOld) SetWindowLong(hMainWindow,DWL_DLGPROC,(long)lpWndProcOld); DestroyWindow(hConfigWindow); - if (was_ok_enabled) EnableWindow(hNextButton,0); - SetWindowText(hCancelButton,old_cancel); - SetWindowText(hNextButton,old_ok); - SetWindowText(hBackButton,old_back); // by ORTIM: 13-August-2002 - if (bCancelEnabled!=0xFFFF0000) EnableWindow(hCancelButton,old_cancel_enabled); if (bCancelShow!=0xFFFF0000) ShowWindow(hCancelButton,old_cancel_visible?SW_SHOWNA:SW_HIDE); - if (pszTitle) SetWindowText(hMainWindow,old_title); - - if (cw_vis) ShowWindow(childwnd,SW_SHOWNA); - FREE(pFilenameStackEntry); FREE(pszTitle); FREE(pszCancelButtonText); diff --git a/Contrib/StartMenu/StartMenu.c b/Contrib/StartMenu/StartMenu.c index 2a026c68..b39c9ca5 100644 --- a/Contrib/StartMenu/StartMenu.c +++ b/Contrib/StartMenu/StartMenu.c @@ -6,12 +6,8 @@ HINSTANCE g_hInstance; HWND hwParent; HWND hwChild; -HWND hwStartMenuSelect; -HWND hwIcon; -HWND hwText; -HWND hwLocation; -HWND hwDirList; -HWND hwCheckBox; +HWND g_hwStartMenuSelect; +HWND g_hwDirList; char buf[MAX_PATH]; char text[1024]; @@ -32,15 +28,14 @@ void AddFolderFromReg(HKEY rootKey); void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) { + HWND hwStartMenuSelect; + hwParent = hwndParent; EXDLL_INIT(); { - int cw_vis; - - hwChild = FindWindowEx(hwndParent, NULL, "#32770", NULL); // find window to replace - if (!hwChild) hwChild = GetDlgItem(hwndParent, 1018); + hwChild = GetDlgItem(hwndParent, 1018); if (!hwChild) { pushstring("error finding childwnd"); @@ -86,10 +81,8 @@ void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variab return; } - cw_vis = IsWindowVisible(hwChild); - if (cw_vis) ShowWindow(hwChild, SW_HIDE); - hwStartMenuSelect = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_DIALOG), hwndParent, dlgProc); + g_hwStartMenuSelect = hwStartMenuSelect; if (!hwStartMenuSelect) { pushstring("error creating dialog"); @@ -110,8 +103,6 @@ void __declspec(dllexport) Select(HWND hwndParent, int string_size, char *variab DestroyWindow(hwStartMenuSelect); SetWindowLong(hwndParent, DWL_DLGPROC, (long) lpWndProcOld); - - if (cw_vis) ShowWindow(hwChild, SW_SHOW); } } @@ -121,7 +112,7 @@ static BOOL CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARA if (message == WM_NOTIFY_OUTER_NEXT && !bRes) { // if leave function didn't abort (lRes != 0 in that case) - PostMessage(hwStartMenuSelect,WM_USER+666,wParam,0); + PostMessage(g_hwStartMenuSelect,WM_USER+666,wParam,0); } return bRes; } @@ -141,10 +132,17 @@ static BOOL CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARA BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { + HWND hwLocation = GetDlgItem(hwndDlg, IDC_LOCATION); + HWND hwDirList = GetDlgItem(hwndDlg, IDC_DIRLIST); + HWND hwCheckBox = GetDlgItem(hwndDlg, IDC_CHECK); + switch (uMsg) { case WM_INITDIALOG: { + HWND hwIcon; + HWND hwText; + RECT dialog_r, temp_r; HFONT hFont = (HFONT)SendMessage(hwParent, WM_GETFONT, 0, 0); @@ -172,9 +170,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) hwIcon = GetDlgItem(hwndDlg, IDC_NSISICON); hwText = GetDlgItem(hwndDlg, IDC_TEXT); - hwLocation = GetDlgItem(hwndDlg, IDC_LOCATION); - hwDirList = GetDlgItem(hwndDlg, IDC_DIRLIST); - hwCheckBox = GetDlgItem(hwndDlg, IDC_CHECK); + g_hwDirList = hwDirList; SendMessage(hwndDlg, WM_SETFONT, (WPARAM) hFont, TRUE); SendMessage(hwIcon, WM_SETFONT, (WPARAM) hFont, TRUE); @@ -218,10 +214,6 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) SWP_NOACTIVATE | (noicon ? SWP_HIDEWINDOW : 0) ); - //GetWindowRect(hwIcon, &temp_r); - //ScreenToClient(hwndDlg, ((LPPOINT) &temp_r)); - //ScreenToClient(hwndDlg, ((LPPOINT) &temp_r) + 1); - if (rtl) { ProgressiveSetWindowPos( @@ -305,7 +297,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) } else if (LOWORD(wParam) == IDC_CHECK && HIWORD(wParam) == BN_CLICKED) { - BOOL bEnable = IsDlgButtonChecked(hwStartMenuSelect, IDC_CHECK) != BST_CHECKED; + BOOL bEnable = IsDlgButtonChecked(hwndDlg, IDC_CHECK) != BST_CHECKED; EnableWindow(hwDirList, bEnable); EnableWindow(hwLocation, bEnable); } @@ -316,7 +308,7 @@ BOOL CALLBACK dlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) pushstring("cancel"); else { - if (IsDlgButtonChecked(hwStartMenuSelect, IDC_CHECK) == BST_CHECKED) + if (IsDlgButtonChecked(hwndDlg, IDC_CHECK) == BST_CHECKED) { short *sbuf = (short *) buf; *sbuf = *(short *) ">"; @@ -383,8 +375,8 @@ void AddFolderFromReg(HKEY rootKey) { if (*(WORD*)FileData.cFileName != *(WORD*)".." || FileData.cFileName[2]) { - if (SendMessage(hwDirList, LB_FINDSTRINGEXACT, -1, (LPARAM)FileData.cFileName) == LB_ERR) - SendMessage(hwDirList, LB_ADDSTRING, 0, (LPARAM)FileData.cFileName); + if (SendMessage(g_hwDirList, LB_FINDSTRINGEXACT, -1, (LPARAM)FileData.cFileName) == LB_ERR) + SendMessage(g_hwDirList, LB_ADDSTRING, 0, (LPARAM)FileData.cFileName); /*idx = */ /*SendMessage(hwDirList, LB_SETITEMDATA, (WPARAM)idx, (LPARAM)ExtractAssociatedIcon(g_hInstance, FileData.cFileName, (WORD*)&idx));*/ diff --git a/Plugins/InstallOptions.dll b/Plugins/InstallOptions.dll index f9f9411a..46a8d8ad 100644 Binary files a/Plugins/InstallOptions.dll and b/Plugins/InstallOptions.dll differ diff --git a/Plugins/StartMenu.dll b/Plugins/StartMenu.dll index 790b3fb3..8f380c8a 100644 Binary files a/Plugins/StartMenu.dll and b/Plugins/StartMenu.dll differ diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index 7abb4056..81ac9125 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -20,7 +20,7 @@ 3. This notice may not be removed or altered from any source distribution. */ -#define RESOURCE_EDITOR_NO_API +#define RESOURCE_EDITOR_NOT_API #include "ResourceEditor.h" ////////////////////////////////////////////////////////////////////// @@ -41,10 +41,9 @@ ////////////////////////////////////////////////////////////////////// CResourceEditor::CResourceEditor(BYTE* pbPE, int iSize) { - // Copy the data + // Copy the data pointer + m_pbPE = pbPE; m_iSize = iSize; - m_pbPE = new BYTE[iSize]; - CopyMemory(m_pbPE, pbPE, iSize); // Get dos header m_dosHeader = (PIMAGE_DOS_HEADER)m_pbPE; @@ -65,10 +64,22 @@ CResourceEditor::CResourceEditor(BYTE* pbPE, int iSize) { // Pointer to the sections headers array PIMAGE_SECTION_HEADER sectionHeadersArray = IMAGE_FIRST_SECTION(m_ntHeaders); + m_dwResourceSectionIndex = -1; + // Find resource section index in the array - for (m_dwResourceSectionIndex = 0; m_dwResourceSectionIndex < m_ntHeaders->FileHeader.NumberOfSections; m_dwResourceSectionIndex++) - if (m_dwResourceSectionVA == sectionHeadersArray[m_dwResourceSectionIndex].VirtualAddress) - break; + for (int i = 0; i < m_ntHeaders->FileHeader.NumberOfSections; i++) { + if (m_dwResourceSectionVA == sectionHeadersArray[i].VirtualAddress) { + // Remember resource section index + m_dwResourceSectionIndex = i; + // Check for invalid resource section pointer + if (!sectionHeadersArray[i].PointerToRawData) + throw runtime_error("Invalid resource section pointer"); + } + + // Invalid section pointer (goes beyond the PE image) + if (sectionHeadersArray[i].PointerToRawData > m_iSize) + throw runtime_error("Invalid section pointer"); + } // No resource section... if (m_dwResourceSectionIndex == m_ntHeaders->FileHeader.NumberOfSections) @@ -214,34 +225,22 @@ BYTE* CResourceEditor::Save(DWORD &dwSize) { BYTE* seeker = pbNewPE; BYTE* oldSeeker = m_pbPE; - // Copy old headers - CopyMemory(seeker, oldSeeker, m_ntHeaders->OptionalHeader.SizeOfHeaders); + PIMAGE_SECTION_HEADER old_sectionHeadersArray = IMAGE_FIRST_SECTION(m_ntHeaders); + + // Copy everything until the resource section (including headers and everything that might come after them) + // We don't use SizeOfHeaders because sometimes (using VC6) it can extend beyond the first section + // or (Borland) there could be some more information between the headers and the first section. + CopyMemory(seeker, oldSeeker, old_sectionHeadersArray[m_dwResourceSectionIndex].PointerToRawData); + + // Skip the headers and whatever comes after them + seeker += old_sectionHeadersArray[m_dwResourceSectionIndex].PointerToRawData; + oldSeeker += old_sectionHeadersArray[m_dwResourceSectionIndex].PointerToRawData; // Get new nt headers pointer PIMAGE_NT_HEADERS ntHeaders = PIMAGE_NT_HEADERS(pbNewPE + PIMAGE_DOS_HEADER(pbNewPE)->e_lfanew); // Get a pointer to the new section headers PIMAGE_SECTION_HEADER sectionHeadersArray = IMAGE_FIRST_SECTION(ntHeaders); - // Copy everything between the headers and the sections (Borland stuff...) - CopyMemory(seeker, oldSeeker, sectionHeadersArray[0].PointerToRawData-ntHeaders->OptionalHeader.SizeOfHeaders); - - // Skip some stuff between the headers and the sections (which is??? ask Borland...) - seeker += sectionHeadersArray[0].PointerToRawData-ntHeaders->OptionalHeader.SizeOfHeaders; - oldSeeker += sectionHeadersArray[0].PointerToRawData-ntHeaders->OptionalHeader.SizeOfHeaders; - - // Skip the headers - seeker += ntHeaders->OptionalHeader.SizeOfHeaders; - oldSeeker += m_ntHeaders->OptionalHeader.SizeOfHeaders; - - // Copy all of the section up until the resource section - DWORD dwSectionsSize = 0; - for (i = 0; i < m_dwResourceSectionIndex; i++) - dwSectionsSize += sectionHeadersArray[i].SizeOfRawData; - - CopyMemory(seeker, oldSeeker, dwSectionsSize); - seeker += dwSectionsSize; - oldSeeker += dwSectionsSize; - // Skip the resource section in the old PE seeker. oldSeeker += sectionHeadersArray[m_dwResourceSectionIndex].SizeOfRawData; @@ -257,8 +256,8 @@ BYTE* CResourceEditor::Save(DWORD &dwSize) { // Set the new virtual size of the image DWORD old = ntHeaders->OptionalHeader.SizeOfImage; ntHeaders->OptionalHeader.SizeOfImage = RALIGN(ntHeaders->OptionalHeader.SizeOfHeaders, ntHeaders->OptionalHeader.SectionAlignment); - for (int j = 0; j < ntHeaders->FileHeader.NumberOfSections; j++) - ntHeaders->OptionalHeader.SizeOfImage += RALIGN(sectionHeadersArray[j].Misc.VirtualSize, ntHeaders->OptionalHeader.SectionAlignment); + for (i = 0; i < ntHeaders->FileHeader.NumberOfSections; i++) + ntHeaders->OptionalHeader.SizeOfImage += RALIGN(sectionHeadersArray[i].Misc.VirtualSize, ntHeaders->OptionalHeader.SectionAlignment); // Set the new AddressOfEntryPoint if needed if (ntHeaders->OptionalHeader.AddressOfEntryPoint > sectionHeadersArray[m_dwResourceSectionIndex].VirtualAddress) @@ -273,19 +272,24 @@ BYTE* CResourceEditor::Save(DWORD &dwSize) { ntHeaders->OptionalHeader.BaseOfData += sectionHeadersArray[m_dwResourceSectionIndex].Misc.VirtualSize - dwOldVirtualSize; // Refresh the headers of the sections that come after the resource section, and the data directory - for (i++; i < ntHeaders->FileHeader.NumberOfSections; i++) { - if ( sectionHeadersArray[i].PointerToRawData ) { + for (i = m_dwResourceSectionIndex + 1; i < ntHeaders->FileHeader.NumberOfSections; i++) { + if (sectionHeadersArray[i].PointerToRawData) { sectionHeadersArray[i].PointerToRawData -= IMAGE_FIRST_SECTION(m_ntHeaders)[m_dwResourceSectionIndex].SizeOfRawData; sectionHeadersArray[i].PointerToRawData += dwRsrcSizeAligned; } - int secInDataDir = 0; + + // We must find the right data directory entry before we change the virtual address + unsigned int uDataDirIdx = 0; for (unsigned int j = 0; j < ntHeaders->OptionalHeader.NumberOfRvaAndSizes; j++) if (ntHeaders->OptionalHeader.DataDirectory[j].VirtualAddress == sectionHeadersArray[i].VirtualAddress) - secInDataDir = j; + uDataDirIdx = j; + sectionHeadersArray[i].VirtualAddress -= RALIGN(dwOldVirtualSize, ntHeaders->OptionalHeader.SectionAlignment); sectionHeadersArray[i].VirtualAddress += RALIGN(sectionHeadersArray[m_dwResourceSectionIndex].Misc.VirtualSize, ntHeaders->OptionalHeader.SectionAlignment); - if (secInDataDir) - ntHeaders->OptionalHeader.DataDirectory[secInDataDir].VirtualAddress = sectionHeadersArray[i].VirtualAddress; + + // Change the virtual address in the data directory too + if (uDataDirIdx) + ntHeaders->OptionalHeader.DataDirectory[uDataDirIdx].VirtualAddress = sectionHeadersArray[i].VirtualAddress; } // Write the resource section @@ -293,22 +297,13 @@ BYTE* CResourceEditor::Save(DWORD &dwSize) { // Advance the pointer seeker += dwRsrcSizeAligned; - // Write all the sections that come after the resource section - dwSectionsSize = 0; - for (i = m_dwResourceSectionIndex + 1; i < m_ntHeaders->FileHeader.NumberOfSections; i++) - dwSectionsSize += sectionHeadersArray[i].SizeOfRawData; + // Copy everything that comes after the resource section (other sections and tacked data) + DWORD dwLeft = m_iSize - (oldSeeker - m_pbPE); + if (dwLeft) + CopyMemory(seeker, oldSeeker, dwLeft); - CopyMemory(seeker, oldSeeker, dwSectionsSize); - seeker += dwSectionsSize; - oldSeeker += dwSectionsSize; - - // Copy data tacked after the PE headers and sections (NSIS installation data for example) - DWORD dwTackedSize = m_iSize - (oldSeeker - m_pbPE); - if (dwTackedSize) - CopyMemory(seeker, oldSeeker, dwTackedSize); - - seeker += dwTackedSize; - oldSeeker += dwTackedSize; + seeker += dwLeft; + oldSeeker += dwLeft; /********************************************************** * To add checksum to the header use MapFileAndCheckSum diff --git a/Source/ResourceEditor.h b/Source/ResourceEditor.h index 89f3e9a2..becacb99 100644 --- a/Source/ResourceEditor.h +++ b/Source/ResourceEditor.h @@ -27,7 +27,7 @@ #pragma once #endif // _MSC_VER > 1000 -#ifdef RESOURCE_EDITOR_NO_API +#ifdef RESOURCE_EDITOR_NOT_API #include #include @@ -35,7 +35,7 @@ #include #include -#endif // #ifdef RESOURCE_EDITOR_NO_API +#endif // #ifdef RESOURCE_EDITOR_NOT_API #include using namespace std; @@ -89,7 +89,7 @@ private: void SetOffsets(CResourceDirectory* resDir, DWORD newResDirAt); }; -#ifdef RESOURCE_EDITOR_NO_API +#ifdef RESOURCE_EDITOR_NOT_API class CResourceDirectory { public: @@ -170,6 +170,6 @@ private: DWORD m_dwCodePage; }; -#endif // #ifdef RESOURCE_EDITOR_NO_API +#endif // #ifdef RESOURCE_EDITOR_NOT_API #endif // !defined(AFX_RESOURCEEDITOR_H__683BF710_E805_4093_975B_D5729186A89A__INCLUDED_) diff --git a/Source/build.cpp b/Source/build.cpp index b3d8d576..f26f0408 100644 --- a/Source/build.cpp +++ b/Source/build.cpp @@ -1818,6 +1818,7 @@ again: warning("%sage instfiles not used, no sections will be executed!", uninstall_mode ? "Uninstall p" : "P"); } } + } #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT if (!uninstall_mode) { @@ -1827,7 +1828,7 @@ again: else set_uninstall_mode(0); #endif//NSIS_CONFIG_UNINSTALL_SUPPORT - } + SCRIPT_MSG("Done!\n"); @@ -2944,8 +2945,9 @@ void CEXEBuild::init_res_editor() void CEXEBuild::close_res_editor() { if (!res_editor) return; + unsigned char *header_data_new_edited = res_editor->Save((DWORD&)exeheader_size_new); free(header_data_new); - header_data_new = res_editor->Save((DWORD&)exeheader_size_new); + header_data_new = header_data_new_edited; delete res_editor; res_editor=0; }