Skip to content

Commit

Permalink
tools/cxbe: Added a patch to set the proper flags for $$XTIMAGE and $…
Browse files Browse the repository at this point in the history
…$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.
  • Loading branch information
PQCraft committed Jul 28, 2023
1 parent 21ce222 commit 44069a5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 44069a5

Please sign in to comment.