Skip to content

Commit

Permalink
cxbe: Populate debug path header fields
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire committed Jul 7, 2023
1 parent 58847f7 commit 14994a7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 19 deletions.
2 changes: 2 additions & 0 deletions tools/cxbe/Exe.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#ifndef EXE_H
#define EXE_H

#include <string>

#include "Error.h"

typedef struct IMAGE_IMPORT_DESCRIPTOR
Expand Down
16 changes: 9 additions & 7 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ int main(int argc, char *argv[])
char szXbeTitle[OPTION_LEN+1] = "Untitled";
char szMode[OPTION_LEN+1] = "retail";
char szLogo[OPTION_LEN+1] = "";
char szDebugPath[OPTION_LEN+1] = "";
bool bRetail;

const char *program = argv[0];
const char *program_desc = "CXBE EXE to XBE (win32 to Xbox) Relinker (Version: " VERSION ")";
Option options[] = {
{ szExeFilename, NULL, "exefile" },
{ szXbeFilename, "OUT", "filename" },
{ szDumpFilename, "DUMPINFO", "filename" },
{ szXbeTitle, "TITLE", "title" },
{ szMode, "MODE", "{debug|retail}" },
{ szLogo, "LOGO", "filename" },
{ szExeFilename, NULL, "exefile" },
{ szXbeFilename, "OUT", "filename" },
{ szDumpFilename, "DUMPINFO", "filename" },
{ szXbeTitle, "TITLE", "title" },
{ szMode, "MODE", "{debug|retail}" },
{ szLogo, "LOGO", "filename" },
{ szDebugPath, "DEBUGPATH", "path" },
{ NULL }
};

Expand Down Expand Up @@ -91,7 +93,7 @@ int main(int argc, char *argv[])
LogoPtr = &logo;
}

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

if(XbeFile->GetError() != 0)
{
Expand Down
45 changes: 34 additions & 11 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,19 @@ Xbe::Xbe(const char *x_szFilename)
return;
}

static size_t BasenameOffset(const std::string &path)
{
size_t sep_offset = path.find_last_of("/\\");
if (sep_offset == std::string::npos)
{
return 0;
}

return sep_offset + 1;
}

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

Expand All @@ -322,6 +333,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
time(&CurrentTime);

printf("Xbe::Xbe: Pass 1 (Simple Pass)...");
std::string debug_path = x_szDebugPath;

// pass 1
{
Expand Down Expand Up @@ -447,12 +459,17 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec

// make room for debug path / debug file names
{
// TODO: allow this to be configured, right now we will just null out these values
uint32 path_bytes = debug_path.size() + 1;
size_t sep_offset = BasenameOffset(debug_path);
uint32 filename_bytes = path_bytes - sep_offset;

mrc = RoundUp(mrc, 0x04);
m_Header.dwDebugUnicodeFilenameAddr = mrc;
m_Header.dwDebugPathnameAddr = mrc;
m_Header.dwDebugFilenameAddr = mrc;
mrc = RoundUp(mrc + filename_bytes * 2, 0x04);

mrc += 2;
m_Header.dwDebugPathnameAddr = mrc;
m_Header.dwDebugFilenameAddr = m_Header.dwDebugPathnameAddr + sep_offset;
mrc += path_bytes;
}

// make room for largest possible logo bitmap
Expand Down Expand Up @@ -520,6 +537,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
uint32 ExSize = RoundUp(m_Header.dwSizeofHeaders - sizeof(m_Header), 0x1000);

m_HeaderEx = new char[ExSize];
memset(m_HeaderEx, 0, ExSize);

printf("OK\n");
}
Expand Down Expand Up @@ -601,8 +619,6 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
}
*c = '\0';



// write section headers / section names
{
m_szSectionName = new char[m_Header.dwSections][9];
Expand Down Expand Up @@ -751,10 +767,17 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec

// write debug path / debug file names
{
*(uint16*)szBuffer = 0x0000;
uint08 *debug_path_field = GetAddr(m_Header.dwDebugPathnameAddr);
uint32 path_size_with_terminator = debug_path.size() + 1;
memcpy(debug_path_field, debug_path.c_str(), path_size_with_terminator);

szBuffer += 2;
hwc += 2;
uint08 *unicode_filename = GetAddr(m_Header.dwDebugUnicodeFilenameAddr);
uint08 *filename = GetAddr(m_Header.dwDebugFilenameAddr);
do
{
*unicode_filename++ = *filename++;
*unicode_filename++ = 0;
} while(*filename);
}

{
Expand Down Expand Up @@ -1160,7 +1183,7 @@ void Xbe::DumpInformation(FILE *x_file)
fprintf(x_file, "\n");
}

char AsciiFilename[40];
char AsciiFilename[40] = {0};

setlocale( LC_ALL, "English" );

Expand Down
2 changes: 1 addition & 1 deletion tools/cxbe/Xbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Xbe : public Error
Xbe(const char *x_szFilename);

// construct via Exe file object
Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vector<uint08> *logo = nullptr);
Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);

// deconstructor
~Xbe();
Expand Down

0 comments on commit 14994a7

Please sign in to comment.