From 980c38e9091652bd0f31fd1ab309cd4b908112bf Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 27 Dec 2002 11:54:48 +0000 Subject: [PATCH] Now works with EXEs that have data tacked after the PE sections (like NSIS installation data) git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@2005 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/ResourceEditor.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Source/ResourceEditor.cpp b/Source/ResourceEditor.cpp index 543a042f..66e22fca 100644 --- a/Source/ResourceEditor.cpp +++ b/Source/ResourceEditor.cpp @@ -82,8 +82,6 @@ CResourceEditor::CResourceEditor(BYTE* pbPE, int iSize) { } CResourceEditor::~CResourceEditor() { - if (m_pbPE) - delete [] m_pbPE; if (m_cResDir) { m_cResDir->Destroy(); delete m_cResDir; @@ -297,11 +295,31 @@ BYTE* CResourceEditor::Save(DWORD &dwSize) { dwSectionsSize += sectionHeadersArray[i].SizeOfRawData; CopyMemory(seeker, oldSeeker, dwSectionsSize); + seeker += dwSectionsSize; + oldSeeker += dwSectionsSize; + + // Copy data tacked after the PE headers and sections (NSIS installation data for example) + DWORD dwTackedSize = oldSeeker - m_pbPE - m_iSize; + if (dwTackedSize) + CopyMemory(seeker, oldSeeker, dwTackedSize); + + seeker += dwTackedSize; + oldSeeker += dwTackedSize; /********************************************************** * To add checksum to the header use MapFileAndCheckSum **********************************************************/ + // From now on, we are working on the new PE + // Freeing the old PE memory is up to the user + m_pbPE = pbNewPE; + m_iSize = dwSize; + m_dosHeader = PIMAGE_DOS_HEADER(m_pbPE); + m_ntHeaders = ntHeaders; + // We just wrote the resource section according to m_cResDir, so we don't need to rescan + // m_dwResourceSectionIndex and m_dwResourceSectionVA have also been left unchanged as + // we didn't move the resources section + return pbNewPE; }