From 44069a50cb6ce8bcbc4a8f5fe7274776a2b448a4 Mon Sep 17 00:00:00 2001 From: PQCraft <0456523@gmail.com> Date: Fri, 21 Jul 2023 07:11:34 -0400 Subject: [PATCH] tools/cxbe: Added a patch to set the proper flags for $$XTIMAGE and $$XSIMAGE bInsertedFile, bHeadPageRO, and bTailPageRO should be set and bPreload should be cleared otherwise it causes memory/stack corruption when running the XBE (my theory is that it overwrites some program data with the image data unless you clear bPreload). A more permanent solution would probably be to add an option set the flags for specific sections. --- tools/cxbe/Xbe.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tools/cxbe/Xbe.cpp b/tools/cxbe/Xbe.cpp index 56a22bf65..344c82222 100644 --- a/tools/cxbe/Xbe.cpp +++ b/tools/cxbe/Xbe.cpp @@ -376,14 +376,27 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, uint32 x_d memset(&m_SectionHeader[v].dwFlags, 0, sizeof(m_SectionHeader->dwFlags)); - if(characteristics & IMAGE_SCN_MEM_WRITE) - m_SectionHeader[v].dwFlags.bWritable = true; + // check for $$XTIMAGE or $$XSIMAGE and set the correct flags + if(x_Exe->m_SectionHeader_longname[v].m_longname && + (!strcmp(x_Exe->m_SectionHeader_longname[v].m_longname, "$$XTIMAGE") || + !strcmp(x_Exe->m_SectionHeader_longname[v].m_longname, "$$XSIMAGE"))) + { + m_SectionHeader[v].dwFlags.bInsertedFile = true; + m_SectionHeader[v].dwFlags.bHeadPageRO = true; + m_SectionHeader[v].dwFlags.bTailPageRO = true; + } + else + { + if(characteristics & IMAGE_SCN_MEM_WRITE) + m_SectionHeader[v].dwFlags.bWritable = true; + + if((characteristics & IMAGE_SCN_MEM_EXECUTE) || + (characteristics & IMAGE_SCN_CNT_CODE)) + m_SectionHeader[v].dwFlags.bExecutable = true; - if((characteristics & IMAGE_SCN_MEM_EXECUTE) || - (characteristics & IMAGE_SCN_CNT_CODE)) - m_SectionHeader[v].dwFlags.bExecutable = true; + m_SectionHeader[v].dwFlags.bPreload = true; + } - m_SectionHeader[v].dwFlags.bPreload = true; m_SectionHeader[v].dwVirtualAddr = x_Exe->m_SectionHeader[v].m_virtual_addr + m_Header.dwPeBaseAddr;