Skip to content

Commit

Permalink
Adds ability to write to LaunchData.
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire committed Sep 15, 2021
1 parent f2c634f commit b7ec3f4
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 36 deletions.
95 changes: 61 additions & 34 deletions lib/hal/xbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,78 @@

#define KernelMode 0

#define LaunchDataPageSize 0x1000

void XReboot()
{
HalReturnToFirmware(HalRebootRoutine);
HalReturnToFirmware(HalRebootRoutine);
}

int XGetLaunchInfo(unsigned long *launchDataType, const unsigned char **launchData)
{
*launchDataType = LDT_NONE;
*launchData = NULL;

if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(LaunchDataPageSize);
if (LaunchDataPage == NULL) {
return -1;
}
memset(LaunchDataPage, 0, LaunchDataPageSize);
LaunchDataPage->Header.dwLaunchDataType = LDT_FROM_DASHBOARD;
}

*launchDataType = LaunchDataPage->Header.dwLaunchDataType;
*launchData = LaunchDataPage->LaunchData;
return 0;
}

/**
* Launches an XBE. Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBE(char *xbePath)
void XLaunchXBE(const char *xbePath)
{
#if 0
struct stat statbuf;
if (stat(xbePath, &statbuf) < 0)
return;
#endif
XLaunchXBEEx(xbePath, NULL);
}

if (LaunchDataPage == NULL)
void XLaunchXBEEx(const char *xbePath, const void *launchData)
{
if (LaunchDataPage == NULL) {
LaunchDataPage = MmAllocateContiguousMemory(0x1000);
if (LaunchDataPage == NULL) {
return;
}
}

// For ease of debugging.
PLAUNCH_DATA_PAGE launchDataPage = LaunchDataPage;

MmPersistContiguousMemory(launchDataPage, LaunchDataPageSize, TRUE);
memset((void*)launchDataPage, 0, LaunchDataPageSize);

if (LaunchDataPage == NULL)
return;
launchDataPage->Header.dwLaunchDataType = LDT_TITLE;
launchDataPage->Header.dwTitleId = CURRENT_XBE_HEADER->CertificateHeader->TitleID;
launchDataPage->Header.dwFlags = 0x0000;

MmPersistContiguousMemory(LaunchDataPage, 0x1000, TRUE);
if (!xbePath) {
launchDataPage->Header.dwLaunchDataType = LDT_LAUNCH_DASHBOARD;
} else {
XConvertDOSFilenameToXBOX(xbePath, launchDataPage->Header.szLaunchPath);

memset((void*)LaunchDataPage, 0, 0x1000);
// one last thing... xbePath now looks like:
// \Device\Harddisk0\Partition2\blah\doom.xbe
// but it has to look like:
// \Device\Harddisk0\Partition2\blah;doom.xbe
char *lastSlash = strrchr(launchDataPage->Header.szLaunchPath, '\\');
if (!lastSlash) {
// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
return;
}

LaunchDataPage->Header.dwLaunchDataType = 0xFFFFFFFF;
LaunchDataPage->Header.dwTitleId = 0;
XConvertDOSFilenameToXBOX(xbePath, LaunchDataPage->Header.szLaunchPath);
*lastSlash = ';';
}

// one last thing... xbePath now looks like:
// \Device\Harddisk0\Partition2\blah\doom.xbe
// but it has to look like:
// \Device\Harddisk0\Partition2\blah;doom.xbe
char *lastSlash = strrchr(LaunchDataPage->Header.szLaunchPath, '\\');
if (lastSlash != NULL)
{
*lastSlash = ';';
HalReturnToFirmware(HalQuickRebootRoutine);
}
if (launchData) {
memcpy(launchDataPage->LaunchData, launchData, sizeof(launchDataPage->LaunchData));
}

// if we couldn't find a trailing slash, the conversion to
// the xbox path mustn't have worked, so we will return
HalReturnToFirmware(HalQuickRebootRoutine);
}
30 changes: 29 additions & 1 deletion lib/hal/xbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,35 @@ extern "C"

void XReboot(void);

void XLaunchXBE(char *xbePath);
/**
* Retrieves information persisted by the process that launched the current XBE.
*
* launchDataType will (likely) be one of the LDT_* defines in xboxkrnl.h
*
* Returns non-zero in the case of failure.
*/
int XGetLaunchInfo(unsigned long *launchDataType, const unsigned char **launchData);

/**
* Launches an XBE. Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBE(const char *xbePath);

/**
* Launches an XBE and sets the LAUNCH_DATA_PAGE's LaunchData, which is
* retrievable by the newly launched process.
*
* Examples of xbePath might be:
* c:\\blah.xbe
* c:/foo/bar.xbe
* If the XBE is able to be launched, this method will
* not return. If there is a problem, then it return.
*/
void XLaunchXBEEx(const char *xbePath, const void *launchData);

#ifdef __cplusplus
}
Expand Down
4 changes: 3 additions & 1 deletion lib/xboxkrnl/xboxkrnl.h
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,9 @@ typedef struct _LAUNCH_DATA_PAGE
UCHAR LaunchData[3072];
} LAUNCH_DATA_PAGE, *PLAUNCH_DATA_PAGE;

#define LDT_LAUNCH_DASHBOARD 1
#define LDT_TITLE 0
#define LDT_LAUNCH_DASHBOARD 1
#define LDT_FROM_DASHBOARD 2
#define LDT_NONE 0xFFFFFFFF

typedef struct _DISPATCHER_HEADER
Expand Down

0 comments on commit b7ec3f4

Please sign in to comment.