Skip to content

Commit

Permalink
cxbe: Always set XBE virtual size >= physical size
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveMHz authored and thrimbor committed Apr 17, 2024
1 parent ed21e83 commit 463647e
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,6 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
m_SectionHeader[v].dwVirtualAddr =
x_Exe->m_SectionHeader[v].m_virtual_addr + m_Header.dwPeBaseAddr;

if(v < m_Header.dwSections - 1)
m_SectionHeader[v].dwVirtualSize =
x_Exe->m_SectionHeader[v + 1].m_virtual_addr -
x_Exe->m_SectionHeader[v].m_virtual_addr;
else
m_SectionHeader[v].dwVirtualSize =
RoundUp(x_Exe->m_SectionHeader[v].m_virtual_size, 4);

m_SectionHeader[v].dwRawAddr = SectionCursor;

// calculate sizeof_raw by locating the last non-zero value in the raw section data
Expand All @@ -411,6 +403,20 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
m_SectionHeader[v].dwSizeofRaw = RoundUp(r + 2, 4);
}

// calculate virtual size
if(v < m_Header.dwSections - 1)
m_SectionHeader[v].dwVirtualSize =
x_Exe->m_SectionHeader[v + 1].m_virtual_addr -
x_Exe->m_SectionHeader[v].m_virtual_addr;
else {
m_SectionHeader[v].dwVirtualSize =
RoundUp(x_Exe->m_SectionHeader[v].m_virtual_size, 4);

// force virtual size to be at least as large as the raw size
m_SectionHeader[v].dwVirtualSize = std::max(m_SectionHeader[v].dwSizeofRaw,
m_SectionHeader[v].dwVirtualSize);
}

SectionCursor += RoundUp(m_SectionHeader[v].dwSizeofRaw, 0x1000);

// head/tail reference count
Expand Down

0 comments on commit 463647e

Please sign in to comment.