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 authored and thrimbor committed Jul 28, 2023
1 parent cb4ec0c commit e955705
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: 8 additions & 8 deletions tools/cxbe/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ 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" },
{ NULL } };
Option options[] = {
{ szExeFilename, NULL, "exefile" }, { szXbeFilename, "OUT", "filename" },
{ szDumpFilename, "DUMPINFO", "filename" }, { szXbeTitle, "TITLE", "title" },
{ szMode, "MODE", "{debug|retail}" }, { szLogo, "LOGO", "filename" },
{ szDebugPath, "DEBUGPATH", "path" }, { NULL }
};

if(ParseOptions(argv, argc, options, szErrorMessage))
{
Expand Down Expand Up @@ -90,7 +90,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
44 changes: 35 additions & 9 deletions tools/cxbe/Xbe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@
static const char kKernelImageName[] = "xboxkrnl.exe";
static uint32 CountNonKernelImportTableEntries(class Exe *x_Exe, uint32_t *extra_bytes);

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 @@ -30,6 +42,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 @@ -159,12 +172,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 @@ -238,6 +256,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 @@ -478,10 +497,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 @@ -894,7 +920,7 @@ void Xbe::DumpInformation(FILE *x_file)
fprintf(x_file, "\n");
}

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

setlocale(LC_ALL, "English");

Expand Down
3 changes: 1 addition & 2 deletions tools/cxbe/Xbe.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class Xbe : public Error
public:
// construct via Exe file object
Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail,
const std::vector<uint08> *logo = nullptr);
const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);

// deconstructor
~Xbe();

// export to Xbe file
void Export(const char *x_szXbeFilename);

Expand Down

0 comments on commit e955705

Please sign in to comment.