Skip to content

Commit 7c46a3d

Browse files
[xbox] graphical exception handler and exception dumper
1 parent a3a7a71 commit 7c46a3d

File tree

10 files changed

+392
-19
lines changed

10 files changed

+392
-19
lines changed

.vscode/c_cpp_properties.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"defines": [
1010
"_DEBUG",
1111
"_XBOX",
12+
"_PPC_",
1213
"RB3E",
1314
"RB3E_XBOX",
1415
"RB3EDEBUG"

include/exceptions.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
RB3Enhanced - exceptions.h
3+
Structures and function definitions for exception handling.
4+
*/
5+
6+
#ifndef _EXCEPTIONS_H
7+
#define _EXCEPTIONS_H
8+
9+
#include <stdint.h>
10+
11+
#ifdef RB3E_XBOX
12+
#include <xtl.h>
13+
#endif
14+
15+
#ifdef RB3E_WII
16+
typedef struct OSContext {
17+
uint32_t gprs[32]; // at 0x0
18+
uint32_t cr; // at 0x80
19+
uint32_t lr; // at 0x84
20+
uint32_t ctr; // at 0x88
21+
uint32_t xer; // at 0x8C
22+
double fprs[32]; // at 0x90
23+
uint32_t fpscr_pad; // at 0x190
24+
uint32_t fpscr; // at 0x194
25+
uint32_t srr0; // at 0x198
26+
uint32_t srr1; // at 0x19C
27+
uint16_t mode; // at 0x1A0
28+
uint16_t state; // at 0x1A2
29+
uint32_t gqrs[8]; // at 0x1A4
30+
uint32_t psf_pad; // at 0x1C4
31+
double psfs[32]; // at 0x1C8
32+
} OSContext;
33+
typedef struct _rb3e_exception_wii {
34+
uint32_t rb3e_base_address;
35+
uint8_t error;
36+
uint32_t dsisr;
37+
uint32_t dar;
38+
OSContext thread_ctx;
39+
} rb3e_exception_wii;
40+
#elif RB3E_XBOX
41+
#define EXCEPTION_CONTEXT_SIZE 560
42+
#endif
43+
44+
// '3EXx' where x is W for Wumbo, X for Xbox and P for PS3
45+
#define EXCEPTIONPACK_HEADER_WII 0x33455857
46+
#define EXCEPTIONPACK_HEADER_XBOX 0x33455858
47+
#define EXCEPTIONPACK_HEADER_PS3 0x33455850
48+
49+
typedef struct _rb3e_exception_header {
50+
uint32_t magic;
51+
uint32_t version;
52+
char rb3e_buildtag[48];
53+
char rb3e_commit[48];
54+
uint16_t num_stackwalk;
55+
uint16_t num_memchunks;
56+
} rb3e_exception_header;
57+
58+
typedef struct _rb3e_exception_memchunk {
59+
uint32_t address;
60+
uint32_t length;
61+
} rb3e_exception_memchunk;
62+
63+
#endif // _EXCEPTIONS_H

include/ports_xbox360.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#define PORT_MULTIPLAYER_CRASH 0x82ae6880 // branch to a function that can crash in online multiplayer
5454
#define PORT_MULTIPLAYER_FIX 0x8282b238 // the function that doesn't crash
5555
#define PORT_QUAZAL_BREAKPOINT 0x828410c0 // address to DbgBreakPoint in Quazal::Platform::Breakpoint
56+
#define PORT_MAINSEH 0x82272e60 // address to __CxxFrameHandler above the main() function
5657
// function patch addresses
5758
#define PORT_SETDISKERROR 0x82516320 // PlatformMgr::SetDiskError
5859
#define PORT_APP_RUN 0x82272e90 // App::Run
@@ -148,6 +149,7 @@
148149
#define PORT_DATASETELEM 0x82760b38 // DataSetElem
149150
#define PORT_DATAONELEM 0x8275ff50 // DataOnElem
150151
#define PORT_DATANODEGETOBJ 0x8274b088 // DataNode::GetObj
152+
#define PORT_DXRND_SUSPEND 0x8273A370 // DxRnd::Suspend
151153
// instance addresses
152154
#define PORT_MODIFIERMGR_POINTER 0x82dfec08 // pointer to ModifierManager
153155
#define PORT_ROCKCENTRALGATEWAY 0x82cc8f60 // address of RockCentralGateway
@@ -164,6 +166,7 @@
164166
#define PORT_THEGAME 0x82e02128 // pointer to TheGame (you lost)
165167
#define PORT_OBJECTDIRMAINDIR 0x82e054b8 // ObjectDir::sMainDir
166168
#define PORT_MESH_GREV 0x82cc2638 // address of RndMesh::gRev
169+
#define PORT_DXRND 0x82e04b38 // address of TheDxRnd
167170
// import function stubs
168171
#define PORT_XEKEYSSETKEY_STUB 0x82c4c47c
169172
#define PORT_XEKEYSAESCBC_STUB 0x82c4c48c
@@ -180,6 +183,7 @@
180183
#define PORT_XAMUSERGETSIGNINSTATE 0x82c4bcfc
181184
#define PORT_XAMUSERCHECKPRIVILEGE 0x82c4bd1c
182185
#define PORT_XAMSHOWFRIENDSUI 0x8283d710
186+
#define PORT_XAMLOADERTERMINATETITLE 0x82c4bccc
183187

184188
// define logging functions
185189
void DbgPrint(const char *s, ...);

include/rb3enhanced.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ int RB3E_FileExists(char *filename);
2323
int RB3E_OpenFile(char *filename, char readWrite);
2424
int RB3E_FileSize(int file);
2525
int RB3E_ReadFile(int file, int offset, void *buffer, int size);
26+
int RB3E_WriteFile(int file, int offset, void *buffer, int size);
2627
void RB3E_CloseFile(int file);
2728
int RB3E_CreateThread(void *address, void *arg, int stack_size);
2829
void RB3E_Sleep(int ms);

include/xbox360.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ DWORD XexGetProcedureAddress(HANDLE ModuleHandle, DWORD Ordinal, PVOID OutAddres
2828
int XeCryptSha(void *input_1, int input_1_size, void *input_2, int input_2_size, void *input_3, int input_3_size, void *output, int output_size);
2929
int XeCryptHmacSha(void *key, int key_size, void *input_1, int input_1_size, void *input_2, int input_2_size, void *input_3, int input_3_size, void *output, int output_size);
3030
int XeKeysConsolePrivateKeySign(unsigned char hash[0x14], unsigned char output_cert_sig[0x228]);
31+
// memory management
32+
int MmIsAddressValid(DWORD address);
3133

3234
// structure for xnet
3335
typedef struct _XnpRouteEntry_t

source/_functions.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ RB3E_STUB(MemNumHeaps)
6262
RB3E_STUB(MemAlloc)
6363
RB3E_STUB(MemFree)
6464
RB3E_STUB(FileIsDLC)
65+
RB3E_STUB(DxRndSuspend)
6566
#ifndef RB3E_XBOX
6667
RB3E_STUB(DataRegisterFunc) // DataRegisterFunc is inlined on 360
6768
#endif

source/wii_exceptions.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <rvl/vi.h>
1212
#include <rvl/ipc.h>
1313
#include <rvl/cache.h>
14+
#include "exceptions.h"
1415
#include "version.h"
1516
#include "ppcasm.h"
1617
#include "ports.h"
@@ -431,23 +432,6 @@ static unsigned char dolphin_osfatal_font[] = {
431432
typedef struct _GXColor {
432433
uint8_t r, g, b, a;
433434
} GXColor;
434-
typedef struct OSContext {
435-
uint32_t gprs[32]; // at 0x0
436-
uint32_t cr; // at 0x80
437-
uint32_t lr; // at 0x84
438-
uint32_t ctr; // at 0x88
439-
uint32_t xer; // at 0x8C
440-
double fprs[32]; // at 0x90
441-
uint32_t fpscr_pad; // at 0x190
442-
uint32_t fpscr; // at 0x194
443-
uint32_t srr0; // at 0x198
444-
uint32_t srr1; // at 0x19C
445-
uint16_t mode; // at 0x1A0
446-
uint16_t state; // at 0x1A2
447-
uint32_t gqrs[8]; // at 0x1A4
448-
uint32_t psf_pad; // at 0x1C4
449-
double psfs[32]; // at 0x1C8
450-
} OSContext;
451435
typedef enum _OSErrorType {
452436
OS_ERR_SYSTEM_RESET,
453437
OS_ERR_MACHINE_CHECK,

source/xbox360.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "ports.h"
1111
#include "rb3enhanced.h"
1212
#include "xbox360.h"
13+
#include "version.h"
1314

1415
static int HasRunDetection = 0;
1516
static int DetectionResult = 0;
@@ -132,11 +133,15 @@ static void EnableSockpatch()
132133
}
133134
}
134135

136+
// defined in xbox360_exceptions.c
137+
int RB3E_ExceptionHandler(EXCEPTION_RECORD *ExceptionRecord, void *EstablisherFrame, CONTEXT *ContextRecord, struct _DISPATCHER_CONTEXT *DispatcherContext);
138+
135139
BOOL APIENTRY DllMain(HANDLE hInstDLL, DWORD reason, LPVOID lpReserved)
136140
{
137141
if (reason == DLL_PROCESS_ATTACH)
138142
{
139-
RB3E_DEBUG("DLL has been loaded");
143+
RB3E_DEBUG("DLL has been loaded", NULL);
144+
POKE_32(PORT_MAINSEH, (DWORD)RB3E_ExceptionHandler);
140145
// Replace App::Run with App::RunWithoutDebugging
141146
POKE_BL(PORT_APP_RUN, PORT_APP_RUNNODEBUG);
142147
// Apply our hook

0 commit comments

Comments
 (0)