Skip to content

Commit e955705

Browse files
abairethrimbor
authored andcommitted
cxbe: Populate debug path header fields
1 parent cb4ec0c commit e955705

File tree

4 files changed

+46
-19
lines changed

4 files changed

+46
-19
lines changed

tools/cxbe/Exe.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef EXE_H
88
#define EXE_H
99

10+
#include <string>
11+
1012
#include "Error.h"
1113

1214
typedef struct IMAGE_IMPORT_DESCRIPTOR

tools/cxbe/Main.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ int main(int argc, char *argv[])
2121
char szXbeTitle[OPTION_LEN + 1] = "Untitled";
2222
char szMode[OPTION_LEN + 1] = "retail";
2323
char szLogo[OPTION_LEN + 1] = "";
24+
char szDebugPath[OPTION_LEN + 1] = "";
2425
bool bRetail;
2526

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

3636
if(ParseOptions(argv, argc, options, szErrorMessage))
3737
{
@@ -90,7 +90,7 @@ int main(int argc, char *argv[])
9090
LogoPtr = &logo;
9191
}
9292

93-
Xbe *XbeFile = new Xbe(ExeFile, szXbeTitle, bRetail, LogoPtr);
93+
Xbe *XbeFile = new Xbe(ExeFile, szXbeTitle, bRetail, LogoPtr, szDebugPath);
9494

9595
if(XbeFile->GetError() != 0)
9696
{

tools/cxbe/Xbe.cpp

+35-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@
2020
static const char kKernelImageName[] = "xboxkrnl.exe";
2121
static uint32 CountNonKernelImportTableEntries(class Exe *x_Exe, uint32_t *extra_bytes);
2222

23+
static size_t BasenameOffset(const std::string &path)
24+
{
25+
size_t sep_offset = path.find_last_of("/\\");
26+
if(sep_offset == std::string::npos)
27+
{
28+
return 0;
29+
}
30+
31+
return sep_offset + 1;
32+
}
33+
2334
// construct via Exe file object
24-
Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vector<uint08> *logo)
35+
Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vector<uint08> *logo,
36+
const char *x_szDebugPath)
2537
{
2638
ConstructorInit();
2739

@@ -30,6 +42,7 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
3042
time(&CurrentTime);
3143

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

3447
// pass 1
3548
{
@@ -159,12 +172,17 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
159172

160173
// make room for debug path / debug file names
161174
{
162-
// TODO: allow this to be configured, right now we will just null out these values
175+
uint32 path_bytes = debug_path.size() + 1;
176+
size_t sep_offset = BasenameOffset(debug_path);
177+
uint32 filename_bytes = path_bytes - sep_offset;
178+
179+
mrc = RoundUp(mrc, 0x04);
163180
m_Header.dwDebugUnicodeFilenameAddr = mrc;
164-
m_Header.dwDebugPathnameAddr = mrc;
165-
m_Header.dwDebugFilenameAddr = mrc;
181+
mrc = RoundUp(mrc + filename_bytes * 2, 0x04);
166182

167-
mrc += 2;
183+
m_Header.dwDebugPathnameAddr = mrc;
184+
m_Header.dwDebugFilenameAddr = m_Header.dwDebugPathnameAddr + sep_offset;
185+
mrc += path_bytes;
168186
}
169187

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

240258
m_HeaderEx = new char[ExSize];
259+
memset(m_HeaderEx, 0, ExSize);
241260

242261
printf("OK\n");
243262
}
@@ -478,10 +497,17 @@ Xbe::Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail, const std::vec
478497

479498
// write debug path / debug file names
480499
{
481-
*(uint16 *)szBuffer = 0x0000;
500+
uint08 *debug_path_field = GetAddr(m_Header.dwDebugPathnameAddr);
501+
uint32 path_size_with_terminator = debug_path.size() + 1;
502+
memcpy(debug_path_field, debug_path.c_str(), path_size_with_terminator);
482503

483-
szBuffer += 2;
484-
hwc += 2;
504+
uint08 *unicode_filename = GetAddr(m_Header.dwDebugUnicodeFilenameAddr);
505+
uint08 *filename = GetAddr(m_Header.dwDebugFilenameAddr);
506+
do
507+
{
508+
*unicode_filename++ = *filename++;
509+
*unicode_filename++ = 0;
510+
} while(*filename);
485511
}
486512

487513
{
@@ -894,7 +920,7 @@ void Xbe::DumpInformation(FILE *x_file)
894920
fprintf(x_file, "\n");
895921
}
896922

897-
char AsciiFilename[40];
923+
char AsciiFilename[40] = { 0 };
898924

899925
setlocale(LC_ALL, "English");
900926

tools/cxbe/Xbe.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class Xbe : public Error
2727
public:
2828
// construct via Exe file object
2929
Xbe(class Exe *x_Exe, const char *x_szTitle, bool x_bRetail,
30-
const std::vector<uint08> *logo = nullptr);
30+
const std::vector<uint08> *logo = nullptr, const char *x_szDebugPath = nullptr);
3131

3232
// deconstructor
3333
~Xbe();
34-
3534
// export to Xbe file
3635
void Export(const char *x_szXbeFilename);
3736

0 commit comments

Comments
 (0)