Skip to content

Commit

Permalink
cxbe: Set proper flags on debug sections
Browse files Browse the repository at this point in the history
Another little "hack" to clear the preload flag on sections named .debug or starting with .debug_ so they won't be loaded and waste memory
  • Loading branch information
PQCraft committed Sep 19, 2023
1 parent bf2f952 commit c160135
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
9 changes: 5 additions & 4 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ int main(int argc, char *argv[])

bool bRetail;
uint32 dwTitleId = 0xFFFF0002;
uint32 dwRegions;
uint32 dwRegions = XBEIMAGE_GAME_REGION_NA | XBEIMAGE_GAME_REGION_JAPAN |
XBEIMAGE_GAME_REGION_RESTOFWORLD | XBEIMAGE_GAME_REGION_MANUFACTURING;
uint32 dwVersion;

const char *program = argv[0];
Expand Down Expand Up @@ -91,7 +92,7 @@ int main(int argc, char *argv[])
{
char titlechar[2];
unsigned titleno;
if (sscanf(szXbeTitleID, "%c%c-%u", &titlechar[0], &titlechar[1], &titleno) != 3)
if(sscanf(szXbeTitleID, "%c%c-%u", &titlechar[0], &titlechar[1], &titleno) != 3)
{
strncpy(szErrorMessage, "invalid TITLEID", ERROR_LEN);
goto cleanup;
Expand Down Expand Up @@ -192,8 +193,8 @@ int main(int argc, char *argv[])
LogoPtr = &logo;
}

Xbe *XbeFile =
new Xbe(ExeFile, szXbeTitle, dwTitleId, dwRegions, dwVersion, bRetail, LogoPtr, szDebugPath);
Xbe *XbeFile = new Xbe(
ExeFile, szXbeTitle, dwTitleId, dwRegions, dwVersion, bRetail, LogoPtr, szDebugPath);

if(XbeFile->GetError() != 0)
{
Expand Down
9 changes: 7 additions & 2 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ static size_t BasenameOffset(const std::string &path)

// construct via Exe file object
Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, uint32 x_dwRegions,
uint32 x_dwVersion, bool x_bRetail, const std::vector<uint08> *logo, const char *x_szDebugPath)
uint32 x_dwVersion, bool x_bRetail, const std::vector<uint08> *logo,
const char *x_szDebugPath)
{
ConstructorInit();

Expand Down Expand Up @@ -394,7 +395,11 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, uint32 x_d
(characteristics & IMAGE_SCN_CNT_CODE))
m_SectionHeader[v].dwFlags.bExecutable = true;

m_SectionHeader[v].dwFlags.bPreload = true;
char *name = (x_Exe->m_SectionHeader_longname[v].m_longname)
? x_Exe->m_SectionHeader_longname[v].m_longname
: (char *)x_Exe->m_SectionHeader[v].m_name;
m_SectionHeader[v].dwFlags.bPreload =
(strcmp(name, ".debug") && strncmp(name, ".debug_", 7));
}

m_SectionHeader[v].dwVirtualAddr =
Expand Down
3 changes: 2 additions & 1 deletion tools/cxbe/Xbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Xbe : public Error
public:
// construct via Exe file object
Xbe(class Exe *x_Exe, const char *x_szTitle, uint32 x_dwTitleID, uint32 x_dwRegions,
uint32 x_dwVersion, bool x_bRetail, const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);
uint32 x_dwVersion, bool x_bRetail, const std::vector<uint08> *logo = nullptr,
const char *x_szDebugPath = nullptr);

// deconstructor
~Xbe();
Expand Down

0 comments on commit c160135

Please sign in to comment.