mirror of
https://github.com/wiiu-env/gdbstub_plugin.git
synced 2024-11-26 13:34:23 +01:00
clang-format
This commit is contained in:
parent
8e2a431827
commit
4993b321ce
@ -1,8 +1,8 @@
|
|||||||
|
|
||||||
#include "cafe/coreinit.h"
|
#include "cafe/coreinit.h"
|
||||||
#include "hbl.h"
|
#include "hbl.h"
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle);
|
int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle);
|
||||||
int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr);
|
int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr);
|
||||||
@ -117,132 +117,132 @@ uint32_t (*MEMGetAllocatableSizeForExpHeapEx)(void *handle, int alignment);
|
|||||||
|
|
||||||
void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
|
void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
|
||||||
void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
|
void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
|
||||||
void (**pMEMFreeToDefaultHeap)(void *ptr);
|
void (**pMEMFreeToDefaultHeap)(void *ptr);
|
||||||
|
|
||||||
OSDynLoad_RPLInfo **pMainRPL;
|
OSDynLoad_RPLInfo **pMainRPL;
|
||||||
OSDynLoad_RPLInfo **pFirstRPL;
|
OSDynLoad_RPLInfo **pFirstRPL;
|
||||||
OSThread **pThreadList;
|
OSThread **pThreadList;
|
||||||
|
|
||||||
void coreinitInitialize() {
|
void coreinitInitialize() {
|
||||||
*(uint32_t *)&OSDynLoad_Acquire = OS_SPECIFICS->OSDynLoad_Acquire;
|
*(uint32_t *) &OSDynLoad_Acquire = OS_SPECIFICS->OSDynLoad_Acquire;
|
||||||
*(uint32_t *)&OSDynLoad_FindExport = OS_SPECIFICS->OSDynLoad_FindExport;
|
*(uint32_t *) &OSDynLoad_FindExport = OS_SPECIFICS->OSDynLoad_FindExport;
|
||||||
|
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("coreinit.rpl", &handle);
|
OSDynLoad_Acquire("coreinit.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSDynLoad_GetModuleName", &OSDynLoad_GetModuleName);
|
OSDynLoad_FindExport(handle, false, "OSDynLoad_GetModuleName", &OSDynLoad_GetModuleName);
|
||||||
OSDynLoad_FindExport(handle, true, "OSDynLoad_gLoaderLock", &OSDynLoad_gLoaderLock);
|
OSDynLoad_FindExport(handle, true, "OSDynLoad_gLoaderLock", &OSDynLoad_gLoaderLock);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSIsDebuggerInitialized", &OSIsDebuggerInitialized);
|
OSDynLoad_FindExport(handle, false, "OSIsDebuggerInitialized", &OSIsDebuggerInitialized);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "exit", &exit);
|
OSDynLoad_FindExport(handle, false, "exit", &exit);
|
||||||
OSDynLoad_FindExport(handle, false, "_Exit", &_Exit);
|
OSDynLoad_FindExport(handle, false, "_Exit", &_Exit);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSFatal", &OSFatal);
|
OSDynLoad_FindExport(handle, false, "OSFatal", &OSFatal);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetSymbolName", &OSGetSymbolName);
|
OSDynLoad_FindExport(handle, false, "OSGetSymbolName", &OSGetSymbolName);
|
||||||
OSDynLoad_FindExport(handle, false, "DisassemblePPCRange", &DisassemblePPCRange);
|
OSDynLoad_FindExport(handle, false, "DisassemblePPCRange", &DisassemblePPCRange);
|
||||||
OSDynLoad_FindExport(handle, false, "DisassemblePPCOpcode", &DisassemblePPCOpcode);
|
OSDynLoad_FindExport(handle, false, "DisassemblePPCOpcode", &DisassemblePPCOpcode);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallback", &OSSetExceptionCallback);
|
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallback", &OSSetExceptionCallback);
|
||||||
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallbackEx", &OSSetExceptionCallbackEx);
|
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallbackEx", &OSSetExceptionCallbackEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSLoadContext", &OSLoadContext);
|
OSDynLoad_FindExport(handle, false, "OSLoadContext", &OSLoadContext);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSDisableInterrupts", &OSDisableInterrupts);
|
OSDynLoad_FindExport(handle, false, "OSDisableInterrupts", &OSDisableInterrupts);
|
||||||
OSDynLoad_FindExport(handle, false, "OSRestoreInterrupts", &OSRestoreInterrupts);
|
OSDynLoad_FindExport(handle, false, "OSRestoreInterrupts", &OSRestoreInterrupts);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "__OSLockScheduler", &__OSLockScheduler);
|
OSDynLoad_FindExport(handle, false, "__OSLockScheduler", &__OSLockScheduler);
|
||||||
OSDynLoad_FindExport(handle, false, "__OSUnlockScheduler", &__OSUnlockScheduler);
|
OSDynLoad_FindExport(handle, false, "__OSUnlockScheduler", &__OSUnlockScheduler);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSInitMutex", &OSInitMutex);
|
OSDynLoad_FindExport(handle, false, "OSInitMutex", &OSInitMutex);
|
||||||
OSDynLoad_FindExport(handle, false, "OSLockMutex", &OSLockMutex);
|
OSDynLoad_FindExport(handle, false, "OSLockMutex", &OSLockMutex);
|
||||||
OSDynLoad_FindExport(handle, false, "OSUnlockMutex", &OSUnlockMutex);
|
OSDynLoad_FindExport(handle, false, "OSUnlockMutex", &OSUnlockMutex);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSInitMessageQueue", &OSInitMessageQueue);
|
OSDynLoad_FindExport(handle, false, "OSInitMessageQueue", &OSInitMessageQueue);
|
||||||
OSDynLoad_FindExport(handle, false, "OSSendMessage", &OSSendMessage);
|
OSDynLoad_FindExport(handle, false, "OSSendMessage", &OSSendMessage);
|
||||||
OSDynLoad_FindExport(handle, false, "OSReceiveMessage", &OSReceiveMessage);
|
OSDynLoad_FindExport(handle, false, "OSReceiveMessage", &OSReceiveMessage);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSCreateAlarm", &OSCreateAlarm);
|
OSDynLoad_FindExport(handle, false, "OSCreateAlarm", &OSCreateAlarm);
|
||||||
OSDynLoad_FindExport(handle, false, "OSSetAlarm", &OSSetAlarm);
|
OSDynLoad_FindExport(handle, false, "OSSetAlarm", &OSSetAlarm);
|
||||||
OSDynLoad_FindExport(handle, false, "OSCancelAlarm", &OSCancelAlarm);
|
OSDynLoad_FindExport(handle, false, "OSCancelAlarm", &OSCancelAlarm);
|
||||||
OSDynLoad_FindExport(handle, false, "OSWaitAlarm", &OSWaitAlarm);
|
OSDynLoad_FindExport(handle, false, "OSWaitAlarm", &OSWaitAlarm);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetCurrentThread", &OSGetCurrentThread);
|
OSDynLoad_FindExport(handle, false, "OSGetCurrentThread", &OSGetCurrentThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetDefaultThread", &OSGetDefaultThread);
|
OSDynLoad_FindExport(handle, false, "OSGetDefaultThread", &OSGetDefaultThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSCreateThread", &OSCreateThread);
|
OSDynLoad_FindExport(handle, false, "OSCreateThread", &OSCreateThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSResumeThread", &OSResumeThread);
|
OSDynLoad_FindExport(handle, false, "OSResumeThread", &OSResumeThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSJoinThread", &OSJoinThread);
|
OSDynLoad_FindExport(handle, false, "OSJoinThread", &OSJoinThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSExitThread", &OSExitThread);
|
OSDynLoad_FindExport(handle, false, "OSExitThread", &OSExitThread);
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetThreadName", &OSGetThreadName);
|
OSDynLoad_FindExport(handle, false, "OSGetThreadName", &OSGetThreadName);
|
||||||
OSDynLoad_FindExport(handle, false, "OSSetThreadName", &OSSetThreadName);
|
OSDynLoad_FindExport(handle, false, "OSSetThreadName", &OSSetThreadName);
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetThreadAffinity", &OSGetThreadAffinity);
|
OSDynLoad_FindExport(handle, false, "OSGetThreadAffinity", &OSGetThreadAffinity);
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetThreadPriority", &OSGetThreadPriority);
|
OSDynLoad_FindExport(handle, false, "OSGetThreadPriority", &OSGetThreadPriority);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetSystemInfo", &OSGetSystemInfo);
|
OSDynLoad_FindExport(handle, false, "OSGetSystemInfo", &OSGetSystemInfo);
|
||||||
OSDynLoad_FindExport(handle, false, "OSSleepTicks", &OSSleepTicks);
|
OSDynLoad_FindExport(handle, false, "OSSleepTicks", &OSSleepTicks);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetTitleID", &OSGetTitleID);
|
OSDynLoad_FindExport(handle, false, "OSGetTitleID", &OSGetTitleID);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSGetMemBound", &OSGetMemBound);
|
OSDynLoad_FindExport(handle, false, "OSGetMemBound", &OSGetMemBound);
|
||||||
OSDynLoad_FindExport(handle, false, "OSEffectiveToPhysical", &OSEffectiveToPhysical);
|
OSDynLoad_FindExport(handle, false, "OSEffectiveToPhysical", &OSEffectiveToPhysical);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenInit", &OSScreenInit);
|
OSDynLoad_FindExport(handle, false, "OSScreenInit", &OSScreenInit);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenEnableEx", &OSScreenEnableEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenEnableEx", &OSScreenEnableEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenPutPixelEx", &OSScreenPutPixelEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenPutPixelEx", &OSScreenPutPixelEx);
|
||||||
OSDynLoad_FindExport(handle, false, "OSScreenPutFontEx", &OSScreenPutFontEx);
|
OSDynLoad_FindExport(handle, false, "OSScreenPutFontEx", &OSScreenPutFontEx);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "DCFlushRange", &DCFlushRange);
|
OSDynLoad_FindExport(handle, false, "DCFlushRange", &DCFlushRange);
|
||||||
OSDynLoad_FindExport(handle, false, "DCInvalidateRange", &DCInvalidateRange);
|
OSDynLoad_FindExport(handle, false, "DCInvalidateRange", &DCInvalidateRange);
|
||||||
OSDynLoad_FindExport(handle, false, "ICInvalidateRange", &ICInvalidateRange);
|
OSDynLoad_FindExport(handle, false, "ICInvalidateRange", &ICInvalidateRange);
|
||||||
OSDynLoad_FindExport(handle, false, "IOS_Open", &IOS_Open);
|
OSDynLoad_FindExport(handle, false, "IOS_Open", &IOS_Open);
|
||||||
OSDynLoad_FindExport(handle, false, "IOS_Ioctl", &IOS_Ioctl);
|
OSDynLoad_FindExport(handle, false, "IOS_Ioctl", &IOS_Ioctl);
|
||||||
OSDynLoad_FindExport(handle, false, "IOS_Close", &IOS_Close);
|
OSDynLoad_FindExport(handle, false, "IOS_Close", &IOS_Close);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "FSInit", &FSInit);
|
OSDynLoad_FindExport(handle, false, "FSInit", &FSInit);
|
||||||
OSDynLoad_FindExport(handle, false, "FSAddClient", &FSAddClient);
|
OSDynLoad_FindExport(handle, false, "FSAddClient", &FSAddClient);
|
||||||
OSDynLoad_FindExport(handle, false, "FSInitCmdBlock", &FSInitCmdBlock);
|
OSDynLoad_FindExport(handle, false, "FSInitCmdBlock", &FSInitCmdBlock);
|
||||||
OSDynLoad_FindExport(handle, false, "FSGetMountSource", &FSGetMountSource);
|
OSDynLoad_FindExport(handle, false, "FSGetMountSource", &FSGetMountSource);
|
||||||
OSDynLoad_FindExport(handle, false, "FSMount", &FSMount);
|
OSDynLoad_FindExport(handle, false, "FSMount", &FSMount);
|
||||||
OSDynLoad_FindExport(handle, false, "FSMakeDir", &FSMakeDir);
|
OSDynLoad_FindExport(handle, false, "FSMakeDir", &FSMakeDir);
|
||||||
OSDynLoad_FindExport(handle, false, "FSChangeDir", &FSChangeDir);
|
OSDynLoad_FindExport(handle, false, "FSChangeDir", &FSChangeDir);
|
||||||
OSDynLoad_FindExport(handle, false, "FSGetCwd", &FSGetCwd);
|
OSDynLoad_FindExport(handle, false, "FSGetCwd", &FSGetCwd);
|
||||||
OSDynLoad_FindExport(handle, false, "FSOpenDir", &FSOpenDir);
|
OSDynLoad_FindExport(handle, false, "FSOpenDir", &FSOpenDir);
|
||||||
OSDynLoad_FindExport(handle, false, "FSReadDir", &FSReadDir);
|
OSDynLoad_FindExport(handle, false, "FSReadDir", &FSReadDir);
|
||||||
OSDynLoad_FindExport(handle, false, "FSCloseDir", &FSCloseDir);
|
OSDynLoad_FindExport(handle, false, "FSCloseDir", &FSCloseDir);
|
||||||
OSDynLoad_FindExport(handle, false, "FSOpenFile", &FSOpenFile);
|
OSDynLoad_FindExport(handle, false, "FSOpenFile", &FSOpenFile);
|
||||||
OSDynLoad_FindExport(handle, false, "FSGetStatFile", &FSGetStatFile);
|
OSDynLoad_FindExport(handle, false, "FSGetStatFile", &FSGetStatFile);
|
||||||
OSDynLoad_FindExport(handle, false, "FSReadFile", &FSReadFile);
|
OSDynLoad_FindExport(handle, false, "FSReadFile", &FSReadFile);
|
||||||
OSDynLoad_FindExport(handle, false, "FSWriteFile", &FSWriteFile);
|
OSDynLoad_FindExport(handle, false, "FSWriteFile", &FSWriteFile);
|
||||||
OSDynLoad_FindExport(handle, false, "FSCloseFile", &FSCloseFile);
|
OSDynLoad_FindExport(handle, false, "FSCloseFile", &FSCloseFile);
|
||||||
OSDynLoad_FindExport(handle, false, "FSGetStat", &FSGetStat);
|
OSDynLoad_FindExport(handle, false, "FSGetStat", &FSGetStat);
|
||||||
OSDynLoad_FindExport(handle, false, "FSRename", &FSRename);
|
OSDynLoad_FindExport(handle, false, "FSRename", &FSRename);
|
||||||
OSDynLoad_FindExport(handle, false, "FSRemove", &FSRemove);
|
OSDynLoad_FindExport(handle, false, "FSRemove", &FSRemove);
|
||||||
OSDynLoad_FindExport(handle, false, "FSDelClient", &FSDelClient);
|
OSDynLoad_FindExport(handle, false, "FSDelClient", &FSDelClient);
|
||||||
OSDynLoad_FindExport(handle, false, "FSShutdown", &FSShutdown);
|
OSDynLoad_FindExport(handle, false, "FSShutdown", &FSShutdown);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_Open", &MCP_Open);
|
OSDynLoad_FindExport(handle, false, "MCP_Open", &MCP_Open);
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_GetDeviceId", &MCP_GetDeviceId);
|
OSDynLoad_FindExport(handle, false, "MCP_GetDeviceId", &MCP_GetDeviceId);
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_TitleList", &MCP_TitleList);
|
OSDynLoad_FindExport(handle, false, "MCP_TitleList", &MCP_TitleList);
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_TitleListByAppType", &MCP_TitleListByAppType);
|
OSDynLoad_FindExport(handle, false, "MCP_TitleListByAppType", &MCP_TitleListByAppType);
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_TitleListByDevice", &MCP_TitleListByDevice);
|
OSDynLoad_FindExport(handle, false, "MCP_TitleListByDevice", &MCP_TitleListByDevice);
|
||||||
OSDynLoad_FindExport(handle, false, "MCP_Close", &MCP_Close);
|
OSDynLoad_FindExport(handle, false, "MCP_Close", &MCP_Close);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "__KernelGetInfo", &__KernelGetInfo);
|
OSDynLoad_FindExport(handle, false, "__KernelGetInfo", &__KernelGetInfo);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "__os_snprintf", &snprintf);
|
OSDynLoad_FindExport(handle, false, "__os_snprintf", &snprintf);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
|
OSDynLoad_FindExport(handle, false, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
|
||||||
OSDynLoad_FindExport(handle, false, "MEMGetAllocatableSizeForExpHeapEx", &MEMGetAllocatableSizeForExpHeapEx);
|
OSDynLoad_FindExport(handle, false, "MEMGetAllocatableSizeForExpHeapEx", &MEMGetAllocatableSizeForExpHeapEx);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
|
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
|
||||||
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
|
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
|
||||||
OSDynLoad_FindExport(handle, true, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
|
OSDynLoad_FindExport(handle, true, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
|
||||||
|
|
||||||
pMainRPL = (OSDynLoad_RPLInfo **)0x10081014;
|
pMainRPL = (OSDynLoad_RPLInfo **) 0x10081014;
|
||||||
pFirstRPL = (OSDynLoad_RPLInfo **)0x10081018;
|
pFirstRPL = (OSDynLoad_RPLInfo **) 0x10081018;
|
||||||
pThreadList = (OSThread **)0x100567F8;
|
pThreadList = (OSThread **) 0x100567F8;
|
||||||
}
|
}
|
||||||
|
@ -1,101 +1,101 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
// Timers
|
// Timers
|
||||||
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
|
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
|
||||||
|
|
||||||
#define OSSecondsToTicks(val) ((uint64_t)(val) * (uint64_t)OSTimerClockSpeed)
|
#define OSSecondsToTicks(val) ((uint64_t) (val) * (uint64_t) OSTimerClockSpeed)
|
||||||
#define OSMillisecondsToTicks(val) (((uint64_t)(val) * (uint64_t)OSTimerClockSpeed) / 1000ull)
|
#define OSMillisecondsToTicks(val) (((uint64_t) (val) * (uint64_t) OSTimerClockSpeed) / 1000ull)
|
||||||
|
|
||||||
#define OSTicksToSeconds(val) ((uint64_t)(val) / (uint64_t)OSTimerClockSpeed)
|
#define OSTicksToSeconds(val) ((uint64_t) (val) / (uint64_t) OSTimerClockSpeed)
|
||||||
#define OSTicksToMilliseconds(val) (((uint64_t)(val) * 1000ull) / (uint64_t)OSTimerClockSpeed)
|
#define OSTicksToMilliseconds(val) (((uint64_t) (val) *1000ull) / (uint64_t) OSTimerClockSpeed)
|
||||||
|
|
||||||
// Memory
|
// Memory
|
||||||
enum OSMemoryType {
|
enum OSMemoryType {
|
||||||
MEM1 = 1,
|
MEM1 = 1,
|
||||||
MEM2 = 2
|
MEM2 = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
// System
|
// System
|
||||||
enum KernelInfoType {
|
enum KernelInfoType {
|
||||||
TITLE_INFO = 0,
|
TITLE_INFO = 0,
|
||||||
SYSTEM_INFO = 1,
|
SYSTEM_INFO = 1,
|
||||||
PLATFORM_INFO = 2,
|
PLATFORM_INFO = 2,
|
||||||
|
|
||||||
KERNEL_STATISTICS = 4,
|
KERNEL_STATISTICS = 4,
|
||||||
PERFORMANCE_NUMBERS = 5,
|
PERFORMANCE_NUMBERS = 5,
|
||||||
|
|
||||||
PROCESS_INFO = 8,
|
PROCESS_INFO = 8,
|
||||||
|
|
||||||
CRASH_INFO = 11,
|
CRASH_INFO = 11,
|
||||||
APP_CRASH_CONTROL = 12,
|
APP_CRASH_CONTROL = 12,
|
||||||
COS_REPORT_MASKS = 13,
|
COS_REPORT_MASKS = 13,
|
||||||
CRASH_RECOVERY = 14,
|
CRASH_RECOVERY = 14,
|
||||||
CRASH_DETAIL_LEVEL = 15,
|
CRASH_DETAIL_LEVEL = 15,
|
||||||
CRASH_DUMP_TYPE = 16,
|
CRASH_DUMP_TYPE = 16,
|
||||||
SHUTDOWN_REASON = 17,
|
SHUTDOWN_REASON = 17,
|
||||||
WRITE_GATHER_REGS = 18,
|
WRITE_GATHER_REGS = 18,
|
||||||
PROC_DATA_BOUNDS = 19
|
PROC_DATA_BOUNDS = 19
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSSystemInfo {
|
struct OSSystemInfo {
|
||||||
uint32_t busClockSpeed;
|
uint32_t busClockSpeed;
|
||||||
uint32_t coreClockSpeed;
|
uint32_t coreClockSpeed;
|
||||||
int64_t baseTime;
|
int64_t baseTime;
|
||||||
char _10[0x10];
|
char _10[0x10];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSTitleInfo {
|
struct OSTitleInfo {
|
||||||
char _0[0xC];
|
char _0[0xC];
|
||||||
uint32_t ramStart;
|
uint32_t ramStart;
|
||||||
uint32_t ramEnd;
|
uint32_t ramEnd;
|
||||||
char _14[0x20];
|
char _14[0x20];
|
||||||
uint32_t systemHeapSize;
|
uint32_t systemHeapSize;
|
||||||
char _38[0x40];
|
char _38[0x40];
|
||||||
uint32_t textStart;
|
uint32_t textStart;
|
||||||
uint32_t _7C;
|
uint32_t _7C;
|
||||||
uint32_t textSize;
|
uint32_t textSize;
|
||||||
uint32_t dataStart;
|
uint32_t dataStart;
|
||||||
uint32_t _88;
|
uint32_t _88;
|
||||||
uint32_t dataSize;
|
uint32_t dataSize;
|
||||||
uint32_t loadStart;
|
uint32_t loadStart;
|
||||||
uint32_t _94;
|
uint32_t _94;
|
||||||
uint32_t loadSize;
|
uint32_t loadSize;
|
||||||
char _9C[0xC];
|
char _9C[0xC];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSTitleInfoEx {
|
struct OSTitleInfoEx {
|
||||||
OSTitleInfo info;
|
OSTitleInfo info;
|
||||||
uint64_t osVersionId;
|
uint64_t osVersionId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// OSDynLoad
|
// OSDynLoad
|
||||||
struct OSDynLoad_NotifyData {
|
struct OSDynLoad_NotifyData {
|
||||||
const char *path;
|
const char *path;
|
||||||
uint32_t textAddr;
|
uint32_t textAddr;
|
||||||
uint32_t textOffset;
|
uint32_t textOffset;
|
||||||
uint32_t textSize;
|
uint32_t textSize;
|
||||||
uint32_t dataAddr;
|
uint32_t dataAddr;
|
||||||
uint32_t dataOffset;
|
uint32_t dataOffset;
|
||||||
uint32_t dataSize;
|
uint32_t dataSize;
|
||||||
uint32_t readAddr;
|
uint32_t readAddr;
|
||||||
uint32_t readOffset;
|
uint32_t readOffset;
|
||||||
uint32_t readSize;
|
uint32_t readSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSDynLoad_RPLInfo {
|
struct OSDynLoad_RPLInfo {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
uint32_t _4;
|
uint32_t _4;
|
||||||
const char *name;
|
const char *name;
|
||||||
char _C[0x1C];
|
char _C[0x1C];
|
||||||
OSDynLoad_NotifyData *notifyData;
|
OSDynLoad_NotifyData *notifyData;
|
||||||
void *entryPoint;
|
void *entryPoint;
|
||||||
char _30[0x24];
|
char _30[0x24];
|
||||||
OSDynLoad_RPLInfo *next;
|
OSDynLoad_RPLInfo *next;
|
||||||
char _58[0x3C];
|
char _58[0x3C];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Thread / mutex / context
|
// Thread / mutex / context
|
||||||
@ -104,188 +104,187 @@ struct OSMutex;
|
|||||||
struct OSAlarm;
|
struct OSAlarm;
|
||||||
|
|
||||||
struct OSContext {
|
struct OSContext {
|
||||||
uint64_t tag;
|
uint64_t tag;
|
||||||
|
|
||||||
uint32_t gpr[32];
|
uint32_t gpr[32];
|
||||||
|
|
||||||
uint32_t cr;
|
uint32_t cr;
|
||||||
uint32_t lr;
|
uint32_t lr;
|
||||||
uint32_t ctr;
|
uint32_t ctr;
|
||||||
uint32_t xer;
|
uint32_t xer;
|
||||||
|
|
||||||
uint32_t srr0;
|
uint32_t srr0;
|
||||||
uint32_t srr1;
|
uint32_t srr1;
|
||||||
|
|
||||||
uint32_t dsisr;
|
uint32_t dsisr;
|
||||||
uint32_t dar;
|
uint32_t dar;
|
||||||
|
|
||||||
char _A8[0xC];
|
char _A8[0xC];
|
||||||
|
|
||||||
uint32_t fpscr;
|
uint32_t fpscr;
|
||||||
double fpr[32];
|
double fpr[32];
|
||||||
|
|
||||||
uint16_t spinLockCount;
|
uint16_t spinLockCount;
|
||||||
uint16_t state;
|
uint16_t state;
|
||||||
|
|
||||||
uint32_t gqr[8];
|
uint32_t gqr[8];
|
||||||
|
|
||||||
uint32_t _1DC;
|
uint32_t _1DC;
|
||||||
|
|
||||||
double psf[32];
|
double psf[32];
|
||||||
|
|
||||||
uint64_t coretime[3];
|
uint64_t coretime[3];
|
||||||
uint64_t starttime;
|
uint64_t starttime;
|
||||||
|
|
||||||
uint32_t error;
|
uint32_t error;
|
||||||
|
|
||||||
uint32_t _304;
|
uint32_t _304;
|
||||||
|
|
||||||
uint32_t pmc1;
|
uint32_t pmc1;
|
||||||
uint32_t pmc2;
|
uint32_t pmc2;
|
||||||
uint32_t pmc3;
|
uint32_t pmc3;
|
||||||
uint32_t pmc4;
|
uint32_t pmc4;
|
||||||
uint32_t mmcr0;
|
uint32_t mmcr0;
|
||||||
uint32_t mmcr1;
|
uint32_t mmcr1;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSThreadQueue {
|
struct OSThreadQueue {
|
||||||
OSThread *head;
|
OSThread *head;
|
||||||
OSThread *tail;
|
OSThread *tail;
|
||||||
void *parent;
|
void *parent;
|
||||||
uint32_t _C;
|
uint32_t _C;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSThreadLink {
|
struct OSThreadLink {
|
||||||
OSThread *next;
|
OSThread *next;
|
||||||
OSThread *prev;
|
OSThread *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSMutexLink {
|
struct OSMutexLink {
|
||||||
OSMutex *next;
|
OSMutex *next;
|
||||||
OSMutex *prev;
|
OSMutex *prev;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSMutexQueue {
|
struct OSMutexQueue {
|
||||||
OSMutex *head;
|
OSMutex *head;
|
||||||
OSMutex *tail;
|
OSMutex *tail;
|
||||||
void *parent;
|
void *parent;
|
||||||
uint32_t _C;
|
uint32_t _C;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSMutex {
|
struct OSMutex {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *name;
|
const char *name;
|
||||||
uint32_t _8;
|
uint32_t _8;
|
||||||
|
|
||||||
OSThreadQueue queue;
|
OSThreadQueue queue;
|
||||||
OSThread *thread;
|
OSThread *thread;
|
||||||
int count;
|
int count;
|
||||||
OSMutexLink link;
|
OSMutexLink link;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef int (*OSThreadFunc)(int argc, void *argv);
|
typedef int (*OSThreadFunc)(int argc, void *argv);
|
||||||
|
|
||||||
struct OSThread {
|
struct OSThread {
|
||||||
OSContext context;
|
OSContext context;
|
||||||
|
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
|
|
||||||
uint8_t state;
|
uint8_t state;
|
||||||
uint8_t attr;
|
uint8_t attr;
|
||||||
uint16_t id;
|
uint16_t id;
|
||||||
uint32_t suspendCounter;
|
uint32_t suspendCounter;
|
||||||
|
|
||||||
int priority;
|
int priority;
|
||||||
int basePriority;
|
int basePriority;
|
||||||
|
|
||||||
int exitValue;
|
int exitValue;
|
||||||
|
|
||||||
char _338[0x24];
|
char _338[0x24];
|
||||||
|
|
||||||
OSThreadQueue *queue;
|
OSThreadQueue *queue;
|
||||||
OSThreadLink link;
|
OSThreadLink link;
|
||||||
|
|
||||||
OSThreadQueue joinQueue;
|
OSThreadQueue joinQueue;
|
||||||
|
|
||||||
OSMutex *mutex;
|
OSMutex *mutex;
|
||||||
OSMutexQueue mutexQueue;
|
OSMutexQueue mutexQueue;
|
||||||
|
|
||||||
OSThreadLink activeLink;
|
OSThreadLink activeLink;
|
||||||
|
|
||||||
void *stackBase;
|
void *stackBase;
|
||||||
void *stackEnd;
|
void *stackEnd;
|
||||||
|
|
||||||
OSThreadFunc entryPoint;
|
OSThreadFunc entryPoint;
|
||||||
|
|
||||||
char _3A0[0x57C - 0x3A0];
|
char _3A0[0x57C - 0x3A0];
|
||||||
|
|
||||||
void *specific[0x10];
|
void *specific[0x10];
|
||||||
|
|
||||||
int type;
|
int type;
|
||||||
|
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
char _5C4[0x6A0 - 0x5C4];
|
|
||||||
|
|
||||||
|
char _5C4[0x6A0 - 0x5C4];
|
||||||
};
|
};
|
||||||
|
|
||||||
// Messages
|
// Messages
|
||||||
enum OSMessageFlags {
|
enum OSMessageFlags {
|
||||||
OS_MESSAGE_FLAGS_NONE = 0,
|
OS_MESSAGE_FLAGS_NONE = 0,
|
||||||
OS_MESSAGE_FLAGS_BLOCKING = 1
|
OS_MESSAGE_FLAGS_BLOCKING = 1
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSMessage {
|
struct OSMessage {
|
||||||
uint32_t message;
|
uint32_t message;
|
||||||
uint32_t args[3];
|
uint32_t args[3];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSMessageQueue {
|
struct OSMessageQueue {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *name;
|
const char *name;
|
||||||
uint32_t _8;
|
uint32_t _8;
|
||||||
OSThreadQueue sendQueue;
|
OSThreadQueue sendQueue;
|
||||||
OSThreadQueue recvQueue;
|
OSThreadQueue recvQueue;
|
||||||
OSMessage *messages;
|
OSMessage *messages;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t first;
|
uint32_t first;
|
||||||
uint32_t used;
|
uint32_t used;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Alarms
|
// Alarms
|
||||||
struct OSAlarmQueue {
|
struct OSAlarmQueue {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *name;
|
const char *name;
|
||||||
uint32_t _8;
|
uint32_t _8;
|
||||||
|
|
||||||
OSThreadQueue threadQueue;
|
OSThreadQueue threadQueue;
|
||||||
OSAlarm *head;
|
OSAlarm *head;
|
||||||
OSAlarm *tail;
|
OSAlarm *tail;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSAlarmLink {
|
struct OSAlarmLink {
|
||||||
OSAlarm *prev;
|
OSAlarm *prev;
|
||||||
OSAlarm *next;
|
OSAlarm *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef void (*OSAlarmCallback)(OSAlarm *alarm, OSContext *context);
|
typedef void (*OSAlarmCallback)(OSAlarm *alarm, OSContext *context);
|
||||||
|
|
||||||
struct OSAlarm {
|
struct OSAlarm {
|
||||||
uint32_t tag;
|
uint32_t tag;
|
||||||
const char *name;
|
const char *name;
|
||||||
uint32_t _8;
|
uint32_t _8;
|
||||||
OSAlarmCallback callback;
|
OSAlarmCallback callback;
|
||||||
uint32_t group;
|
uint32_t group;
|
||||||
uint32_t _14;
|
uint32_t _14;
|
||||||
uint64_t nextFire;
|
uint64_t nextFire;
|
||||||
OSAlarmLink link;
|
OSAlarmLink link;
|
||||||
uint64_t period;
|
uint64_t period;
|
||||||
uint64_t start;
|
uint64_t start;
|
||||||
void *userData;
|
void *userData;
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
OSThreadQueue threadQueue;
|
OSThreadQueue threadQueue;
|
||||||
OSAlarmQueue *alarmQueue;
|
OSAlarmQueue *alarmQueue;
|
||||||
OSContext *context;
|
OSContext *context;
|
||||||
};
|
};
|
||||||
|
|
||||||
// PPC disassembly
|
// PPC disassembly
|
||||||
@ -293,94 +292,94 @@ typedef void (*DisassemblyPrintFn)(const char *fmt, ...);
|
|||||||
typedef uint32_t (*DisassemblyFindSymbolFn)(uint32_t addr, char *buffer, size_t bufsize);
|
typedef uint32_t (*DisassemblyFindSymbolFn)(uint32_t addr, char *buffer, size_t bufsize);
|
||||||
|
|
||||||
enum DisassemblyFlags {
|
enum DisassemblyFlags {
|
||||||
DISASSEMBLY_FLAGS_NONE = 0,
|
DISASSEMBLY_FLAGS_NONE = 0,
|
||||||
DISASSEMBLY_FLAGS_SIMPLIFY = 1,
|
DISASSEMBLY_FLAGS_SIMPLIFY = 1,
|
||||||
DISASSEMBLY_FLAGS_SPACE = 0x20,
|
DISASSEMBLY_FLAGS_SPACE = 0x20,
|
||||||
DISASSEMBLY_FLAGS_PLAIN = 0x40,
|
DISASSEMBLY_FLAGS_PLAIN = 0x40,
|
||||||
DISASSEMBLY_FLAGS_NO_OPCODE = 0x80,
|
DISASSEMBLY_FLAGS_NO_OPCODE = 0x80,
|
||||||
DISASSEMBLY_FLAGS_PRINT_SYMBOLS = 0x100
|
DISASSEMBLY_FLAGS_PRINT_SYMBOLS = 0x100
|
||||||
};
|
};
|
||||||
|
|
||||||
// Exceptions
|
// Exceptions
|
||||||
enum OSExceptionMode {
|
enum OSExceptionMode {
|
||||||
OS_EXCEPTION_MODE_THREAD = 1,
|
OS_EXCEPTION_MODE_THREAD = 1,
|
||||||
OS_EXCEPTION_MODE_GLOBAL = 2,
|
OS_EXCEPTION_MODE_GLOBAL = 2,
|
||||||
OS_EXCEPTION_MODE_THREAD_ALL_CORES = 3,
|
OS_EXCEPTION_MODE_THREAD_ALL_CORES = 3,
|
||||||
OS_EXCEPTION_MODE_GLOBAL_ALL_CORES = 4
|
OS_EXCEPTION_MODE_GLOBAL_ALL_CORES = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
enum OSExceptionType {
|
enum OSExceptionType {
|
||||||
OS_EXCEPTION_TYPE_DSI = 2,
|
OS_EXCEPTION_TYPE_DSI = 2,
|
||||||
OS_EXCEPTION_TYPE_ISI = 3,
|
OS_EXCEPTION_TYPE_ISI = 3,
|
||||||
OS_EXCEPTION_TYPE_PROGRAM = 6
|
OS_EXCEPTION_TYPE_PROGRAM = 6
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef bool (*OSExceptionCallback)(OSContext *context);
|
typedef bool (*OSExceptionCallback)(OSContext *context);
|
||||||
|
|
||||||
// File system
|
// File system
|
||||||
enum FSMode {
|
enum FSMode {
|
||||||
FS_MODE_READ_OWNER = 0x400,
|
FS_MODE_READ_OWNER = 0x400,
|
||||||
FS_MODE_WRITE_OWNER = 0x200,
|
FS_MODE_WRITE_OWNER = 0x200,
|
||||||
FS_MODE_EXEC_OWNER = 0x100,
|
FS_MODE_EXEC_OWNER = 0x100,
|
||||||
|
|
||||||
FS_MODE_READ_GROUP = 0x040,
|
FS_MODE_READ_GROUP = 0x040,
|
||||||
FS_MODE_WRITE_GROUP = 0x020,
|
FS_MODE_WRITE_GROUP = 0x020,
|
||||||
FS_MODE_EXEC_GROUP = 0x010,
|
FS_MODE_EXEC_GROUP = 0x010,
|
||||||
|
|
||||||
FS_MODE_READ_OTHER = 0x004,
|
FS_MODE_READ_OTHER = 0x004,
|
||||||
FS_MODE_WRITE_OTHER = 0x002,
|
FS_MODE_WRITE_OTHER = 0x002,
|
||||||
FS_MODE_EXEC_OTHER = 0x001
|
FS_MODE_EXEC_OTHER = 0x001
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FSStatFlags {
|
enum FSStatFlags {
|
||||||
FS_STAT_DIRECTORY = 0x80000000
|
FS_STAT_DIRECTORY = 0x80000000
|
||||||
};
|
};
|
||||||
|
|
||||||
enum FSMountSourceType {
|
enum FSMountSourceType {
|
||||||
FS_MOUNT_SOURCE_SD = 0
|
FS_MOUNT_SOURCE_SD = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FSClient {
|
struct FSClient {
|
||||||
char data[0x1700];
|
char data[0x1700];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FSCmdBlock {
|
struct FSCmdBlock {
|
||||||
char data[0xA80];
|
char data[0xA80];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FSMountSource {
|
struct FSMountSource {
|
||||||
char data[0x300];
|
char data[0x300];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct __attribute__((packed)) FSStat {
|
struct __attribute__((packed)) FSStat {
|
||||||
FSStatFlags flags;
|
FSStatFlags flags;
|
||||||
FSMode mode;
|
FSMode mode;
|
||||||
uint32_t owner;
|
uint32_t owner;
|
||||||
uint32_t group;
|
uint32_t group;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
char _14[0xC];
|
char _14[0xC];
|
||||||
uint32_t entryId;
|
uint32_t entryId;
|
||||||
int64_t created;
|
int64_t created;
|
||||||
int64_t modified;
|
int64_t modified;
|
||||||
char _34[0x30];
|
char _34[0x30];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FSDirectoryEntry {
|
struct FSDirectoryEntry {
|
||||||
FSStat info;
|
FSStat info;
|
||||||
char name[256];
|
char name[256];
|
||||||
};
|
};
|
||||||
|
|
||||||
// MCP
|
// MCP
|
||||||
struct MCPTitleListType {
|
struct MCPTitleListType {
|
||||||
uint64_t titleId;
|
uint64_t titleId;
|
||||||
uint32_t _4;
|
uint32_t _4;
|
||||||
char path[56];
|
char path[56];
|
||||||
uint32_t appType;
|
uint32_t appType;
|
||||||
char _48[0xC];
|
char _48[0xC];
|
||||||
uint8_t device;
|
uint8_t device;
|
||||||
char _55;
|
char _55;
|
||||||
char indexedDevice[10];
|
char indexedDevice[10];
|
||||||
uint8_t _60;
|
uint8_t _60;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function pointers
|
// Function pointers
|
||||||
@ -497,17 +496,17 @@ extern uint32_t (*MEMGetAllocatableSizeForExpHeapEx)(void *handle, int alignment
|
|||||||
|
|
||||||
extern void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
|
extern void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
|
||||||
extern void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
|
extern void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
|
||||||
extern void (**pMEMFreeToDefaultHeap)(void *ptr);
|
extern void (**pMEMFreeToDefaultHeap)(void *ptr);
|
||||||
#define MEMAllocFromDefaultHeap (*pMEMAllocFromDefaultHeap)
|
#define MEMAllocFromDefaultHeap (*pMEMAllocFromDefaultHeap)
|
||||||
#define MEMAllocFromDefaultHeapEx (*pMEMAllocFromDefaultHeapEx)
|
#define MEMAllocFromDefaultHeapEx (*pMEMAllocFromDefaultHeapEx)
|
||||||
#define MEMFreeToDefaultHeap (*pMEMFreeToDefaultHeap)
|
#define MEMFreeToDefaultHeap (*pMEMFreeToDefaultHeap)
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
extern OSDynLoad_RPLInfo **pMainRPL;
|
extern OSDynLoad_RPLInfo **pMainRPL;
|
||||||
extern OSDynLoad_RPLInfo **pFirstRPL;
|
extern OSDynLoad_RPLInfo **pFirstRPL;
|
||||||
extern OSThread **pThreadList;
|
extern OSThread **pThreadList;
|
||||||
#define MainRPL (*pMainRPL)
|
#define MainRPL (*pMainRPL)
|
||||||
#define FirstRPL (*pFirstRPL)
|
#define FirstRPL (*pFirstRPL)
|
||||||
#define ThreadList (*pThreadList)
|
#define ThreadList (*pThreadList)
|
||||||
|
|
||||||
void coreinitInitialize();
|
void coreinitInitialize();
|
||||||
|
@ -3,18 +3,18 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace nn::act {
|
namespace nn::act {
|
||||||
uint32_t (*Initialize)();
|
uint32_t (*Initialize)();
|
||||||
uint8_t (*GetSlotNo)();
|
uint8_t (*GetSlotNo)();
|
||||||
uint32_t (*GetPersistentIdEx)(uint8_t slot);
|
uint32_t (*GetPersistentIdEx)(uint8_t slot);
|
||||||
uint32_t (*Finalize)();
|
uint32_t (*Finalize)();
|
||||||
}
|
} // namespace nn::act
|
||||||
|
|
||||||
void nnactInitialize() {
|
void nnactInitialize() {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("nn_act.rpl", &handle);
|
OSDynLoad_Acquire("nn_act.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "Initialize__Q2_2nn3actFv", &nn::act::Initialize);
|
OSDynLoad_FindExport(handle, false, "Initialize__Q2_2nn3actFv", &nn::act::Initialize);
|
||||||
OSDynLoad_FindExport(handle, false, "GetSlotNo__Q2_2nn3actFv", &nn::act::GetSlotNo);
|
OSDynLoad_FindExport(handle, false, "GetSlotNo__Q2_2nn3actFv", &nn::act::GetSlotNo);
|
||||||
OSDynLoad_FindExport(handle, false, "GetPersistentIdEx__Q2_2nn3actFUc", &nn::act::GetPersistentIdEx);
|
OSDynLoad_FindExport(handle, false, "GetPersistentIdEx__Q2_2nn3actFUc", &nn::act::GetPersistentIdEx);
|
||||||
OSDynLoad_FindExport(handle, false, "Finalize__Q2_2nn3actFv", &nn::act::Finalize);
|
OSDynLoad_FindExport(handle, false, "Finalize__Q2_2nn3actFv", &nn::act::Finalize);
|
||||||
}
|
}
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
namespace nn::act {
|
namespace nn::act {
|
||||||
extern uint32_t (*Initialize)();
|
extern uint32_t (*Initialize)();
|
||||||
extern uint8_t (*GetSlotNo)();
|
extern uint8_t (*GetSlotNo)();
|
||||||
extern uint32_t (*GetPersistentIdEx)(uint8_t slot);
|
extern uint32_t (*GetPersistentIdEx)(uint8_t slot);
|
||||||
extern uint32_t (*Finalize)();
|
extern uint32_t (*Finalize)();
|
||||||
}
|
} // namespace nn::act
|
||||||
|
|
||||||
void nnactInitialize();
|
void nnactInitialize();
|
||||||
|
@ -8,11 +8,11 @@ int (*SAVEGetSharedDataTitlePath)(uint64_t titleId, const char *path, char *outp
|
|||||||
void (*SAVEShutdown)();
|
void (*SAVEShutdown)();
|
||||||
|
|
||||||
void nnsaveInitialize() {
|
void nnsaveInitialize() {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("nn_save.rpl", &handle);
|
OSDynLoad_Acquire("nn_save.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "SAVEInit", &SAVEInit);
|
OSDynLoad_FindExport(handle, false, "SAVEInit", &SAVEInit);
|
||||||
OSDynLoad_FindExport(handle, false, "SAVEOpenFile", &SAVEOpenFile);
|
OSDynLoad_FindExport(handle, false, "SAVEOpenFile", &SAVEOpenFile);
|
||||||
OSDynLoad_FindExport(handle, false, "SAVEGetSharedDataTitlePath", &SAVEGetSharedDataTitlePath);
|
OSDynLoad_FindExport(handle, false, "SAVEGetSharedDataTitlePath", &SAVEGetSharedDataTitlePath);
|
||||||
OSDynLoad_FindExport(handle, false, "SAVEShutdown", &SAVEShutdown);
|
OSDynLoad_FindExport(handle, false, "SAVEShutdown", &SAVEShutdown);
|
||||||
}
|
}
|
||||||
|
@ -17,19 +17,19 @@ int (*socketclose)(int socket);
|
|||||||
int (*socket_lib_finish)();
|
int (*socket_lib_finish)();
|
||||||
|
|
||||||
void nsysnetInitialize() {
|
void nsysnetInitialize() {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("nsysnet.rpl", &handle);
|
OSDynLoad_Acquire("nsysnet.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "socket_lib_init", &socket_lib_init);
|
OSDynLoad_FindExport(handle, false, "socket_lib_init", &socket_lib_init);
|
||||||
OSDynLoad_FindExport(handle, false, "inet_aton", &inet_aton);
|
OSDynLoad_FindExport(handle, false, "inet_aton", &inet_aton);
|
||||||
OSDynLoad_FindExport(handle, false, "socket", &socket);
|
OSDynLoad_FindExport(handle, false, "socket", &socket);
|
||||||
OSDynLoad_FindExport(handle, false, "setsockopt", &setsockopt);
|
OSDynLoad_FindExport(handle, false, "setsockopt", &setsockopt);
|
||||||
OSDynLoad_FindExport(handle, false, "connect", &connect);
|
OSDynLoad_FindExport(handle, false, "connect", &connect);
|
||||||
OSDynLoad_FindExport(handle, false, "bind", &bind);
|
OSDynLoad_FindExport(handle, false, "bind", &bind);
|
||||||
OSDynLoad_FindExport(handle, false, "listen", &listen);
|
OSDynLoad_FindExport(handle, false, "listen", &listen);
|
||||||
OSDynLoad_FindExport(handle, false, "accept", &accept);
|
OSDynLoad_FindExport(handle, false, "accept", &accept);
|
||||||
OSDynLoad_FindExport(handle, false, "send", &send);
|
OSDynLoad_FindExport(handle, false, "send", &send);
|
||||||
OSDynLoad_FindExport(handle, false, "recv", &recv);
|
OSDynLoad_FindExport(handle, false, "recv", &recv);
|
||||||
OSDynLoad_FindExport(handle, false, "socketclose", &socketclose);
|
OSDynLoad_FindExport(handle, false, "socketclose", &socketclose);
|
||||||
OSDynLoad_FindExport(handle, false, "socket_lib_finish", &socket_lib_finish);
|
OSDynLoad_FindExport(handle, false, "socket_lib_finish", &socket_lib_finish);
|
||||||
}
|
}
|
||||||
|
@ -3,22 +3,22 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#define AF_INET 2
|
#define AF_INET 2
|
||||||
|
|
||||||
#define SOCK_STREAM 1
|
#define SOCK_STREAM 1
|
||||||
#define SOCK_DGRAM 2
|
#define SOCK_DGRAM 2
|
||||||
|
|
||||||
#define IPPROTO_TCP 6
|
#define IPPROTO_TCP 6
|
||||||
#define IPPROTO_UDP 17
|
#define IPPROTO_UDP 17
|
||||||
|
|
||||||
#define SOL_SOCKET -1
|
#define SOL_SOCKET -1
|
||||||
#define SO_REUSEADDR 4
|
#define SO_REUSEADDR 4
|
||||||
|
|
||||||
struct sockaddr {
|
struct sockaddr {
|
||||||
uint16_t family;
|
uint16_t family;
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
uint32_t addr;
|
uint32_t addr;
|
||||||
char zero[8];
|
char zero[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern int (*socket_lib_init)();
|
extern int (*socket_lib_init)();
|
||||||
|
@ -9,12 +9,12 @@ void (*SYSLaunchMenu)();
|
|||||||
void (*SYSLaunchTitleByPathFromLauncher)(const char *path, int len);
|
void (*SYSLaunchTitleByPathFromLauncher)(const char *path, int len);
|
||||||
|
|
||||||
void sysappInitialize() {
|
void sysappInitialize() {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("sysapp.rpl", &handle);
|
OSDynLoad_Acquire("sysapp.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "SYSCheckTitleExists", &SYSCheckTitleExists);
|
OSDynLoad_FindExport(handle, false, "SYSCheckTitleExists", &SYSCheckTitleExists);
|
||||||
OSDynLoad_FindExport(handle, false, "SYSLaunchTitle", &SYSLaunchTitle);
|
OSDynLoad_FindExport(handle, false, "SYSLaunchTitle", &SYSLaunchTitle);
|
||||||
OSDynLoad_FindExport(handle, false, "SYSLaunchMenu", &SYSLaunchMenu);
|
OSDynLoad_FindExport(handle, false, "SYSLaunchMenu", &SYSLaunchMenu);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "_SYSLaunchTitleByPathFromLauncher", &SYSLaunchTitleByPathFromLauncher);
|
OSDynLoad_FindExport(handle, false, "_SYSLaunchTitleByPathFromLauncher", &SYSLaunchTitleByPathFromLauncher);
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);
|
void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);
|
||||||
|
|
||||||
void vpadInitialize() {
|
void vpadInitialize() {
|
||||||
uint32_t handle;
|
uint32_t handle;
|
||||||
OSDynLoad_Acquire("vpad.rpl", &handle);
|
OSDynLoad_Acquire("vpad.rpl", &handle);
|
||||||
|
|
||||||
OSDynLoad_FindExport(handle, false, "VPADRead", &VPADRead);
|
OSDynLoad_FindExport(handle, false, "VPADRead", &VPADRead);
|
||||||
}
|
}
|
||||||
|
114
src/cafe/vpad.h
114
src/cafe/vpad.h
@ -4,84 +4,84 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
enum VPADButtons {
|
enum VPADButtons {
|
||||||
VPAD_BUTTON_A = 0x8000,
|
VPAD_BUTTON_A = 0x8000,
|
||||||
VPAD_BUTTON_B = 0x4000,
|
VPAD_BUTTON_B = 0x4000,
|
||||||
VPAD_BUTTON_X = 0x2000,
|
VPAD_BUTTON_X = 0x2000,
|
||||||
VPAD_BUTTON_Y = 0x1000,
|
VPAD_BUTTON_Y = 0x1000,
|
||||||
VPAD_BUTTON_LEFT = 0x0800,
|
VPAD_BUTTON_LEFT = 0x0800,
|
||||||
VPAD_BUTTON_RIGHT = 0x0400,
|
VPAD_BUTTON_RIGHT = 0x0400,
|
||||||
VPAD_BUTTON_UP = 0x0200,
|
VPAD_BUTTON_UP = 0x0200,
|
||||||
VPAD_BUTTON_DOWN = 0x0100,
|
VPAD_BUTTON_DOWN = 0x0100,
|
||||||
VPAD_BUTTON_ZL = 0x0080,
|
VPAD_BUTTON_ZL = 0x0080,
|
||||||
VPAD_BUTTON_ZR = 0x0040,
|
VPAD_BUTTON_ZR = 0x0040,
|
||||||
VPAD_BUTTON_L = 0x0020,
|
VPAD_BUTTON_L = 0x0020,
|
||||||
VPAD_BUTTON_R = 0x0010,
|
VPAD_BUTTON_R = 0x0010,
|
||||||
VPAD_BUTTON_PLUS = 0x0008,
|
VPAD_BUTTON_PLUS = 0x0008,
|
||||||
VPAD_BUTTON_MINUS = 0x0004,
|
VPAD_BUTTON_MINUS = 0x0004,
|
||||||
VPAD_BUTTON_HOME = 0x0002,
|
VPAD_BUTTON_HOME = 0x0002,
|
||||||
VPAD_BUTTON_SYNC = 0x0001,
|
VPAD_BUTTON_SYNC = 0x0001,
|
||||||
|
|
||||||
VPAD_BUTTON_STICK_R = 0x00020000,
|
VPAD_BUTTON_STICK_R = 0x00020000,
|
||||||
VPAD_BUTTON_STICK_L = 0x00040000,
|
VPAD_BUTTON_STICK_L = 0x00040000,
|
||||||
VPAD_BUTTON_TV = 0x00010000
|
VPAD_BUTTON_TV = 0x00010000
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADVec2D {
|
struct VPADVec2D {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADVec3D {
|
struct VPADVec3D {
|
||||||
float x;
|
float x;
|
||||||
float y;
|
float y;
|
||||||
float z;
|
float z;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADDirection {
|
struct VPADDirection {
|
||||||
VPADVec3D x;
|
VPADVec3D x;
|
||||||
VPADVec3D y;
|
VPADVec3D y;
|
||||||
VPADVec3D z;
|
VPADVec3D z;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADTouchData {
|
struct VPADTouchData {
|
||||||
uint16_t x;
|
uint16_t x;
|
||||||
uint16_t y;
|
uint16_t y;
|
||||||
uint16_t touched;
|
uint16_t touched;
|
||||||
uint16_t validity;
|
uint16_t validity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADAccStatus {
|
struct VPADAccStatus {
|
||||||
VPADVec3D acc;
|
VPADVec3D acc;
|
||||||
float magnitude;
|
float magnitude;
|
||||||
float variation;
|
float variation;
|
||||||
VPADVec2D vertical;
|
VPADVec2D vertical;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VPADStatus {
|
struct VPADStatus {
|
||||||
uint32_t hold;
|
uint32_t hold;
|
||||||
uint32_t pressed;
|
uint32_t pressed;
|
||||||
uint32_t released;
|
uint32_t released;
|
||||||
VPADVec2D leftStick;
|
VPADVec2D leftStick;
|
||||||
VPADVec2D rightStick;
|
VPADVec2D rightStick;
|
||||||
VPADAccStatus accelerometer;
|
VPADAccStatus accelerometer;
|
||||||
VPADVec3D gyro;
|
VPADVec3D gyro;
|
||||||
VPADVec3D angle;
|
VPADVec3D angle;
|
||||||
uint8_t error;
|
uint8_t error;
|
||||||
uint8_t _51;
|
uint8_t _51;
|
||||||
|
|
||||||
VPADTouchData tpNormal;
|
VPADTouchData tpNormal;
|
||||||
VPADTouchData tpFiltered1;
|
VPADTouchData tpFiltered1;
|
||||||
VPADTouchData tpFiltered2;
|
VPADTouchData tpFiltered2;
|
||||||
uint16_t _6A;
|
uint16_t _6A;
|
||||||
|
|
||||||
VPADDirection direction;
|
VPADDirection direction;
|
||||||
bool headphones;
|
bool headphones;
|
||||||
VPADVec3D mag;
|
VPADVec3D mag;
|
||||||
uint8_t volume;
|
uint8_t volume;
|
||||||
uint8_t battery;
|
uint8_t battery;
|
||||||
uint8_t micStatus;
|
uint8_t micStatus;
|
||||||
uint8_t volumeEx;
|
uint8_t volumeEx;
|
||||||
char _A4[8];
|
char _A4[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
extern void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);
|
extern void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);
|
||||||
|
16
src/color.h
16
src/color.h
@ -2,14 +2,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
enum Colors {
|
enum Colors {
|
||||||
COLOR_WHITE = 0xFFFFFFFF,
|
COLOR_WHITE = 0xFFFFFFFF,
|
||||||
COLOR_BLACK = 0x000000FF,
|
COLOR_BLACK = 0x000000FF,
|
||||||
|
|
||||||
COLOR_RED = 0xFF0000FF,
|
COLOR_RED = 0xFF0000FF,
|
||||||
COLOR_GREEN = 0x00FF00FF,
|
COLOR_GREEN = 0x00FF00FF,
|
||||||
COLOR_BLUE = 0x0000FFFF,
|
COLOR_BLUE = 0x0000FFFF,
|
||||||
|
|
||||||
COLOR_LIGHT_RED = 0xFF8080FF,
|
COLOR_LIGHT_RED = 0xFF8080FF,
|
||||||
COLOR_LIGHT_GREEN = 0x80FF80FF,
|
COLOR_LIGHT_GREEN = 0x80FF80FF,
|
||||||
COLOR_LIGHT_BLUE = 0x8080FFFF,
|
COLOR_LIGHT_BLUE = 0x8080FFFF,
|
||||||
};
|
};
|
||||||
|
1311
src/debugger.cpp
1311
src/debugger.cpp
File diff suppressed because it is too large
Load Diff
334
src/debugger.h
334
src/debugger.h
@ -9,256 +9,256 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define MESSAGE_COUNT 10
|
#define MESSAGE_COUNT 10
|
||||||
#define STACK_SIZE 0x8000
|
#define STACK_SIZE 0x8000
|
||||||
|
|
||||||
#define TRAP 0x7FE00008
|
#define TRAP 0x7FE00008
|
||||||
|
|
||||||
|
|
||||||
template <int N>
|
template<int N>
|
||||||
class Bits {
|
class Bits {
|
||||||
public:
|
public:
|
||||||
Bits(uint32_t value) {
|
Bits(uint32_t value) {
|
||||||
this->value = value;
|
this->value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator [](int index) {
|
bool operator[](int index) {
|
||||||
return (value >> (N - index - 1)) & 1;
|
return (value >> (N - index - 1)) & 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ExceptionState {
|
class ExceptionState {
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
DSI,
|
DSI,
|
||||||
ISI,
|
ISI,
|
||||||
PROGRAM
|
PROGRAM
|
||||||
};
|
};
|
||||||
|
|
||||||
bool isBreakpoint();
|
bool isBreakpoint();
|
||||||
void resume();
|
void resume();
|
||||||
|
|
||||||
Type type;
|
Type type;
|
||||||
OSContext context;
|
OSContext context;
|
||||||
|
|
||||||
OSThread *thread;
|
OSThread *thread;
|
||||||
|
|
||||||
OSMessageQueue queue;
|
OSMessageQueue queue;
|
||||||
OSMessage message;
|
OSMessage message;
|
||||||
|
|
||||||
bool isPaused;
|
bool isPaused;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class ExceptionMgr {
|
class ExceptionMgr {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
ExceptionState *find(OSThread *thread);
|
ExceptionState *find(OSThread *thread);
|
||||||
ExceptionState *findOrCreate(OSThread *thread);
|
ExceptionState *findOrCreate(OSThread *thread);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OSMutex mutex;
|
OSMutex mutex;
|
||||||
std::vector<ExceptionState *> list;
|
std::vector<ExceptionState *> list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BreakPoint {
|
class BreakPoint {
|
||||||
public:
|
public:
|
||||||
bool isRange(uint32_t addr, uint32_t length);
|
bool isRange(uint32_t addr, uint32_t length);
|
||||||
|
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
uint32_t instruction;
|
uint32_t instruction;
|
||||||
bool isSpecial;
|
bool isSpecial;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SpecialBreakPoint : public BreakPoint {
|
class SpecialBreakPoint : public BreakPoint {
|
||||||
public:
|
public:
|
||||||
OSThread *thread;
|
OSThread *thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <class T>
|
template<class T>
|
||||||
class BreakPointList {
|
class BreakPointList {
|
||||||
public:
|
public:
|
||||||
size_t size() {
|
size_t size() {
|
||||||
return list.size();
|
return list.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
T *alloc() {
|
T *alloc() {
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
if (list[i].address == 0) {
|
if (list[i].address == 0) {
|
||||||
return &list[i];
|
return &list[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
T newBp;
|
T newBp;
|
||||||
newBp.address = 0;
|
newBp.address = 0;
|
||||||
newBp.instruction = 0;
|
newBp.instruction = 0;
|
||||||
list.push_back(newBp);
|
list.push_back(newBp);
|
||||||
return &list.back();
|
return &list.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
T *find(uint32_t addr) {
|
T *find(uint32_t addr) {
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
if (list[i].address == addr) {
|
if (list[i].address == addr) {
|
||||||
return &list[i];
|
return &list[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *findRange(uint32_t addr, uint32_t length, int *index) {
|
T *findRange(uint32_t addr, uint32_t length, int *index) {
|
||||||
int i = *index;
|
int i = *index;
|
||||||
while (i < size()) {
|
while (i < size()) {
|
||||||
if (list[i].isRange(addr, length)) {
|
if (list[i].isRange(addr, length)) {
|
||||||
*index = i + 1;
|
*index = i + 1;
|
||||||
return &list[i];
|
return &list[i];
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > *index) {
|
if (i > *index) {
|
||||||
*index = i;
|
*index = i;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
T *operator [](int index) {
|
T *operator[](int index) {
|
||||||
return &list[index];
|
return &list[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup() {
|
void cleanup() {
|
||||||
for (int i = 0; i < size(); i++) {
|
for (int i = 0; i < size(); i++) {
|
||||||
if (list[i].address != 0) {
|
if (list[i].address != 0) {
|
||||||
KernelWriteU32(list[i].address, list[i].instruction);
|
KernelWriteU32(list[i].address, list[i].instruction);
|
||||||
list[i].address = 0;
|
list[i].address = 0;
|
||||||
list[i].instruction = 0;
|
list[i].instruction = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<T> list;
|
std::vector<T> list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class BreakPointMgr {
|
class BreakPointMgr {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
bool isCustom(uint32_t addr);
|
bool isCustom(uint32_t addr);
|
||||||
bool isSoftware(uint32_t addr);
|
bool isSoftware(uint32_t addr);
|
||||||
bool isSpecial(uint32_t addr);
|
bool isSpecial(uint32_t addr);
|
||||||
void read(void *buffer, uint32_t addr, uint32_t length);
|
void read(void *buffer, uint32_t addr, uint32_t length);
|
||||||
void write(const void *buffer, uint32_t addr, uint32_t length);
|
void write(const void *buffer, uint32_t addr, uint32_t length);
|
||||||
void toggle(uint32_t addr);
|
void toggle(uint32_t addr);
|
||||||
uint32_t getInstr(uint32_t addr);
|
uint32_t getInstr(uint32_t addr);
|
||||||
BreakPoint *find(uint32_t addr, bool includeSpecial);
|
BreakPoint *find(uint32_t addr, bool includeSpecial);
|
||||||
BreakPoint *findRange(uint32_t addr, uint32_t length, int *index, bool includeSpecial);
|
BreakPoint *findRange(uint32_t addr, uint32_t length, int *index, bool includeSpecial);
|
||||||
SpecialBreakPoint *findSpecial(uint32_t addr, OSThread *thread);
|
SpecialBreakPoint *findSpecial(uint32_t addr, OSThread *thread);
|
||||||
void clearSpecial(OSThread *thread);
|
void clearSpecial(OSThread *thread);
|
||||||
void predictStep(ExceptionState *state, bool stepOver);
|
void predictStep(ExceptionState *state, bool stepOver);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BreakPoint *alloc();
|
BreakPoint *alloc();
|
||||||
SpecialBreakPoint *allocSpecial();
|
SpecialBreakPoint *allocSpecial();
|
||||||
void disable(BreakPoint *bp);
|
void disable(BreakPoint *bp);
|
||||||
void enable(BreakPoint *bp, uint32_t addr);
|
void enable(BreakPoint *bp, uint32_t addr);
|
||||||
|
|
||||||
BreakPointList<BreakPoint> breakpoints;
|
BreakPointList<BreakPoint> breakpoints;
|
||||||
BreakPointList<SpecialBreakPoint> special;
|
BreakPointList<SpecialBreakPoint> special;
|
||||||
|
|
||||||
OSMutex mutex;
|
OSMutex mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class StepMgr {
|
class StepMgr {
|
||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
void lock();
|
void lock();
|
||||||
void unlock();
|
void unlock();
|
||||||
void singleStep(ExceptionState *state, uint32_t instruction);
|
void singleStep(ExceptionState *state, uint32_t instruction);
|
||||||
void handleBreakPoint(ExceptionState *state);
|
void handleBreakPoint(ExceptionState *state);
|
||||||
void adjustAddress(ExceptionState *state);
|
void adjustAddress(ExceptionState *state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static uint32_t buffer[96];
|
static uint32_t buffer[96];
|
||||||
|
|
||||||
uint32_t *alloc();
|
uint32_t *alloc();
|
||||||
void free(int index);
|
void free(int index);
|
||||||
void branchConditional(ExceptionState *state, uint32_t instruction, uint32_t target, bool checkCtr);
|
void branchConditional(ExceptionState *state, uint32_t instruction, uint32_t target, bool checkCtr);
|
||||||
|
|
||||||
OSMutex mutex;
|
OSMutex mutex;
|
||||||
|
|
||||||
uint32_t usedMask;
|
uint32_t usedMask;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Debugger {
|
class Debugger {
|
||||||
public:
|
public:
|
||||||
enum StepCommand {
|
enum StepCommand {
|
||||||
STEP_CONTINUE,
|
STEP_CONTINUE,
|
||||||
STEP_INTO,
|
STEP_INTO,
|
||||||
STEP_OVER
|
STEP_OVER
|
||||||
};
|
};
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Command {
|
enum Command {
|
||||||
COMMAND_CLOSE,
|
COMMAND_CLOSE,
|
||||||
COMMAND_READ,
|
COMMAND_READ,
|
||||||
COMMAND_WRITE,
|
COMMAND_WRITE,
|
||||||
COMMAND_WRITE_CODE,
|
COMMAND_WRITE_CODE,
|
||||||
COMMAND_GET_MODULE_NAME,
|
COMMAND_GET_MODULE_NAME,
|
||||||
COMMAND_GET_MODULE_LIST,
|
COMMAND_GET_MODULE_LIST,
|
||||||
COMMAND_GET_THREAD_LIST,
|
COMMAND_GET_THREAD_LIST,
|
||||||
COMMAND_GET_STACK_TRACE,
|
COMMAND_GET_STACK_TRACE,
|
||||||
COMMAND_TOGGLE_BREAKPOINT,
|
COMMAND_TOGGLE_BREAKPOINT,
|
||||||
COMMAND_POKE_REGISTERS,
|
COMMAND_POKE_REGISTERS,
|
||||||
COMMAND_RECEIVE_MESSAGES,
|
COMMAND_RECEIVE_MESSAGES,
|
||||||
COMMAND_SEND_MESSAGE
|
COMMAND_SEND_MESSAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
static int threadEntry(int argc, void *argv);
|
static int threadEntry(int argc, void *argv);
|
||||||
static bool dsiHandler(OSContext *context);
|
static bool dsiHandler(OSContext *context);
|
||||||
static bool isiHandler(OSContext *context);
|
static bool isiHandler(OSContext *context);
|
||||||
static bool programHandler(OSContext *context);
|
static bool programHandler(OSContext *context);
|
||||||
static void exceptionHandler(OSContext *context, ExceptionState::Type type);
|
static void exceptionHandler(OSContext *context, ExceptionState::Type type);
|
||||||
|
|
||||||
void threadFunc();
|
void threadFunc();
|
||||||
void mainLoop(Client *client);
|
void mainLoop(Client *client);
|
||||||
void handleException(OSContext *context, ExceptionState::Type type);
|
void handleException(OSContext *context, ExceptionState::Type type);
|
||||||
void handleFatalCrash(OSContext *context, ExceptionState::Type type);
|
void handleFatalCrash(OSContext *context, ExceptionState::Type type);
|
||||||
void handleCrash(ExceptionState *state);
|
void handleCrash(ExceptionState *state);
|
||||||
void handleBreakPoint(ExceptionState *state);
|
void handleBreakPoint(ExceptionState *state);
|
||||||
void processBreakPoint(ExceptionState *state);
|
void processBreakPoint(ExceptionState *state);
|
||||||
void resumeBreakPoint(ExceptionState *state);
|
void resumeBreakPoint(ExceptionState *state);
|
||||||
StepCommand notifyBreak(ExceptionState *state);
|
StepCommand notifyBreak(ExceptionState *state);
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
|
||||||
bool checkDataRead(uint32_t addr, uint32_t length);
|
bool checkDataRead(uint32_t addr, uint32_t length);
|
||||||
|
|
||||||
OSMessageQueue eventQueue;
|
OSMessageQueue eventQueue;
|
||||||
OSMessage eventMessages[MESSAGE_COUNT];
|
OSMessage eventMessages[MESSAGE_COUNT];
|
||||||
|
|
||||||
OSThread *serverThread;
|
OSThread *serverThread;
|
||||||
|
|
||||||
BreakPointMgr breakpoints;
|
BreakPointMgr breakpoints;
|
||||||
ExceptionMgr exceptions;
|
ExceptionMgr exceptions;
|
||||||
StepMgr stepper;
|
StepMgr stepper;
|
||||||
|
|
||||||
bool initialized;
|
bool initialized;
|
||||||
bool connected;
|
bool connected;
|
||||||
bool firstTrap;
|
bool firstTrap;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Debugger *debugger;
|
extern Debugger *debugger;
|
||||||
|
@ -2,50 +2,49 @@
|
|||||||
#include "cafe/coreinit.h"
|
#include "cafe/coreinit.h"
|
||||||
|
|
||||||
void DumpContext(OSContext *context, const char *excType) {
|
void DumpContext(OSContext *context, const char *excType) {
|
||||||
char buffer[1000];
|
char buffer[1000];
|
||||||
snprintf(buffer, 1000,
|
snprintf(buffer, 1000,
|
||||||
"%s exception occurred!\n"
|
"%s exception occurred!\n"
|
||||||
"r0 :%08X r1 :%08X r2 :%08X r3 :%08X r4 :%08X\n"
|
"r0 :%08X r1 :%08X r2 :%08X r3 :%08X r4 :%08X\n"
|
||||||
"r5 :%08X r6 :%08X r7 :%08X r8 :%08X r9 :%08X\n"
|
"r5 :%08X r6 :%08X r7 :%08X r8 :%08X r9 :%08X\n"
|
||||||
"r10:%08X r11:%08X r12:%08X r13:%08X r14:%08X\n"
|
"r10:%08X r11:%08X r12:%08X r13:%08X r14:%08X\n"
|
||||||
"r15:%08X r16:%08X r17:%08X r18:%08X r19:%08X\n"
|
"r15:%08X r16:%08X r17:%08X r18:%08X r19:%08X\n"
|
||||||
"r20:%08X r21:%08X r22:%08X r23:%08X r24:%08X\n"
|
"r20:%08X r21:%08X r22:%08X r23:%08X r24:%08X\n"
|
||||||
"r25:%08X r26:%08X r27:%08X r28:%08X r29:%08X\n"
|
"r25:%08X r26:%08X r27:%08X r28:%08X r29:%08X\n"
|
||||||
"r30:%08X r31:%08X LR :%08X CTR:%08X XER:%08X\n"
|
"r30:%08X r31:%08X LR :%08X CTR:%08X XER:%08X\n"
|
||||||
"\n"
|
"\n"
|
||||||
"SRR0:%08X SRR1:%08X DSISR:%08X DAR:%08X",
|
"SRR0:%08X SRR1:%08X DSISR:%08X DAR:%08X",
|
||||||
excType,
|
excType,
|
||||||
context->gpr[0], context->gpr[1], context->gpr[2], context->gpr[3],
|
context->gpr[0], context->gpr[1], context->gpr[2], context->gpr[3],
|
||||||
context->gpr[4], context->gpr[5], context->gpr[6], context->gpr[7],
|
context->gpr[4], context->gpr[5], context->gpr[6], context->gpr[7],
|
||||||
context->gpr[8], context->gpr[9], context->gpr[10], context->gpr[11],
|
context->gpr[8], context->gpr[9], context->gpr[10], context->gpr[11],
|
||||||
context->gpr[12], context->gpr[13], context->gpr[14], context->gpr[15],
|
context->gpr[12], context->gpr[13], context->gpr[14], context->gpr[15],
|
||||||
context->gpr[16], context->gpr[17], context->gpr[18], context->gpr[19],
|
context->gpr[16], context->gpr[17], context->gpr[18], context->gpr[19],
|
||||||
context->gpr[20], context->gpr[21], context->gpr[22], context->gpr[23],
|
context->gpr[20], context->gpr[21], context->gpr[22], context->gpr[23],
|
||||||
context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27],
|
context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27],
|
||||||
context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31],
|
context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31],
|
||||||
context->lr, context->ctr, context->xer, context->srr0, context->srr1,
|
context->lr, context->ctr, context->xer, context->srr0, context->srr1,
|
||||||
context->dsisr, context->dar
|
context->dsisr, context->dar);
|
||||||
);
|
OSFatal(buffer);
|
||||||
OSFatal(buffer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DSIHandler(OSContext *context) {
|
bool DSIHandler(OSContext *context) {
|
||||||
DumpContext(context, "A DSI");
|
DumpContext(context, "A DSI");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ISIHandler(OSContext *context) {
|
bool ISIHandler(OSContext *context) {
|
||||||
DumpContext(context, "An ISI");
|
DumpContext(context, "An ISI");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ProgramHandler(OSContext *context) {
|
bool ProgramHandler(OSContext *context) {
|
||||||
DumpContext(context, "A program");
|
DumpContext(context, "A program");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InstallExceptionHandlers() {
|
void InstallExceptionHandlers() {
|
||||||
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_DSI, DSIHandler);
|
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_DSI, DSIHandler);
|
||||||
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_ISI, ISIHandler);
|
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_ISI, ISIHandler);
|
||||||
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_PROGRAM, ProgramHandler);
|
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_PROGRAM, ProgramHandler);
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,10 @@
|
|||||||
#define MEM_BASE 0x800000
|
#define MEM_BASE 0x800000
|
||||||
|
|
||||||
struct OsSpecifics {
|
struct OsSpecifics {
|
||||||
uint32_t OSDynLoad_Acquire;
|
uint32_t OSDynLoad_Acquire;
|
||||||
uint32_t OSDynLoad_FindExport;
|
uint32_t OSDynLoad_FindExport;
|
||||||
};
|
};
|
||||||
#define OS_SPECIFICS ((OsSpecifics *)(MEM_BASE + 0x1500))
|
#define OS_SPECIFICS ((OsSpecifics *) (MEM_BASE + 0x1500))
|
||||||
|
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#define EXIT_RELAUNCH_ON_LOAD -3
|
#define EXIT_RELAUNCH_ON_LOAD -3
|
||||||
|
@ -3,19 +3,19 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
uint32_t GetInput(uint32_t mask) {
|
uint32_t GetInput(uint32_t mask) {
|
||||||
VPADStatus input;
|
VPADStatus input;
|
||||||
int error;
|
int error;
|
||||||
VPADRead(0, &input, 1, &error);
|
VPADRead(0, &input, 1, &error);
|
||||||
return input.pressed & mask;
|
return input.pressed & mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t WaitInput(uint32_t mask) {
|
uint32_t WaitInput(uint32_t mask) {
|
||||||
VPADStatus input;
|
VPADStatus input;
|
||||||
int error;
|
int error;
|
||||||
while (true) {
|
while (true) {
|
||||||
VPADRead(0, &input, 1, &error);
|
VPADRead(0, &input, 1, &error);
|
||||||
if (input.pressed & mask) {
|
if (input.pressed & mask) {
|
||||||
return input.pressed & mask;
|
return input.pressed & mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,52 +13,50 @@ extern "C" void SCKernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
|
|||||||
extern "C" void KernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
|
extern "C" void KernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
|
||||||
|
|
||||||
void KernelWrite(uint32_t addr, const void *data, uint32_t length) {
|
void KernelWrite(uint32_t addr, const void *data, uint32_t length) {
|
||||||
uint32_t dst = OSEffectiveToPhysical(addr);
|
uint32_t dst = OSEffectiveToPhysical(addr);
|
||||||
uint32_t src = OSEffectiveToPhysical((uint32_t)data);
|
uint32_t src = OSEffectiveToPhysical((uint32_t) data);
|
||||||
KernelCopyData(dst, src, length);
|
KernelCopyData(dst, src, length);
|
||||||
DCFlushRange((void *)addr, length);
|
DCFlushRange((void *) addr, length);
|
||||||
ICInvalidateRange((void *)addr, length);
|
ICInvalidateRange((void *) addr, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelWriteU32(uint32_t addr, uint32_t value) {
|
void KernelWriteU32(uint32_t addr, uint32_t value) {
|
||||||
uint32_t dst = OSEffectiveToPhysical(addr);
|
uint32_t dst = OSEffectiveToPhysical(addr);
|
||||||
uint32_t src = OSEffectiveToPhysical((uint32_t)&value);
|
uint32_t src = OSEffectiveToPhysical((uint32_t) &value);
|
||||||
KernelCopyData(dst, src, 4);
|
KernelCopyData(dst, src, 4);
|
||||||
DCFlushRange((void *)addr, 4);
|
DCFlushRange((void *) addr, 4);
|
||||||
ICInvalidateRange((void *)addr, 4);
|
ICInvalidateRange((void *) addr, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a 32-bit word with kernel permissions */
|
/* Write a 32-bit word with kernel permissions */
|
||||||
void __attribute__ ((noinline)) kern_write(uint32_t addr, uint32_t value)
|
void __attribute__((noinline)) kern_write(uint32_t addr, uint32_t value) {
|
||||||
{
|
asm volatile(
|
||||||
asm volatile (
|
"li 3,1\n"
|
||||||
"li 3,1\n"
|
"li 4,0\n"
|
||||||
"li 4,0\n"
|
"mr 5,%1\n"
|
||||||
"mr 5,%1\n"
|
"li 6,0\n"
|
||||||
"li 6,0\n"
|
"li 7,0\n"
|
||||||
"li 7,0\n"
|
"lis 8,1\n"
|
||||||
"lis 8,1\n"
|
"mr 9,%0\n"
|
||||||
"mr 9,%0\n"
|
"mr %1,1\n"
|
||||||
"mr %1,1\n"
|
"li 0,0x3500\n"
|
||||||
"li 0,0x3500\n"
|
"sc\n"
|
||||||
"sc\n"
|
"nop\n"
|
||||||
"nop\n"
|
"mr 1,%1\n"
|
||||||
"mr 1,%1\n"
|
:
|
||||||
:
|
: "r"(addr), "r"(value)
|
||||||
: "r"(addr), "r"(value)
|
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
"11", "12");
|
||||||
"11", "12"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PatchSyscall(int index, uint32_t addr) {
|
void PatchSyscall(int index, uint32_t addr) {
|
||||||
kern_write(KERN_SYSCALL_TBL1 + index * 4, addr);
|
kern_write(KERN_SYSCALL_TBL1 + index * 4, addr);
|
||||||
kern_write(KERN_SYSCALL_TBL2 + index * 4, addr);
|
kern_write(KERN_SYSCALL_TBL2 + index * 4, addr);
|
||||||
kern_write(KERN_SYSCALL_TBL3 + index * 4, addr);
|
kern_write(KERN_SYSCALL_TBL3 + index * 4, addr);
|
||||||
kern_write(KERN_SYSCALL_TBL4 + index * 4, addr);
|
kern_write(KERN_SYSCALL_TBL4 + index * 4, addr);
|
||||||
kern_write(KERN_SYSCALL_TBL5 + index * 4, addr);
|
kern_write(KERN_SYSCALL_TBL5 + index * 4, addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void kernelInitialize() {
|
void kernelInitialize() {
|
||||||
PatchSyscall(0x25, (uint32_t)SCKernelCopyData);
|
PatchSyscall(0x25, (uint32_t) SCKernelCopyData);
|
||||||
}
|
}
|
||||||
|
111
src/main.cpp
111
src/main.cpp
@ -1,90 +1,87 @@
|
|||||||
|
|
||||||
#include "cafe/coreinit.h"
|
#include "cafe/coreinit.h"
|
||||||
#include "cafe/sysapp.h"
|
|
||||||
#include "cafe/nsysnet.h"
|
|
||||||
#include "cafe/vpad.h"
|
|
||||||
#include "cafe/nn_save.h"
|
|
||||||
#include "cafe/nn_act.h"
|
#include "cafe/nn_act.h"
|
||||||
#include "kernel.h"
|
#include "cafe/nn_save.h"
|
||||||
|
#include "cafe/nsysnet.h"
|
||||||
|
#include "cafe/sysapp.h"
|
||||||
|
#include "cafe/vpad.h"
|
||||||
#include "hbl.h"
|
#include "hbl.h"
|
||||||
|
#include "kernel.h"
|
||||||
|
|
||||||
#include "patches.h"
|
|
||||||
#include "debugger.h"
|
#include "debugger.h"
|
||||||
#include "exceptions.h"
|
#include "exceptions.h"
|
||||||
#include "screen.h"
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
|
#include "patches.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
|
|
||||||
bool GetTitleIdOnDisk(uint64_t *titleId) {
|
bool GetTitleIdOnDisk(uint64_t *titleId) {
|
||||||
MCPTitleListType title;
|
MCPTitleListType title;
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
|
||||||
int handle = MCP_Open();
|
int handle = MCP_Open();
|
||||||
MCP_TitleListByDevice(handle, "odd", &count, &title, sizeof(title));
|
MCP_TitleListByDevice(handle, "odd", &count, &title, sizeof(title));
|
||||||
MCP_Close(handle);
|
MCP_Close(handle);
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
*titleId = title.titleId;
|
*titleId = title.titleId;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MenuMain() {
|
int MenuMain() {
|
||||||
Screen screen;
|
Screen screen;
|
||||||
screen.init();
|
screen.init();
|
||||||
|
|
||||||
Menu menu(&screen);
|
Menu menu(&screen);
|
||||||
|
|
||||||
Menu::Option result = menu.show();
|
Menu::Option result = menu.show();
|
||||||
if (result == Menu::Exit) return EXIT_SUCCESS;
|
if (result == Menu::Exit) return EXIT_SUCCESS;
|
||||||
else if (result == Menu::LaunchDisk) {
|
else if (result == Menu::LaunchDisk) {
|
||||||
uint64_t titleId;
|
uint64_t titleId;
|
||||||
if (GetTitleIdOnDisk(&titleId)) {
|
if (GetTitleIdOnDisk(&titleId)) {
|
||||||
SYSLaunchTitle(titleId);
|
SYSLaunchTitle(titleId);
|
||||||
}
|
} else {
|
||||||
else {
|
menu.setMessage("Please insert a valid disk");
|
||||||
menu.setMessage("Please insert a valid disk");
|
}
|
||||||
}
|
} else if (result == Menu::ReturnToMenu) {
|
||||||
}
|
SYSLaunchMenu();
|
||||||
else if (result == Menu::ReturnToMenu) {
|
}
|
||||||
SYSLaunchMenu();
|
return EXIT_RELAUNCH_ON_LOAD;
|
||||||
}
|
|
||||||
return EXIT_RELAUNCH_ON_LOAD;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int DebuggerMain() {
|
int DebuggerMain() {
|
||||||
ApplyPatches();
|
ApplyPatches();
|
||||||
debugger = new Debugger();
|
debugger = new Debugger();
|
||||||
debugger->start();
|
debugger->start();
|
||||||
return EXIT_RELAUNCH_ON_LOAD;
|
return EXIT_RELAUNCH_ON_LOAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool firstRun = true;
|
bool firstRun = true;
|
||||||
int start() {
|
int start() {
|
||||||
coreinitInitialize();
|
coreinitInitialize();
|
||||||
kernelInitialize();
|
kernelInitialize();
|
||||||
vpadInitialize();
|
vpadInitialize();
|
||||||
sysappInitialize();
|
sysappInitialize();
|
||||||
nsysnetInitialize();
|
nsysnetInitialize();
|
||||||
nnsaveInitialize();
|
nnsaveInitialize();
|
||||||
nnactInitialize();
|
nnactInitialize();
|
||||||
|
|
||||||
InstallExceptionHandlers();
|
InstallExceptionHandlers();
|
||||||
|
|
||||||
int result;
|
int result;
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
result = MenuMain();
|
result = MenuMain();
|
||||||
}
|
} else {
|
||||||
else {
|
result = DebuggerMain();
|
||||||
result = DebuggerMain();
|
}
|
||||||
}
|
firstRun = false;
|
||||||
firstRun = false;
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" int entryPoint() {
|
extern "C" int entryPoint() {
|
||||||
return start();
|
return start();
|
||||||
}
|
}
|
||||||
|
@ -3,26 +3,26 @@
|
|||||||
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
|
||||||
void * operator new(size_t size) {
|
void *operator new(size_t size) {
|
||||||
return MEMAllocFromDefaultHeap(size);
|
return MEMAllocFromDefaultHeap(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * operator new[](size_t size) {
|
void *operator new[](size_t size) {
|
||||||
return MEMAllocFromDefaultHeap(size);
|
return MEMAllocFromDefaultHeap(size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * operator new(size_t size, int alignment) {
|
void *operator new(size_t size, int alignment) {
|
||||||
return MEMAllocFromDefaultHeapEx(size, alignment);
|
return MEMAllocFromDefaultHeapEx(size, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void * operator new[](size_t size, int alignment) {
|
void *operator new[](size_t size, int alignment) {
|
||||||
return MEMAllocFromDefaultHeapEx(size, alignment);
|
return MEMAllocFromDefaultHeapEx(size, alignment);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void *ptr) {
|
void operator delete(void *ptr) {
|
||||||
MEMFreeToDefaultHeap(ptr);
|
MEMFreeToDefaultHeap(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void operator delete(void *ptr, size_t size) {
|
void operator delete(void *ptr, size_t size) {
|
||||||
MEMFreeToDefaultHeap(ptr);
|
MEMFreeToDefaultHeap(ptr);
|
||||||
}
|
}
|
||||||
|
57
src/menu.cpp
57
src/menu.cpp
@ -1,44 +1,43 @@
|
|||||||
|
|
||||||
#include "cafe/vpad.h"
|
|
||||||
#include "menu.h"
|
#include "menu.h"
|
||||||
#include "screen.h"
|
#include "cafe/vpad.h"
|
||||||
#include "input.h"
|
|
||||||
#include "color.h"
|
#include "color.h"
|
||||||
|
#include "input.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
Menu::Menu(Screen *screen) : screen(screen) {
|
Menu::Menu(Screen *screen) : screen(screen) {
|
||||||
currentOption = LaunchDisk;
|
currentOption = LaunchDisk;
|
||||||
message = nullptr;
|
message = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Menu::Option Menu::show() {
|
Menu::Option Menu::show() {
|
||||||
while (true) {
|
while (true) {
|
||||||
redraw();
|
redraw();
|
||||||
uint32_t buttons = WaitInput(VPAD_BUTTON_A | VPAD_BUTTON_DOWN | VPAD_BUTTON_UP);
|
uint32_t buttons = WaitInput(VPAD_BUTTON_A | VPAD_BUTTON_DOWN | VPAD_BUTTON_UP);
|
||||||
if (buttons & VPAD_BUTTON_A) return (Option)currentOption;
|
if (buttons & VPAD_BUTTON_A) return (Option) currentOption;
|
||||||
else if (buttons & VPAD_BUTTON_DOWN) {
|
else if (buttons & VPAD_BUTTON_DOWN) {
|
||||||
if (currentOption < 2) currentOption++;
|
if (currentOption < 2) currentOption++;
|
||||||
}
|
} else if (buttons & VPAD_BUTTON_UP) {
|
||||||
else if (buttons & VPAD_BUTTON_UP) {
|
if (currentOption > 0) currentOption--;
|
||||||
if (currentOption > 0) currentOption--;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::setMessage(const char *message) {
|
void Menu::setMessage(const char *message) {
|
||||||
this->message = message;
|
this->message = message;
|
||||||
redraw();
|
redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::redraw() {
|
void Menu::redraw() {
|
||||||
screen->clear(COLOR_BLUE);
|
screen->clear(COLOR_BLUE);
|
||||||
screen->drawText(5, 5, "Wii U Debugger");
|
screen->drawText(5, 5, "Wii U Debugger");
|
||||||
screen->drawText(5, 7, "Choose an option:");
|
screen->drawText(5, 7, "Choose an option:");
|
||||||
screen->drawText(8, 9, "Install and launch disc");
|
screen->drawText(8, 9, "Install and launch disc");
|
||||||
screen->drawText(8, 10, "Install and return to system menu");
|
screen->drawText(8, 10, "Install and return to system menu");
|
||||||
screen->drawText(8, 11, "Exit without installing");
|
screen->drawText(8, 11, "Exit without installing");
|
||||||
screen->drawText(5, 9 + currentOption, ">");
|
screen->drawText(5, 9 + currentOption, ">");
|
||||||
if (message) {
|
if (message) {
|
||||||
screen->drawText(5, 13, message);
|
screen->drawText(5, 13, message);
|
||||||
}
|
}
|
||||||
screen->flip();
|
screen->flip();
|
||||||
}
|
}
|
||||||
|
28
src/menu.h
28
src/menu.h
@ -4,21 +4,21 @@
|
|||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
|
||||||
class Menu {
|
class Menu {
|
||||||
public:
|
public:
|
||||||
enum Option {
|
enum Option {
|
||||||
LaunchDisk,
|
LaunchDisk,
|
||||||
ReturnToMenu,
|
ReturnToMenu,
|
||||||
Exit
|
Exit
|
||||||
};
|
};
|
||||||
|
|
||||||
Menu(Screen *screen);
|
Menu(Screen *screen);
|
||||||
Option show();
|
Option show();
|
||||||
void setMessage(const char *message);
|
void setMessage(const char *message);
|
||||||
void redraw();
|
void redraw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Screen *screen;
|
Screen *screen;
|
||||||
int currentOption;
|
int currentOption;
|
||||||
|
|
||||||
const char *message;
|
const char *message;
|
||||||
};
|
};
|
||||||
|
@ -5,53 +5,52 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
int OSSetExceptionCallback_Patch() {
|
int OSSetExceptionCallback_Patch() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int OSSetExceptionCallbackEx_Patch() {
|
int OSSetExceptionCallbackEx_Patch() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OSIsDebuggerInitialized_Patch() {
|
bool OSIsDebuggerInitialized_Patch() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Patch(void *funcPtr, void *patchPtr) {
|
void Patch(void *funcPtr, void *patchPtr) {
|
||||||
OSDynLoad_NotifyData *sectionInfo = MainRPL->notifyData;
|
OSDynLoad_NotifyData *sectionInfo = MainRPL->notifyData;
|
||||||
|
|
||||||
uint32_t func = (uint32_t)funcPtr;
|
uint32_t func = (uint32_t) funcPtr;
|
||||||
uint32_t patch = (uint32_t)patchPtr;
|
uint32_t patch = (uint32_t) patchPtr;
|
||||||
if (func < 0x01800000) { //OS function (with trampoline)
|
if (func < 0x01800000) { //OS function (with trampoline)
|
||||||
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
|
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
|
||||||
uint32_t *instrs = (uint32_t *)addr;
|
uint32_t *instrs = (uint32_t *) addr;
|
||||||
if (instrs[0] == (0x3D600000 | (func >> 16)) && //lis r11, func@h
|
if (instrs[0] == (0x3D600000 | (func >> 16)) && //lis r11, func@h
|
||||||
instrs[1] == (0x616B0000 | (func & 0xFFFF)) && //ori r11, r11, func@l
|
instrs[1] == (0x616B0000 | (func & 0xFFFF)) && //ori r11, r11, func@l
|
||||||
instrs[2] == 0x7D6903A6 && //mtctr r11
|
instrs[2] == 0x7D6903A6 && //mtctr r11
|
||||||
instrs[3] == 0x4E800420) //bctr
|
instrs[3] == 0x4E800420) //bctr
|
||||||
{
|
{
|
||||||
KernelWriteU32(addr, 0x3D600000 | (patch >> 16)); //lis r11, patch@h
|
KernelWriteU32(addr, 0x3D600000 | (patch >> 16)); //lis r11, patch@h
|
||||||
KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l
|
KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else { //Dynamic function
|
||||||
else { //Dynamic function
|
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
|
||||||
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
|
uint32_t instr = *(uint32_t *) addr;
|
||||||
uint32_t instr = *(uint32_t *)addr;
|
if ((instr & 0xFC000002) == 0x48000000) { //b or bl
|
||||||
if ((instr & 0xFC000002) == 0x48000000) { //b or bl
|
if ((instr & 0x03FFFFFC) == func - addr) {
|
||||||
if ((instr & 0x03FFFFFC) == func - addr) {
|
instr = instr & ~0x03FFFFFC;
|
||||||
instr = instr & ~0x03FFFFFC;
|
instr |= patch;
|
||||||
instr |= patch;
|
instr |= 2; //Turn b/bl into ba/bla
|
||||||
instr |= 2; //Turn b/bl into ba/bla
|
KernelWriteU32(addr, instr);
|
||||||
KernelWriteU32(addr, instr);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyPatches() {
|
void ApplyPatches() {
|
||||||
Patch((void *)OSSetExceptionCallback, (void *)OSSetExceptionCallback_Patch);
|
Patch((void *) OSSetExceptionCallback, (void *) OSSetExceptionCallback_Patch);
|
||||||
Patch((void *)OSSetExceptionCallbackEx, (void *)OSSetExceptionCallbackEx_Patch);
|
Patch((void *) OSSetExceptionCallbackEx, (void *) OSSetExceptionCallbackEx_Patch);
|
||||||
|
|
||||||
Patch((void *)OSIsDebuggerInitialized, (void *)OSIsDebuggerInitialized_Patch);
|
Patch((void *) OSIsDebuggerInitialized, (void *) OSIsDebuggerInitialized_Patch);
|
||||||
}
|
}
|
||||||
|
@ -1,87 +1,87 @@
|
|||||||
|
|
||||||
#include "cafe/coreinit.h"
|
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
|
#include "cafe/coreinit.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
Screen::Screen() : screenBuffer(0) {}
|
Screen::Screen() : screenBuffer(0) {}
|
||||||
Screen::~Screen() {
|
Screen::~Screen() {
|
||||||
if (screenBuffer) {
|
if (screenBuffer) {
|
||||||
operator delete(screenBuffer);
|
operator delete(screenBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::init() {
|
void Screen::init() {
|
||||||
OSScreenInit();
|
OSScreenInit();
|
||||||
|
|
||||||
uint32_t bufferSize0 = OSScreenGetBufferSizeEx(0);
|
uint32_t bufferSize0 = OSScreenGetBufferSizeEx(0);
|
||||||
uint32_t bufferSize1 = OSScreenGetBufferSizeEx(1);
|
uint32_t bufferSize1 = OSScreenGetBufferSizeEx(1);
|
||||||
screenBuffer = operator new(bufferSize0 + bufferSize1, 0x40);
|
screenBuffer = operator new(bufferSize0 + bufferSize1, 0x40);
|
||||||
OSScreenSetBufferEx(0, screenBuffer);
|
OSScreenSetBufferEx(0, screenBuffer);
|
||||||
OSScreenSetBufferEx(1, (char *)screenBuffer + bufferSize0);
|
OSScreenSetBufferEx(1, (char *) screenBuffer + bufferSize0);
|
||||||
|
|
||||||
OSScreenEnableEx(0, 1);
|
OSScreenEnableEx(0, 1);
|
||||||
OSScreenEnableEx(1, 1);
|
OSScreenEnableEx(1, 1);
|
||||||
OSScreenClearBufferEx(0, 0);
|
OSScreenClearBufferEx(0, 0);
|
||||||
OSScreenClearBufferEx(1, 0);
|
OSScreenClearBufferEx(1, 0);
|
||||||
OSScreenFlipBuffersEx(0);
|
OSScreenFlipBuffersEx(0);
|
||||||
OSScreenFlipBuffersEx(1);
|
OSScreenFlipBuffersEx(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::clear(Display screen, uint32_t color) {
|
void Screen::clear(Display screen, uint32_t color) {
|
||||||
OSScreenClearBufferEx(screen, color);
|
OSScreenClearBufferEx(screen, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
void Screen::drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
||||||
for (int x = x1; x < x2; x++) {
|
for (int x = x1; x < x2; x++) {
|
||||||
OSScreenPutPixelEx(screen, x, y1, color);
|
OSScreenPutPixelEx(screen, x, y1, color);
|
||||||
OSScreenPutPixelEx(screen, x, y2, color);
|
OSScreenPutPixelEx(screen, x, y2, color);
|
||||||
}
|
}
|
||||||
for (int y = y1; y < y2; y++) {
|
for (int y = y1; y < y2; y++) {
|
||||||
OSScreenPutPixelEx(screen, x1, y, color);
|
OSScreenPutPixelEx(screen, x1, y, color);
|
||||||
OSScreenPutPixelEx(screen, x2, y, color);
|
OSScreenPutPixelEx(screen, x2, y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
void Screen::fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
|
||||||
for (int x = x1; x < x2; x++) {
|
for (int x = x1; x < x2; x++) {
|
||||||
for (int y = y1; y < y2; y++) {
|
for (int y = y1; y < y2; y++) {
|
||||||
OSScreenPutPixelEx(screen, x, y, color);
|
OSScreenPutPixelEx(screen, x, y, color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::drawText(Display screen, int x, int y, const char *text) {
|
void Screen::drawText(Display screen, int x, int y, const char *text) {
|
||||||
OSScreenPutFontEx(screen, x, y, text);
|
OSScreenPutFontEx(screen, x, y, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::flip(Display screen) {
|
void Screen::flip(Display screen) {
|
||||||
OSScreenFlipBuffersEx(screen);
|
OSScreenFlipBuffersEx(screen);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Screen::convx(int x) { return x * 854 / 1280; }
|
int Screen::convx(int x) { return x * 854 / 1280; }
|
||||||
int Screen::convy(int y) { return y * 480 / 720; }
|
int Screen::convy(int y) { return y * 480 / 720; }
|
||||||
|
|
||||||
void Screen::clear(uint32_t color) {
|
void Screen::clear(uint32_t color) {
|
||||||
clear(TV, color);
|
clear(TV, color);
|
||||||
clear(DRC, color);
|
clear(DRC, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::drawRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
void Screen::drawRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
||||||
drawRect(TV, x1, y1, x2, y2, color);
|
drawRect(TV, x1, y1, x2, y2, color);
|
||||||
drawRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
drawRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::fillRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
void Screen::fillRect(int x1, int y1, int x2, int y2, uint32_t color) {
|
||||||
fillRect(TV, x1, y1, x2, y2, color);
|
fillRect(TV, x1, y1, x2, y2, color);
|
||||||
fillRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
fillRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::drawText(int x, int y, const char *text) {
|
void Screen::drawText(int x, int y, const char *text) {
|
||||||
drawText(TV, x, y, text);
|
drawText(TV, x, y, text);
|
||||||
drawText(DRC, x, y, text);
|
drawText(DRC, x, y, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Screen::flip() {
|
void Screen::flip() {
|
||||||
flip(TV);
|
flip(TV);
|
||||||
flip(DRC);
|
flip(DRC);
|
||||||
}
|
}
|
||||||
|
44
src/screen.h
44
src/screen.h
@ -4,31 +4,31 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
class Screen {
|
class Screen {
|
||||||
public:
|
public:
|
||||||
enum Display {
|
enum Display {
|
||||||
TV,
|
TV,
|
||||||
DRC
|
DRC
|
||||||
};
|
};
|
||||||
|
|
||||||
Screen();
|
Screen();
|
||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void clear(uint32_t color);
|
void clear(uint32_t color);
|
||||||
void drawRect(int x1, int y1, int x2, int y2, uint32_t color);
|
void drawRect(int x1, int y1, int x2, int y2, uint32_t color);
|
||||||
void fillRect(int x1, int y1, int x2, int y2, uint32_t color);
|
void fillRect(int x1, int y1, int x2, int y2, uint32_t color);
|
||||||
void drawText(int x, int y, const char *text);
|
void drawText(int x, int y, const char *text);
|
||||||
void flip();
|
void flip();
|
||||||
|
|
||||||
void clear(Display screen, uint32_t color);
|
void clear(Display screen, uint32_t color);
|
||||||
void drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
|
void drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
|
||||||
void fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
|
void fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
|
||||||
void drawText(Display screen, int x, int y, const char *text);
|
void drawText(Display screen, int x, int y, const char *text);
|
||||||
void flip(Display screen);
|
void flip(Display screen);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *screenBuffer;
|
void *screenBuffer;
|
||||||
|
|
||||||
int convx(int x);
|
int convx(int x);
|
||||||
int convy(int y);
|
int convy(int y);
|
||||||
};
|
};
|
||||||
|
131
src/socket.cpp
131
src/socket.cpp
@ -6,96 +6,95 @@
|
|||||||
Socket::Socket() : sock(-1) {}
|
Socket::Socket() : sock(-1) {}
|
||||||
|
|
||||||
Socket::~Socket() {
|
Socket::~Socket() {
|
||||||
if (sock >= 0) {
|
if (sock >= 0) {
|
||||||
socketclose(sock);
|
socketclose(sock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::init(Type type) {
|
bool Socket::init(Type type) {
|
||||||
if (type == TCP) {
|
if (type == TCP) {
|
||||||
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||||
}
|
} else {
|
||||||
else {
|
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
}
|
||||||
}
|
return sock >= 0;
|
||||||
return sock >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Socket::close() {
|
bool Socket::close() {
|
||||||
if (sock >= 0) {
|
if (sock >= 0) {
|
||||||
int result = socketclose(sock);
|
int result = socketclose(sock);
|
||||||
sock = -1;
|
sock = -1;
|
||||||
return result == 0;
|
return result == 0;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Client::sendall(const void *data, size_t length) {
|
bool Client::sendall(const void *data, size_t length) {
|
||||||
size_t sent = 0;
|
size_t sent = 0;
|
||||||
while (sent < length) {
|
while (sent < length) {
|
||||||
int num = send(sock, data, length - sent, 0);
|
int num = send(sock, data, length - sent, 0);
|
||||||
if (num < 0) {
|
if (num < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sent += num;
|
sent += num;
|
||||||
data = (const char *)data + num;
|
data = (const char *) data + num;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Client::recvall(void *data, size_t length) {
|
bool Client::recvall(void *data, size_t length) {
|
||||||
size_t received = 0;
|
size_t received = 0;
|
||||||
while (received < length) {
|
while (received < length) {
|
||||||
int num = recv(sock, data, length - received, 0);
|
int num = recv(sock, data, length - received, 0);
|
||||||
if (num <= 0) {
|
if (num <= 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
received += num;
|
received += num;
|
||||||
data = (char *)data + num;
|
data = (char *) data + num;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Server::bind(int port) {
|
bool Server::bind(int port) {
|
||||||
uint32_t reuseaddr = 1;
|
uint32_t reuseaddr = 1;
|
||||||
int result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, 4);
|
int result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, 4);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
sockaddr serverAddr = {0};
|
sockaddr serverAddr = {0};
|
||||||
serverAddr.family = AF_INET;
|
serverAddr.family = AF_INET;
|
||||||
serverAddr.port = port;
|
serverAddr.port = port;
|
||||||
serverAddr.addr = 0;
|
serverAddr.addr = 0;
|
||||||
|
|
||||||
result = ::bind(sock, &serverAddr, 16);
|
result = ::bind(sock, &serverAddr, 16);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Server::accept(Client *client) {
|
bool Server::accept(Client *client) {
|
||||||
int result = listen(sock, 1);
|
int result = listen(sock, 1);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int fd = ::accept(sock, 0, 0);
|
int fd = ::accept(sock, 0, 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
close();
|
close();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
client->sock = fd;
|
client->sock = fd;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
26
src/socket.h
26
src/socket.h
@ -5,27 +5,27 @@
|
|||||||
|
|
||||||
class Socket {
|
class Socket {
|
||||||
public:
|
public:
|
||||||
enum Type {
|
enum Type {
|
||||||
TCP,
|
TCP,
|
||||||
UDP
|
UDP
|
||||||
};
|
};
|
||||||
|
|
||||||
Socket();
|
Socket();
|
||||||
~Socket();
|
~Socket();
|
||||||
bool init(Type type);
|
bool init(Type type);
|
||||||
bool close();
|
bool close();
|
||||||
|
|
||||||
int sock;
|
int sock;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Client : public Socket {
|
class Client : public Socket {
|
||||||
public:
|
public:
|
||||||
bool sendall(const void *data, size_t length);
|
bool sendall(const void *data, size_t length);
|
||||||
bool recvall(void *data, size_t length);
|
bool recvall(void *data, size_t length);
|
||||||
};
|
};
|
||||||
|
|
||||||
class Server : public Socket {
|
class Server : public Socket {
|
||||||
public:
|
public:
|
||||||
bool bind(int port);
|
bool bind(int port);
|
||||||
bool accept(Client *client);
|
bool accept(Client *client);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user