From baeae8637600ac71c02b7611010a8bf5ffa9a83a Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 3 Mar 2022 23:08:30 -0700 Subject: [PATCH] Added projects from 2.0 though not the daemon as I will be re writing it. Kernel could also probably use some work to tidy it up. --- Misc/DriverDefinitions.h | 176 ++ Misc/Increment.bat | 66 + Orbis Suite 3.0.sln | 63 +- Playstation/Daemon/Daemon.vcxproj | 68 + Playstation/Daemon/Daemon.vcxproj.filters | 23 + Playstation/Daemon/build.bat | 31 + Playstation/Daemon/main.cpp | 7 + .../Kernel/.vscode/c_cpp_properties.json | 23 + Playstation/Kernel/.vscode/settings.json | 19 + Playstation/Kernel/Increment.bat | 1 + Playstation/Kernel/Kernel/Kernel.elf | Bin 0 -> 31720 bytes Playstation/Kernel/Kernel/Linker | 29 + Playstation/Kernel/Kernel/Makefile | 50 + .../Kernel/Resources/LoaderShellCode.bin | Bin 0 -> 928 bytes .../Kernel/Resources/UnLoaderShellCode.bin | Bin 0 -> 754 bytes .../Kernel/Kernel/build/LoaderShellCode.o | Bin 0 -> 1600 bytes .../Kernel/Kernel/build/OrbisLib/KDriver.o | Bin 0 -> 4624 bytes .../Kernel/Kernel/build/OrbisLib/OrbisLib.o | Bin 0 -> 3080 bytes .../Kernel/Kernel/build/UnLoaderShellCode.o | Bin 0 -> 1440 bytes Playstation/Kernel/Kernel/build/Util/ASM.o | Bin 0 -> 560 bytes Playstation/Kernel/Kernel/build/Util/Heap.o | Bin 0 -> 3048 bytes Playstation/Kernel/Kernel/build/Util/Kernel.o | Bin 0 -> 3992 bytes .../Kernel/build/Util/Patches/Patches-505.o | Bin 0 -> 1016 bytes .../Kernel/build/Util/Patches/Patches-672.o | Bin 0 -> 1656 bytes .../Kernel/build/Util/Patches/Patches-702.o | Bin 0 -> 1824 bytes .../Kernel/build/Util/Patches/Patches-755.o | Bin 0 -> 1824 bytes .../Kernel/build/Util/Patches/Patches-900.o | Bin 0 -> 1240 bytes .../Kernel/build/Util/Patches/Patches.o | Bin 0 -> 1704 bytes .../Kernel/build/Util/Resolver/Resolver.o | Bin 0 -> 12448 bytes .../build/Util/ShellCode/SPRXShellCode.o | Bin 0 -> 800 bytes Playstation/Kernel/Kernel/build/Util/System.o | Bin 0 -> 4640 bytes Playstation/Kernel/Kernel/build/Util/kproc.o | Bin 0 -> 4664 bytes Playstation/Kernel/Kernel/crt0.s | 5 + Playstation/Kernel/Kernel/source/Common.hpp | 69 + .../source/OrbisLib/KDriver/KDriver.cpp | 98 ++ .../source/OrbisLib/KDriver/KDriver.hpp | 18 + .../Kernel/source/OrbisLib/KDriver/Kernel.cpp | 16 + .../Kernel/source/OrbisLib/KDriver/Kernel.hpp | 9 + .../Kernel/source/OrbisLib/KDriver/Proc.cpp | 289 ++++ .../Kernel/source/OrbisLib/KDriver/Proc.hpp | 17 + .../Kernel/source/OrbisLib/OrbisLib.cpp | 90 + .../Kernel/source/OrbisLib/OrbisLib.hpp | 32 + Playstation/Kernel/Kernel/source/Util/ASM.h | 10 + Playstation/Kernel/Kernel/source/Util/ASM.s | 31 + .../Kernel/Kernel/source/Util/Heap.cpp | 45 + .../Kernel/Kernel/source/Util/Heap.hpp | 9 + .../Kernel/Kernel/source/Util/Kernel.cpp | 128 ++ .../Kernel/Kernel/source/Util/Kernel.hpp | 9 + .../source/Util/Patches/Patches-505.cpp | 74 + .../source/Util/Patches/Patches-672.cpp | 145 ++ .../source/Util/Patches/Patches-702.cpp | 215 +++ .../source/Util/Patches/Patches-755.cpp | 215 +++ .../source/Util/Patches/Patches-900.cpp | 8 + .../Kernel/source/Util/Patches/Patches.cpp | 34 + .../Kernel/source/Util/Patches/Patches.hpp | 8 + .../Kernel/Kernel/source/Util/Proc.cpp | 248 +++ .../Kernel/Kernel/source/Util/Proc.hpp | 34 + .../Util/Resolver/Offsets/Offsets-505.hpp | 139 ++ .../Util/Resolver/Offsets/Offsets-672.hpp | 135 ++ .../Util/Resolver/Offsets/Offsets-702.hpp | 137 ++ .../Util/Resolver/Offsets/Offsets-755.hpp | 137 ++ .../Util/Resolver/Offsets/Offsets-900.hpp | 137 ++ .../Util/Resolver/Offsets/Offsets-NA.hpp | 136 ++ .../Kernel/source/Util/Resolver/Resolver.cpp | 252 +++ .../Kernel/source/Util/Resolver/Resolver.hpp | 158 ++ .../Kernel/Kernel/source/Util/Settings.hpp | 32 + .../source/Util/ShellCode/SPRXShellCode.cpp | 413 +++++ .../source/Util/ShellCode/SPRXShellCode.hpp | 31 + .../Kernel/Kernel/source/Util/System.cpp | 402 +++++ .../Kernel/Kernel/source/Util/System.hpp | 17 + .../Kernel/Kernel/source/Util/Types.hpp | 25 + .../Kernel/Kernel/source/Util/kproc.cpp | 42 + .../Kernel/Kernel/source/Util/kproc.hpp | 17 + Playstation/Kernel/Kernel/source/main.cpp | 49 + Playstation/Kernel/Kernel/temp.txt | 4 + Playstation/Kernel/Makefile | 42 + Playstation/Kernel/README.md | 3 + .../Kernel/ShellCode/LoaderShellCode.s | 221 +++ Playstation/Kernel/ShellCode/Makefile | 18 + .../Kernel/ShellCode/UnLoaderShellCode.s | 191 +++ Playstation/Orbis Toolbox/Build_Overlay.cpp | 46 + Playstation/Orbis Toolbox/Build_Overlay.h | 16 + Playstation/Orbis Toolbox/Common.h | 29 + Playstation/Orbis Toolbox/Config.cpp | 266 +++ Playstation/Orbis Toolbox/Config.h | 62 + Playstation/Orbis Toolbox/Custom_Content.cpp | 111 ++ Playstation/Orbis Toolbox/Daemons.cpp | 131 ++ Playstation/Orbis Toolbox/Daemons.h | 8 + .../Orbis Toolbox/DebugTitleIdLabel.cpp | 130 ++ Playstation/Orbis Toolbox/Debug_Features.h | 71 + Playstation/Orbis Toolbox/Detour.cpp | 109 ++ Playstation/Orbis Toolbox/Detour.h | 28 + Playstation/Orbis Toolbox/DevkitPanel.cpp | 109 ++ Playstation/Orbis Toolbox/Embed.s | 37 + Playstation/Orbis Toolbox/GamePad.cpp | 7 + Playstation/Orbis Toolbox/GamePad.h | 31 + Playstation/Orbis Toolbox/Game_Overlay.cpp | 259 +++ Playstation/Orbis Toolbox/Game_Overlay.h | 36 + Playstation/Orbis Toolbox/Increment.bat | 66 + Playstation/Orbis Toolbox/KDriver.cpp | 147 ++ Playstation/Orbis Toolbox/KDriver.h | 25 + Playstation/Orbis Toolbox/Label.cpp | 107 ++ Playstation/Orbis Toolbox/Label.h | 59 + Playstation/Orbis Toolbox/LncUtil.cpp | 97 ++ Playstation/Orbis Toolbox/LncUtil.h | 71 + Playstation/Orbis Toolbox/Menu.cpp | 204 +++ Playstation/Orbis Toolbox/Menu.h | 117 ++ Playstation/Orbis Toolbox/Mono.cpp | 274 ++++ Playstation/Orbis Toolbox/Mono.h | 458 ++++++ .../Orbis Toolbox/Orbis Toolbox.vcxproj | 133 ++ .../Orbis Toolbox.vcxproj.filters | 227 +++ Playstation/Orbis Toolbox/Orbis_Toolbox.cpp | 46 + Playstation/Orbis Toolbox/Panel.cpp | 71 + Playstation/Orbis Toolbox/Panel.h | 33 + Playstation/Orbis Toolbox/Patcher.cpp | 68 + Playstation/Orbis Toolbox/Patcher.h | 17 + Playstation/Orbis Toolbox/Settings_Menu.cpp | 310 ++++ Playstation/Orbis Toolbox/Settings_Menu.h | 34 + .../Orbis Toolbox/SysfileUtilWrapper.cpp | 68 + .../Orbis Toolbox/SysfileUtilWrapper.h | 16 + Playstation/Orbis Toolbox/System_Monitor.cpp | 181 ++ Playstation/Orbis Toolbox/System_Monitor.h | 42 + Playstation/Orbis Toolbox/UI.h | 7 + Playstation/Orbis Toolbox/UI_Utilities.cpp | 226 +++ Playstation/Orbis Toolbox/UI_Utilities.h | 32 + Playstation/Orbis Toolbox/Utilities.cpp | 112 ++ Playstation/Orbis Toolbox/Utilities.h | 69 + Playstation/Orbis Toolbox/Version.h | 11 + Playstation/Orbis Toolbox/Widget.cpp | 58 + Playstation/Orbis Toolbox/Widget.h | 41 + Playstation/Orbis Toolbox/build.bat | 63 + Playstation/Orbis Toolbox/external_hdd.xml | 28 + Playstation/Orbis Toolbox/hde64.cpp | 344 ++++ Playstation/Orbis Toolbox/hde64.h | 124 ++ Playstation/Orbis Toolbox/orbis_toolbox.xml | 204 +++ Playstation/Orbis Toolbox/settings_root.xml | 41 + Playstation/Orbis Toolbox/table64.h | 74 + Playstation/OrbisSuite/Common.h | 20 + Playstation/OrbisSuite/Config.h | 10 + Playstation/OrbisSuite/KernelLoader.cpp | 205 +++ Playstation/OrbisSuite/KernelLoader.h | 75 + Playstation/OrbisSuite/MsgDialog.cpp | 108 ++ Playstation/OrbisSuite/MsgDialog.h | 16 + Playstation/OrbisSuite/OrbisDriver.cpp | 122 ++ Playstation/OrbisSuite/OrbisDriver.h | 17 + Playstation/OrbisSuite/OrbisSuite.vcxproj | 83 + .../OrbisSuite/OrbisSuite.vcxproj.filters | 61 + Playstation/OrbisSuite/Utilities.cpp | 295 ++++ Playstation/OrbisSuite/Utilities.h | 105 ++ Playstation/OrbisSuite/build.bat | 46 + Playstation/OrbisSuite/kELF.cpp | 189 +++ Playstation/OrbisSuite/kELF.h | 1457 +++++++++++++++++ Playstation/OrbisSuite/main.cpp | 114 ++ .../MVVM/View/SettingsView.xaml.cs | 5 - .../Resources/BuildNumber.txt | 2 +- .../Resources/BuildString.txt | 2 +- 156 files changed, 13864 insertions(+), 9 deletions(-) create mode 100644 Misc/DriverDefinitions.h create mode 100644 Misc/Increment.bat create mode 100644 Playstation/Daemon/Daemon.vcxproj create mode 100644 Playstation/Daemon/Daemon.vcxproj.filters create mode 100644 Playstation/Daemon/build.bat create mode 100644 Playstation/Daemon/main.cpp create mode 100644 Playstation/Kernel/.vscode/c_cpp_properties.json create mode 100644 Playstation/Kernel/.vscode/settings.json create mode 100644 Playstation/Kernel/Increment.bat create mode 100644 Playstation/Kernel/Kernel/Kernel.elf create mode 100644 Playstation/Kernel/Kernel/Linker create mode 100644 Playstation/Kernel/Kernel/Makefile create mode 100644 Playstation/Kernel/Kernel/Resources/LoaderShellCode.bin create mode 100644 Playstation/Kernel/Kernel/Resources/UnLoaderShellCode.bin create mode 100644 Playstation/Kernel/Kernel/build/LoaderShellCode.o create mode 100644 Playstation/Kernel/Kernel/build/OrbisLib/KDriver.o create mode 100644 Playstation/Kernel/Kernel/build/OrbisLib/OrbisLib.o create mode 100644 Playstation/Kernel/Kernel/build/UnLoaderShellCode.o create mode 100644 Playstation/Kernel/Kernel/build/Util/ASM.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Heap.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Kernel.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches-505.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches-672.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches-702.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches-755.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches-900.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Patches/Patches.o create mode 100644 Playstation/Kernel/Kernel/build/Util/Resolver/Resolver.o create mode 100644 Playstation/Kernel/Kernel/build/Util/ShellCode/SPRXShellCode.o create mode 100644 Playstation/Kernel/Kernel/build/Util/System.o create mode 100644 Playstation/Kernel/Kernel/build/Util/kproc.o create mode 100644 Playstation/Kernel/Kernel/crt0.s create mode 100644 Playstation/Kernel/Kernel/source/Common.hpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.cpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.hpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.cpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.hpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.cpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.hpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.cpp create mode 100644 Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/ASM.h create mode 100644 Playstation/Kernel/Kernel/source/Util/ASM.s create mode 100644 Playstation/Kernel/Kernel/source/Util/Heap.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Heap.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Kernel.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Kernel.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches-505.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches-672.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches-702.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches-755.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches-900.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Patches/Patches.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Proc.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Proc.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-505.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-672.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-702.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-755.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-900.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-NA.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Settings.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/System.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/System.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/Types.hpp create mode 100644 Playstation/Kernel/Kernel/source/Util/kproc.cpp create mode 100644 Playstation/Kernel/Kernel/source/Util/kproc.hpp create mode 100644 Playstation/Kernel/Kernel/source/main.cpp create mode 100644 Playstation/Kernel/Kernel/temp.txt create mode 100644 Playstation/Kernel/Makefile create mode 100644 Playstation/Kernel/README.md create mode 100644 Playstation/Kernel/ShellCode/LoaderShellCode.s create mode 100644 Playstation/Kernel/ShellCode/Makefile create mode 100644 Playstation/Kernel/ShellCode/UnLoaderShellCode.s create mode 100644 Playstation/Orbis Toolbox/Build_Overlay.cpp create mode 100644 Playstation/Orbis Toolbox/Build_Overlay.h create mode 100644 Playstation/Orbis Toolbox/Common.h create mode 100644 Playstation/Orbis Toolbox/Config.cpp create mode 100644 Playstation/Orbis Toolbox/Config.h create mode 100644 Playstation/Orbis Toolbox/Custom_Content.cpp create mode 100644 Playstation/Orbis Toolbox/Daemons.cpp create mode 100644 Playstation/Orbis Toolbox/Daemons.h create mode 100644 Playstation/Orbis Toolbox/DebugTitleIdLabel.cpp create mode 100644 Playstation/Orbis Toolbox/Debug_Features.h create mode 100644 Playstation/Orbis Toolbox/Detour.cpp create mode 100644 Playstation/Orbis Toolbox/Detour.h create mode 100644 Playstation/Orbis Toolbox/DevkitPanel.cpp create mode 100644 Playstation/Orbis Toolbox/Embed.s create mode 100644 Playstation/Orbis Toolbox/GamePad.cpp create mode 100644 Playstation/Orbis Toolbox/GamePad.h create mode 100644 Playstation/Orbis Toolbox/Game_Overlay.cpp create mode 100644 Playstation/Orbis Toolbox/Game_Overlay.h create mode 100644 Playstation/Orbis Toolbox/Increment.bat create mode 100644 Playstation/Orbis Toolbox/KDriver.cpp create mode 100644 Playstation/Orbis Toolbox/KDriver.h create mode 100644 Playstation/Orbis Toolbox/Label.cpp create mode 100644 Playstation/Orbis Toolbox/Label.h create mode 100644 Playstation/Orbis Toolbox/LncUtil.cpp create mode 100644 Playstation/Orbis Toolbox/LncUtil.h create mode 100644 Playstation/Orbis Toolbox/Menu.cpp create mode 100644 Playstation/Orbis Toolbox/Menu.h create mode 100644 Playstation/Orbis Toolbox/Mono.cpp create mode 100644 Playstation/Orbis Toolbox/Mono.h create mode 100644 Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj create mode 100644 Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj.filters create mode 100644 Playstation/Orbis Toolbox/Orbis_Toolbox.cpp create mode 100644 Playstation/Orbis Toolbox/Panel.cpp create mode 100644 Playstation/Orbis Toolbox/Panel.h create mode 100644 Playstation/Orbis Toolbox/Patcher.cpp create mode 100644 Playstation/Orbis Toolbox/Patcher.h create mode 100644 Playstation/Orbis Toolbox/Settings_Menu.cpp create mode 100644 Playstation/Orbis Toolbox/Settings_Menu.h create mode 100644 Playstation/Orbis Toolbox/SysfileUtilWrapper.cpp create mode 100644 Playstation/Orbis Toolbox/SysfileUtilWrapper.h create mode 100644 Playstation/Orbis Toolbox/System_Monitor.cpp create mode 100644 Playstation/Orbis Toolbox/System_Monitor.h create mode 100644 Playstation/Orbis Toolbox/UI.h create mode 100644 Playstation/Orbis Toolbox/UI_Utilities.cpp create mode 100644 Playstation/Orbis Toolbox/UI_Utilities.h create mode 100644 Playstation/Orbis Toolbox/Utilities.cpp create mode 100644 Playstation/Orbis Toolbox/Utilities.h create mode 100644 Playstation/Orbis Toolbox/Version.h create mode 100644 Playstation/Orbis Toolbox/Widget.cpp create mode 100644 Playstation/Orbis Toolbox/Widget.h create mode 100644 Playstation/Orbis Toolbox/build.bat create mode 100644 Playstation/Orbis Toolbox/external_hdd.xml create mode 100644 Playstation/Orbis Toolbox/hde64.cpp create mode 100644 Playstation/Orbis Toolbox/hde64.h create mode 100644 Playstation/Orbis Toolbox/orbis_toolbox.xml create mode 100644 Playstation/Orbis Toolbox/settings_root.xml create mode 100644 Playstation/Orbis Toolbox/table64.h create mode 100644 Playstation/OrbisSuite/Common.h create mode 100644 Playstation/OrbisSuite/Config.h create mode 100644 Playstation/OrbisSuite/KernelLoader.cpp create mode 100644 Playstation/OrbisSuite/KernelLoader.h create mode 100644 Playstation/OrbisSuite/MsgDialog.cpp create mode 100644 Playstation/OrbisSuite/MsgDialog.h create mode 100644 Playstation/OrbisSuite/OrbisDriver.cpp create mode 100644 Playstation/OrbisSuite/OrbisDriver.h create mode 100644 Playstation/OrbisSuite/OrbisSuite.vcxproj create mode 100644 Playstation/OrbisSuite/OrbisSuite.vcxproj.filters create mode 100644 Playstation/OrbisSuite/Utilities.cpp create mode 100644 Playstation/OrbisSuite/Utilities.h create mode 100644 Playstation/OrbisSuite/build.bat create mode 100644 Playstation/OrbisSuite/kELF.cpp create mode 100644 Playstation/OrbisSuite/kELF.h create mode 100644 Playstation/OrbisSuite/main.cpp diff --git a/Misc/DriverDefinitions.h b/Misc/DriverDefinitions.h new file mode 100644 index 0000000..407effe --- /dev/null +++ b/Misc/DriverDefinitions.h @@ -0,0 +1,176 @@ +#pragma once + +#if defined(__cplusplus) +extern "C" { +#endif + +#if defined(KERNELDRIVER) +#include +#else +#include +#define IOC_VOID 0x20000000 /* no parameters */ +#define IOC_OUT 0x40000000 /* copy out parameters */ +#define IOC_IN 0x80000000 /* copy in parameters */ +#define IOC_INOUT (IOC_IN|IOC_OUT) +#endif + +#if defined(__cplusplus) +}; +#endif + +enum KDriverCommands +{ + /* ######## Proc Commands ####### */ + CMD_PROC_LIST, + CMD_PROC_INFO, + CMD_PROC_MODULE_LIST, + CMD_PROC_READ_WRITE_MEMORY, + CMD_PROC_ALLOC_MEMORY, + CMD_PROC_FREE_MEMORY, + CMD_PROC_SPRX, + CMD_PROC_ELF, + /* ############################## */ + + /* ###### Kernel Commands ####### */ + CMD_KERN_READ_WRITE_MEMORY, + /* ############################## */ + + /* ###### KDriver Commands ###### */ + CMD_KDRIVER_INFO, + /* ############################## */ +}; + +// Process Commands +struct KDriver_ProcList +{ + uint64_t UserlandAddr; + size_t UserlandSize; + int ProcCount; +}; + +struct ProcInfo +{ + int PID; + bool Attached; + char ProcName[32]; + char TitleID[10]; + uint64_t TextSegmentBase; + uint64_t TextSegmentLen; + uint64_t DataSegmentBase; + uint64_t DataSegmentLen; +}; + +struct KDriver_ProcSPRX +{ + int CallType; + char ProcName[32]; + int Handle; + char Path[4096]; + bool CallEntryExit; +}; + +struct KDriver_ProcInfo +{ + int ProcessID; + uint64_t UserlandAddr; + size_t UserlandSize; + int ThreadCount; +}; + +struct ProcInfoExt +{ + struct ThreadInfo + { + int ThreadId; + char Name[36]; + int Errno; + int RetVal; + }; + + int ProcessID; + int Attached; + int Signal; + int Code; + int Stops; + int StopType; + char ProcName[32]; + char TitleID[10]; + char ElfPath[1024]; + char RandomizedPath[256]; + uint64_t TextSegmentBase; + uint64_t TextSegmentLen; + uint64_t DataSegmentBase; + uint64_t DataSegmentLen; + + int ThreadCount; + ThreadInfo Threads[]; +}; + +struct KDriver_ModuleList +{ + int ProcessID; + uint64_t UserlandAddr; + size_t UserlandSize; + int ModuleCount; +}; + +struct ModuleInfo +{ + int Handle; + char Name[36]; + char Path[256]; + uint64_t TextSegmentBase; + uint64_t TextSegmentLen; + uint64_t DataSegmentBase; + uint64_t DataSegmentLen; +}; + +struct KDriver_ReadWriteMemory +{ + int ProcessID; + bool IsRead; + uint64_t ProcessAddress; + uint64_t UserlandAddr; + size_t Length; +}; + +struct KDriver_AllocFreeMemory +{ + int ProcessID; + size_t Ammount; + uint64_t ProcessAddress; +}; + +struct KDriver_ProcELF +{ + int ProcessID; + uint64_t ELFAddress; + size_t ELFSize; +}; + +#define PROC_LIST _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_LIST), sizeof(KDriver_ProcList)) +#define PROC_INFO _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_INFO), sizeof(KDriver_ProcInfo)) +#define PROC_MODULE_LIST _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_MODULE_LIST), sizeof(KDriver_ModuleList)) +#define PROC_READ_WRITE_MEMORY _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_READ_WRITE_MEMORY), sizeof(KDriver_ReadWriteMemory)) +#define PROC_ALLOC_MEMORY _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_ALLOC_MEMORY), sizeof(KDriver_AllocFreeMemory)) +#define PROC_FREE_MEMORY _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_FREE_MEMORY), sizeof(KDriver_AllocFreeMemory)) +#define PROC_SPRX _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_SPRX), sizeof(KDriver_ProcSPRX)) +#define PROC_ELF _IOC(IOC_INOUT, 'P', (uint32_t)(KDriverCommands::CMD_PROC_ELF), sizeof(KDriver_ProcELF)) + +// Kernel Commands +#define KERN_READ_WRITE_MEMORY _IOC(IOC_INOUT, 'K', (uint32_t)(KDriverCommands::CMD_KERN_READ_WRITE_MEMORY), sizeof(KDriver_ReadWriteMemory)) + +// Kdriver Commands +struct KDriver_Info +{ + int MajorVersion; + int MinorVersion; + int BuildVersion; + bool Running; + int(*Shutdown)(); + int(*Entry)(void* p); + void* ELFBase; + int Size; +}; + +#define KDRIVER_INFO _IOC(IOC_OUT, 'D', (uint32_t)(KDriverCommands::CMD_KDRIVER_INFO), sizeof(KDriver_Info)) diff --git a/Misc/Increment.bat b/Misc/Increment.bat new file mode 100644 index 0000000..17d40cc --- /dev/null +++ b/Misc/Increment.bat @@ -0,0 +1,66 @@ +@echo off + REM you need this to set and read a variable inside + REM a parethetical structure such as a FOR loop + setlocal enabledelayedexpansion + + REM This is the file we are going to alter + set filepath=%1 + set filename=%~n1%~x1 + + REM Use temp file + REM delete if already exists + REM so we can use append operator for all output + if exist "%filepath%.temp" del "%filepath%.temp" + + REM For each line in the file... + REM ...using FOR alone to parse the file skips blank lines so we... + REM ...parse the output (note single quotes) of... + REM running TYPE on the file and piping the output through FINDSTR... + REM ...with the /n switch (this adds a line number and a colon at the start of each line) + REM the FINDSTR search string is ".*" (find any characters including cr/lf) + REM Split into 2* tokens, the asterisk means %%R is the entire remainder of the line + REM delimiter being the colon thus... + REM The number is token 1, %%Q (discarded, along with the colon) + REM The original source file line is token 2, %%R + REM note we escape the pipe character with a caret ^ in the FOR dataset block + for /f "tokens=1,2* delims=:" %%Q in ('type "%filepath%" ^| findstr /n ".*"') do ( + + REM if token 2 is null then the line is blank so we echo a blank line to the temp output file + if "%%R"=="" echo. >> "%filepath%.temp" + + REM This flag gets set to 1 if we have a line that needs changing + set incflag=0 + + REM Split the line into 3 tokens with white space the delimiter + for /f "tokens=1-3 delims= " %%A in ("%%R") do ( + + REM test if an increment needs to happen and set the flag if it does + if "%%B"==%2 set incflag=1 + REM %%C is the number + + REM If the line contains a number to increment... + if !incflag! equ 1 ( + REM do it... + set /a num=%%C+1 + + REM info msg to console + echo Incrementing %%B from %%C to !num! + + REM write the altered line to file + echo %%A %%B !num! >>"%filepath%.temp" + + REM the line is a nonblank one that simply needs copying + ) else ( + + echo %%R >> "%filepath%.temp" + + REM Match those parentheses! + ) + ) + ) + + REM delete original file + del "%filepath%" + + REM rename temp file to original file name + ren "%filepath%.temp" "%filename%" \ No newline at end of file diff --git a/Orbis Suite 3.0.sln b/Orbis Suite 3.0.sln index 5bd93c1..7c5ecd6 100644 --- a/Orbis Suite 3.0.sln +++ b/Orbis Suite 3.0.sln @@ -10,6 +10,10 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Playstation", "Playstation", "{8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Misc", "Misc", "{DBCE3AAD-373D-4EB6-8964-2A4BE1E9F575}" + ProjectSection(SolutionItems) = preProject + Misc\DriverDefinitions.h = Misc\DriverDefinitions.h + Misc\Increment.bat = Misc\Increment.bat + EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisNeighborHood", "Windows\OrbisNeighborHood\OrbisNeighborHood.csproj", "{81B068F7-776C-429F-BB7B-5563F75F1A39}" ProjectSection(ProjectDependencies) = postProject @@ -18,45 +22,97 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisNeighborHood", "Window EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Installer", "Installer", "{6046C772-BE17-4BC8-A362-AD8C77F9178E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbisLib", "Windows\Libraries\OrbisLib\OrbisLib.csproj", "{6AE42BFE-1833-4804-96EB-38D323B6C28E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisLib", "Windows\Libraries\OrbisLib\OrbisLib.csproj", "{6AE42BFE-1833-4804-96EB-38D323B6C28E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbisSuiteService", "Windows\OrbisSuiteService\OrbisSuiteService.csproj", "{D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisSuiteService", "Windows\OrbisSuiteService\OrbisSuiteService.csproj", "{D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}" ProjectSection(ProjectDependencies) = postProject {6AE42BFE-1833-4804-96EB-38D323B6C28E} = {6AE42BFE-1833-4804-96EB-38D323B6C28E} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Daemon", "Playstation\Daemon\Daemon.vcxproj", "{88E11D06-FCB4-4707-A48E-B8D66966A154}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Orbis Toolbox", "Playstation\Orbis Toolbox\Orbis Toolbox.vcxproj", "{CED79D48-621A-4076-81E8-11F77DE1E41B}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OrbisSuite", "Playstation\OrbisSuite\OrbisSuite.vcxproj", "{228AA300-11F5-49B1-A6B5-4986635C6D0B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|Any CPU.Build.0 = Debug|Any CPU + {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|x64.ActiveCfg = Debug|Any CPU + {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|x64.Build.0 = Debug|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|x86.ActiveCfg = Debug|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Debug|x86.Build.0 = Debug|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|Any CPU.ActiveCfg = Release|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|Any CPU.Build.0 = Release|Any CPU + {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|x64.ActiveCfg = Release|Any CPU + {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|x64.Build.0 = Release|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|x86.ActiveCfg = Release|Any CPU {81B068F7-776C-429F-BB7B-5563F75F1A39}.Release|x86.Build.0 = Release|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|x64.ActiveCfg = Debug|Any CPU + {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|x64.Build.0 = Debug|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|x86.ActiveCfg = Debug|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Debug|x86.Build.0 = Debug|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|Any CPU.ActiveCfg = Release|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|Any CPU.Build.0 = Release|Any CPU + {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|x64.ActiveCfg = Release|Any CPU + {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|x64.Build.0 = Release|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|x86.ActiveCfg = Release|Any CPU {6AE42BFE-1833-4804-96EB-38D323B6C28E}.Release|x86.Build.0 = Release|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|x64.ActiveCfg = Debug|Any CPU + {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|x64.Build.0 = Debug|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|x86.ActiveCfg = Debug|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Debug|x86.Build.0 = Debug|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|Any CPU.Build.0 = Release|Any CPU + {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|x64.ActiveCfg = Release|Any CPU + {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|x64.Build.0 = Release|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|x86.ActiveCfg = Release|Any CPU {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF}.Release|x86.Build.0 = Release|Any CPU + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Debug|Any CPU.ActiveCfg = Debug|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Debug|x64.ActiveCfg = Debug|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Debug|x64.Build.0 = Debug|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Debug|x86.ActiveCfg = Debug|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Release|Any CPU.ActiveCfg = Release|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Release|x64.ActiveCfg = Release|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Release|x64.Build.0 = Release|x64 + {88E11D06-FCB4-4707-A48E-B8D66966A154}.Release|x86.ActiveCfg = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|Any CPU.ActiveCfg = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|Any CPU.Build.0 = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|x64.ActiveCfg = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|x64.Build.0 = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|x86.ActiveCfg = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Debug|x86.Build.0 = Debug|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|Any CPU.ActiveCfg = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|Any CPU.Build.0 = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|x64.ActiveCfg = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|x64.Build.0 = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|x86.ActiveCfg = Release|x64 + {CED79D48-621A-4076-81E8-11F77DE1E41B}.Release|x86.Build.0 = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|Any CPU.ActiveCfg = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|Any CPU.Build.0 = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|x64.ActiveCfg = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|x64.Build.0 = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|x86.ActiveCfg = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Debug|x86.Build.0 = Debug|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|Any CPU.ActiveCfg = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|Any CPU.Build.0 = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|x64.ActiveCfg = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|x64.Build.0 = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|x86.ActiveCfg = Release|x64 + {228AA300-11F5-49B1-A6B5-4986635C6D0B}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -67,6 +123,9 @@ Global {6046C772-BE17-4BC8-A362-AD8C77F9178E} = {8F0E1457-FB1E-47A4-9DA8-74A6B757CAA4} {6AE42BFE-1833-4804-96EB-38D323B6C28E} = {72E29C1E-8723-4885-A5ED-BD3A929D81B6} {D7CFB2D5-FAC2-42D5-ABA7-81CE762575EF} = {8F0E1457-FB1E-47A4-9DA8-74A6B757CAA4} + {88E11D06-FCB4-4707-A48E-B8D66966A154} = {8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45} + {CED79D48-621A-4076-81E8-11F77DE1E41B} = {8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45} + {228AA300-11F5-49B1-A6B5-4986635C6D0B} = {8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4B6EE1D0-5ADF-44A2-B6EE-E5C8E110EE47} diff --git a/Playstation/Daemon/Daemon.vcxproj b/Playstation/Daemon/Daemon.vcxproj new file mode 100644 index 0000000..cc15b61 --- /dev/null +++ b/Playstation/Daemon/Daemon.vcxproj @@ -0,0 +1,68 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {88e11d06-fcb4-4707-a48e-b8d66966a154} + Win32Proj + + + + Makefile + true + v141 + + + Makefile + false + v141 + + + + + + + + + + + + + + + eboot.bin + _DEBUG;$(NMakePreprocessorDefinitions) + call build.bat $(IntDir) "$(TargetName)" "$(SolutionDir)" + del /s /q /f $(IntDir)\*.o +del /s /q /f $(IntDir)\*.elf +del /s /q /f $(IntDir)\*.oelf +call build.bat $(IntDir) "$(TargetName)" "$(SolutionDir)" + del /s /q /f $(IntDir)\*.o +del /s /q /f $(IntDir)\*.elf +del /s /q /f $(IntDir)\*.oelf + $(SolutionDir) + $(OO_PS4_TOOLCHAIN)\include;$(NMakeIncludeSearchPath) + + + eboot.bin + NDEBUG;$(NMakePreprocessorDefinitions) + + + + + + + + + + + \ No newline at end of file diff --git a/Playstation/Daemon/Daemon.vcxproj.filters b/Playstation/Daemon/Daemon.vcxproj.filters new file mode 100644 index 0000000..4661e72 --- /dev/null +++ b/Playstation/Daemon/Daemon.vcxproj.filters @@ -0,0 +1,23 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + + \ No newline at end of file diff --git a/Playstation/Daemon/build.bat b/Playstation/Daemon/build.bat new file mode 100644 index 0000000..b40bd2a --- /dev/null +++ b/Playstation/Daemon/build.bat @@ -0,0 +1,31 @@ +SETLOCAL EnableDelayedExpansion + +Rem Libraries to link in +set libraries=-lc -lkernel + +Rem Read the script arguments into local vars +set intdir=%1 +set targetname=%~2 +set outputPath=%3 + +set outputElf=%intdir%%targetname%.elf +set outputOelf=%intdir%%targetname%.oelf + +Rem Compile object files for all the source files +for %%f in (*.cpp) do ( + clang++ -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -I"%OO_PS4_TOOLCHAIN%\\include" -emit-obj -o %intdir%\%%~nf.o %%~nf.cpp +) + +Rem Get a list of object files for linking +set obj_files= +for %%f in (%1\\*.o) do set obj_files=!obj_files! .\%%f + +Rem Link the input ELF +ld.lld -m elf_x86_64 -pie --script "%OO_PS4_TOOLCHAIN%\link.x" --eh-frame-hdr -o "%outputElf%" "-L%OO_PS4_TOOLCHAIN%\\lib" %libraries% --verbose "%OO_PS4_TOOLCHAIN%\lib\crt1.o" %obj_files% + +Rem Create the eboot +%OO_PS4_TOOLCHAIN%\bin\windows\create-eboot.exe -in "%outputElf%" --out "%outputOelf%" --paid 0x3800000000000011 + +Rem Cleanup +copy "eboot.bin" %outputPath%\eboot.bin +del "eboot.bin" diff --git a/Playstation/Daemon/main.cpp b/Playstation/Daemon/main.cpp new file mode 100644 index 0000000..ec1c64d --- /dev/null +++ b/Playstation/Daemon/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + // Your code here... + return 0; +} \ No newline at end of file diff --git a/Playstation/Kernel/.vscode/c_cpp_properties.json b/Playstation/Kernel/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..0491701 --- /dev/null +++ b/Playstation/Kernel/.vscode/c_cpp_properties.json @@ -0,0 +1,23 @@ +{ + "configurations": [ + { + "name": "PS4", + "includePath": [ + "C:\\Users\\grego\\source\\repos\\Orbis-Suite-2.0\\Misc/**", + "${workspaceFolder}/**", + "E:\\Modding\\PS4\\Projects\\2020\\FreeBSD\\include/**" + ], + "defines": [ + "_DEBUG", + "UNICODE", + "_UNICODE" + ], + "windowsSdkVersion": "10.0.17763.0", + "compilerPath": "/usr/bin/g++", + "cStandard": "c11", + "cppStandard": "c++17", + "intelliSenseMode": "gcc-x64" + } + ], + "version": 4 +} \ No newline at end of file diff --git a/Playstation/Kernel/.vscode/settings.json b/Playstation/Kernel/.vscode/settings.json new file mode 100644 index 0000000..e631540 --- /dev/null +++ b/Playstation/Kernel/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "files.associations": { + "cstring": "cpp", + "system_error": "cpp", + "xlocale": "cpp", + "typeinfo": "cpp", + "complex": "cpp", + "functional": "cpp", + "memory": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "xmemory0": "cpp", + "xtr1common": "cpp", + "xutility": "cpp", + "array": "cpp", + "cstdlib": "cpp" + } +} \ No newline at end of file diff --git a/Playstation/Kernel/Increment.bat b/Playstation/Kernel/Increment.bat new file mode 100644 index 0000000..3fd5742 --- /dev/null +++ b/Playstation/Kernel/Increment.bat @@ -0,0 +1 @@ +call "C:\Users\grego\source\repos\Orbis-Suite-2.0\Misc\Increment.bat" "C:\Users\grego\source\repos\Orbis-Suite-2.0\Playstation\Kernel\Kernel\source\Util\Settings.hpp" "KDRIVER_BUILD_VERSION" \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/Kernel.elf b/Playstation/Kernel/Kernel/Kernel.elf new file mode 100644 index 0000000000000000000000000000000000000000..f376dbf2ff5205727fcb50d455e241cd656b8fc8 GIT binary patch literal 31720 zcmeHwdwf*Ywf_ku8W5ZyMB)QI=tP4+$Y2H|IyFNQI3p7n2@$NdAxs7snaoV*0imLX zCQ**(H*KuFS9|-SS8VOIzn0bqK@@^WBHr5K8|7A_^>JcAqE^IencsKqea_68lVF_w z?(g%vfAmzc_g-s#*Is+=_c|x(?KSTCqjGWt{TVHMO<<)wPN~!wYnJH}f>0?`2zmJV zec^5OTt{~?%Wxlr&)N^UV(xmW(oGF#g7 zmMD!mu-77XOXCGBa+Zs_S)n+YJej0|-k^F(ey2`qdwWo7J5nGe9Idki!Pc$rJ5vxO zCGYI{g3wbr4%sOak(D|Q#R??(uzCrUQW_+&MBb;wOE})RQV@0>I9(8ur0E8(=@y9C zx}}8g#Emzh*3A0k&(*aP1wnmxf*|ZJgH7rY(%f-q--%`2`@WbU;9n(b%uCb=LhL*# zG5!cLkCUV%_e$~`$qBGB4BGA$L`#gHkxV9~Ubd|FR_5;W_#ns72#D(swTIm2PE5IOfgrdOg+E}5 z^P-UGU64OUJZrKfpOg~I@^=u%*+oBVZ2R5vGBj*KrLB8+3DK9VNx}?ga-!7sbV1vR z39<1V-SP8b=wj#_I31ark%3v4v8EikX|LP^;ys*Ls1wN^=Q8K@&U)uky(ZEmo@>q zMv(@<&+p3NxwwRhb`_nwW%Fx-C_LUgEl6OIY z3!`0*Sqr2+eYsNN>Q;5f7}D=}5o$31&{J#J49xp*9udA_&6nEt7T4I0x`8T^6v3^C zt4b{wwo`S2%R9fob>%+G_sF-kiASt%)+onmth3zmarInib1LoDZ4kf$@Sjc^-=De@ zxAe(XhlueY7<<$+tT~&j4ogaoguySOmmY^;62tkpTcLUro*cKFOfF@-JHT_Hvd+;M zz0__vCRyNuvNdR>E4fcnHg7>rk{6zV>}JaDdGkyZC!+Wu=bR@gt(}b12Ts++Xr`xD zv05=xEFD%FH#DDW#sk{b z2|)#Qk=8#hIU&*1Np}$_9!{ZNLTNcGr8>$bcdP)#g&rwz_I9j6o*v9$OZ%P3INNS7 z5-i`{h-|HV#MbTF^mG6+tMu_I-KQv<36OZW9ZiuEx$s|Kt}C%IH`ghT%OxAV2~w-H zRj{Ev&V``^UiG*VrR_cpILgj&Dy(ivxv?NgD~MBO<=AP?s}>Y({2_LGt4moAS1!g7 zexC-7>YPd=|CqV~^V!xta0y1qvn6bldYh3cD>N^*ZPcUBkiRxWgb@G`fymDDDF`}E0V(kb8BjYLvz$*)x|QLCn~)=6@YGx?IF zMDtyV-71MC&z6*`GMBtSRjMkH45BC@J)u;2T=MCtfozeK^H6tu3(YyqF^p`QXEXsZ z*(4>Lui%uBypRk%tX=`T;lX0KYxAYdU5|n?P@r56%B9?=_k%K=1K|(jGn_wZ{$WSZ zefdMQ48DxH(bS^qyVmBqjqYt6o|N@6Q}Y%?IajH4~two2eli@}a3(9>l6R zc%$>1sjZ%MOR7J#(-BUfd;UtJ45J|t71ckSjmAPeC0M)h52w`v>e>C+zVbQv zB`)!DiV0Q$>0oTfQ^c05iqyB!Gca=(rk{$&|_spEL;8WPeEyKv#h*blU0!dixr68F$ft{$U>Kt9Zk`gf5T#jho>l0T&H z>Qn2RouTh%Tpxy9y*QjQs5JC1jg+}$0Ch3^;c%np$ZeSW7Ig3)Vq)IPy|~pR9Mx$q zM$P#988?armb2$(vfDWut>^3+nQR|tV^1fxa^rGZh#`DfJw&4)>HRQvm_ADTfBbb7 zB$4-ZB#)yHV5=?jEDahKvSjQ+1L%AXnn}s2>wkjF zKS#-M`bjk(8k>&viL|Evt-U*T&At=Us;wUUbX!;8=Td7JKYwg(MGKJGYVG8iUt72E z%p>f03Dy(VZcwBIogr~v#bUP9S|;HxRY8}kN;h(nl&D9K{n&bdBzNFoB9!5uTYiO( zp5Wx&PSyg5&U_2Lm*jC)S{cTFk2S_|A>AM3H*DQB4zznS6tE}Vp0*>EQ1yd3kX7(s zB{qcCmK#vQaJp7fZYq#^*>Qqk65pEXRGx@YwTDrA5o{H!VNwZMU6wr1(JkkdLtpHi zPY+7>X;n+T-RzFT4UzZ}C2f|`9ufBBl0CQ~rA+D?4?^#E=wLIfC9m>&pRl9eF{qc< zW3GmS@zY%24}i<4uOxS9ee62I8?IGX`xUF>^B4E&)bdg*_f#u21-R(`j?JO#`JGvdG zyp>vCPe6SmLfO)ePI`PwIrWgd`O>o|3q7sUa~9$Bp4RIrS=HOR`j;07ot?;h=NDS$ zo`9|M+^I_x$Cs zr>#PWEr3G;ta)nf7s;erca%0fM-wN_C6b-(fsSu-(xpTaxfHFu*fl1Bl-@Oj)T7mR z0zS61-vhFwEUuI~_FLNTV1)$|&6itg*}q&;uESJ5Te&V*zCK^ME?>TWoO0bH`Fh;X z?xr}tGFQHB($jz0kXu=_2%S8?2w@q{!LB-yTBFRN|Kx9#Nxe>tLqvd_lUPFQCAzHe z6NH;2Wvrx3kYtZ2DPs_w!lFDR9zpiPFUkVg+8z5EjE0^2V|KQ*D6=IwT&6_w<#4VN z87JfL8Yz&&la$CLtN~=HTt;TjV`e&s(?7WTJA%-y9vC1`cNXmYQI3?@*4I7;$>vHr zb<2fw$<##WwxSuMB-vihO4~f>cS#<9HkIVUOSwpRD-rF}G?8l-;*MQ7k@G4)glgGd z$a$T81%$J3-j=thWFNzM;rmHT;b_hia%U6o?=~`Gn=mGic%QOTXJ6UtvmF#;o z+&39-C+AfzBQ5qvIWK(f`Gor|=Ng1WJp^D0WIRJfY+gv#+` zOC#rX{;7=WyOHzC`k2q^IZu3*@fK^ma)xtp-hn#ud|?&mZ9Dfe(&^B6N6#VN6`Us= zp_1Lkd9BA7Z#w54U?qDo=WY3f@h;@NEmO`V+&P@rEl{a&BIlLiDgfSi4aZ7_r*mFG z5yRzhUS|cveU3dD!@Iko5Fa1;k@wIErk0s=Xq|T zQX#xUI{V%!A>Q+xH^@qb|H*lkPqDeOkMj=fV`H8|-(*WK8qQ@~rThjv zoT;CELhIS#o@(nXoJ6Xv60OB*6`e~cfxv#e4xTSpp%C5F2E9t;uX`g`- zotc&+vQmvx)Kc|7K1(KDN(b>Jr3mL}OZ!r+^=>(U<6mOtEjYZ@*xsgKX2rnxP9Ar# zw67vPER=DppspWBg^gB3Eqc_OQNWdv1vXwKgZ9%_!9?SN>LyXV>PXnHN2{F4SMXK< zfp~9Om*~zHTscptBri%yUNwT`2?UP0POC0y>8QgF%k-9YGQIut_?CMyE^_SkLlwKx z;Z&+Vh%1A07o7_EE!!9(fctA92&wNtYTzJirg{fzq%dnGS_z4ICV>EiwCO22#HiOp zcHb8T)z;+{l4)V?Xt#>!*L`11Yqtv2!HDb;frW4PeNn=xct4bDReMjs6eU{HA7G83 zjzDD<6liVlB21!i3tgKN_RlV&#Bnn-fXNRd#?J5RZJh8+CUg=K&7AOL zitr5(a4~FzU1<4I33it`d*)9PT)p$Z4MPOy=J|yK>{@x%IEq>y!>bxN zP=3wXg^?wwZ^Ogw-ER4FOM3$>b1O~Oid}+`&+qZ(Hl^C*maSIxK{ATkbSH1qc38(7 zwCf{kP~P6DASkyMICqdnsHNcN2|DXixUY=XE-nIucNc z<_Dp#btC3s9Ko(?YZ>OtP6V>um|(LIPx%Q&!V=4IirGj*1#g)?+QC{kA7i^62L6DW zCcmeJSLy|(D|UcdTgJy%VyTs1xzH&zjM{p>t>$a!iM)9sZp&LAqHPHCayKFNPf_=o ztbgngD-4-#KZZ~rsw2iEFourMEod(rp{>Z!2qi*#gc6mH&|*Z8sBdvMbSy^wQeu8m za$t1b4o96v1k1b=a8NCbswTPqpVNUBV+jE<(Cwfbs+VL$&EXkVcQ-OrHxbfx6BWaR zSN{tvf&DJ7@w=q)ICQ=_I7H_bU1zJNlL%>@MD5>6O-wkZOxD!=8`NNCU2`$W)9p_n zUL+|?trZkgI6Tzq6?zSoS`9=<*Fe<%8u$e@4DzPW<@yg_#PolI^wSHox71BTwTrrT zLDNozw05GVeDZzFHZXH}Kyjd|`E%H}~)go@C@o45t9Qyh*DiX=?y|LAW_#Zld@ zcMYfFW!{K$xr%#fF{1UKM%LqCnY)&a8!UX?4ASJ>Y8DRV037R4>pH$H&vhOKc0DN##KLv6GkT)@02AzqF9(z&eA$@aaD z7cA|SBcRGZBx)tre@pa+2{3oWF`asrP%eO0&Q) ze?-l+Bsj0EDT!Z#)h1u%FKU(&ly;3nd^}tRo42vIcpj3fRW4O8%_H~FCTW{Uo8(Kh zN!BWHeUt1VL6>r&dJ>xr7n}^iWNw5w3tAYVs@ zFZ*}mYC2#$j`rrzU|Jr(ik5XW!G$KE&oTL$NaReAUIPl{r6})&!sL**dF)U^OBWW% zKVbY|&3y4fs7W}so<-1FdM)q)CPeKtYzm*LW9eQDPgbxE4co*pi$AMLlCgFEnxv_( zpQP?hI2OS|1RwbFzxxOq+BY#8ZC}3u0jk}J@$+CwtsEcc?5UZ=#&RXwklyFpk#loR zq2xtxR!{49$u(!IHRvH)z;9-Q27B|D?oG@*+IQ9Qx_QgFc{ei$(o5uv$u`(h=~C)* z4I7h7K1drA#jLS4A+C?@C-0|N&)qqH%iO5g##9Z3(DpJe!q|pOA?HdoOmZihXhWJg z4(mdCGkS|}Mmw~&9L0#mYNBmMXY;-2c_t2DNZ5&1u;3r|pbOM?fY_l#N=!LzDt88Z zcb0J6$W2&6cX3)2m}}_m%ob|m^eNw>PM2{G`3R#+Rj3QTVO`Px;@?^4lp?^;zmw+| zBag=9LsS1Fob)V_Xtn?NeY9|Tu@%bL`ph)G+kY<_fo?y*k$>buNf^j$#4f6ygBtsN zT-^;cT1nkjNV0`8Z89xpM_E9@ZWW<*x_vv>1IEB?RC28jUd_P9ranrz=~M1VRZLCY zLhX1DyB2KJpW)WG0-XF^@?Y`cf!dsdifK4+1^`t~V{?+m%g6nwq3xCeA+`bZi}|d3 zgAsSKvwkcF`WcK)2mM@i4>6TC<3V4BRt$@KVW#E6Ro6&9TphKb)Aj(dxh@l#f*(c@uvS!~_y`(qbL^51AdPOZnS zpUtv7c5RMiseVdIKGnWI{sG)6B`S%6&!^IXDox|C{lS85QewZRU2 z6ovuhRxmS1f&4C(SGq+d@_qyXv<;Jz`7L%G&3{bEi6UMPr|pB}R8VMiChn)ZgIg)V zI}|>eCHX05@?|(50XF9R=WU1FO1X95G<-U7uI&)OS2J_$LDY-d9)%idId{5 z+2sXKw<{y6tJ`DzzRSb>eGm}0vRxQWR{g;xzl`_v*!Z!1#K*hwu9)p3w9D2~DD+{L z!Cp<78oDU`2Qp~fJr_`dH~EhjfPhU5+jcH3m3bS$p<8Z#jrteteXoMUws5>DP#3;~RR`mgws<<{ez1eS3$(pJ&argx1*muqaT8N= z#!zCP4m@5hP=YtH-B@nv)iXcmOd+29COdSbsb?}OKKJ{K-c3Ljb4G-USE%#l-fFyk zn9$MfwEW=dfpg*M^B~SV{b#mRp#kdFx9RrZH)N?9&OdZ*$NJ3Nkasy%ov=?s((wX? zY!Z(5pjEQe3`(2!(u`&;P^(aZddbU(wa|dbJD*whmXvT?^RePd+G}sRbV0e zXbO&0q>tX8sVDzJOZYfzO*?ug0Wk?3k|=x%0s!oQU4nWUx|oh8?E4lh7U1tS^2ciY zj|k5B-A4ZV*cl0bD9wM;$bT06hjSp&QI3v;c@Kiyet!lsHPjlM?g^ zO`@<16OauUa>!veT3GWQ03FR^FP7BvsfBo@O&4=IGyE6ahEwf1*rh%^pLF4!ADU`= z!I`WV(92F3;3NZnO6DdUyP>TA`#fKcJe;=wEgFH2^B^^F3o<)F9*7|GC(8KApRn|2 zDCm}+iTrSuer_>X8X>g?OJ{RS&l+OlR8&Qa51;=)4VluK30E3SP*BxyCbSq$IQC|y z3BQH&;H;r0jDrc+L3@7-o$+~tRnnw&&6HErHr80%CR1(BFRShEK=zMCZ4c-4k3)hU zVUKw}QM|Jo91NKW2pc%%<20@KOG8Yn7omnGGrNhh!$MSK1jOkv9m%s10N1 zrLm|&5#r-^AtNLYu#m>CE+|PJ0Q<+ZVI=G|_y~%9d#+xBqZ@^N%KNXyYBP1}RIyH~ zUs}C**`i@GU<)KN?}i$Y@{%tQ2#KpAp=NQRFB0?x#xAUm_}BR&VsTVlSKL&}{u35Q zR{EoLaevGwH2K!~y*{ytOL-%{#+a{3jK;lQUo^TZ9tdohDtJTjK$92@#YD~*Ge9#k zi(+E{N}4u^z7~Hp7A+kCEtV8FO)C`^L_+cKT(Q_IRy8*v^$Ry@mfs{ULdCA;aKPW} z3&OZkac+rF-56^W!y!Ki5z!x9*BJ0Om6nzY8pst~6&j8`ztJB+^I{><8wzg_L-Cl{ z1Wl#FSuZA&R>MEv3&|w?BO0ZiC5x*X>O4!93paWqA@A@;xni)UG3F1h7D)&W^hKu% zO`)J~s*tXEl|R^|^TqZ4*cvgm#wUjTO=$I4p*mCtns<$$X`njiiZ0$lv8pi;Sh^wX z6VZ=`Uer2USiEFjT^Sym5Zw@s`I;M|@o3l=Y-$LvX^i?()QB${Z}#cLFgLZq*W&Xw zKv+l<{4t@<>#JLXQC05}>X=T^9~JAkS~Qe=o~AD$#Ts>SP;Wu3F%m{M9%?8evZ;Yz`$$)#ggoc`OF&9y~gGoA9@m87eM!zd@(=b^JQAa zJz~~b72IT*?&w%BCA;Q>KP5ollvf|JaPm)R8uL_&N2Z(zGcDVr=f2 z?@e~nTIMK8NpSZ3$8gBIZN`-aJ4b6?=2HIm8CA}Z=<7LCC z1sa>0uv0~$ISkGESZ)$^I(AIGIxeEA@&~ac#LN|?kIJikv9x_@a+8l1O@2gQ*DS(n z?F6h>qV4y_b2F*Zj{(h%nEZT=N&5ktD#>Ujr|JA`o35OcG(^^87u70V6^-FEDbS%| zRa967-^JDlT$@lAYWBs}(DDoytdE3(t7pJm5l8K~k4OX(8&}Z*9M$7M8H|k;w9&r4 zF)A*qce`mJFOK3^Rv(;Mi)D6vc{zz23MZ`e@hgIAoa1@^*t_ekB{AXi0 zEZ%C|>J+xnM5rW7!#HZ&j+K_z|os2 zY6cC@WD_ucwvz~>7KsWLm;(3z8Og2eFf*~6~~srIKC&R8r` z=Zi(@6cxpR@Dw609BET5bB6n$ZUrJcsYFr&&Fm=N0PT?&;sTD_DXNU$##46np*z&K z@M8xFBdYN}SP14(-tjK->JP!B@a#3Z#4`qo7fE8hCNV{q_=Q1&ev?kECy7MiZO9|+ zKqMH^N}Tze6X2Z3IcF7d_=j(W&vVWW&T$jxERK1dbGkTZHgQhyHXP!dJ)BcSoHxKx zx8g^e;~3(h!fj`^IyO-zmZu^TEcE0>P|Dejte`%DANURL!Y8?&U0hEW1k`^8tIcsg zD8l;D_>B;F=~finN--IYH~%aU3hHW3wR0*yqyHvy+(AlV6Y_9G6-ylDNTA?7=!XI* zt+nm1Ma&hikZmtWw&T!t5TP!J)Nm2}J%Z`TL9&Z}Y1<_~YsuT&wK$#qEj*-AAArF; zOOd=fe2sz6v2RtSL|omyi5mMlMHt(jF2Y|&p!rE||Hq#H-Z@kk3x)Y+|Nm_g)dx>C zjY46XMXyo!rDxH1;W>Q<&@YDSv*>N))fzA}W>Jqpg2uRdu_lq4MOzILPmu)sb)-b$ zM&vPghy){OPO0qGK%($w&e3KB4Knp0`Vu4gKn90md@7j-4r@fhzMTXVM;UQwnt-Ft zFaA5Qj7xG|PToVF!oyw?A)P_dT0F~5^gqn!^iNJELo9bKFX!<@IN{X}` zKCMjgU3$m{dJy7e4`RdY!S@6i4}DxpkErR_?JDDB0dMr!qvP>?8n;Jl0zN)wWqNh> z|Kid8qx<7je>cjDz{qM5LFT9*M}1paDgHOJJiZdgy|_&jgwp7mXe<(ITq%^sd@V8l zv$UaZO+3~VS|8NQbh6d+Ute^E7RjxeU9)Z|^@_zoSI8R+)OgCh2u3%1ynfFdzON4z zuFg;~haVKal7@0RT77j%n|*;VMi7cjx)J@Z@py-t#gt}Za5_;168pSuRDT`%|1ZV)?P6m;Q?*v%-gWY%$}3M_PDCkew;l!HI+0x zk5g*iSyyLkxY=OY6(oI1!L&gYLu0{4jVZwjcA2gANAw}$@uJ4GdA2!BfCbv>VRs~| zsj;sMBGhZJtQ@bG_}d(Y;9}rMLhOEA%HF4ig;Km&h;G0Dr!*E3N>>NtrFez329mx& zBas=evDpv*t`1>M$B)u*0GXB1XsO{X94F{22pe}nua8sdO+y0w~+U$Zy7A(fB%G?j>%c$?uFQVEv?e42XXQ}W0MjRhkhXe=I z;RQ^Zx6W9IM!k(e9TbZ+#WlMyVd+H)*M`+04QES51An)cVq@y!9j(?rF0q#Hp$&*6 zaj|e?T#f)+wwz+CgCEuL?A-j;4jQMj5CL(Uyj2+9FouQXGX7 zf-h2q_gsE&V*pVqTI@9r#@nzA-#R#lzsQNeud8u*@?qVf?#y5{`M!in;opV;pd9G; zdK-f4qK0nLDeLJS92Y{|XNhlh?dk{)S#`A3v1zFj5eFJdgrqB|)sccjawrj!^YnGd zD48NQH?H-e7uGdsGg#{oB5_OBV%=#l&T1;BMNl4PdhWD zht^NmPGkEEw2Ppgj?piWnjUlgVG~}|E{=M7&ItA2VZv8xcs<4MAY?q|`hRc2uh8&% zO26`Be9ZX&GU3D8MORO^j(|TMd=k;ekEmU=^|Z`%AvV`P+l2Rw=ho_}bAp7!u!>ZiH>6DItihS$@P#(&}H%>HZD0&{xWl&YC$ z%=Oz$_(2V?r`{3pi%s|y+JdX6kB)$kn(!ipf$`|+_job&(`^4;Cj2%HucwVEB+r=f z518=ujV?WU`YT>c{WRlWFyRkqcs;!#h2$ACp8nXrasHKQ8=js%VLC9F@#mZHgZLc{ zdh~R%9+>6iA?F9X316TMcs+f2g!&ho@PpHMMS6NUHO}yu?O$ucmrduwdOFX5rK}m> zYQnc_cs+e}1pLoT_!ToaKu?ts@H&-CZ=bG?g4X>y4tJ22DjQ_d`-#Lp*>#2nKVSLQ^HWR*YHka1Zzm8Bp{kc*S z(W}w_|19+MeQiC}ZGgKoo`*C%mSOhna%HCYU6YK*WRCDK@N{I;@%sA{J=OhB%_6M+ zUPPzw1fFcy@%sB1JvG;7F7E{%e}f^U;|1;gi=OKC+fWBRdi}g42+sjeKGE^|`x`wi z(*(_U-TqgBr?ac>fBn6Rp0Y-RuXSsxetjJD0Z(m8;TQ4>_4ix49H*x3*W2-q3BN+a z>#1(%sqh~FPrCH_TQt0$>h+lMdO2yrw`Peig!7E`Z#Lo0#8;Z|m099zO?W9w{0%0&CriA~ zgkPQ|K4QYJ$P$0M3BM*w{M{yeI7|G`P5729@m(f-YnJ%ECj90s@h_S1omt}FHR12e z5}$*~Yn;DZvc#Wf!atZLex?b(Eld1d6TT};yvu~|&Jurv3I9x%_<#w2AWQrP6aHY9 z_&ZJbzAW+IH{sPR@jo@;2eZU)H{nlYiQjL+3$@wp|A$TZ{4DXGn(zf#;tTM;0xDAX zpQ0@BmzeNkmiQ}8_>wH~*P8HUS>kUp;VZJl(|aDH|0=V@x0~=%miX_R@SZI3_nYv` zv&3&V;a6mdf6jzolO_JYO!#n?_@gF#OP2W4@u94-|68-fizfW$Eb&*F@SR!Wmz(hS zWr@eHNoBNuOP2UMO!x=0#Q)HQ-lhH@CUNQk2)i> z{|;t}pKQYSWr@Gkgjch~SD5gFS>h!V{zR7eWhT6^D7*cCwF#e}CBDUkFUS(V*@Q33 z5`UiwFJ_7Vr3qh>C4RdJUzR1l7kG+4>v3-0d+GQS{vcV#qsQNksUABv3f{YrmkvO` K@zHTQ?f(GU temp.txt + echo user anonymous anonymous>> temp.txt + echo put \"$(shell pwd)/$(shell basename "$(CURDIR)").elf\" \"/data/Orbis Suite/$(shell basename "$(CURDIR)").$(VERSION).ELF\">> temp.txt + echo bye>> temp.txt + + ftp -n < temp.txt \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/Resources/LoaderShellCode.bin b/Playstation/Kernel/Kernel/Resources/LoaderShellCode.bin new file mode 100644 index 0000000000000000000000000000000000000000..d80f93f4bb9edec72994182188197f2d33cfab2d GIT binary patch literal 928 zcmd6kK}Zx)7{{N#3nF{9tOHJTfDg$8}4Ja?zv<2l4D0Z z(%KOuW}tb{u1gqVR+Gm>Tq5g4UTE@w$Uc!ZBDN;YL=K6Ri9FQgh~Dsp$TpFrCSO6q zw+Kb+@Bb)bGk0dKIW3eCHlw_2NMsFLkSyFlsA1ks>QkXUWf;OmprW;m3M(|4Rk*Ba zB({G~58WAk!tQS4t=3Dbwo}y(jOS3aAU~0V#v;1vht-Ay4Su0N8lY*)+)J5NZtijO zfSdo&?elTn(oGg#GVVjcS?<5ZSWoFglTj=8UdVUY&{=f_1Cvbi(hr9h|0H>7I^@B4 SxHYFAdl+Gs;!g6}K&7UiYp=oJ?fRWQK0@#U#W=t9Mn#So$5 z5u~D5v?L6TPO}A$klz zGD{#bw;*~BKxD)~GF?EK7vdno8%P{uz4!P3f5!blCc}#=AaS_C_AF3@p+pyG@NtOt z6A&EEQlLv9%utWcr@ literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/LoaderShellCode.o b/Playstation/Kernel/Kernel/build/LoaderShellCode.o new file mode 100644 index 0000000000000000000000000000000000000000..5a0ec9caabf79a21933fc311518c9de902595eb8 GIT binary patch literal 1600 zcmc&zO=uHA6rMB<)QdlbKtP0g@T3+Z7Eh}wA!UjQEeU~uXxL;&6S_^x?u0Z#{|pKt zC9u9P10H|RSqoMGPfdxJP|3PXtHOI6ZQ^)lMZIRe%vdB_SN-yb1 z>1lSpQxw-##ukX3hx4)$%jr2idv!O< zbS}&7YA2Y{Qdxa0HXBWhi3yly8|FK6B%!;;39U*izfF@?&(LaP8(xR;9=3I1rZw+p zkQ#`kkARI^Akyniey;0y*5`O797W4!^fJ$3kg^ao%bTV{Y&KV xlK)!UR>MV05vlNvSh>%N`ye`>Eu_RS8m?imcjxmDfikGRZPg#OD-k&B{{W@BqDBA! literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/OrbisLib/KDriver.o b/Playstation/Kernel/Kernel/build/OrbisLib/KDriver.o new file mode 100644 index 0000000000000000000000000000000000000000..4ae009b6b84bb34abbfe1fde2019a88ac8e42355 GIT binary patch literal 4624 zcmbtWU1%It6uxPyO>2K*YW%G_t%)YsPIuC@Nfqm^*)+3cOqRs{nEouA*=e(8v$O2Z z#zqUKh9E;+C_edE5%H;7P(4eMc=EsQU_`(3kkPTlrSA57eu6Pf(e?(1Q5DND=&oiW}9bZ|bKO z@3+=X&*nF&g%?nNeibpw>~)k?d*R5OebEQRctQt4`v);7b!wsBzDZgU`%1S`RAyEC z=h7Od{#xH320N0v*t5`ohYqgPC$i75D&2J&d z8*S*qgP21txDVTlYQeaED0DOwJ2D3-*RSmH#UhjivV%D!nqOoL<#KLcKW+&ih?KzIGo*7SB?W+*n;-MpR%1`q*9rup^NE_s2Je`mNCz?~KgQ7P)5ZT{75R3Hf?HA#=6_+w*GHpSe$@F+Ul}yO8EV?Se znVAWgk*pEO2eda!&51Q4nl&+%!RWxjme%K_<{bR@8ku>^W7QjW3KB^lGyR;O z{xRWvT{aT_IpGh}xR&tmNS0`_~J#!*MVwyb}eINXN@ zu^jJn@Kt4f-p8k^;GY8Sm#pzVkkXL_K z33l``XV!Pxw2yv-^ida21?wMl;g7j+{=H#5cv@Khb<+37Gf6n=<0)l*+l8YI<9xon z>$vxElS}_mTE`oIs|$C>A0*rxf5e5m;~a3|?l@m1+#4sxhJ^88Y@FBg2m+yB%!TnV zfPX<`uJPmbuv}--*(~nyJ7tT;TWg8J|7W|>*Jll`kxT)&9_m+hT2C{ z=JBZh2DI#)l{F_~(1nGZHBxceGEP`>Y^bk;+E%!&yV_J2PPtW;rE(X_&VtamGZWC+ zgp6(3NCTtE;2GMo(;H6j+dLWVbkA@}s{+m^H9`lygosqwK` zJduFzc)aAr9k#Nw$FQ(pW5d?q_0Sz{*J1IosGf}OvPSS-Q6*!g9ZX$K`|d3}`qL3p zw^Da+p(w65g|C@+Ka}?VG}~D5EaWvFZO=fW0t;%zhhdx;!!b70shRNvzE+~W`d}bN zMVEIo)5%N+GrO4C$xJ&lJD6!>Mp4Qfl+tuwEf9kuSMUHG!v8T`g+5p5T9t)9pcb0O zgYP0xUqWe+5W~CPO+mNd;_>(5rcMz4&7SW+w!z=5n|6TUT@&Yn)N*H00NMy2=7~K6 ziQhF5aPH^-a!E~a-zRZduMLB-pMQ2#hl>NDf9wxl|JZ~5{7;e{_g_$R$eTar;pe{& zFESv`6a8aJy#CLEA3y(R$UokBZu0uyP{sZn+4K90*YMh}0X@I?C5rzv8Dji+B)##! zS;fCZ=a%1v)%=fF@qdo|-*EZI{^Irj17Mh{_xxWY|NNe$WtN?veV~W-ZLC1!?_@uO zlP+SB$CEIJe88oHY=nv`d2qJl@e7z|-mRMS+Y}$&i-6T?MH7Ze_{wyK?hjrY_YaBX ak|e}604P<4oH0ZGFViI2;d{(m|9=3&yOsC= literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/OrbisLib/OrbisLib.o b/Playstation/Kernel/Kernel/build/OrbisLib/OrbisLib.o new file mode 100644 index 0000000000000000000000000000000000000000..717bdf41050d9461ee986dc1851e012feae51a6b GIT binary patch literal 3080 zcmbuB&uw1u}wWaq@;&VQ(IG%=-b}*I4Oon8l*SdP>%lW-~VDd>t21@=eGX(d4=f{%($(4 zZtIR1Uip-@@<0%CmxnNQq5s`cqMv4k)#}6YYF=dwY;_55q8}sNoT(ox9J>Njyj|zs3V{m){7xqoQlwlNFZxIOCr4 zGrs~W5%JyY)q%Uc~>qL(tdU34_Jluv)6bkbuxBny3nWujo1nMV>>>SIMxtq z;?i*3jvskH#PHh8ZGamp8b3Epn}}AxEN=fM*qhDtd@ahxirhKGNYx9 zqS{WrL#U{HqgbRJ8g1I5K1~aUJ4LtA9@|MA=XKF{{#cO|&nq^#)0j1j!fMS4i?*AH z-eEGRJ@4nzVuX9_n<*}XDE?&^Ug^SvF8mwjgW9@Hu@1SxEh_IV=27;)2;N@J4_Jph zm@=U2RWrxN%} zPNvC5m5U3M8&6M;oJr><$HubGRBr0bNZQFEz%lvmrxH$+YWYUpqjE6kd->U%w^#}~ za-@dYhJB8fYksxJ9+|Obrs-tkxy(c{dn8vXb($ljUgN0rS2;&RgV}jeX8TzL=LKO2 z&vE#E<97UeEtLIYHsr8T+?E_~C{DlPIA;*>UECDU0FK{3DVLzuvfwvftJ(~~m zWEbjnvi&L)Ti=py#|GgNHlH)!o6p;b^uOF9bKuzgM?7(|y5th4#x7PD7Q6~SPo)}o zHec~W^&np?Oa1Fg!{#$t^Za0mSLf9QYm9Hh79&*B(3J{XT@J7UW`2K?x{)?E{oms` z-0Cmu{}KBl<}f#1l2S4ADP8p*+hJ@ze@6PN`&+6T?z*pd0%thMO_z-L%Rsa!VL$gk z>I)WrpNPI=hWuvz-!p^YozX?rt@7?#^6~nx%Z}CJ_{r4m4N9|_)zcY)< zACm>H-|w;jGyiX0@+akn#HAnB5BHFn{|PgsQg%EPa#rU5PyyLXEPQ~Tb5l&3h^`R@ zBW&>(822ykRb3XPe@urwR`n|kGt(DyH>LlNauVx?ru^0U*~-j(cNkFyo67Pc?ACu} T*mWIuew2SruKzB>!BFWRe6Ng3 literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/UnLoaderShellCode.o b/Playstation/Kernel/Kernel/build/UnLoaderShellCode.o new file mode 100644 index 0000000000000000000000000000000000000000..3a5e50bd2d639321b2fb045549c672d9a8207cf7 GIT binary patch literal 1440 zcmbVM&1(}u6rZ#Ws2A%&4Tw+?ZyMY~v6pB{iA-%mOO}A3vTm{iiQR6(&J>$ss}dAr zh*$rCdKA4iUfN)!T0v0ppgo8Og*|w&hu(C3voo8IC2DaF^FDsR-+OOfK5izG=LbR| zRgDl3*UmRZz|RMD6>2}fpF-X^*+0T(0fNjktdW41~dWqNLw78d_R znY0S5tqwZVcD6uA)S2|fk&Kmu_QY;e=DbNX3Zo%hi+%d#y0~@**Vewk(wqlyJ>y(l zKj;9oCj8h}@SOyJ_)e3Z^BEgmjCY)ITr!UOjFm3NbI#zOEY!XMKCX}Q6b!MAInH zaFMeJSL;^n4P+2I1%+P<`70q`g}f)K#2!NiE$>U#PVg6wyC0NhE2V6vlqOa-vGN`( zJMgZ%AOOlkFhIf8@Dg~yY@`PenykLwA8s|KJMI(Mjm$oRNraoh)o&`Ue2?Jjl7s8> z&iZXW>Xr+etGtL@y3&I1A7`-7F9>>}Vf4e@hW_0r>g74wdoDvb40VEhq-6`1ZkM$* zp~ZPSN2un1=hQqg&55ExI7Rcm%)2Ht-DbNkO)LYUC@s%1JqwoE!sdO?(3#%*n*WcE zfRt}%Fi;{c{Zc*uEsWE_!pFW6vj4n390dy?myVE+RE^wW>Y M|I=f>P}-pWH>Oy2#sB~S literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/ASM.o b/Playstation/Kernel/Kernel/build/Util/ASM.o new file mode 100644 index 0000000000000000000000000000000000000000..b30fb276156730806d8b3a1f6a6f94d79f5351fe GIT binary patch literal 560 zcmb<-^>JfjWMqH=Mg}_u1P><4z+iwR=l~XWU|<2NO!eqyQ3df2cmCuz@;LZN!GrU{ zVSa@J9=r@dX?~>xV2D00R>P7n&SDR9qQNTn;KOh9<596-N_h zV9+Z`ttep#N=;13EiPh6E+~yp$t+Gx%1MncF935>^WePFqLPdvph^b4;*z40#3UeH znG2#R2WCJcn6Vi10xIT)CWjR4U>Oh}gxS#4IY9XaXyPnrd^;eY2~7;dEr5zuKxvpg K98kUllm-9~)-hNB literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Heap.o b/Playstation/Kernel/Kernel/build/Util/Heap.o new file mode 100644 index 0000000000000000000000000000000000000000..d123dfee3083604ea5775358d0e4b304681dead9 GIT binary patch literal 3048 zcmbtW%}-N75FdE>ttp}c#;6!ILX>B#5F!WDh)55j9Kci$;-h_N>}T3ng@Yd#6N!oO z?!|w=#FH_eNK8C?^*`{4@n%fw%)Z&~cDs*OoaDWo`R&a9=FOB@o=soB*4@MWo zgs@1o2j9K;Y{O^f#sXk%)(La)*-WVRJ@B(`^Kq=5p);xSt>Q$mImloW2ec+@4i4

z#h#~sssC!p=l1pG)t)t^eIEr95|p^N_AkrGFYPw`?T-vXPj2*k10nH zu;Hf=@6+mYm;=v8_>T#HRkxGuKPhlkH|cRj;HqxYKP7NgH_3Zb;HqvChm`M?-AuU* zi+3h+1uvg3WePC6I6pl*2cd~O&E`)D{(DKO2=7o{jfUTOVuj46+iE}gt~f@n&3utq&g5%Bk*=hV4jHkb~ zt;Q#qKPrDYSI|v}IYZ7NN>eu}cGYW`M{%5?gSZkT=fWW4GzV<;yT|*Dzkjw({wc(5 z{Amk6eWS^L7cm?EbHqvHyb7(>8G0KxZ2T`R{KReYKSa#N|A7gmKbtKx{7FRoItR4N ze+B()`G2zHPg7jxBm4InF4&P25#~QD0bUsvF$8_YM`G+EmU$a!@%@Sz-C=Ye>5}I7Ass|r x<}YD#Gh=CQh2zt_c?dDv_wPd7oIMo(jlo-FXkvaA-F>$B6xaW|7E7ub{}-%aEYko0 literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Kernel.o b/Playstation/Kernel/Kernel/build/Util/Kernel.o new file mode 100644 index 0000000000000000000000000000000000000000..de49019baf24088738f47ce71c2852695148a949 GIT binary patch literal 3992 zcmbtXU2GIp6h37@D-gO=lp6omWQav!vIT5K(d_p3VkdSZZ9=GIyKDzqx7}TLXOSAC zEp1J1wwpAD2OfNAqHp@p2cn5Fu?9_pK1d`{-o*IVm_|`dK!VnDX71hIozD26r@6i7 ze&^itoqO)jw6ArTo$G39KuQff4XY!G0-U{LRgXGq6dGVVT&sKF<{`$fvB~8SD{UYP ze?_ll{2Nw^*0R$0;q?G)@%6KsGYMGP)@xTTPA_oBw^&!2BomwbB-DSt?mkUr)KE{7I#3sML%J}EV6P7#&bjH7MXgCICyjKq~{v&cWZY0hL$*ItV1YPOqjSEN@ z1%}%7%NMHnVtujRJ|tYmn16kA8eoB6it#^|C?{5)jsCr|!uVY@vdq%19i$vwoR(~C z!`1iqLX2N-=ih!nrDXgUlmALd6z_?Z96wxcZU52O^Rc6t#5e^Y1lR3i1PGz}VkQk@ z%`twXoww6suZ#LNBE{PJVz>rpO*CJr-z9aQsD58l7`J>>xup}MGKzLQh&74|b{G8qxMl(O7N3cK0Z!$ikKaQ%& zr}U`P&*%($n|*p?=ae2t6_pu%z*WxZIahg8A9t0v^;uVWSD$m0bNalie5fy=!pa>X zvplGW8J07|%2Rq6(M2q6Es(WWuf@UU2o6mC6*)DS{HGOX*G)WR<)_dBO$!1kS$LkH ztF7&caAV)GV#Y3p_ZxeS$nK_=qBCrIbx*{I?Az(W0C+2?3_!P_>)Ae7ho_7%ybJ#- zHE3NAzpeN=X}&j?Vq$b3(E`{sC%d&1G`MXoh=>MMv$di@_1Taf8f=zoRji>p3lO3wyu#qXGD206vR&y|OO{a7^+Rwt8h>1_(rX4_m!b|62|U z@GNp*2~soUo~pY{6QcO)&?Hxjjn2#F2gJk?e_h>SZ`t$mNGK_Hjsy-YtYY znRLVGwA@;88V6@QiY zih@%PlJ{o?r#mR|-xd6R1qY)rHfkr2VQ=T%en@Jzb;<@~Fli^jI94ctk+(*Y2BC)E z>8LXM9f~Rkzw=S$(46+{f0cF3Q84mZ$`mt`M}k(=WHeQ$Esf5KjH;7tq_U%>@y-@l8;GYxx^1Bhl zUk>2EDEMWass0@*!=R3i}~_9Dr0!_{|*g)`8S9}nV3lRqi>Km|33xhy?>?vy!m^_n=pCG zKY~paIsZ`=MBTgoZDPL14PNplBpl>?>8~R|TP4aRVK^n`hbxGy$n{H@;(6ziP5x(d qQ5fl)N`IZn`SM)Szq@{^4v7cpOSG%v&7WfW%^wg%EuIOUA^ZcHMOEtn literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Patches/Patches-505.o b/Playstation/Kernel/Kernel/build/Util/Patches/Patches-505.o new file mode 100644 index 0000000000000000000000000000000000000000..603c4233c0018c8f8c07a5676485b3ca70986c5d GIT binary patch literal 1016 zcmbtRze^)Q6n^oyC@2Z=H$56gIwv{l53T?|aNJ2lM&wU8xl4O2Jon?X(JT zVTev5J1~gO6}Nut9{zuH8@;5umrW|sm~k86){mw>e1ul){u_b*R=i5E^*8p6Vi&m{F#J1w|@Wg8oYpqe!3)eogC$j-!#s8 z;Gu0>hEW)U?vBhATSFY}sIO#5(LqE?J+)s7SVaV!N%2dv!dfo37)Fu@L18vKTZ2Rf z=9P*?5lUF*(%TkM24~DGmw|;PDcHi&N(M9DF0de|6$^ZG6R+xnU;ZH~p$NY5NC1mu zMe+^A{UYJJ%UAcX7dh&k_pE{O{K;ej|D^R%Dt86mfwC8%Gx_A@|gx$ z<1YXMi1c2BR9gRpoUBT*+78YcnrXc<8-we-mhwot^X(EstTjT%GU{_% WGElI~3@U!3a9ttg$fx({`#%Fd$Z?qf literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Patches/Patches-672.o b/Playstation/Kernel/Kernel/build/Util/Patches/Patches-672.o new file mode 100644 index 0000000000000000000000000000000000000000..3e653e612d5b7dccb0fb5e5709d70c634fdec392 GIT binary patch literal 1656 zcmbW0&ubGw6vtn(t%*@I7Q}*9;xAM*W40B88YEh4D~eRGmmVyebep32MRp^Npw3kU z?cbnxjRzqIl|o?mD#bs*gNI5^BBF>;-`mV=mfZxT50dxhGw=Im=FRMrshiirp%6$5 z!6oR8Bn4PedU4hXv#=9(z>nPr|I9oaCSvpXr(^KV4uQq*VgySz|Mc=QsB0EqN8h&i z!*?-ATl^6@octJv778u?86(uU#-?Bu4TbNW(BeNM#~@;HC5jI5uYDQJz(5(Lz~aN? zaU7NtyPUw{aq>3LW{yA$4}>XKF@(0wXM5<5KwsBmxJ|0Jff3bvbwDii#tAI`mb}G3 z?9D*O;*H;N=-9mZdI_4LHm>uax>ge>XIS2!+5%aVkM?s@I8-nkf!5Px_yHVm;y^kpa zR#Tka1qBL3f)I%U(E)s0fbT&v;;DaBZ22&9>PNt4H8a1g8_9F&ah9)EVPRfXua^x| zD;5`!J%B>>hF&Y{#VeYjgS$gIaSVTdH@gPRXp~GXhu*Ap{j!WqeZ>T}sF@nDoM8Z~ z=|znZWr5XLzEUdbWy~*EOr7D?C2=qL`(j)u*IBhzsp>Ve5je_Lz( zdXmDQ*A_*iPI)25vVYRw_Aqbi3z^`BeR4Hq^wo&%y4kBjpKwVxko%XI()?PQYYKf- nczWy91F4tiC+5F9M9>mN&(OeQqMS?Ud+n!}&~!7qfnWa*3J}g~ literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Patches/Patches-702.o b/Playstation/Kernel/Kernel/build/Util/Patches/Patches-702.o new file mode 100644 index 0000000000000000000000000000000000000000..141deefadfe4f68ca7a0077514b921e09a232e74 GIT binary patch literal 1824 zcmbW0&ubGw6vtn((MDUaRZ+noL=S4IohFS?e}G1dHexGPs7NpECf&B!bQ6<}SP&hG z;K55#yh@QGJ!#QPMbJWExBr0ugBlO5KPVKTzBidk)=lD}1H140J~Qvln_mwv^1_P3Aid-#o_=wJ4o|g~ zQ~`RryU&D<469lo`Sw;9XNrM-bGCGR(>K5_XW|YTo+k Qz1E7Km(X&>lJv&^1xj}qP5=M^ literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Patches/Patches-755.o b/Playstation/Kernel/Kernel/build/Util/Patches/Patches-755.o new file mode 100644 index 0000000000000000000000000000000000000000..7c34884fa7f5a3278432d208e04c9b103f128499 GIT binary patch literal 1824 zcmbW0OHUI~6vt0nu=pS%G0{Xr3Jbv~*H)zU5zPdUM?}R3#<&oMGC*P>mH7`-lB z7&m+X7siDeb-{v#OA?Y97DgcI!jE9ssAz&jt>;|sZO3Wrf}6~o|M}f>&VAoI-QVr^ z`9L)voPwgKC_t#Hs5K!q*all+WqZR~@1trWHm~cu;sb{_EOo;aHk&t*a`<#t6y9Lf zF^A8fggJ*V_7~6xl!U$%(RYDt{`&GR2-8XjG!5ceN0irTKnDMfFzx$a;ApZ0^e=uzBrj3oP6G$KEI`JA9!r z3ZL)zapCV#;ldLOG3dogHaAh>_|Lwb6gz<>Ukd5)`JG{f-U^9*Pd+7a0yck&b`E{* z{uoUAY~F#Ed{g=v={K+LgXI$re}2=iYP}ND;Sb_Lg&qot>Gi+mY8r)bc+<*xafA+k zTsQhfWi!E#ar;k-RN68a9$hQWC4NKt zE??My3#ov^i&~Aw~qop`?6BX}8M&pO^bGI7#Bo4SCYPEi4FSwXH zv`yx_8EKWLxQ>EejW_(L1R)hDt(w2WRL`4BeOD!{kpt3Qr#(>lYW>8#XNL%eB|Joq Ut9j>7@3mb13kfY(E=h0xUkyqbEC2ui literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/Patches/Patches-900.o b/Playstation/Kernel/Kernel/build/Util/Patches/Patches-900.o new file mode 100644 index 0000000000000000000000000000000000000000..c6e0592774a33a760cf5ed77d9910237c2f4bb62 GIT binary patch literal 1240 zcmbVL%}T>S5S}*m|KQK5AV~D0qFoXdq#mSDY7vTf=|zN+#$drV3C%|AMSTRH!6y-X zA;p^)ok@4w?Y0r=z%Vo4e&6iuX7g03onKz=7R3+yT~%B47ltu@=k?IvvkPsvmHV;k_4d z1NTnUw|>mRZV-B1-W#2I`f44e^v(2}E2Xs5-`u9q>+j;f`fb$Dqfe{f7yGBpKlpyg zBcnI1S{VyElcj=~S46$1;qv@4)^J_sDm7FKCD*yvxJIv2{{y7nRJ4@RU8zR>bSA|;>^oTce^wm>V(aA=JV#w?&Qtpd82t_s#F5864W4z zgaXXXWPaVab(qD>WoP5Nv;OUu^KuVSXZ;eSi_YuI6xf?TNX*x6khAgg!N=>XiEanJ zb*}|2oq7-b#Hy-F6&j)7n_-gbAaHqk?yOa=SxW=YPm)srUZBISHT3(*Y7|;_Md7Es zFlZ0LbYNTbd^=i ztOZfGiwACJJoWCQ z*o3|rc8Yk&l^4gL!YK9C;+^F(z5w1Ds2~{jT;1v5taqUs-}d{VA6(Um4^%kSZPX_{ zqvlrX0^d{3i(_LKQAekmcG$}1w*On+VTEjZvvPHYUo&Jpn(MsL9||!#^SssbLC&Xh z%G(hP{>6IgDiq}G3;R}%kz3sVEXTH`O5!${?HBwCo$2N%LU|#KRL)Nr^-oqT`yLtpRAzna OixVwY5<27J@AnrtZTYsn$OS10n+x5NO zO=3R`{jg*hYQ}zzw%Sx+>{Lfno$6Rd$=K=O)N11}9kA*&TJdX28?4pN)G?lO-aES| zxf%cPUfAqCzw>eLJ@>wQ-+Rdyns#iRRaRzjDKl<2N)l7U2v?QrQL09b{b0GLdGLJm z{ePS|b)R93{sk4yM~5m;K3Ud$bY%R23ivu4{m}H#A-emK=Kc4=Ax;_83NCol$;+&>0nTgl;@jFLXl_ zbA@i=C$ojFazTyIg&(dKx{2Q{7P`>`TZC@NLW%p*MiTdP;!dfH?!_pq%T_HFeq(RR z@eNGztGj!V@Eg7tC2ntIQ0fl+utDgC4@up?1JZB!u+$kxr0!hpMlp>WBPeluMs&XD z%g}3eqP@CtnX~ZODZ2I2Z>$3|&oM`;t`{-KE?g;e#@i@y&IaCST%enT6j-{^{{h*`H1rJ`T8)Q#6jU3ULM;n&uQ68nvxUoCVK zB(W~~Q+ch7y)4)K=xM1NI<`y19D4?(n}W-5=qagdJ0f+JC#3GcajDCG>J|}mWH(A2 zv+Z%5Y3}FHlXBiiUs))1uYxouY<|0VWe0A9bNr3r?ar5sSjuv`!v)**5*a7Ft}X)q zYS-rv=AB%AT^Q|VEN!z4qujVSIbAslJY+N$@!X*HP2x=oKLuS08J8;jRpRp$UJh|8 zi?mcZ1l7xo*+tM(?pL3KO*dpji=6v&5AjV3Z-EdYW3$5d5#OTlH1+d3g&!sR)e3)u z@^Fd5zYip2R4BZP;;&KoQ)J(+@DRn{rtnd+Z&rAO?6)fX2avyzu|VPX6NgR(h4WcU z{cK@uFprY`Cl#In5;E!({t)$NkHR0J_#Fy=jN}wSc2P2I4T7@sCc2_9;BS1pNDuq8y?XFaKJH=V6@FysrcPRYx)E~M* zARW)wU1T3p>~W=qjD-sCq;^YJB*(dv>~B--8_E6?3O_~sc7;Dmyg}i8l;>*{evZcV zQH8Ieyj`#GrNlq3@GnxFs}w#;?eZv%;yVA3^0rH{pHKa7Rro)MZ&&!AC{CNgKL8Rk zb}IZ$inBxEusMVMl?s24#=At})nva^;RmTdblQ-PM}7-PA!CtZ-$M2^3a_MgFH^Wf z_E#vp2}sEJn8MG{co!@D7|j=6HGbiKcF?$PWn7%E-xA-Tav&k&W`*BP{oknYz0~fF z3J(Jb8FXfoj{B3K{?{w^35t(d^$XiKQ2h0bi~V0k{a>f>BZ9Q(jLfe;FE z+=ZC;B7}k*QdQ&+B7}k*$H4ZFAcTS(Pi^MUAcTS(S3C3XB7}k*cM0Y{MhFEtp3cmF zjt~lR%oX!rBZPu{3w)UW86gzpo8ZIzeS}buH^GPbY*;^7kVoOeJS2Fd;8zQdbHVnt zg5$2syk2nJy_vTNj;Ag2y@KQE%-j|ncW>sN;F|?MBsg9*Z2u*}aaUpfHNkP0X8tX~ z@$_f@Bf-OhpB5aiCboZF@M{ErOYmz2zbN=h!6yY@A^3cpKq&Zyr!co$EjZp4Grvx7 z+-;cOEI95G%$o$q)0ugP;L8QK1Yah2MsU0v;W+mQj;9RsBZA{y2lKB8j`tGG@wosC ze&H#``~|`BG-Upg;JAk{|CQi)7s~ui!SODX`31r86lRX+I2QcE)0}w)?2}lKH^Ybd zV!`orX1+r3h~PI0UMu(}!Pg4DOYl0uI|aW)@TB1L1n(Cd$H4u3NN}t&e@t*Zg_$1{ z98YuR&kMdt@Kb{0>BjcI5FGCYng2#`JX4teRd75#ng2_0Jhhq6!A&0ujulUT=8FW! zy9nmX1joB0=4%CCE%v3%>ZhCgk zw7R+yP9oRuYYJ&IZDq|=CX>u(P20)2fx^qVv23aC6os^%F4c2=X50qTOkkO8v{M$; zUHFRR?7m#Y+`n!^yX|FC1$%4WiRIw!fLHL_4m=?O05tY-ER*feW`_b{ zmeF7}F(sjK+qJtPpY}}3sVZnPp3g!ono2hk%VvWvz(Prv>P}I>g~E!Y?K*Y} zms*elD{14rn}OT}$=~88a*3Fg>VW*gD)9}Q9O&GP8eArcz)H^cW(7hTN-*c9?7)kr z+3kgX`fZV%Or%o2n9O>KZpR8F)9W)moC;q_qCd4h2D;|fJYu!O}SvTS2x&pzI(p15bDp=ViFVBlv4o66P zSu19nR_t^6gln6w9Vim9nCTQevlk}Eo-)$7ow6DES4<4{7$#XO?*;bV+3hs@n=K|u zNV(bN+Qoo=<0Vq6xtUC^;AG-~X)>F0p`TMag1Z6*@TuPyPAnuXz`+(+1b%N#ANw{u zSllb8G!b0G3a3l6M1%SDUDF_CVtyS=N&<~u$X>r!u)z?nu$*-ezWdYkjT?8X*}7}b z&fR{LR&#e#Ynxw(iS#lKp5%JvIe6F!j=m{@qIg(C83(;A!EI;}JqtBt_-rRjR0^UV z98*Pd7u5cjKfixv2fPQBr2xY8n5ZAcn_egb!7H3kLmkJ-&!u=aW4RZckxkFRvq4a{ zCu8_AUH&@cN5}t+rvFLJ{(mPJ)BijE*Wt!UXZ)u%$N!?He_qr7dCmOevxiRp_QA!Y z<6qF6zj?55blS&fO&$NJrhljA_!FA`zto(+cQo_=p{D=1rvDjD|0^`FzedgZJEXaP zRA~0!()3@ex&AI_w(n{Bmuu#~MsxgM)m*>Oyw?7AShM{e&HSy>Y#-ly>FocPYxe&Y z&GolIv;VD{>+iFg>u0&<_@CDFZ`Yi^TQ&Xh-I~t&JF7YVvzqPqYOcSyrvFaO@y9jS ze}kq!J{RiD|BIUK2!{sJVXNj|jEKe^T@Q?Hii@`1>@S`MXrp|D@*n zU9Gu))@xq>?`p2UH#Gg{YWlyYng4%k&j0T<{lBc~|AglFAJ$xdLz?UFKF#s}4aN^k zNc;sN2vGR_VVI=S546R?-!H)a$8}%h|NI$@Yo;>Y_GR#&y<;*1wgb|h-`_IBa}LXN b|L;NmAq7g|_CE;TpQ0by;a-P@-=F>$W{189 literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/ShellCode/SPRXShellCode.o b/Playstation/Kernel/Kernel/build/Util/ShellCode/SPRXShellCode.o new file mode 100644 index 0000000000000000000000000000000000000000..54b6770a1c9c811befdb6b356a1b86e0b9484385 GIT binary patch literal 800 zcmbVJze~eV5WciUyD3hN!M%?}9GoN|YQUhyP!T~wnuJ!&FPfL4lLe>#M~;I3if%4$ zZuKtaCC@iFc!AvaefQnvxI7*?#~n=r5gHso%Y+J`OQKcD7WC0MvX}4n)7zK%VlO{# zULlD6bfV9rS#g`Cx@jI8oQ(zr_k%lNaXe2vKMZlT39y3CxIf1HkW`t*G4Fcc z$^4Lp4Nn8t@Wj{toh|Haw{OQh*KpcO6_U=}aMIQkpQUg?djiyXi21Mn=AN~m{(~Ir zNT}bCMa1Vd*A-ptFY*r71(vOuOeCy&cd^!WR%BmDHW2p{8tqA;_S>j+s><(IUQ?=5 OP#^jFL@>605_|)b)Z+vj*Z@W+PD#K;O4O({c|XS<6kwVsH`sDPvl0mX;f*4LDdZSIZ=8)UImD$u0di1ARx(%9>N7 z4OFA0(?8<144k~@v|buq2Bk9AZ2b_lY`cp6V1vW9 z&uckIm-;(^nPKP?DwK9r(7LJ(=oh!EJJg-(8*0dzL!1vBKOVa(7`s5>{q}kHypey^0saL=(K4=6KastlKW~mthttc+uZhGGSIgZJAqLc zr{>&V$r{nDpP@ywF4(}iNjqjYA>(i8x>s5sulo6L@U4-sk-R^cx z%hkcWQTpU%QjOL>Y$}{m#W&zl8B;E-vF+*3{}-Sr`j{u^pBa( zP$o?lhrj-WuVckt8>wt2qAzYUWAVkCdJI!f$dPnfY}DV(>QIYHn_~O)m!$dgx);bo zjdo@WAYrj&S2!MvN?i#f9ggU-=t_hV;dH1ymW(=xl+n#>CJCW5iNPNvW0Lx2P_=E1NX4iiERRUN%D01aXI_yFgqIT7{TYsLv$L zhPg+a>oW)+BOFg3lxc1uZW69ieKM6-2*>y+lJhUb2;mv3FQD=Q;U7}{IVy(EO=6?zF8Y#>-Ha@{e|<@OT-#s|?-_aZCBZ6SEYqm%;HA zEX7|}#(!HGd`cNV@0Y>fDT6-`ILbu$X2JI-9C0YTUJ=JN!ng`L$~gKM$9;ieGTN(Zs;TRXsB=$esGyd4d_zNB!PZh>% z3HRqC0S5(rc*m31vwu8SIc%3d8+7*H>cPF^gZml<{X7OA^HT_d`19#@VTX^WCG+R7Y!MpO8(x+vJWd#<)Cbs z8R2;kKs6ajqy?05Jt;y)cgR2kS96_lya#Iz3$F5XCKU-e6&bE%U0%1LZINMy!G)aB z<6$RbIkZh#u{NXYtw4r{K#QJ8WqMlc(6+U!^FihkMWqKq33extaSXuYa>zNdJJY&8 z5-VUU04sv=IJ_h9jbX$(xD)Q%fNO=v3_eOQn}VnMU138{h7&sYe=tAj2|R%)x79rx zm;<5B@Gc=6Jqf3D##(L=?x4%{tgK*VIV;Opsbgg+D@#~WAc<5oY=&_L6{kDW{kvuCZ<8Iri`b1n|6Z{7j|p8T_^I||z281oAX?_`v#@FB%N z{N+aDj_k)`6NX;Ja}4}GEd;|~H>Dt;xczdRa& zpdFr*{`i&9PmI3=KCk>m@uyS%+{RTdC1^msmI+i&#Y+xEa{h~dY{%s%(8PL?CB#y) t_hP8~xi~-LgEn3h2e6%m_aE1J-2C>R0^r-Cj!8Yor*S|#+^hca`x|(5=Jfyo literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/build/Util/kproc.o b/Playstation/Kernel/Kernel/build/Util/kproc.o new file mode 100644 index 0000000000000000000000000000000000000000..2d7f0960a88bcada336f962103229440668d4981 GIT binary patch literal 4664 zcmbtXU2IcT96zI=v#6U441U4YY_h4`^lrdFgK25IoxufWwk3QxE?rw#-DsQM+rgrO zF!yjNGfPa6#Q30z3BDK}H2PRYSR^sRgP8d7=7SH0XpA8NlllLjdro_HdfOO1Nzcdc z{QjT!-2b^f6*v2qH8l~@n#hZ!x)LZMTOX*-!)zKRt4SN_OJpX~Db2}g$wE5eq_u4N zxHeeGCDXR82MLKXG^OpS!rD*~caIb&C#Usbhuztc>C!rEPye4S>+XyU(V5?xse5<8 zy+#)TxIq`9%{ZFwm8;QK5-Y{pHR|4uxnEQFrcvJQ-k|Oei))ZFTQ2UTr5EVzqO*g# zx9I7Gc~If)(NYhHH_^H6$TZ5O^OsV znF!>{y-nxLcF5e#$V+quh5=a_G~I8Ea@_qQ?q2t@aDbND_M0X4L`!Ee1LoWr44$6; z5``dxopk0k(Ca{wZy9BtfXLzv3W;xqoUA=KdbwqN3=J&Zhb^NFn>*oLj6w7hK{8>d zonj^xBu>gI!YP4SzL2qV*-(%aaye%zn@gpGBw4WRWI9rG#s^|z6;0%AI7Cvz_#-2c z;SuV7H#Fe>g(s!rpm@k}@yKZDy%3ycvvimmWpCG51ebqBjdb?MmN!3vi7LMkg(NU| zA-Wo8Jbtcz=G72!PSMf|X^WO16VZ?`vU~OyXS9Yf;KHfJ4pQXlGTn)Nwblw0=TZxs=+d%p^i^$e-yw{u+G z>Ebv$r;;|E%?0T^4#%>dKo3Y!1T`zW9vD=275hB)s zJ)4=9Xm@dpjWC`zqxlu z#I*MI^$o>`t>MTHGj54%sd_6B_!{yWR38VvYziH{9%dzvxLihqTAEQoWvN6PQe?;#mq^caEP8tI0>SU**4J&Ib7(K z7tZfRMm>fOFMc6Cnb1*1V?I$h>?N+T)Zq1PWUzr)Z8QzubUSJIg z3j!ZCenksCSd;K>7xve3-WeFt7u9~4J1D*fIK9UHc`mQUPr1CfAB4QHFXI1}%d7S; zal%C*$Vc^?0qcri{FiwAhq)ZakC3o0;=cnJno|AWw+ujN;y&?K)#oPs?|})jzt;`T$r03WaL1O2Rmb9KyT+&aqT6&m?neIYnO z$P4~)0Pue2;R?7SuT>ClBK#LH>QiNLuN9L5t<3$vyAc0d2zl}R@R|C#dL5mDwpVdj TSrW{vpZrDs2ji?Fpe)HhlrS9Z literal 0 HcmV?d00001 diff --git a/Playstation/Kernel/Kernel/crt0.s b/Playstation/Kernel/Kernel/crt0.s new file mode 100644 index 0000000..66efb72 --- /dev/null +++ b/Playstation/Kernel/Kernel/crt0.s @@ -0,0 +1,5 @@ +.intel_syntax noprefix +.text +.global _start +_start: + jmp _main \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Common.hpp b/Playstation/Kernel/Kernel/source/Common.hpp new file mode 100644 index 0000000..a36a7d8 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Common.hpp @@ -0,0 +1,69 @@ +#include +#include + +#include "Util/Types.hpp" +#include "Util/Settings.hpp" +#include "Util/Resolver/Resolver.hpp" +#include "Util/Kernel.hpp" +#include "Util/kproc.hpp" +#include "Util/ASM.h" +#include "Util/Heap.hpp" + +#include "OrbisLib/OrbisLib.hpp" +#include "OrbisLib/KDriver/KDriver.hpp" + +#include "DriverDefinitions.h" + +class OrbisLib; + +extern "C" +{ + #include + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + #include + #include + #include + #include + #include + + #include + #include "sys/mount.h" + + #include + #include +} + +#define offsetof(TYPE, MEMBER) __builtin_offsetof (TYPE, MEMBER) +#define LIST_FOREACH(var, head, field) \ + for ((var) = ((head)->lh_first); \ + (var); \ + (var) = ((var)->field.le_next)) +#define FOREACH_PROC_IN_SYSTEM(p) \ + LIST_FOREACH((p), _allproc, p_list) +#define mtx_lock(m) _mtx_lock_flags((m), 0, __FILE__, __LINE__) +#define PROC_LOCK(p) mtx_lock(&(p)->p_mtx) +#define mtx_unlock(m) _mtx_unlock_flags((m), 0, __FILE__, __LINE__) +#define PROC_UNLOCK(p) mtx_unlock(&(p)->p_mtx) +#define Sleep(u) (pause("", u)) + +extern OrbisLib* OrbisLibInstance; +extern KDriver_Info* KDriverInfo; \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.cpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.cpp new file mode 100644 index 0000000..9f0056f --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.cpp @@ -0,0 +1,98 @@ +#include "../../Common.hpp" +#include "KDriver.hpp" +#include "DriverDefinitions.h" + +#include "Proc.hpp" +#include "Kernel.hpp" + +KDriver::KDriver() +{ + m_DeviceSw.d_version = D_VERSION; + m_DeviceSw.d_name = "OrbisSuite"; + m_DeviceSw.d_ioctl = OnIoctl; + + int ret = make_dev_p(MAKEDEV_CHECKNAME | MAKEDEV_WAITOK, + &m_Device, + &m_DeviceSw, + nullptr, + UID_ROOT, + GID_WHEEL, + S_IRWXU | S_IRWXG | S_IRWXO, + "OrbisSuite"); + + if (ret == 0) + klog("device driver created successfully!"); + else if (ret == EEXIST) + klog("could not create device driver, device driver already exists."); + else + klog("could not create device driver (%d).", ret); +} + +KDriver::~KDriver() +{ + destroy_dev(m_Device); +} + +void KDriver::OnProcessStart(void *arg, struct proc *p) +{ + +} + +int KDriver::OnIoctl(cdev* dev, unsigned long cmd, caddr_t data, int fflag, thread* td) +{ + cmd = cmd & 0xFFFFFFFF; // Clear the upper32 + auto group = IOCGROUP(cmd); + + klog("Group: %c Cmd: %i", group, cmd); + + switch (group) + { + case 'P': + return Proc::OnIoctl(dev, cmd, data, fflag, td); + + case 'K': + return Kernel::OnIoctl(dev, cmd, data, fflag, td); + + case 'D': + switch (cmd) + { + case KDRIVER_INFO: + return GetKDriverInfo(data); + + default: + klog("[KDriver] Not Implimented. :("); + break; + } + break; + + default: + klog("[KDriver] Not Implimented. :("); + break; + } + + return 0; +} + +int KDriver::GetKDriverInfo(caddr_t data) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + if(KDriverInfo == nullptr) + { + klog("KDriverInfo pointer invalid..."); + return EINVAL; + } + + int res = copyout(KDriverInfo, data, sizeof(KDriver_Info)); + if(res != 0) + { + klog("Failed to copy out data."); + return res; + } + + return 0; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.hpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.hpp new file mode 100644 index 0000000..5468c63 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/KDriver.hpp @@ -0,0 +1,18 @@ +#pragma once +#include "../../Common.hpp" +#include "DriverDefinitions.h" + +class KDriver +{ +private: + cdev* m_Device; + cdevsw m_DeviceSw; + + static int GetKDriverInfo(caddr_t data); + +public: + KDriver(); + ~KDriver(); + void OnProcessStart(void *arg, struct proc *p); + static int OnIoctl(cdev* p_Device, unsigned long p_Command, caddr_t p_Data, int p_FFlag, thread* p_Thread); +}; diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.cpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.cpp new file mode 100644 index 0000000..07d67f4 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.cpp @@ -0,0 +1,16 @@ +#include "../../Common.hpp" +#include "Kernel.hpp" + +#include "DriverDefinitions.h" +#include "../../Util/System.hpp" + +int Kernel::OnIoctl(cdev* dev, unsigned long cmd, caddr_t data, int fflag, thread* td) +{ + switch(cmd) + { + + default: + klog("Not Implimented. :("); + break; + } +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.hpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.hpp new file mode 100644 index 0000000..6bc4e10 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Kernel.hpp @@ -0,0 +1,9 @@ +#pragma once + +class Kernel +{ +private: + +public: + static int OnIoctl(cdev* dev, unsigned long cmd, caddr_t data, int fflag, thread* td); +}; diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.cpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.cpp new file mode 100644 index 0000000..23b8413 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.cpp @@ -0,0 +1,289 @@ +#include "../../Common.hpp" +#include "Proc.hpp" + +#include "DriverDefinitions.h" +#include "../../Util/ShellCode/SPRXShellCode.hpp" +#include "../../Util/System.hpp" + +int Proc::OnIoctl(cdev* dev, unsigned long cmd, caddr_t data, int fflag, thread* td) +{ + switch(cmd) + { + case PROC_LIST: + return GetProccessList(data, td); + + case PROC_INFO: + return GetProccessInfo(data, td); + + case PROC_MODULE_LIST: + return GetProccessModuleList(data, td); + + case PROC_READ_WRITE_MEMORY: + return ProcessReadWrite(data, td); + + case PROC_ALLOC_MEMORY: + return ProcessAlloc(data, td); + + case PROC_FREE_MEMORY: + return ProcessFree(data); + + case PROC_SPRX: + return ProcessSPRX(data); + + case PROC_ELF: + return ProcessELF(data, td); + + default: + klog("[Proc] Not Implimented. :("); + break; + } +} + +int Proc::GetProccessList(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + auto Input = (KDriver_ProcList*)data; + auto Temp = (ProcInfo*)kmalloc(sizeof(ProcInfo) * Input->ProcCount); + + klog("Itterating Processes!"); + int ProccessCount = 0; + proc* CurrentProc = *(proc**)allproc; + do + { + if(ProccessCount > Input->ProcCount) + break; + + klog("%s", CurrentProc->p_comm); + + Temp[ProccessCount].PID = CurrentProc->p_pid; + Temp[ProccessCount].Attached = ((CurrentProc->p_flag & 0x800) != 0); + memcpy(&Temp[ProccessCount].ProcName, CurrentProc->p_comm, strlen(CurrentProc->p_comm) + 1); + memcpy(&Temp[ProccessCount].TitleID, CurrentProc->titleId, 10); + Temp[ProccessCount].TextSegmentBase = (uint64_t)CurrentProc->p_vmspace->vm_taddr; + Temp[ProccessCount].TextSegmentLen = (uint64_t)(CurrentProc->p_vmspace->vm_tsize * PAGE_SIZE); + Temp[ProccessCount].DataSegmentBase = (uint64_t)CurrentProc->p_vmspace->vm_daddr; + Temp[ProccessCount].DataSegmentLen = (uint64_t)(CurrentProc->p_vmspace->vm_dsize * PAGE_SIZE); + + ProccessCount++; + CurrentProc = CurrentProc->p_list.le_next; + } while (CurrentProc != nullptr); + + Input->ProcCount = ProccessCount; + + WriteProcessMemory(td->td_proc, (void*)Input->UserlandAddr, Temp, Input->UserlandSize); + + kfree(Temp); + + klog("done!"); + + return 0; +} + +int Proc::GetProccessInfo(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + auto Input = (KDriver_ProcInfo*)data; + + proc* CurrentProc = FindProcessByPID(Input->ProcessID); + + if(CurrentProc == nullptr) + { + klog("Failed to find Process with the pid %i\n", Input->ProcessID); + return EINVAL; + } + + auto Temp = (ProcInfoExt*)kmalloc(sizeof(ProcInfoExt) + (sizeof(ProcInfoExt::ThreadInfo) * Input->ThreadCount)); + + Temp->ProcessID = CurrentProc->p_pid; + Temp->Attached = ((CurrentProc->p_flag & 0x800) != 0); + Temp->Signal = CurrentProc->p_sig; + Temp->Code = CurrentProc->p_code; + Temp->Stops = CurrentProc->p_stops; + Temp->StopType = CurrentProc->p_stype; + strcpy(Temp->ProcName, CurrentProc->p_comm); + strcpy(Temp->TitleID, CurrentProc->titleId); + strcpy(Temp->RandomizedPath, CurrentProc->p_elfpath); + strcpy(Temp->RandomizedPath, CurrentProc->p_randomized_path); + Temp->TextSegmentBase = (uint64_t)CurrentProc->p_vmspace->vm_taddr; + Temp->TextSegmentLen = (uint64_t)(CurrentProc->p_vmspace->vm_tsize * PAGE_SIZE); + Temp->DataSegmentBase = (uint64_t)CurrentProc->p_vmspace->vm_daddr; + Temp->DataSegmentLen = (uint64_t)(CurrentProc->p_vmspace->vm_dsize * PAGE_SIZE); + + //TODO: Threads... + thread* CurrentThread = CurrentProc->p_threads.tqh_first; + for (Temp->ThreadCount = 0; (Temp->ThreadCount < Input->ThreadCount) && CurrentThread != nullptr; Temp->ThreadCount++) + { + Temp->Threads[Temp->ThreadCount].ThreadId = CurrentThread->td_tid; + strcpy(Temp->Threads[Temp->ThreadCount].Name, CurrentThread->td_name); + Temp->Threads[Temp->ThreadCount].Errno = CurrentThread->td_errno; + Temp->Threads[Temp->ThreadCount].RetVal = CurrentThread->td_retval[0]; + + CurrentThread = CurrentThread->td_plist.tqe_next; + } + + WriteProcessMemory(td->td_proc, (void*)Input->UserlandAddr, Temp, Input->UserlandSize); + + kfree(Temp); + + return 0; +} + +int Proc::GetProccessModuleList(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + auto Input = (KDriver_ModuleList*)data; + + proc* CurrentProc = FindProcessByPID(Input->ProcessID); + + if(CurrentProc == nullptr) + { + klog("Failed to find Process with the pid %i\n", Input->ProcessID); + return EINVAL; + } + + auto Temp = (ModuleInfo*)kmalloc(sizeof(ModuleInfo) * Input->ModuleCount); + + int ModuleCount = 0; + auto CurrentModule = CurrentProc->p_dynlibptr->p_dynlib; + while(CurrentModule != 0) + { + Temp[ModuleCount].Handle = CurrentModule->ModuleHandle; + strcpy(Temp[ModuleCount].Name, (char*)basename(CurrentModule->ModulePath)); + strcpy(Temp[ModuleCount].Path, (char*)CurrentModule->ModulePath); + Temp[ModuleCount].TextSegmentBase = (uint64_t)CurrentModule->codeBase; + Temp[ModuleCount].TextSegmentLen = CurrentModule->codeSize; + Temp[ModuleCount].DataSegmentBase = (uint64_t)CurrentModule->dataBase; + Temp[ModuleCount].DataSegmentLen = CurrentModule->dataSize; + + ModuleCount ++; + CurrentModule = CurrentModule->dynlib_next; + } + + WriteProcessMemory(td->td_proc, (void*)Input->UserlandAddr, Temp, Input->UserlandSize); + + kfree(Temp); + + return 0; +} + +int Proc::ProcessReadWrite(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + auto Input = (KDriver_ReadWriteMemory*)data; + + proc* CurrentProc = FindProcessByPID(Input->ProcessID); + + if(CurrentProc == nullptr) + { + klog("Failed to find Process with the pid %i\n", Input->ProcessID); + return EINVAL; + } + + // TODO: Error handling. + if (Input->IsRead) + { + auto Temp = (char*)kmalloc(Input->Length); + + ReadProcessMemory(CurrentProc, (void*)Input->ProcessAddress, Temp, Input->Length); + WriteProcessMemory(td->td_proc, (void*)Input->UserlandAddr, Temp, Input->Length); + + kfree(Temp); + } + else + { + auto Temp = (char*)kmalloc(Input->Length); + + ReadProcessMemory(td->td_proc, (void*)Input->UserlandAddr, Temp, Input->Length); + WriteProcessMemory(CurrentProc, (void*)Input->ProcessAddress, Temp, Input->Length); + + kfree(Temp); + } + + return 0; +} + +int Proc::ProcessAlloc(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + return 0; +} + +int Proc::ProcessFree(caddr_t data) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + return 0; +} + +int Proc::ProcessSPRX(caddr_t data) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + auto Input = (KDriver_ProcSPRX*)data; + + klog("DoSwitch"); + switch (Input->CallType) + { + case 0: + LoadSPRX(Input->ProcName, Input->Path, Input->CallEntryExit); + break; + + case 1: + UnloadSPRX(Input->ProcName, Input->Path, Input->CallEntryExit); + break; + + case 2: + UnloadSPRX(Input->ProcName, Input->Handle, Input->CallEntryExit); + break; + + default: + klog("ProcessSPRX: Invalid CallType %d.", Input->CallType); + break; + } + + return 0; +} + +int Proc::ProcessELF(caddr_t data, thread* td) +{ + if (data == nullptr) + { + klog("Data pointer invalid..."); + return EINVAL; + } + + return 0; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.hpp b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.hpp new file mode 100644 index 0000000..8f5c958 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/KDriver/Proc.hpp @@ -0,0 +1,17 @@ +#pragma once + +class Proc +{ +private: + static int GetProccessList(caddr_t data, thread* td); + static int GetProccessInfo(caddr_t data, thread* td); + static int GetProccessModuleList(caddr_t data, thread* td); + static int ProcessReadWrite(caddr_t data, thread* td); + static int ProcessAlloc(caddr_t data, thread* td); + static int ProcessFree(caddr_t data); + static int ProcessSPRX(caddr_t data); + static int ProcessELF(caddr_t data, thread* td); + +public: + static int OnIoctl(cdev* dev, unsigned long cmd, caddr_t data, int fflag, thread* td); +}; diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.cpp b/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.cpp new file mode 100644 index 0000000..92d58b8 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.cpp @@ -0,0 +1,90 @@ +#include "../Common.hpp" +#include "OrbisLib.hpp" +#include "../Util/ShellCode/SPRXShellCode.hpp" +#include "../Util/System.hpp" + +void OrbisLib::OrbisLibKernelEntry(void* arg) +{ + auto OrbisLibInstance = (OrbisLib*)arg; + + proc_Jailbreak(curthread()->td_proc, &OrbisLibInstance->BackupJail); + + //LoadSPRX("SceShellUI", "/data/Orbis Toolbox/Orbis Toolbox.sprx"); + + // Set up Kernel Instances... + OrbisLibInstance->KDriverInstance = new KDriver(); + + // Block to keep alive. + while(OrbisLibInstance->ShouldRun) + { + kthread_suspend_check(); + Sleep(100); + } + + kproc_exit(0); +} + +OrbisLib::OrbisLib() +{ + // Set Initial Vars. + ShouldRun = true; + + // Start up Kernel Process. + KprocInstance = new kproc(OrbisLibKernelEntry, this, "OrbisSuite Kernel", "ORBS00001", 0, 0); + + // Register Events. + SystemSuspendEvent = EVENTHANDLER_REGISTER(system_suspend_phase1, (void*)OnSystemSuspend, nullptr, EVENTHANDLER_PRI_FIRST); + SystemResumeEvent = EVENTHANDLER_REGISTER(system_resume_phase1, (void*)OnSystemResume, nullptr, EVENTHANDLER_PRI_FIRST); + ProcessStartEvent = EVENTHANDLER_REGISTER(process_exec_end, (void*)OnProcessStart, nullptr, EVENTHANDLER_PRI_ANY); + ProcessExitEvent = EVENTHANDLER_REGISTER(process_exit, (void*)OnProcessExit, nullptr, EVENTHANDLER_PRI_ANY); + + // Do the thing. + DoShellUIMount(FindProcessByName("SceShellUI"), true); +} + +OrbisLib::~OrbisLib() +{ + // Teardown Kernel Process. + ShouldRun = false; + + // De-Register Events. + EVENTHANDLER_DEREGISTER(system_suspend_phase1, SystemSuspendEvent); + EVENTHANDLER_DEREGISTER(system_resume_phase1, SystemResumeEvent); + EVENTHANDLER_DEREGISTER(process_exec_end, ProcessStartEvent); + EVENTHANDLER_DEREGISTER(process_exit, ProcessExitEvent); + + // Clean up. + delete KDriverInstance; +} + +void OrbisLib::OnSystemSuspend(void* arg) +{ + klog("System is Suspending..."); + +} + +void OrbisLib::OnSystemResume(void* arg) +{ + klog("System is Resuming..."); + +} + +void OrbisLib::OnProcessStart(void *arg, struct proc *p) +{ + if(!p) + return; + + klog("OnProcessStart: %s(%s)", p->p_comm, p->titleId); + + DoShellUIMount(p, true); +} + +void OrbisLib::OnProcessExit(void *arg, struct proc *p) +{ + if(!p) + return; + + klog("OnProcessExit: %s(%s)", p->p_comm, p->titleId); + + DoShellUIMount(p, false); +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.hpp b/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.hpp new file mode 100644 index 0000000..52c7882 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/OrbisLib/OrbisLib.hpp @@ -0,0 +1,32 @@ +#pragma once +#include "../Common.hpp" +#include "../Util/kproc.hpp" +#include "../Util/Proc.hpp" + +class kproc; +class KDriver; + +class OrbisLib +{ +private: + eventhandler_entry* SystemSuspendEvent; + eventhandler_entry* SystemResumeEvent; + eventhandler_entry* ProcessStartEvent; + eventhandler_entry* ProcessExitEvent; + Backup_Jail BackupJail; + bool ShouldRun; + + static void OrbisLibKernelEntry(void* arg); + + static void OnSystemSuspend(void* arg); + static void OnSystemResume(void* arg); + static void OnProcessStart(void *arg, struct proc *p); + static void OnProcessExit(void *arg, struct proc *p); + +public: + kproc* KprocInstance; + KDriver* KDriverInstance; + + OrbisLib(); + ~OrbisLib(); +}; diff --git a/Playstation/Kernel/Kernel/source/Util/ASM.h b/Playstation/Kernel/Kernel/source/Util/ASM.h new file mode 100644 index 0000000..f7c261e --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/ASM.h @@ -0,0 +1,10 @@ +#pragma once +#include "../Common.hpp" + +extern "C" +{ + extern thread* curthread(); + extern uint64_t Readmsr(int Reg); + extern void cpu_enable_wp(); + extern void cpu_disable_wp(); +} diff --git a/Playstation/Kernel/Kernel/source/Util/ASM.s b/Playstation/Kernel/Kernel/source/Util/ASM.s new file mode 100644 index 0000000..ec6ec05 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/ASM.s @@ -0,0 +1,31 @@ +.intel_syntax noprefix +.text + +.global curthread +.global Readmsr +.global cpu_enable_wp +.global cpu_disable_wp + +curthread: + mov rax, gs:0 + ret + +Readmsr: + mov ecx, edi + rdmsr + shl rdx, 32 + or rax, rdx + ret + +cpu_enable_wp: + mov rax, cr0 + or rax, 0x10000 + mov cr0, rax + ret + +cpu_disable_wp: + mov rax, cr0 + and rax, ~0x10000 + mov cr0, rax + ret + \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Heap.cpp b/Playstation/Kernel/Kernel/source/Util/Heap.cpp new file mode 100644 index 0000000..5ccc433 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Heap.cpp @@ -0,0 +1,45 @@ +#include "../Common.hpp" +#include "Heap.hpp" + +void* kmalloc(long unsigned int size) { + return malloc(size, M_TEMP, 2); +} + +void kfree(void* addr) +{ + if (addr == nullptr) + return; + + free(addr, M_TEMP); +} + +void* operator new(long unsigned int size) +{ + if (size == 0) + return nullptr; + + return malloc(size, M_TEMP, M_ZERO | M_NOWAIT); +} + +void* operator new(long unsigned int size, void * addr) +{ + return addr; +} + +void* operator new[] (long unsigned int size) +{ + return ::operator new(size); +} + +void operator delete(void* addr) noexcept +{ + if (addr == nullptr) + return; + + free(addr, M_TEMP); +} + +void operator delete[](void* addr) noexcept +{ + ::operator delete(addr); +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Heap.hpp b/Playstation/Kernel/Kernel/source/Util/Heap.hpp new file mode 100644 index 0000000..b0e9907 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Heap.hpp @@ -0,0 +1,9 @@ +#pragma once + +void* kmalloc(long unsigned int size); +void kfree(void* addr); +void* operator new(long unsigned int size); +void* operator new(long unsigned int size, void * addr); +void* operator new[] (long unsigned int size); +void operator delete(void* addr) noexcept; +void operator delete[](void* addr) noexcept; \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Kernel.cpp b/Playstation/Kernel/Kernel/source/Util/Kernel.cpp new file mode 100644 index 0000000..49f73a5 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Kernel.cpp @@ -0,0 +1,128 @@ +#include "../Common.hpp" +#include "Kernel.hpp" + +extern "C" +{ + #include + #include + #include + #include + #include + + #include + #include + + #include +} + + +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + +int kern_errorno = 0; + +int ksetuid(uid_t uid, thread* td) +{ + setuid_args uap; + sysent* sysents = sysvec->sv_table; + auto sys_setuid = (int(*)(thread*, setuid_args*))sysents[23].sy_call; + + // clear errors + td->td_retval[0] = 0; + + // Set up Params + uap.uid = uid; + + // Call System call + kern_errorno = sys_setuid(td, &uap); + if(kern_errorno) + return -kern_errorno; + + // success + return td->td_retval[0]; +} + +void klog(char* fmt, ...) +{ + char Buffer[0x2000]; + + va_list args; + va_start(args, fmt); + vsprintf(Buffer, fmt, args); + va_end(args); + + kprintf("%s\n", Buffer); +} + +caddr_t kmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t pos, struct thread* td) +{ + struct mmap_args uap; + sysent* sysents = sysvec->sv_table; + auto sys_mmap = (int(*)(thread*, mmap_args*))sysents[477].sy_call; + if (!sys_mmap) + return (caddr_t)-1; + + // clear errors + td->td_retval[0] = 0; + + // Set up Params + uap.addr = addr; + uap.len = len; + uap.prot = prot; + uap.flags = flags; + uap.fd = fd; + uap.pos = pos; + + // Call System call + kern_errorno = sys_mmap(td, &uap); + if(kern_errorno) + return (caddr_t)-kern_errorno; + + // success + return (caddr_t)td->td_retval[0]; +} + +int kmunmap(void *addr, size_t len, struct thread* td) +{ + munmap_args uap; + sysent* sysents = sysvec->sv_table; + auto sys_munmap = (int(*)(thread*, munmap_args*))sysents[73].sy_call; + + // clear errors + td->td_retval[0] = 0; + + // Set up Params + uap.addr = addr; + uap.len = len; + + // Call System call + kern_errorno = sys_munmap(td, &uap); + if(kern_errorno) + return -kern_errorno; + + // success + return td->td_retval[0]; +} + +int kunmount(const char* path, int flags, struct thread* td) +{ + unmount_args uap; + sysent* sysents = sysvec->sv_table; + auto sys_unmount = (int(*)(thread*, unmount_args*))sysents[22].sy_call; + + // clear errors + td->td_retval[0] = 0; + + // Set up Params + uap.path = (char*)path; + uap.flags = flags; + + // Call System call + kern_errorno = sys_unmount(td, &uap); + if(kern_errorno) + return -kern_errorno; + + // success + return td->td_retval[0]; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Kernel.hpp b/Playstation/Kernel/Kernel/source/Util/Kernel.hpp new file mode 100644 index 0000000..e861109 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Kernel.hpp @@ -0,0 +1,9 @@ +#pragma once +#include "../Common.hpp" + +int ksetuid(uid_t uid, thread* td); +void klog(char* fmt, ...); + +caddr_t kmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t pos, struct thread* td); +int kmunmap(void *addr, size_t len, struct thread* td); +int kunmount(const char* path, int flags, struct thread* td); \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches-505.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-505.cpp new file mode 100644 index 0000000..2b1eee3 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-505.cpp @@ -0,0 +1,74 @@ +#include "../../Common.hpp" +#include "../Resolver/Resolver.hpp" +#include "Patches.hpp" + +void Install_505() +{ + uint8_t *kmem; + + // Verbose Panics + kmem = (uint8_t *)&gpKernelBase[0x00171627]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x65; + kmem[6] = 0x8B; + kmem[7] = 0x34; + + // Enable rwx mapping + kmem = (uint8_t *)&gpKernelBase[0x000FCD48]; + kmem[0] = 0x07; + + kmem = (uint8_t *)&gpKernelBase[0x000FCD56]; + kmem[0] = 0x07; + + // Patch copyin/copyout to allow userland + kernel addresses in both params + kmem = (uint8_t *)&gpKernelBase[0x001EA767]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x001EA682]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + // Patch copyinstr + kmem = (uint8_t *)&gpKernelBase[0x001EAB93]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x001EABC3]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + // Patch memcpy stack + kmem = (uint8_t *)&gpKernelBase[0x001EA53D]; + kmem[0] = 0xEB; + + // Enable *all* debugging logs (in vprintf) + // Patch by: SiSTRo + kmem = (uint8_t *)&gpKernelBase[0x0043612A]; + kmem[0] = 0xEB; + kmem[1] = 0x38; + + // patch suword_lwpid + // has a check to see if child_tid/parent_tid is in kernel memory, and it in so patch it + // Patch by: JOGolden + kmem = (uint8_t *)&gpKernelBase[0x001EA9D2]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x001EA9E1]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + // Patch to remove vm_fault: fault on nofault entry, addr %llx + kmem = (uint8_t *)&gpKernelBase[0x002A4EB3]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches-672.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-672.cpp new file mode 100644 index 0000000..5a844bf --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-672.cpp @@ -0,0 +1,145 @@ +#include "../../Common.hpp" +#include "../Resolver/Resolver.hpp" +#include "Patches.hpp" + +void Install_672() +{ + uint8_t *kmem; + + // Patch dynlib_dlsym + kmem = (uint8_t*)&gpKernelBase[0x1D895A]; + kmem[0] = 0xE9; + kmem[1] = 0xC7; + kmem[2] = 0x01; + kmem[3] = 0x00; + kmem[4] = 0x00; + + // Patch a function called by dynlib_dlsym + kmem = (uint8_t*)&gpKernelBase[0x0041A2D0]; + kmem[0] = 0x31; // xor eax, eax + kmem[1] = 0xC0; + kmem[2] = 0xC3; // ret + + // Patch sys_mmap + kmem = (uint8_t*)&gpKernelBase[0x000AB57A]; + kmem[0] = 0x37; // mov [rbp+var_61], 33h ; '3' + kmem[3] = 0x37; // mov sil, 33h ; '3' + + // patch sys_setuid + kmem = (uint8_t*)&gpKernelBase[0x0010BED0]; // call priv_check_cred; overwrite with mov eax, 0 + kmem[0] = 0xB8; // mov eax, 0 + kmem[1] = 0x00; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + + // patch sys_mprotect + kmem = (uint8_t*)&gpKernelBase[0x00451DB8]; // jnz loc_FFFFFFFF82652426; nop it out + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // Enable rwx mapping in kmem_alloc + kmem = (uint8_t *)&gpKernelBase[0x002507F5]; + kmem[0] = 0x07; // set maxprot to RWX + + kmem = (uint8_t *)&gpKernelBase[0x00250803]; + kmem[0] = 0x07; // set maxprot to RWX + + // Patch copyin/copyout to allow userland + kernel addresses in both params + // copyin + kmem = (uint8_t *)&gpKernelBase[0x003C17F7]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x003C1803]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // copyout + kmem = (uint8_t *)&gpKernelBase[0x003C1702]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x003C170E]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Enable MAP_SELF + + // Patches: sceSblACMgrHasMmapSelfCapability + kmem = (uint8_t *)&gpKernelBase[0x00233C40]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + // Patches: sceSblACMgrIsAllowedToMmapSelf + kmem = (uint8_t *)&gpKernelBase[0x00233C50]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + // Patches: call sceSblAuthMgrIsLoadable in vm_mmap2 (right above the only call to allowed to mmap self) + kmem = (uint8_t *)&gpKernelBase[0x000AD2E4]; // xor eax, eax; nop; nop; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // Patch copyinstr + kmem = (uint8_t *)&gpKernelBase[0x003C1CA3]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x003C1CAF]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Patch memcpy stack + kmem = (uint8_t *)&gpKernelBase[0x003C15BD]; + kmem[0] = 0xEB; + + // ptrace patches + kmem = (uint8_t *)&gpKernelBase[0x0010F879]; + kmem[0] = 0xEB; + + // Enable debug rif's + kmem = (uint8_t*)&gpKernelBase[0x66AEB0]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + kmem[3] = 0x90; + + // Enable debug rifs 2 + kmem = (uint8_t*)&gpKernelBase[0x66AEE0]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + kmem[3] = 0x90; + + // Disable pfs checks + kmem = (uint8_t*)&gpKernelBase[0x6A8EB0]; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0xC3; + kmem[3] = 0x90; + + // Enable *all* debugging logs (in vprintf) + // Patch by: SiSTRo + kmem = (uint8_t*)&gpKernelBase[0x00123367]; + kmem[0] = 0xEB; // jmp +0x3D + kmem[1] = 0x3B; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches-702.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-702.cpp new file mode 100644 index 0000000..d1011e8 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-702.cpp @@ -0,0 +1,215 @@ +#include "../../Common.hpp" +#include "../Resolver/Resolver.hpp" +#include "Patches.hpp" + +void Install_702() +{ + // Use "kmem" for all patches + uint8_t *kmem; + + // Enable UART + kmem = (uint8_t *)&gpKernelBase[0x01A6EAA0]; + kmem[0] = 0x00; + + // Verbose Panics + kmem = (uint8_t *)&gpKernelBase[0x0013A4AE]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // sceSblACMgrIsAllowedSystemLevelDebugging + kmem = (uint8_t *)&gpKernelBase[0x001CB060]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x001CB880]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x001CB8A0]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + // Enable rwx mapping + kmem = (uint8_t *)&gpKernelBase[0x001171BE]; + kmem[0] = 0x07; + + kmem = (uint8_t *)&gpKernelBase[0x001171C6]; + kmem[0] = 0x07; + + // Patch copyin/copyout: Allow userland + kernel addresses in both params + // copyin + kmem = (uint8_t *)&gpKernelBase[0x0002F287]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0002F293]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // copyout + kmem = (uint8_t *)&gpKernelBase[0x0002F192]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0002F19E]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Enable MAP_SELF + kmem = (uint8_t *)&gpKernelBase[0x001CB8F0]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x001CB910]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x001D40BB]; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // Patch copyinstr + kmem = (uint8_t *)&gpKernelBase[0x0002F733]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0002F73F]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Patch memcpy stack + kmem = (uint8_t *)&gpKernelBase[0x0002F04D]; + kmem[0] = 0xEB; + + // ptrace patches + kmem = (uint8_t *)&gpKernelBase[0x000448D5]; + kmem[0] = 0xEB; + + // second ptrace patch + kmem = (uint8_t *)&gpKernelBase[0x00044DAF]; + kmem[0] = 0xE9; + kmem[1] = 0x7C; + kmem[2] = 0x02; + kmem[3] = 0x00; + kmem[4] = 0x00; + + // setlogin patch (for autolaunch check) + kmem = (uint8_t *)&gpKernelBase[0x0008A8EC]; + kmem[0] = 0x48; + kmem[1] = 0x31; + kmem[2] = 0xC0; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // Patch to remove vm_fault: fault on nofault entry, addr %llx + kmem = (uint8_t *)&gpKernelBase[0x002BF756]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // Patch mprotect: Allow RWX (mprotect) mapping + kmem = (uint8_t *)&gpKernelBase[0x00264C08]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // flatz disable pfs signature check + kmem = (uint8_t *)&gpKernelBase[0x006BE880]; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0xC3; + + // flatz enable debug RIFs + kmem = (uint8_t *)&gpKernelBase[0x00668270]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x006682A0]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + + // Enable *all* debugging logs (in vprintf) + // Patch by: SiSTRo + kmem = (uint8_t *)&gpKernelBase[0x000BC817]; + kmem[0] = 0xEB; + kmem[1] = 0x3B; + + // flatz allow mangled symbol in dynlib_do_dlsym + kmem = (uint8_t *)&gpKernelBase[0x002F0367]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // Enable mount for unprivileged user + kmem = (uint8_t *)&gpKernelBase[0x0029636A]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // patch suword_lwpid + // has a check to see if child_tid/parent_tid is in kernel memory, and it in so patch it + // Patch by: JOGolden + kmem = (uint8_t *)&gpKernelBase[0x0002F552]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0002F561]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + // Patch debug setting errors + kmem = (uint8_t *)&gpKernelBase[0x005016FA]; + kmem[0] = 0x00; + kmem[1] = 0x00; + kmem[2] = 0x00; + kmem[3] = 0x00; + + kmem = (uint8_t *)&gpKernelBase[0x0050296C]; + kmem[0] = 0x00; + kmem[1] = 0x00; + kmem[2] = 0x00; + kmem[3] = 0x00; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches-755.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-755.cpp new file mode 100644 index 0000000..9ce6dd2 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-755.cpp @@ -0,0 +1,215 @@ +#include "../../Common.hpp" +#include "../Resolver/Resolver.hpp" +#include "Patches.hpp" + +void Install_755() +{ + // Use "kmem" for all patches + uint8_t *kmem; + + // Enable UART + kmem = (uint8_t *)&gpKernelBase[0x01564910]; + kmem[0] = 0x00; + + // Verbose Panics + kmem = (uint8_t *)&gpKernelBase[0x0046D11E]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // sceSblACMgrIsAllowedSystemLevelDebugging + kmem = (uint8_t *)&gpKernelBase[0x003644B0]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x00364CD0]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x00364CF0]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + // Enable rwx mapping + kmem = (uint8_t *)&gpKernelBase[0x001754AC]; + kmem[0] = 0x07; + + kmem = (uint8_t *)&gpKernelBase[0x001754B4]; + kmem[0] = 0x07; + + // Patch copyin/copyout: Allow userland + kernel addresses in both params + // copyin + kmem = (uint8_t *)&gpKernelBase[0x0028FA47]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0028FA53]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // copyout + kmem = (uint8_t *)&gpKernelBase[0x0028F952]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0028F95E]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Enable MAP_SELF + kmem = (uint8_t *)&gpKernelBase[0x00364D40]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x00364D60]; + kmem[0] = 0xB8; + kmem[1] = 0x01; + kmem[2] = 0x00; + kmem[3] = 0x00; + kmem[4] = 0x00; + kmem[5] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x000DCED1]; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // Patch copyinstr + kmem = (uint8_t *)&gpKernelBase[0x0028FEF3]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0028FEFF]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + + // Patch memcpy stack + kmem = (uint8_t *)&gpKernelBase[0x0028F80D]; + kmem[0] = 0xEB; + + // ptrace patches + kmem = (uint8_t *)&gpKernelBase[0x00361CF5]; + kmem[0] = 0xEB; + + // second ptrace patch + kmem = (uint8_t *)&gpKernelBase[0x003621CF]; + kmem[0] = 0xE9; + kmem[1] = 0x7C; + kmem[2] = 0x02; + kmem[3] = 0x00; + kmem[4] = 0x00; + + // setlogin patch (for autolaunch check) + kmem = (uint8_t *)&gpKernelBase[0x0037CF6C]; + kmem[0] = 0x48; + kmem[1] = 0x31; + kmem[2] = 0xC0; + kmem[3] = 0x90; + kmem[4] = 0x90; + + // Patch to remove vm_fault: fault on nofault entry, addr %llx + kmem = (uint8_t *)&gpKernelBase[0x003DF2A6]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // Patch mprotect: Allow RWX (mprotect) mapping + kmem = (uint8_t *)&gpKernelBase[0x003014C8]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // flatz disable pfs signature check + kmem = (uint8_t *)&gpKernelBase[0x006DD9A0]; + kmem[0] = 0x31; + kmem[1] = 0xC0; + kmem[2] = 0xC3; + + // flatz enable debug RIFs + kmem = (uint8_t *)&gpKernelBase[0x00668140]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + + kmem = (uint8_t *)&gpKernelBase[0x00668170]; + kmem[0] = 0xB0; + kmem[1] = 0x01; + kmem[2] = 0xC3; + + // Enable *all* debugging logs (in vprintf) + // Patch by: SiSTRo + kmem = (uint8_t *)&gpKernelBase[0x0026F827]; + kmem[0] = 0xEB; + kmem[1] = 0x3B; + + // flatz allow mangled symbol in dynlib_do_dlsym + kmem = (uint8_t *)&gpKernelBase[0x000271A7]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // Enable mount for unprivileged user + kmem = (uint8_t *)&gpKernelBase[0x00076385]; + kmem[0] = 0x90; + kmem[1] = 0x90; + kmem[2] = 0x90; + kmem[3] = 0x90; + kmem[4] = 0x90; + kmem[5] = 0x90; + + // patch suword_lwpid + // has a check to see if child_tid/parent_tid is in kernel memory, and it in so patch it + // Patch by: JOGolden + kmem = (uint8_t *)&gpKernelBase[0x0028FD12]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + kmem = (uint8_t *)&gpKernelBase[0x0028FD21]; + kmem[0] = 0x90; + kmem[1] = 0x90; + + // Patch debug setting errors + kmem = (uint8_t *)&gpKernelBase[0x004FF322]; + kmem[0] = 0x00; + kmem[1] = 0x00; + kmem[2] = 0x00; + kmem[3] = 0x00; + + kmem = (uint8_t *)&gpKernelBase[0x0050059C]; + kmem[0] = 0x00; + kmem[1] = 0x00; + kmem[2] = 0x00; + kmem[3] = 0x00; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches-900.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-900.cpp new file mode 100644 index 0000000..202ad15 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches-900.cpp @@ -0,0 +1,8 @@ +#include "../../Common.hpp" +#include "../Resolver/Resolver.hpp" +#include "Patches.hpp" + +void Install_900() +{ + +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches.cpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches.cpp new file mode 100644 index 0000000..408ca41 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches.cpp @@ -0,0 +1,34 @@ +#include "../../Common.hpp" +#include "Patches.hpp" +#include "../Resolver/Resolver.hpp" + +// +// Credits to Mira for the patches. Was just easier to slap them in :P +// + +void Install_Patches() +{ + if(!gpKernelBase) + return; + + klog("Disable WP"); + cpu_disable_wp(); + + #if defined(SOFTWARE_VERSION_505) || defined(SOFTWARE_VERSION_NA) + klog("Patches 5.05"); + Install_505(); + #elif defined(SOFTWARE_VERSION_672) + Install_672(); + #elif defined(SOFTWARE_VERSION_702) + Install_702(); + #elif defined(SOFTWARE_VERSION_755) + Install_755(); + #elif defined(SOFTWARE_VERSION_900) + Install_900(); + #endif + + klog("Enable WP"); + cpu_enable_wp(); + + klog("Install_Patches() -> Sucess!"); +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Patches/Patches.hpp b/Playstation/Kernel/Kernel/source/Util/Patches/Patches.hpp new file mode 100644 index 0000000..7d9fb46 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Patches/Patches.hpp @@ -0,0 +1,8 @@ +#pragma once + +void Install_505(); +void Install_672(); +void Install_702(); +void Install_755(); +void Install_900(); +void Install_Patches(); \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Proc.cpp b/Playstation/Kernel/Kernel/source/Util/Proc.cpp new file mode 100644 index 0000000..56b75e8 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Proc.cpp @@ -0,0 +1,248 @@ +#include "../Common.hpp" +#include "Proc.hpp" + +proc* GetCurrentGame() +{ + proc *allproc = *(proc**)allproc; + char TitleID[10]; + strcpy(TitleID, "N/A"); + + while (allproc != NULL) + { + if(strstr(allproc->titleId, "CUSA")) + break; + + allproc = allproc->p_list.le_next; + } + + return allproc; +} + +int get_proc_count() +{ + int count = 0; + proc *p = *(proc**)allproc; + + do { + count++; + } while ((p = p->p_list.le_next)); + + return count; +} + +proc *proc_find_by_name(const char *name) +{ + if (!name) { + return NULL; + } + + proc *p = *(proc**)allproc; + + do { + //klog("%s\n", p->p_comm); + if (!memcmp(p->p_comm, name, strlen(name))) { + return p; + } + } while ((p = p->p_list.le_next)); + + return NULL; +} + +proc *proc_find_by_pid(int pid) +{ + proc *p = *(proc**)allproc; + + do { + if (p->p_pid == pid) { + return p; + } + } while ((p = p->p_list.le_next)); + + return NULL; +} + +int proc_rw_mem(proc *p, void *ptr, size_t size, void *data, size_t *n, int write) +{ + thread *td = curthread(); + iovec iov; + uio uio; + int r = 0; + + if (!p) { + return 1; + } + + if (size == 0) { + if (n) { + *n = 0; + } + + return 0; + } + + memset(&iov, NULL, sizeof(iov)); + iov.iov_base = (void*)data; + iov.iov_len = size; + + memset(&uio, NULL, sizeof(uio)); + uio.uio_iov = &iov; + uio.uio_iovcnt = 1; + uio.uio_offset = (uint64_t)ptr; + uio.uio_resid = (uint64_t)size; + uio.uio_segflg = UIO_SYSSPACE; + uio.uio_rw = write ? UIO_WRITE : UIO_READ; + uio.uio_td = td; + + r = proc_rwmem(p, &uio); + + if (n) { + *n = (size_t)((uint64_t)size - uio.uio_resid); + } + + return r; +} + +int proc_read_mem(struct proc *p, void *ptr, size_t size, void *data, size_t *n) +{ + return proc_rw_mem(p, ptr, size, data, n, 0); +} + +int proc_write_mem(struct proc *p, void *ptr, size_t size, void *data, size_t *n) +{ + return proc_rw_mem(p, ptr, size, data, n, 1); +} + +int proc_allocate(struct proc *p, void **address, size_t size) { + uint64_t addr = NULL; + int r = 0; + + if (!address) + return 1; + + vmspace *vm = p->p_vmspace; + vm_map *map = &vm->vm_map; + + vm_map_lock(map, __FILE__, __LINE__); + + r = vm_map_findspace(map, NULL, size, &addr); + if (r) { + vm_map_unlock(map); + return r; + } + + r = vm_map_insert(map, NULL, NULL, addr, addr + size, VM_PROT_ALL, VM_PROT_ALL, 0); + + vm_map_unlock(map); + + if (r) + return r; + + if (address) { + *address = (void *)addr; + } + + return r; +} + +int proc_deallocate(proc *p, void *address, size_t size) { + int r = 0; + + vmspace *vm = p->p_vmspace; + vm_map *map = &vm->vm_map; + + vm_map_lock(map, __FILE__, __LINE__); + + r = vm_map_delete(map, (uint64_t)address, (uint64_t)address + size); + + vm_map_unlock(map); + + return r; +} + +int proc_mprotect(proc *p, void *address, void *end, int new_prot) { + int r = 0; + + uint64_t addr = (uint64_t)address; + uint64_t addrend = (uint64_t)end; + + vmspace *vm = p->p_vmspace; + vm_map *map = &vm->vm_map; + + r = vm_map_protect(map, addr, addrend, new_prot, 1); + r = vm_map_protect(map, addr, addrend, new_prot, 0); + + return r; +} + + +uint64_t proc_alloc_size(uint64_t p) +{ + uint64_t ldrsize = p; + ldrsize += (PAGE_SIZE - (ldrsize % PAGE_SIZE)); + return ldrsize; +} + +void proc_Jailbreak(proc* proc, Backup_Jail* jail) +{ + if(proc) + { + ucred* cred = proc->p_ucred; + filedesc* fd = proc->p_fd; + + if(!cred || !fd) + return; + + if(jail) + { + jail->cr_prison = cred->cr_prison; + jail->cr_uid = cred->cr_uid; + jail->cr_ruid = cred->cr_ruid; + jail->cr_rgid = cred->cr_rgid; + jail->cr_groups = cred->cr_groups[0]; + + jail->fd_jdir = fd->fd_jdir; + jail->fd_rdir = fd->fd_rdir; + } + + cred->cr_prison = *(prison**)prison0; + + cred->cr_uid = 0; + cred->cr_ruid = 0; + cred->cr_rgid = 0; + cred->cr_groups[0] = 0; + + /*thread* Cur = proc->p_threads.tqh_first; + while(Cur != nullptr) + { + Cur->td_ucred->cr_sceAuthID = 0x3801000000000013; + Cur->td_ucred->cr_sceCaps[0] = 0xffffffffffffffff; + Cur->td_ucred->cr_sceCaps[1] = 0xffffffffffffffff; + Cur = Cur->td_plist.tqe_next; + }*/ + + fd->fd_jdir = *(vnode**)rootvnode; + fd->fd_rdir = *(vnode**)rootvnode; + } +} + +void proc_RestoreJail(proc* proc, Backup_Jail jail) +{ + if(proc) + { + ucred* cred = proc->p_ucred; + filedesc* fd = proc->p_fd; + + if(!cred || !fd) + return; + + cred->cr_prison = jail.cr_prison; + cred->cr_uid = jail.cr_uid; + cred->cr_ruid = jail.cr_ruid; + cred->cr_rgid = jail.cr_rgid; + cred->cr_groups[0] = jail.cr_groups; + + fd->fd_jdir = jail.fd_jdir; + fd->fd_rdir = jail.fd_rdir; + } +} + diff --git a/Playstation/Kernel/Kernel/source/Util/Proc.hpp b/Playstation/Kernel/Kernel/source/Util/Proc.hpp new file mode 100644 index 0000000..d4c521a --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Proc.hpp @@ -0,0 +1,34 @@ +#pragma once + +extern "C" +{ + #include +} + +proc* GetCurrentGame(); +int get_proc_count(); +proc *proc_find_by_name(const char *name); +proc *proc_find_by_pid(int pid); + +int proc_rw_mem(proc *p, void *ptr, size_t size, void *data, size_t *n, int write); +int proc_read_mem(struct proc *p, void *ptr, size_t size, void *data, size_t *n); +int proc_write_mem(struct proc *p, void *ptr, size_t size, void *data, size_t *n); +int proc_allocate(struct proc *p, void **address, size_t size); +int proc_deallocate(proc *p, void *address, size_t size); +int proc_mprotect(proc *p, void *address, void *end, int new_prot); +uint64_t proc_alloc_size(uint64_t p); + +struct Backup_Jail +{ + prison* cr_prison; + uid_t cr_uid; + uid_t cr_ruid; + gid_t cr_rgid; + gid_t cr_groups; + + vnode* fd_jdir; + vnode* fd_rdir; +}; + +void proc_Jailbreak(proc* proc, Backup_Jail* jail); +void proc_RestoreJail(proc* proc, Backup_Jail jail); diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-505.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-505.hpp new file mode 100644 index 0000000..6f7b63b --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-505.hpp @@ -0,0 +1,139 @@ +#pragma once + +#ifdef SOFTWARE_VERSION_505 + +/* Util */ +#define addr_Xfast_syscall 0x1C0 +#define addr_sysvec 0x19BBCD0 +#define addr_kernel_map 0x1AC60E0 +#define addr_prison0 0x10986A0 +#define addr_rootvnode 0x22C1A70 +#define addr_copyin 0x001EA710 +#define addr_copyout 0x1EA630 + +/* STD Lib */ +#define addr_M_TEMP 0x14B4110 +#define addr_M_MOUNT 0x19BF300 +#define addr_malloc 0x10E250 +#define addr_free 0x10E460 +#define addr_memcpy 0x1EA530 +#define addr_memset 0x3205C0 +#define addr_memcmp 0x50AC0 +#define addr_strlen 0x3B71A0 +#define addr_strcpy 0x8F250 +#define addr_strncpy 0x3C0B0 +#define addr_strcmp 0x1D0FD0 +#define addr_strncmp 0x001B8FE0 +#define addr_strstr 0x17DFB0 +#define addr_sprintf 0x436280 +#define addr_snprintf 0x436350 +#define addr_vsprintf 0x436310 +#define addr_vprintf 0x4360B0 +#define addr_sscanf 0x175900 +#define addr_strdup 0x1C1C30 +#define addr_realloc 0x10E590 +#define addr_kprintf 0x436040 + +/* Kproc */ +#define addr_kproc_create 0x137DF0 +#define addr_kproc_exit 0x138060 +#define addr_kproc_resume 0x1381B0 +#define addr_kproc_shutdown 0x10DCA0 +#define addr_kproc_start 0x137D70 +#define addr_kproc_suspend 0x138110 +#define addr_kproc_suspend_check 0x138240 +#define addr_kproc_kthread_add 0x138B70 +#define addr_pause 0x3FB920 +#define addr_kthread_add 0x138360 +#define addr_kthread_exit 0x138640 +#define addr_kthread_suspend 0x0 +#define addr_kthread_suspend_check 0x138A60 +#define addr_kthread_set_affinity 0x138CC0 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x84C20 +#define addr_thr_initial_libkernel_web 0x84C20 +#define addr_thr_initial_libkernel_sys 0x89030 + +/* Proc */ +#define addr_allproc_lock 0x02382F98 +#define addr_allproc 0x2382FF8 +#define addr_proc_kill 0xD41C0 +#define addr_proc_rwmem 0x30D150 +#define addr_create_thread 0x1BE1F0 + +/* ptrace */ +#define addr_kptrace 0x30D8E0 +#define addr_kpsignal 0xD35F0 +#define addr_kwait 0x35590 +#define addr_kDelay 0x2A1C70 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x19EF90 +#define addr_vmspace_free 0x19EDC0 +#define addr_vm_map_lock_read 0x19F140 +#define addr_vm_map_unlock_read 0x19F190 +#define addr_vm_map_lookup_entry 0x19F760 +#define addr_vm_map_findspace 0x1A1F60 +#define addr_vm_map_insert 0x1A0280 +#define addr_vm_map_lock 0x19EFF0 +#define addr_vm_map_unlock 0x19F060 +#define addr_vm_map_delete 0x1A19D0 +#define addr_vm_map_protect 0x1A3A50 + +/*Mutex Locks*/ +#define addr_mtx_init 0x402780 +#define addr_mtx_destroy 0x4027F0 +#define addr_mtx_lock_flags 0x401CD0 +#define addr_mtx_unlock_flags 0x401FA0 + +#define addr__sx_slock 0x000F5C30 +#define addr__sx_sunlock 0x000F5F10 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x28E7A0 +#define addr_ExitCriticalSection 0x28E7B0 + +/* Event Handling */ +#define addr_eventhandler_register 0x1EC400 +#define addr_eventhandler_deregister 0x1EC790 +#define addr_eventhandler_find_list 0x1EC980 + +/* Trap Hooks */ +#define addr_trapHook 0x170E80 +#define addr_trap_fatalHook 0x171580 + +/* FileIO */ +#define addr_kern_open 0x33B9B0 +#define addr_kern_mkdir 0x340B70 + +/* Registry Functions */ +#define addr_sceRegMgrGetStr 0x4FA550 +#define addr_sceRegMgrSetStr 0x4FA390 +#define addr_sceRegMgrGetInt 0x4F9E50 +#define addr_sceRegMgrSetInt 0x4F8D10 +#define addr_sceRegMgrGetBin 0x4FA6D0 +#define addr_sceRegMgrSetBin 0x4FA620 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x395830 +#define addr_icc_nvs_write 0x395670 + +/* Driver */ +#define addr_make_dev_p 0x1B9810 +#define addr_destroy_dev 0x1B9D50 + +/* kmem */ +#define addr_kmem_alloc 0xFCC80 +#define addr_kmem_free 0xFCE50 +#define addr_kernel_map 0x1AC60E0 + +/* File IO */ +#define addr_vn_fullpath 0xA11A0 +#define addr_kern_rmdir 0x340EE0 +#define addr_kern_mkdir 0x340B70 +#define addr_kern_open 0x33B9B0 +#define addr_kern_mount 0x1E1920 +#define addr_mount_argf 0x1E1780 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-672.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-672.hpp new file mode 100644 index 0000000..18ac240 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-672.hpp @@ -0,0 +1,135 @@ +#pragma once + +#if defined(SOFTWARE_VERSION_672) + +/* Util */ +#define addr_Xfast_syscall 0x1C0 +#define addr_sysvec 0x1A8A398 +#define addr_kernel_map 0x220DFC0 +#define addr_prison0 0x113E518 +#define addr_rootvnode 0x2300320 +#define addr_copyin 0x3C17A0 +#define addr_copyout 0x3C16B0 + +/* STD Lib */ +#define addr_M_TEMP 0x1540EB0 +#define addr_M_MOUNT 0x1A90CA0 +#define addr_malloc 0xD7A0 +#define addr_free 0xD9A0 +#define addr_memcpy 0x3C15B0 +#define addr_memset 0x1687D0 +#define addr_memcmp 0x207E40 +#define addr_strlen 0x2433E0 +#define addr_strcpy 0x2390C0 +#define addr_strncpy 0x329010 +#define addr_strcmp 0x341810 +#define addr_strncmp 0x39B6E0 +#define addr_strstr 0x4817F0 +#define addr_sprintf 0x1234C0 +#define addr_snprintf 0x123590 +#define addr_vsprintf 0x123550 +#define addr_vprintf 0x1232F0 +#define addr_sscanf 0x243810 +#define addr_strdup 0x2504C0 +#define addr_realloc 0xDAD0 +#define addr_kprintf 0x123280 + +/* Kproc */ +#define addr_kproc_create 0x8A0A0 +#define addr_kproc_exit 0x8A310 +#define addr_kproc_resume 0x8A460 +#define addr_kproc_shutdown 0x207670 +#define addr_kproc_start 0x8A020 +#define addr_kproc_suspend 0x8A3C0 +#define addr_kproc_suspend_check 0x8A4F0 +#define addr_kproc_kthread_add 0x8AE20 +#define addr_pause 0x22A080 +#define addr_kthread_add 0x8A600 +#define addr_kthread_exit 0x8A8F0 +#define addr_kthread_suspend 0x8AA40 +#define addr_kthread_suspend_check 0x8AD10 +#define addr_kthread_set_affinity 0x8AF70 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x435420 +#define addr_thr_initial_libkernel_web 0x435420 +#define addr_thr_initial_libkernel_sys 0x435830 + +/* Proc */ +#define addr_allproc_lock 0x0 +#define addr_allproc 0x22BBE80 +#define addr_proc_kill 0x2DC80 +#define addr_proc_rwmem 0x10EE10 +#define addr_create_thread 0x4A6FB0 + +/* ptrace */ +#define addr_kptrace 0x10F7A0 +#define addr_kpsignal 0x1CF510 +#define addr_kwait 0x406950 +#define addr_kDelay 0x2F9DE0 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x44CB90 +#define addr_vmspace_free 0x44C9C0 +#define addr_vm_map_lock_read 0x44CD40 +#define addr_vm_map_unlock_read 0x44CD90 +#define addr_vm_map_lookup_entry 0x44D330 +#define addr_vm_map_findspace 0x44FE60 +#define addr_vm_map_insert 0x44DEF0 +#define addr_vm_map_lock 0x44CBF0 +#define addr_vm_map_unlock 0x44CC60 +#define addr_vm_map_delete 0x44F8A0 +#define addr_vm_map_protect 0x451BF0 + +/*Mutex Locks*/ +#define addr_mtx_init 0x00496FE0 +#define addr_mtx_destroy 0x00497050 +#define addr_mtx_lock_flags 0x00496540 +#define addr_mtx_unlock_flags 0x00496810 + +#define addr__sx_slock 0x0 +#define addr__sx_sunlock 0x0 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x2AA0A0 +#define addr_ExitCriticalSection 0x2AA0B0 + +/* Event Handling */ +#define addr_eventhandler_register 0x402E80 +#define addr_eventhandler_deregister 0x403220 +#define addr_eventhandler_find_list 0x403420 + +/* Trap Hooks */ +#define addr_trapHook 0 +#define addr_trap_fatalHook 0x2ED2E0 + +/* Registry */ +#define addr_sceRegMgrGetStr 0x509220 +#define addr_sceRegMgrSetStr 0x509060 +#define addr_sceRegMgrGetInt 0x508A60 +#define addr_sceRegMgrSetInt 0x5077D0 +#define addr_sceRegMgrGetBin 0x5093A0 +#define addr_sceRegMgrSetBin 0x5092F0 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x464450 +#define addr_icc_nvs_write 0x464290 + +/* Driver */ +#define addr_make_dev_p 0x0 +#define addr_destroy_dev 0x0 + +/* kmem */ +#define addr_kmem_alloc 0x0 +#define addr_kmem_free 0x0 +#define addr_kernel_map 0x0 + +/* File IO */ +#define addr_vn_fullpath 0x2F0C40 +#define addr_kern_rmdir 0x4A3DF0 +#define addr_kern_mkdir 0x4A3A80 +#define addr_kern_open 0x49E990 +#define addr_kern_mount 0x442F90 +#define addr_mount_argf 0x442DE0 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-702.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-702.hpp new file mode 100644 index 0000000..ef3a8ec --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-702.hpp @@ -0,0 +1,137 @@ +#pragma once + +#if defined(SOFTWARE_VERSION_702) + +/* Util */ +#define addr_Xfast_syscall 0x0 +#define addr_sysvec 0x0 +#define addr_kernel_map 0x0 +#define addr_prison0 0x0 +#define addr_rootvnode 0x0 +#define addr_copyin 0x0 +#define addr_copyout 0x0 + +/* STD Lib */ +#define addr_M_TEMP 0x0 +#define addr_M_MOUNT 0x0 +#define addr_malloc 0x0 +#define addr_free 0x0 +#define addr_memcpy 0x0 +#define addr_memset 0x0 +#define addr_memcmp 0x0 +#define addr_strlen 0x0 +#define addr_strcpy 0x0 +#define addr_strncpy 0x0 +#define addr_strcmp 0x0 +#define addr_strncmp 0x0 +#define addr_strstr 0x0 +#define addr_sprintf 0x0 +#define addr_snprintf 0x0 +#define addr_vsprintf 0x0 +#define addr_vprintf 0x0 +#define addr_sscanf 0x0 +#define addr_strdup 0x0 +#define addr_realloc 0x0 +#define addr_kprintf 0x0 + +#define addr_kmem_alloc 0x0 + +/* Kproc */ +#define addr_kproc_create 0x0 +#define addr_kproc_exit 0x0 +#define addr_kproc_resume 0x0 +#define addr_kproc_shutdown 0x0 +#define addr_kproc_start 0x0 +#define addr_kproc_suspend 0x0 +#define addr_kproc_suspend_check 0x0 +#define addr_kproc_kthread_add 0x0 +#define addr_pause 0x0 +#define addr_kthread_add 0x0 +#define addr_kthread_exit 0x0 +#define addr_kthread_suspend 0x0 +#define addr_kthread_suspend_check 0x0 +#define addr_kthread_set_affinity 0x0 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x8D420 +#define addr_thr_initial_libkernel_web 0x8D420 +#define addr_thr_initial_libkernel_sys 0x8D830 + +/* Proc */ +#define addr_allproc_lock 0x0 +#define addr_allproc 0x0 +#define addr_proc_kill 0x0 +#define addr_proc_rwmem 0x0 +#define addr_create_thread 0x0 + +/* ptrace */ +#define addr_kptrace 0x0 +#define addr_kpsignal 0x0 +#define addr_kwait 0x0 +#define addr_kDelay 0x0 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x0 +#define addr_vmspace_free 0x0 +#define addr_vm_map_lock_read 0x0 +#define addr_vm_map_unlock_read 0x0 +#define addr_vm_map_lookup_entry 0x0 +#define addr_vm_map_findspace 0x0 +#define addr_vm_map_insert 0x0 +#define addr_vm_map_lock 0x0 +#define addr_vm_map_unlock 0x0 +#define addr_vm_map_delete 0x0 +#define addr_vm_map_protect 0x0 + +/*Mutex Locks*/ +#define addr_mtx_init 0x0 +#define addr_mtx_destroy 0x0 +#define addr_mtx_lock_flags 0x0 +#define addr_mtx_unlock_flags 0x0 + +#define addr__sx_slock 0x0 +#define addr__sx_sunlock 0x0 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x0 +#define addr_ExitCriticalSection 0x0 + +/* Event Handling */ +#define addr_eventhandler_register 0x0 +#define addr_eventhandler_deregister 0x0 +#define addr_eventhandler_find_list 0x0 + +/* Trap Hooks */ +#define addr_trapHook 0x0 +#define addr_trap_fatalHook 0x0 + +/* Registry Functions */ +#define addr_sceRegMgrGetStr 0x0 +#define addr_sceRegMgrSetStr 0x0 +#define addr_sceRegMgrGetInt 0x0 +#define addr_sceRegMgrSetInt 0x0 +#define addr_sceRegMgrGetBin 0x0 +#define addr_sceRegMgrSetBin 0x0 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x0 +#define addr_icc_nvs_write 0x0 + +/* Driver */ +#define addr_make_dev_p 0x0 +#define addr_destroy_dev 0x0 + +/* kmem */ +#define addr_kmem_alloc 0x0 +#define addr_kmem_free 0x0 +#define addr_kernel_map 0x0 + +/* File IO */ +#define addr_vn_fullpath 0x15F470 +#define addr_kern_rmdir 0x35ADE0 +#define addr_kern_mkdir 0x35AA60 +#define addr_kern_open 0x355960 +#define addr_kern_mount 0x299080 +#define addr_mount_argf 0x298ED0 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-755.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-755.hpp new file mode 100644 index 0000000..0f1546e --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-755.hpp @@ -0,0 +1,137 @@ +#pragma once + +#if defined(SOFTWARE_VERSION_755) + +/* Util */ +#define addr_Xfast_syscall 0x0 +#define addr_sysvec 0x0 +#define addr_kernel_map 0x0 +#define addr_prison0 0x0 +#define addr_rootvnode 0x0 +#define addr_copyin 0x0 +#define addr_copyout 0x0 + +/* STD Lib */ +#define addr_M_TEMP 0x0 +#define addr_M_MOUNT 0x0 +#define addr_malloc 0x0 +#define addr_free 0x0 +#define addr_memcpy 0x0 +#define addr_memset 0x0 +#define addr_memcmp 0x0 +#define addr_strlen 0x0 +#define addr_strcpy 0x0 +#define addr_strncpy 0x0 +#define addr_strcmp 0x0 +#define addr_strncmp 0x0 +#define addr_strstr 0x0 +#define addr_sprintf 0x0 +#define addr_snprintf 0x0 +#define addr_vsprintf 0x0 +#define addr_vprintf 0x0 +#define addr_sscanf 0x0 +#define addr_strdup 0x0 +#define addr_realloc 0x0 +#define addr_kprintf 0x0 + +#define addr_kmem_alloc 0x0 + +/* Kproc */ +#define addr_kproc_create 0x0 +#define addr_kproc_exit 0x0 +#define addr_kproc_resume 0x0 +#define addr_kproc_shutdown 0x0 +#define addr_kproc_start 0x0 +#define addr_kproc_suspend 0x0 +#define addr_kproc_suspend_check 0x0 +#define addr_kproc_kthread_add 0x0 +#define addr_pause 0x0 +#define addr_kthread_add 0x0 +#define addr_kthread_exit 0x0 +#define addr_kthread_suspend 0x0 +#define addr_kthread_suspend_check 0x0 +#define addr_kthread_set_affinity 0x0 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x8D420 +#define addr_thr_initial_libkernel_web 0x8D420 +#define addr_thr_initial_libkernel_sys 0x8D830 + +/* Proc */ +#define addr_allproc_lock 0x0 +#define addr_allproc 0x0 +#define addr_proc_kill 0x0 +#define addr_proc_rwmem 0x0 +#define addr_create_thread 0x0 + +/* ptrace */ +#define addr_kptrace 0x0 +#define addr_kpsignal 0x0 +#define addr_kwait 0x0 +#define addr_kDelay 0x0 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x0 +#define addr_vmspace_free 0x0 +#define addr_vm_map_lock_read 0x0 +#define addr_vm_map_unlock_read 0x0 +#define addr_vm_map_lookup_entry 0x0 +#define addr_vm_map_findspace 0x0 +#define addr_vm_map_insert 0x0 +#define addr_vm_map_lock 0x0 +#define addr_vm_map_unlock 0x0 +#define addr_vm_map_delete 0x0 +#define addr_vm_map_protect 0x0 + +/*Mutex Locks*/ +#define addr_mtx_init 0x0 +#define addr_mtx_destroy 0x0 +#define addr_mtx_lock_flags 0x0 +#define addr_mtx_unlock_flags 0x0 + +#define addr__sx_slock 0x0 +#define addr__sx_sunlock 0x0 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x0 +#define addr_ExitCriticalSection 0x0 + +/* Event Handling */ +#define addr_eventhandler_register 0x0 +#define addr_eventhandler_deregister 0x0 +#define addr_eventhandler_find_list 0x0 + +/* Trap Hooks */ +#define addr_trapHook 0x0 +#define addr_trap_fatalHook 0x0 + +/* Registry Functions */ +#define addr_sceRegMgrGetStr 0x0 +#define addr_sceRegMgrSetStr 0x0 +#define addr_sceRegMgrGetInt 0x0 +#define addr_sceRegMgrSetInt 0x0 +#define addr_sceRegMgrGetBin 0x0 +#define addr_sceRegMgrSetBin 0x0 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x0 +#define addr_icc_nvs_write 0x0 + +/* Driver */ +#define addr_make_dev_p 0x0 +#define addr_destroy_dev 0x0 + +/* kmem */ +#define addr_kmem_alloc 0x0 +#define addr_kmem_free 0x0 +#define addr_kernel_map 0x0 + +/* File IO */ +#define addr_vn_fullpath 0x2C3570 +#define addr_kern_rmdir 0xF9E90 +#define addr_kern_mkdir 0xF9B10 +#define addr_kern_open 0xF49E0 +#define addr_kern_mount 0x790D0 +#define addr_mount_argf 0x78F20 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-900.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-900.hpp new file mode 100644 index 0000000..dfea33f --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-900.hpp @@ -0,0 +1,137 @@ +#pragma once + +#pragma once + +#if defined(SOFTWARE_VERSION_900) + +/* Util */ +#define addr_Xfast_syscall 0x000001C0 +#define addr_sysvec 0x01528E30 +#define addr_kernel_map 0x02268D48 +#define addr_prison0 0x0111F870 +#define addr_rootvnode 0x021EFF20 +#define addr_copyin 0x002716A0 +#define addr_copyout 0x002715B0 + +/* STD Lib */ +#define addr_M_TEMP 0x015621E0 +#define addr_M_MOUNT 0x015279F0 +#define addr_malloc 0x00301B20 +#define addr_free 0x00301CE0 +#define addr_memcpy 0x002714B0 +#define addr_memset 0x001496C0 +#define addr_memcmp 0x00271E20 +#define addr_strlen 0x0030F450 +#define addr_strcpy 0x00189F80 +#define addr_strncpy 0x0041E380 +#define addr_strcmp 0x0040E700 +#define addr_strncmp 0x00124750 +#define addr_strstr 0x00487AB0 +#define addr_sprintf 0x000B7C70 +#define addr_snprintf 0x000B7D30 +#define addr_vsprintf 0x000B7D00 +#define addr_vprintf 0x000B7AA0 +#define addr_sscanf 0x0026C8D0 +#define addr_strdup 0x00278540 +#define addr_realloc 0x00301DE0 +#define addr_kprintf 0x000B7A30 + +/* Kproc */ +#define addr_kproc_create 0x000969E0 +#define addr_kproc_exit 0x00096C50 +#define addr_kproc_resume 0x00096DA0 +#define addr_kproc_shutdown 0x0029AC80 +#define addr_kproc_start 0x00096960 +#define addr_kproc_suspend 0x00096D00 +#define addr_kproc_suspend_check 0x00096E30 +#define addr_kproc_kthread_add 0x00097750 +#define addr_pause 0x00453EA0 +#define addr_kthread_add 0x00096F40 +#define addr_kthread_exit 0x00097230 +#define addr_kthread_suspend 0x0 +#define addr_kthread_suspend_check 0x00097640 +#define addr_kthread_set_affinity 0x000978A0 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x0008E430 +#define addr_thr_initial_libkernel_web 0x0008E430 +#define addr_thr_initial_libkernel_sys 0x0008E830 + +/* Proc */ +#define addr_allproc_lock 0x01B94680 +#define addr_allproc 0x01B946E0 +#define addr_proc_kill 0x00029780 +#define addr_proc_rwmem 0x0041EB00 +#define addr_create_thread 0x001ED670 + +/* ptrace */ +#define addr_kptrace 0x0041F410 +#define addr_kpsignal 0x002F9BA0 +#define addr_kwait 0x00174110 +#define addr_kDelay 0x0018A6B0 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x0007B9E0 +#define addr_vmspace_free 0x0007B810 +#define addr_vm_map_lock_read 0x0007BB80 +#define addr_vm_map_unlock_read 0x0007BBD0 +#define addr_vm_map_lookup_entry 0x0007C1C0 +#define addr_vm_map_findspace 0x0007EC40 +#define addr_vm_map_insert 0x0007CD80 +#define addr_vm_map_lock 0x0007BA30 +#define addr_vm_map_unlock 0x0007BAA0 +#define addr_vm_map_delete 0x0007E680 +#define addr_vm_map_protect 0x000809C0 + +/*Mutex Locks*/ +#define addr_mtx_init 0x002EF960 +#define addr_mtx_destroy 0x002EF9D0 +#define addr_mtx_lock_flags 0x002EEEB0 +#define addr_mtx_unlock_flags 0x002EF170 + +#define addr__sx_slock 0x0043E1A0 +#define addr__sx_sunlock 0x0043E710 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x0 +#define addr_ExitCriticalSection 0x0 + +/* Event Handling */ +#define addr_eventhandler_register 0x000F8370 +#define addr_eventhandler_deregister 0x000F8700 +#define addr_eventhandler_find_list 0x000F88F0 + +/* Trap Hooks */ +#define addr_trapHook 0x0 +#define addr_trap_fatalHook 0x0 + +/* Registry Functions */ +#define addr_sceRegMgrGetStr 0x004EA5F0 +#define addr_sceRegMgrSetStr 0x004F65B5 +#define addr_sceRegMgrGetInt 0x004E9DD0 +#define addr_sceRegMgrSetInt 0x004E8B10 +#define addr_sceRegMgrGetBin 0x004EA770 +#define addr_sceRegMgrSetBin 0x004EA6C0 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x0010B310 +#define addr_icc_nvs_write 0x0 + +/* Driver */ +#define addr_make_dev_p 0x001EF590 +#define addr_destroy_dev 0x001EFAB0 + +/* kmem */ +#define addr_kmem_alloc 0x0037BE70 +#define addr_kmem_free 0x0037C040 +#define addr_kernel_map 0x02268D48 + +/* File IO */ +#define addr_vn_fullpath 0x002648C0 +#define addr_kern_rmdir 0x001DF3A0 +#define addr_kern_mkdir 0x001DF020 +#define addr_kern_open 0x001D9EE0 +#define addr_kern_mount 0x0004DF50 +#define addr_mount_argf 0x0004DDB0 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-NA.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-NA.hpp new file mode 100644 index 0000000..c546107 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Offsets/Offsets-NA.hpp @@ -0,0 +1,136 @@ +#pragma once + +#if defined(SOFTWARE_VERSION_NA) + +/* Util */ +#define addr_Xfast_syscall 0x0 +#define addr_sysvec 0x0 +#define addr_kernel_map 0x0 +#define addr_prison0 0x0 +#define addr_rootvnode 0x0 +#define addr_copyin 0x0 +#define addr_copyout 0x0 + +/* STD Lib */ +#define addr_M_TEMP 0x0 +#define addr_M_MOUNT 0x0 +#define addr_malloc 0x0 +#define addr_free 0x0 +#define addr_memcpy 0x0 +#define addr_memset 0x0 +#define addr_memcmp 0x0 +#define addr_strlen 0x0 +#define addr_strcpy 0x0 +#define addr_strncpy 0x0 +#define addr_strcmp 0x0 +#define addr_strstr 0x0 +#define addr_sprintf 0x0 +#define addr_snprintf 0x0 +#define addr_vsprintf 0x0 +#define addr_vprintf 0x0 +#define addr_sscanf 0x0 +#define addr_strdup 0x0 +#define addr_realloc 0x0 +#define addr_kprintf 0x0 + +#define addr_kmem_alloc 0x0 + +/* Kproc */ +#define addr_kproc_create 0x0 +#define addr_kproc_exit 0x0 +#define addr_kproc_resume 0x0 +#define addr_kproc_shutdown 0x0 +#define addr_kproc_start 0x0 +#define addr_kproc_suspend 0x0 +#define addr_kproc_suspend_check 0x0 +#define addr_kproc_kthread_add 0x0 +#define addr_pause 0x0 +#define addr_kthread_add 0x0 +#define addr_kthread_exit 0x0 +#define addr_kthread_suspend 0x0 +#define addr_kthread_suspend_check 0x0 +#define addr_kthread_set_affinity 0x0 + +/* Module Offsets */ +#define addr_thr_initial_libkernel 0x0 +#define addr_thr_initial_libkernel_web 0x0 +#define addr_thr_initial_libkernel_sys 0x0 + +/* Proc */ +#define addr_allproc_lock 0x0 +#define addr_allproc 0x0 +#define addr_proc_kill 0x0 +#define addr_proc_rwmem 0x0 +#define addr_create_thread 0x0 + +/* ptrace */ +#define addr_kptrace 0x0 +#define addr_kpsignal 0x0 +#define addr_kwait 0x0 +#define addr_kDelay 0x0 + +/* Virtual Memory */ +#define addr_vmspace_acquire_ref 0x0 +#define addr_vmspace_free 0x0 +#define addr_vm_map_lock_read 0x0 +#define addr_vm_map_unlock_read 0x0 +#define addr_vm_map_lookup_entry 0x0 +#define addr_vm_map_findspace 0x0 +#define addr_vm_map_insert 0x0 +#define addr_vm_map_lock 0x0 +#define addr_vm_map_unlock 0x0 +#define addr_vm_map_delete 0x0 +#define addr_vm_map_protect 0x0 + +/*Mutex Locks*/ +#define addr_mtx_init 0x0 +#define addr_mtx_destroy 0x0 +#define addr_mtx_lock_flags 0x0 +#define addr_mtx_unlock_flags 0x0 + +#define addr__sx_slock 0x0 +#define addr__sx_sunlock 0x0 + +/* Critical Sections */ +#define addr_EnterCriticalSection 0x0 +#define addr_ExitCriticalSection 0x0 + +/* Event Handling */ +#define addr_eventhandler_register 0x0 +#define addr_eventhandler_deregister 0x0 +#define addr_eventhandler_find_list 0x0 + +/* Trap Hooks */ +#define addr_trapHook 0x0 +#define addr_trap_fatalHook 0x0 + +/* Registry Functions */ +#define addr_sceRegMgrGetStr 0x0 +#define addr_sceRegMgrSetStr 0x0 +#define addr_sceRegMgrGetInt 0x0 +#define addr_sceRegMgrSetInt 0x0 +#define addr_sceRegMgrGetBin 0x0 +#define addr_sceRegMgrSetBin 0x0 + +/* Flash & NVS */ +#define addr_icc_nvs_read 0x0 +#define addr_icc_nvs_write 0x0 + +/* Driver */ +#define addr_make_dev_p 0x0 +#define addr_destroy_dev 0x0 + +/* kmem */ +#define addr_kmem_alloc 0x0 +#define addr_kmem_free 0x0 +#define addr_kernel_map 0x0 + +/* File IO */ +#define addr_vn_fullpath 0x0 +#define addr_kern_rmdir 0x0 +#define addr_kern_mkdir 0x0 +#define addr_kern_open 0x0 +#define addr_kern_mount 0x0 +#define addr_mount_argf 0x0 + +#endif \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.cpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.cpp new file mode 100644 index 0000000..b5e1789 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.cpp @@ -0,0 +1,252 @@ +#include "../../Common.hpp" +#include "Resolver.hpp" +#include "../ASM.h" + +uint8_t* gpKernelBase = nullptr; + +/* Util */ +sysentvec* sysvec = nullptr; +prison* prison0 = nullptr; +vnode* rootvnode = nullptr; +int (*copyout)(const void *kaddr, void *udaddr, size_t len) = nullptr; +int (*copyin)(const void *uaddr, void *kaddr, size_t len) = nullptr; + +/* STD Lib */ +void *M_TEMP = nullptr; +void* M_MOUNT = nullptr; +void *(*malloc)(unsigned long size, void *type, int flags) = nullptr; +void (*free)(void *addr, void *type) = nullptr; +void (*memcpy)(void *dst, const void *src, size_t len) = nullptr; +void *(*memset)(void *ptr, int value, size_t num) = nullptr; +int (*memcmp)(const void *ptr1, const void *ptr2, size_t num) = nullptr; +size_t (*strlen)(const char *str) = nullptr; +int (*strcpy)(char * str1, char * str2) = nullptr; +char* (*strncpy)(char *destination, const char *source, size_t num) = nullptr; +int (*strcmp)(const char * str1, const char * str2) = nullptr; +int (*strncmp)(const char * str1, const char * str2, size_t) = nullptr; +char* (*strstr)(const char * str1, const char * str2) = nullptr; +int (*sprintf)(char* dst, const char *fmt, ...) = nullptr; +int (*snprintf)(char *str, size_t size, const char *format, ...) = nullptr; +int (*vsprintf)(char* dst, const char* fmt, va_list ap) = nullptr; +int (*vprintf)(const char *fmt, va_list arg) = nullptr; +int(*sscanf)(const char *str, const char *format, ...) = nullptr; +char *(*strdup)(const char *s, void* type) = nullptr; +char *(*realloc)(void *addr, unsigned long size, void* mtp, int flags) = nullptr; +void(*kprintf)(const char* fmt, ...) = nullptr; + +/* Kproc */ +int (*kproc_create)(void (*func)(void *), void *arg, struct proc **newpp, int flags, int pages, const char *fmt, ...) = nullptr; +int (*kproc_exit)(int code) = nullptr; +//kproc_resume +//kproc_shutdown +//kproc_start +//kproc_suspend +//kproc_suspend_check +int (*kproc_kthread_add)(void (*func)(void *), void *arg, struct proc **procptr, struct thread **tdptr, int flags, int pages, char * procname, const char *fmt, ...) = nullptr; +void (*pause)(const char *wmesg, int timo) = nullptr; +int (*kthread_add)(void (*func)(void *), void *arg, struct proc *procp, struct thread **newtdpp, int flags, int pages, const char *fmt, ...) = nullptr; +void (*kthread_exit)(void) = nullptr; +//void (*kthread_suspend)(thread *td, int timo); +void (*kthread_suspend_check)(void) = nullptr; +void (*kthread_set_affinity)(const char *tdname, uint64_t prio, uint64_t cpuset, uint64_t unknown) = nullptr; + +/* Proc */ +sx* allproc_lock = nullptr; +proc *allproc = nullptr; +int (*proc_kill)(proc *p, char* why) = nullptr; +int (*proc_rwmem)(proc *p, uio *uio) = nullptr; +int (*create_thread)(thread * td, uint64_t ctx, void* start_func, void *arg, char *stack_base, size_t stack_size, char *tls_base, long * child_tid, long * parent_tid, uint64_t flags, uint64_t rtp) = nullptr; + +/* ptrace */ +int (*kptrace)(thread * td, int req, int pid, void * addr, int data) = nullptr; +int (*kpsignal)(proc* proc, int sig) = nullptr; +int (*kwait)(thread *td, int wpid, int *status, int options, void *rusage) = nullptr; +int (*kDelay)(uint64_t time) = nullptr; + +/* Virtual memory */ +vmspace *(*vmspace_acquire_ref)(proc *p) = nullptr; +void (*vmspace_free)(vmspace* vm) = nullptr; +void (*vm_map_lock_read)(vm_map* map) = nullptr; +void (*vm_map_unlock_read)(vm_map* map) = nullptr; +int (*vm_map_lookup_entry)(vm_map* map, uint64_t address, vm_map_entry **entries) = nullptr; +int (*vm_map_findspace)(vm_map* map, uint64_t start, uint64_t length, uint64_t *addr) = nullptr; +int (*vm_map_insert)(vm_map* map, uint64_t object, uint64_t offset, uint64_t start, uint64_t end, int prot, int max, int cow) = nullptr; +void (*vm_map_lock)(vm_map* map, const char* file, int line) = nullptr; +void (*vm_map_unlock)(vm_map* map) = nullptr; +int (*vm_map_delete)(vm_map* map, uint64_t start, uint64_t end) = nullptr; +int (*vm_map_protect)(vm_map* map, uint64_t start, uint64_t end, int new_prot, uint64_t set_max) = nullptr; + +/*Mutex Locks*/ +void (*mtx_init)(mtx *m, const char *name, const char *type, int opts); +void (*mtx_destroy)(mtx *mutex); +void (*mtx_lock_flags)(mtx *mutex, int flags); +void (*mtx_unlock_flags)(mtx *mutex, int flags); +void (*_mtx_lock_flags)(mtx *mutex, int flags, const char *file, int line); +void (*_mtx_unlock_flags)(mtx *mutex, int flags, const char *file, int line); + +int (*_sx_slock)(sx *sx, int opts, const char *file, int line); +void (*_sx_sunlock)(sx *sx, const char *file, int line); + +/*Critical Sections*/ +void (*EnterCriticalSection)() = nullptr; +void (*ExitCriticalSection)() = nullptr; + +/* Event Handling */ +#if defined(SOFTWARE_VERSION_505) || defined(SOFTWARE_VERSION_NA) +eventhandler_tag (*eventhandler_register)(eventhandler_list *list, const char *name, void *func, void *arg, int priority) = nullptr; +#endif +#if defined(SOFTWARE_VERSION_672) || defined(SOFTWARE_VERSION_702) || defined(SOFTWARE_VERSION_755) || defined(SOFTWARE_VERSION_900) //5.5X -> 9.00 +eventhandler_tag (*eventhandler_register)(eventhandler_list *list, const char *name, void *func, const char* unk, void *arg, int priority) = nullptr; +#endif +void (*eventhandler_deregister)(eventhandler_list* a, eventhandler_entry* b) = nullptr; +eventhandler_list* (*eventhandler_find_list)(const char *name) = nullptr; + +/* Flash & NVS */ +int (*icc_nvs_read)(uint32_t block, uint32_t offset, uint32_t size, uint8_t* value) = nullptr; +int (*icc_nvs_write)(uint32_t block, uint32_t offset, uint32_t size, uint8_t* value) = nullptr; + +/* Registry */ +int (*sceRegMgrGetStr)(uint64_t RegID, char* Value, int len) = nullptr; +int (*sceRegMgrSetStr)(uint64_t RegID, char* Value, int len) = nullptr; +int (*sceRegMgrGetInt)(uint64_t RegID, int32_t* Value) = nullptr; +int (*sceRegMgrSetInt)(uint64_t RegID, int32_t Value) = nullptr; +int (*sceRegMgrGetBin)(uint64_t RegID, char* Value, int size) = nullptr; +int (*sceRegMgrSetBin)(uint64_t RegID, char* Value, int size) = nullptr; + +/* Driver */ +int(*make_dev_p)(int _flags, cdev **_cdev, cdevsw *_devsw, ucred *_cr, uid_t _uid, gid_t _gid, int _mode, const char *_fmt, ...) = nullptr; +void(*destroy_dev)(cdev *_dev) = nullptr; + +/* kmem */ +vm_offset_t(*kmem_alloc)(vm_map_t map, vm_size_t size) = nullptr; +void(*kmem_free)(void* map, void* addr, size_t size) = nullptr; +vm_map_t kernel_map; + +/* FileIO */ +int (*vn_fullpath)(struct thread *td, struct vnode *vp, char **retbuf, char **freebuf) = nullptr; +int (*kern_rmdir)(thread* td, char *path, int flags) = nullptr; +int (*kern_mkdir)(thread* td, char *path, int pathseg, int mode) = nullptr; +int (*kern_open)(thread* td, char *path, int pathseg, int flags, int mode) = nullptr; +int (*kern_mount)(struct mntarg *ma, int flags) = nullptr; +struct mntarg*(*mount_argf)(struct mntarg *ma, const char *name, const char *fmt, ...) = nullptr; + +#define NATIVE_RESOLVE(_Ty) _Ty = (decltype(_Ty))(void*)((uint8_t *)&gpKernelBase[addr_ ## _Ty]); + +void ResolveFunctions() +{ + gpKernelBase = (uint8_t*)Readmsr(0xC0000082) - addr_Xfast_syscall; + + /* Util */ + NATIVE_RESOLVE(sysvec); + NATIVE_RESOLVE(prison0); + NATIVE_RESOLVE(rootvnode); + NATIVE_RESOLVE(copyin); + NATIVE_RESOLVE(copyout); + + /* STD Lib */ + NATIVE_RESOLVE(M_TEMP); + NATIVE_RESOLVE(M_MOUNT); + NATIVE_RESOLVE(malloc); + NATIVE_RESOLVE(free); + NATIVE_RESOLVE(memcpy); + NATIVE_RESOLVE(memset); + NATIVE_RESOLVE(memcmp); + NATIVE_RESOLVE(strlen); + NATIVE_RESOLVE(strcpy); + NATIVE_RESOLVE(strncpy); + NATIVE_RESOLVE(strcmp); + NATIVE_RESOLVE(strncmp); + NATIVE_RESOLVE(strstr); + NATIVE_RESOLVE(sprintf); + NATIVE_RESOLVE(snprintf); + NATIVE_RESOLVE(vsprintf); + NATIVE_RESOLVE(vprintf); + NATIVE_RESOLVE(sscanf); + NATIVE_RESOLVE(strdup); + NATIVE_RESOLVE(realloc); + NATIVE_RESOLVE(kprintf); + + /* Kproc */ + NATIVE_RESOLVE(kproc_create); + NATIVE_RESOLVE(kproc_exit); + NATIVE_RESOLVE(kproc_kthread_add); + NATIVE_RESOLVE(pause); + NATIVE_RESOLVE(kthread_add); + NATIVE_RESOLVE(kthread_exit); + NATIVE_RESOLVE(kthread_suspend_check); + NATIVE_RESOLVE(kthread_set_affinity); + + /* Proc */ + NATIVE_RESOLVE(allproc_lock); + NATIVE_RESOLVE(allproc); + NATIVE_RESOLVE(proc_kill); + NATIVE_RESOLVE(proc_rwmem); + NATIVE_RESOLVE(create_thread); + + /* ptrace */ + NATIVE_RESOLVE(kptrace); + NATIVE_RESOLVE(kpsignal); + NATIVE_RESOLVE(kwait); + NATIVE_RESOLVE(kDelay); + + /* Virtual Memory */ + NATIVE_RESOLVE(vmspace_acquire_ref); + NATIVE_RESOLVE(vmspace_free); + NATIVE_RESOLVE(vm_map_lock_read); + NATIVE_RESOLVE(vm_map_unlock_read); + NATIVE_RESOLVE(vm_map_lookup_entry); + NATIVE_RESOLVE(vm_map_findspace); + NATIVE_RESOLVE(vm_map_insert); + NATIVE_RESOLVE(vm_map_lock); + NATIVE_RESOLVE(vm_map_unlock); + NATIVE_RESOLVE(vm_map_delete); + NATIVE_RESOLVE(vm_map_protect); + + /*Mutex Locks*/ + NATIVE_RESOLVE(mtx_init); + NATIVE_RESOLVE(mtx_destroy); + NATIVE_RESOLVE(mtx_lock_flags); + NATIVE_RESOLVE(mtx_unlock_flags); + + NATIVE_RESOLVE(_sx_slock); + NATIVE_RESOLVE(_sx_sunlock); + + /* Critical Sections */ + NATIVE_RESOLVE(EnterCriticalSection); + NATIVE_RESOLVE(ExitCriticalSection); + + /* Event Handling */ + NATIVE_RESOLVE(eventhandler_register); + NATIVE_RESOLVE(eventhandler_deregister); + NATIVE_RESOLVE(eventhandler_find_list); + + /* Registry Functions */ + NATIVE_RESOLVE(sceRegMgrGetStr); + NATIVE_RESOLVE(sceRegMgrSetStr); + NATIVE_RESOLVE(sceRegMgrGetInt); + NATIVE_RESOLVE(sceRegMgrSetInt); + NATIVE_RESOLVE(sceRegMgrGetBin); + NATIVE_RESOLVE(sceRegMgrSetBin); + + /* Flash & NVS */ + NATIVE_RESOLVE(icc_nvs_read); + NATIVE_RESOLVE(icc_nvs_write); + + /* Driver */ + NATIVE_RESOLVE(make_dev_p); + NATIVE_RESOLVE(destroy_dev); + + /* kmem */ + NATIVE_RESOLVE(kmem_alloc); + NATIVE_RESOLVE(kmem_free); + NATIVE_RESOLVE(kernel_map); + + /* FileIO */ + NATIVE_RESOLVE(vn_fullpath); + NATIVE_RESOLVE(kern_rmdir); + NATIVE_RESOLVE(kern_mkdir); + NATIVE_RESOLVE(kern_open); + NATIVE_RESOLVE(kern_mount); + NATIVE_RESOLVE(mount_argf); + +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.hpp b/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.hpp new file mode 100644 index 0000000..0c645b8 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Resolver/Resolver.hpp @@ -0,0 +1,158 @@ +#pragma once +#include "../Settings.hpp" +#include "../../Common.hpp" + +#include "Offsets/Offsets-505.hpp" +#include "Offsets/Offsets-672.hpp" +#include "Offsets/Offsets-702.hpp" +#include "Offsets/Offsets-755.hpp" +#include "Offsets/Offsets-900.hpp" +#include "Offsets/Offsets-NA.hpp" + +extern "C" +{ + #include + #include +} + +extern uint8_t* gpKernelBase; + +/* Util */ +extern sysentvec* sysvec; +extern prison* prison0; +extern vnode* rootvnode; +extern int (*copyout)(const void *kaddr, void *udaddr, size_t len); +extern int (*copyin)(const void *uaddr, void *kaddr, size_t len); + +/* STD Lib */ +extern void *M_TEMP; +extern void* M_MOUNT; +extern void *(*malloc)(unsigned long size, void *type, int flags); +extern void (*free)(void *addr, void *type); +extern void (*memcpy)(void *dst, const void *src, size_t len); +extern void *(*memset)(void *ptr, int value, size_t num); +extern int (*memcmp)(const void *ptr1, const void *ptr2, size_t num); +extern size_t (*strlen)(const char *str); +extern int (*strcpy)(char * str1, char * str2); +extern char* (*strncpy)(char *destination, const char *source, size_t num); +extern int (*strcmp)(const char * str1, const char * str2); +extern int (*strncmp)(const char * str1, const char * str2, size_t); +extern char* (*strstr)(const char * str1, const char * str2); +extern int (*sprintf)(char* dst, const char *fmt, ...); +extern int (*snprintf)(char *str, size_t size, const char *format, ...); +extern int (*vsprintf)(char* dst, const char* fmt, va_list ap); +extern int (*vprintf)(const char *fmt, va_list arg); +extern int(*sscanf)(const char *str, const char *format, ...); +extern char *(*strdup)(const char *s, void* type); +extern char *(*realloc)(void *addr, unsigned long size, void* mtp, int flags); +extern void(*kprintf)(const char* fmt, ...); + +/* Kproc */ +extern int (*kproc_create)(void (*func)(void *), void *arg, proc **newpp, int flags, int pages, const char *fmt, ...); +extern int (*kproc_exit)(int code); +extern int (*kproc_kthread_add)(void (*func)(void *), void *arg, proc **procptr, thread **tdptr, int flags, int pages, char * procname, const char *fmt, ...); +extern void (*pause)(const char *wmesg, int timo); +extern int (*kthread_add)(void (*func)(void *), void *arg, proc *procp, thread **newtdpp, int flags, int pages, const char *fmt, ...); +extern void (*kthread_exit)(void); +extern void (*kthread_suspend_check)(void); +extern void (*kthread_set_affinity)(const char *tdname, uint64_t prio, uint64_t cpuset, uint64_t unknown); + +/* Proc */ +LIST_HEAD(proclist, proc); +extern sx* allproc_lock; +extern proc *allproc; +extern int (*proc_kill)(proc *p, char* why); +extern int (*proc_rwmem)(proc *p, uio *uio); +extern int (*create_thread)(thread * td, uint64_t ctx, void* start_func, void *arg, char *stack_base, size_t stack_size, char *tls_base, long * child_tid, long * parent_tid, uint64_t flags, uint64_t rtp); + +/* ptrace */ +extern int (*kptrace)(thread * td, int req, int pid, void * addr, int data); +extern int (*kpsignal)(proc* proc, int sig); +extern int (*kwait)(thread *td, int wpid, int *status, int options, void *rusage); +extern int (*kDelay)(uint64_t time); + +/* Virtual Memory */ +extern vmspace *(*vmspace_acquire_ref)(proc* p); +extern void (*vmspace_free)(vmspace* vm); +extern void (*vm_map_lock_read)(vm_map* map); +extern void (*vm_map_unlock_read)(vm_map* map); +extern int (*vm_map_lookup_entry)(vm_map* map, uint64_t address, vm_map_entry **entries); +extern int (*vm_map_findspace)(vm_map* map, uint64_t start, uint64_t length, uint64_t *addr); +extern int (*vm_map_insert)(vm_map* map, uint64_t object, uint64_t offset, uint64_t start, uint64_t end, int prot, int max, int cow); +extern void (*vm_map_lock)(vm_map* map, const char* file, int line); +extern void (*vm_map_unlock)(vm_map* map); +extern int (*vm_map_delete)(vm_map* map, uint64_t start, uint64_t end); +extern int (*vm_map_protect)(vm_map* map, uint64_t start, uint64_t end, int new_prot, uint64_t set_max); + +/*Mutex Locks*/ +extern void (*mtx_init)(mtx *m, const char *name, const char *type, int opts); +extern void (*mtx_destroy)(mtx *mutex); +extern void (*mtx_lock_flags)(mtx *mutex, int flags); +extern void (*mtx_unlock_flags)(mtx *mutex, int flags); +extern void (*_mtx_lock_flags)(mtx *mutex, int flags, const char *file, int line); +extern void (*_mtx_unlock_flags)(mtx *mutex, int flags, const char *file, int line); + +extern int (*_sx_slock)(sx *sx, int opts, const char *file, int line); +extern void (*_sx_sunlock)(sx *sx, const char *file, int line); + +/* Critical Sections */ +extern void (*EnterCriticalSection)(); +extern void (*ExitCriticalSection)(); + +/* Event Resolving */ +#if defined(SOFTWARE_VERSION_505) || defined(SOFTWARE_VERSION_NA) +extern eventhandler_tag (*eventhandler_register)(eventhandler_list *list, const char *name, void *func, void *arg, int priority); +#endif +#if defined(SOFTWARE_VERSION_672) || defined(SOFTWARE_VERSION_702) || defined(SOFTWARE_VERSION_755) || defined(SOFTWARE_VERSION_900) +extern eventhandler_tag (*eventhandler_register)(eventhandler_list *list, const char *name, void *func, const char* unk, void *arg, int priority); +#endif +extern void (*eventhandler_deregister)(eventhandler_list* a, eventhandler_entry* b); +extern eventhandler_list* (*eventhandler_find_list)(const char *name); + +#if defined(SOFTWARE_VERSION_505) || defined(SOFTWARE_VERSION_NA) +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ + eventhandler_register(NULL, #name, func, arg, priority) +#endif +#if defined(SOFTWARE_VERSION_672) || defined(SOFTWARE_VERSION_702) || defined(SOFTWARE_VERSION_755) || defined(SOFTWARE_VERSION_900) +#define EVENTHANDLER_REGISTER(name, func, arg, priority) \ + eventhandler_register(NULL, #name, func, "", arg, priority) +#endif + +#define EVENTHANDLER_DEREGISTER(name, tag) \ +do { \ + struct eventhandler_list *_el; \ + \ + if ((_el = eventhandler_find_list(#name)) != NULL) \ + eventhandler_deregister(_el, tag); \ +} while(0) + +/* Flash & NVS */ +extern int (*icc_nvs_read)(uint32_t block, uint32_t offset, uint32_t size, uint8_t* value); +extern int (*icc_nvs_write)(uint32_t block, uint32_t offset, uint32_t size, uint8_t* value); + +/* Registry */ +extern int (*sceRegMgrGetStr)(uint64_t RegID, char* Value, int len); +extern int (*sceRegMgrSetStr)(uint64_t RegID, char* Value, int len); +extern int (*sceRegMgrGetInt)(uint64_t RegID, int32_t* Value); +extern int (*sceRegMgrSetInt)(uint64_t RegID, int32_t Value); +extern int (*sceRegMgrGetBin)(uint64_t RegID, char* Value, int size); +extern int (*sceRegMgrSetBin)(uint64_t RegID, char* Value, int size); + +/* Driver */ +extern int(*make_dev_p)(int _flags, cdev **_cdev, cdevsw *_devsw, ucred *_cr, uid_t _uid, gid_t _gid, int _mode, const char *_fmt, ...); +extern void(*destroy_dev)(cdev *_dev); + +/* kmem */ +extern vm_offset_t(*kmem_alloc)(vm_map_t map, vm_size_t size); +extern void(*kmem_free)(void* map, void* addr, size_t size); +extern vm_map_t kernel_map; + +/* FileIO */ +extern int (*vn_fullpath)(struct thread *td, struct vnode *vp, char **retbuf, char **freebuf); +extern int (*kern_rmdir)(thread* td, char *path, int flags); +extern int (*kern_mkdir)(thread* td, char *path, int pathseg, int mode); +extern int (*kern_open)(thread* td, char *path, int pathseg, int flags, int mode); +extern int (*kern_mount)(struct mntarg *ma, int flags); +extern struct mntarg*(*mount_argf)(struct mntarg *ma, const char *name, const char *fmt, ...); + +void ResolveFunctions(); \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Settings.hpp b/Playstation/Kernel/Kernel/source/Util/Settings.hpp new file mode 100644 index 0000000..b634a4f --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Settings.hpp @@ -0,0 +1,32 @@ +#pragma once +#define KERNELDRIVER +#define KDRIVER_MAJOR_VERSION 1 +#define KDRIVER_MINOR_VERSION 0 +#define KDRIVER_BUILD_VERSION 699 +//Which software version we want to compile for +#define SOFTWARE_VERSION_NA +#ifdef VERSION_505 +#define SOFTWARE_VERSION_STR "5.05" +#define SOFTWARE_VERSION_505 +#undef SOFTWARE_VERSION_NA +#endif +#ifdef VERSION_672 +#define SOFTWARE_VERSION_STR "6.72" +#define SOFTWARE_VERSION_672 +#undef SOFTWARE_VERSION_NA +#endif +#ifdef VERSION_702 +#define SOFTWARE_VERSION_STR "7.02" +#define SOFTWARE_VERSION_702 +#undef SOFTWARE_VERSION_NA +#endif +#ifdef VERSION_755 +#define SOFTWARE_VERSION_STR "7.55" +#define SOFTWARE_VERSION_755 +#undef SOFTWARE_VERSION_NA +#endif +#ifdef VERSION_900 +#define SOFTWARE_VERSION_STR "9.00" +#define SOFTWARE_VERSION_900 +#undef SOFTWARE_VERSION_NA +#endif diff --git a/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.cpp b/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.cpp new file mode 100644 index 0000000..5ce313d --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.cpp @@ -0,0 +1,413 @@ +#include "../../Common.hpp" +#include "SPRXShellCode.hpp" +#include "../System.hpp" +#include "../Proc.hpp" + +extern char _binary_Resources_LoaderShellCode_bin_start[]; +extern char _binary_Resources_LoaderShellCode_bin_end[]; + +extern char _binary_Resources_UnLoaderShellCode_bin_start[]; +extern char _binary_Resources_UnLoaderShellCode_bin_end[]; + +int LoadSPRX(const char* ProcessName, const char* Path, bool ShouldCallEntry) +{ + klog("LoadSPRX(%s, %s)", ProcessName, Path); + + uint64_t thr_initial = 0; + uint8_t ShellCodeComplete = 0; + uint64_t ModuleHandle = 0; + + auto Process = FindProcessByName(ProcessName); + if(Process == nullptr) + { + klog("LoadSPRX(): Could not find process \"%s\".", ProcessName); + + return -1; + } + + auto ProcessThread = TAILQ_FIRST(&(Process)->p_threads); + if(ProcessThread == nullptr) + { + klog("LoadSPRX(): Could not find thread on process \"%s\".", ProcessName); + + return -1; + } + + if(Process->p_dynlibptr == nullptr) + { + klog("LoadSPRX(): p_dynlibptr returned nullptr."); + return -1; + } + + // Jailbreak the process. + Backup_Jail bkJail; + proc_Jailbreak(Process, &bkJail); + + // Gets the Thread Initial for the shellcore thread. Also checking to make sure were not trying to load a prx already loaded. + dynlib* m_library = Process->p_dynlibptr->p_dynlib; + while(m_library != 0) + { + if(!strcmp(basename(m_library->ModulePath), basename(Path))) + { + klog("LoadSPRX(): Module %s is already loaded on proc %s...", basename(Path), Process->p_comm); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return m_library->ModuleHandle; + } + + if(!strcmp(basename(m_library->ModulePath), "libkernel.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel; + + if(!strcmp(basename(m_library->ModulePath), "libkernel_web.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel_web; + + if(!strcmp(basename(m_library->ModulePath), "libkernel_sys.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel_sys; + + m_library = m_library->dynlib_next; + } + + if(thr_initial == 0) + { + klog("LoadSPRX(): Failed to resolve thr_initial."); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return -1; + } + + auto ShellCodeSize = (size_t)(_binary_Resources_LoaderShellCode_bin_end - _binary_Resources_LoaderShellCode_bin_start); + + klog("Start: %llX\nEnd %llX\nSize: 0x%X", + _binary_Resources_LoaderShellCode_bin_start, + _binary_Resources_LoaderShellCode_bin_end, + ShellCodeSize); + + // Allocate space on the process for the shellcode and its threads stack. + auto UserlandShellCode = kmap(nullptr, ShellCodeSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PREFAULT_READ, -1, 0, ProcessThread); + if(UserlandShellCode == nullptr || (uint64_t)UserlandShellCode < 0) + { + klog("LoadSPRX(): Failed to allocate memory on process for ShellCode. Err: %d", UserlandShellCode); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return -1; + } + + klog("LoadSPRX(): thr_initial = 0x%llX", thr_initial); + klog("LoadSPRX(): ShellCodeSize = 0x%llX", ShellCodeSize); + klog("LoadSPRX(): UserlandShellCode = 0x%llX", UserlandShellCode); + klog("LoadSPRX(): UserlandShellCode = %d", UserlandShellCode); + + auto ShellCodeHeader = (OrbisLoader_header*)_binary_Resources_LoaderShellCode_bin_start; + ShellCodeHeader->ShellCodeComplete = 0; + ShellCodeHeader->ModuleHandle = 0; + ShellCodeHeader->ShouldCallEntry = ShouldCallEntry; + ShellCodeHeader->thr_initial = thr_initial; + strcpy(ShellCodeHeader->Path, (char*)Path); + + // Write the shellcode to the allocated memory on the process. + auto res = ReadWriteProcessMemory(Process, (void*)UserlandShellCode, (void*)_binary_Resources_LoaderShellCode_bin_start, ShellCodeSize, true); + if(!res) + { + klog("LoadSPRX(): WriteProcessMemory failed with error %d.", res); + + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return -1; + } + + // Allocate memory on process for the threads stack. + auto StackMemory = kmap(nullptr, 0x80000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PREFAULT_READ, -1, 0, ProcessThread);// AllocateProcessMemory(Process, 0x80000, VM_PROT_ALL); + if(StackMemory == nullptr) + { + klog("LoadSPRX(): Failed to allocate memory on process for the Stack."); + + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return -1; + } + + // Start a thread with the entry pointing to +0x4 in our shellcode because that holds the offset to the starting instructions. + + klog("LoadSPRX(): Starting Shellcode Thread..."); + struct thread *thr = TAILQ_FIRST(&Process->p_threads); + uint64_t ShellCodeEntry = (uint64_t)UserlandShellCode + ShellCodeHeader->entry; + create_thread(thr, NULL, (void*)ShellCodeEntry, NULL, (char*)StackMemory, 0x80000, NULL, NULL, NULL, 0, NULL); + + klog("LoadSPRX(): Thread Started!! Waiting for shellcode to complete..."); + + // Wait for the shellcode to complete by reading the byte that will be set to 1 on completion. + while (!ShellCodeComplete) + { + auto err = ReadProcessMemory(Process, UserlandShellCode + offsetof(OrbisLoader_header, ShellCodeComplete), (void *)&ShellCodeComplete, sizeof(ShellCodeComplete)); + if(!err) + { + klog("LoadSPRX(): Failed to read ModuleHandle. %d", err); + + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + return -1; + } + + pause("", 100); + } + + // Grab the Module handle from the shellcode to see if the loading was a sucess or not. + auto err = ReadProcessMemory(Process, UserlandShellCode + offsetof(OrbisLoader_header, ModuleHandle), (void *)&ModuleHandle, sizeof(ModuleHandle)); + if(!err) + { + klog("LoadSPRX(): Failed to read ModuleHandle. %d", err); + + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return -1; + } + + // Clean up. + klog("LoadSPRX(): Freeing Shellcode Memory..."); + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + // Restore previous jail. + proc_RestoreJail(Process, bkJail); + + if(ModuleHandle > 0 && ModuleHandle < 0x80000000) + klog("LoadSPRX(): Completed! Module Loaded with handle 0x%llX", ModuleHandle); + else + klog("LoadSPRX(): Failed with error 0x%llX", ModuleHandle); + + return ModuleHandle; +} + +int UnloadSPRX(const char* ProcessName, int Handle, bool ShouldCallExit) +{ + klog("UnloadSPRX(%s, %i)", ProcessName, Handle); + + uint64_t thr_initial = 0; + uint8_t ShellCodeComplete = 0; + uint64_t Result = 0; + + auto Process = FindProcessByName(ProcessName); + if(Process == nullptr) + { + klog("UnloadSPRX(): Could not find process \"%s\".", ProcessName); + + return -1; + } + + auto ProcessThread = TAILQ_FIRST(&(Process)->p_threads); + if(ProcessThread == nullptr) + { + klog("UnloadSPRX(): Could not find thread on process \"%s\".", ProcessName); + + return -1; + } + + if(Process->p_dynlibptr == nullptr) + { + klog("UnloadSPRX(): p_dynlibptr returned nullptr."); + return -1; + } + + // Gets the Thread Initial for the shellcore thread. Also checking to make sure were not trying to un load a prx that is not loaded. + bool FoundModule = false; + dynlib* m_library = Process->p_dynlibptr->p_dynlib; + while(m_library != 0) + { + if(m_library->ModuleHandle == Handle) + { + klog("UnloadSPRX(): Found Module \"%s\" in Process \"%s\".", basename(m_library->ModulePath), ProcessName); + + FoundModule = true; + } + + if(!strcmp(basename(m_library->ModulePath), "libkernel.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel; + + if(!strcmp(basename(m_library->ModulePath), "libkernel_web.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel_web; + + if(!strcmp(basename(m_library->ModulePath), "libkernel_sys.sprx")) + thr_initial = (uint64_t)m_library->codeBase + addr_thr_initial_libkernel_sys; + + m_library = m_library->dynlib_next; + } + + if(!FoundModule) + { + klog("UnloadSPRX(): Could not find Module %i on Process \"%s\".", Handle, ProcessName); + + return -1; + } + + if(thr_initial == 0) + { + klog("UnloadSPRX(): Failed to resolve thr_initial."); + + return -1; + } + + auto ShellCodeSize = (size_t)(_binary_Resources_UnLoaderShellCode_bin_end - _binary_Resources_UnLoaderShellCode_bin_start); + + klog("Start: %llX\nEnd %llX\nSize: 0x%X", + _binary_Resources_UnLoaderShellCode_bin_start, + _binary_Resources_UnLoaderShellCode_bin_end, + ShellCodeSize); + + // Allocate space on the process for the shellcode and its threads stack. + auto UserlandShellCode = kmap(nullptr, ShellCodeSize, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PREFAULT_READ, -1, 0, ProcessThread);// AllocateProcessMemory(Process, ShellCodeSize, VM_PROT_ALL); + if(UserlandShellCode == nullptr) + { + klog("UnloadSPRX(): Failed to allocate memory on process for ShellCode."); + + return -1; + } + + klog("UnloadSPRX(): thr_initial = 0x%llX", thr_initial); + klog("UnloadSPRX(): UserlandShellCode = 0x%llX", UserlandShellCode); + + auto ShellCodeHeader = (OrbisUnLoader_header*)_binary_Resources_UnLoaderShellCode_bin_start; + ShellCodeHeader->thr_initial = thr_initial; + ShellCodeHeader->ShellCodeComplete = 0; + ShellCodeHeader->ShouldCallExit = ShouldCallExit; + ShellCodeHeader->ModuleHandle = Handle; + + // Write the shellcode to the allocated memory on the process. + auto res = ReadWriteProcessMemory(Process, (void*)UserlandShellCode, (void*)_binary_Resources_UnLoaderShellCode_bin_start, ShellCodeSize, true); + if(!res) + { + klog("UnloadSPRX(): copy out failed with error %d.", res); + + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return -1; + } + + // Allocate memory on process for the threads stack. + auto StackMemory = kmap(nullptr, 0x80000, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PREFAULT_READ, -1, 0, ProcessThread);// AllocateProcessMemory(Process, 0x80000, VM_PROT_ALL); + if(StackMemory == nullptr) + { + klog("UnloadSPRX(): Failed to allocate memory on process for the Stack."); + + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return -1; + } + + // Start a thread with the entry pointing to +0x4 in our shellcode because that holds the offset to the starting instructions. + + klog("UnloadSPRX(): Starting Shellcode Thread..."); + struct thread *thr = TAILQ_FIRST(&Process->p_threads); + uint64_t ShellCodeEntry = (uint64_t)UserlandShellCode + ShellCodeHeader->entry; + create_thread(thr, NULL, (void*)ShellCodeEntry, NULL, (char*)StackMemory, 0x80000, NULL, NULL, NULL, 0, NULL); + + klog("UnloadSPRX(): Thread Started!! Waiting for shellcode to complete..."); + + // Wait for the shellcode to complete by reading the byte that will be set to 1 on completion. + while (!ShellCodeComplete) + { + auto err = ReadProcessMemory(Process, UserlandShellCode + offsetof(OrbisUnLoader_header, ShellCodeComplete), (void *)&ShellCodeComplete, sizeof(ShellCodeComplete)); + if(!err) + { + klog("UnloadSPRX(): Failed to read ModuleHandle. %d", err); + + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return -1; + } + + pause("", 100); + } + + // Grab the Result from the shellcode to see if the Un Loading was a sucess or not. + auto err = ReadProcessMemory(Process, UserlandShellCode + offsetof(OrbisUnLoader_header, Result), (void *)&Result, sizeof(Result)); + if(!err) + { + klog("UnloadSPRX(): Failed to read Result. %d", err); + + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return -1; + } + + // Clean up. + klog("UnloadSPRX(): Freeing Shellcode Memory..."); + kmunmap(StackMemory, 0x80000, ProcessThread); + kmunmap(UserlandShellCode, ShellCodeSize, ProcessThread); + + return Result; +} + +int UnloadSPRX(const char* ProcessName, const char* Name, bool ShouldCallExit) +{ + auto Process = FindProcessByName(ProcessName); + if(Process == nullptr) + { + klog("UnloadSPRX(): Could not find process \"%s\".", ProcessName); + + return -1; + } + + klog("Found Process...\n"); + + auto ProcessThread = TAILQ_FIRST(&(Process)->p_threads); + if(ProcessThread == nullptr) + { + klog("UnloadSPRX(): Could not find thread on process \"%s\".", ProcessName); + + return -1; + } + + klog("Found Thread...\n"); + + if(Process->p_dynlibptr == nullptr) + { + klog("UnloadSPRX(): p_dynlibptr returned nullptr."); + return -1; + } + + klog("Found Thread...\n"); + + int ModuleHandle = -1; + dynlib* m_library = Process->p_dynlibptr->p_dynlib; + while(m_library != 0) + { + if(!strcmp(basename(m_library->ModulePath), Name)) + { + klog("UnloadSPRX(): Found Module \"%s\" in Process \"%s\".", Name, ProcessName); + + ModuleHandle = m_library->ModuleHandle; + + break; + } + + m_library = m_library->dynlib_next; + } + + if(ModuleHandle == -1) + { + klog("UnloadSPRX(): Could not find Module \"%s\" on Process \"%s\".", Name, ProcessName); + + return -1; + } + + return UnloadSPRX(ProcessName, ModuleHandle, ShouldCallExit); +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.hpp b/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.hpp new file mode 100644 index 0000000..edf6195 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/ShellCode/SPRXShellCode.hpp @@ -0,0 +1,31 @@ +#pragma once + +struct OrbisLoader_header +{ + uint32_t magic; + uint64_t entry; + + uint64_t thr_initial; + uint8_t ShellCodeComplete; + uint8_t ShouldCallEntry; + + char Path[100]; + uint64_t ModuleHandle; +}__attribute__((packed)); + +struct OrbisUnLoader_header +{ + uint32_t magic; + uint64_t entry; + + uint64_t thr_initial; + uint8_t ShellCodeComplete; + uint8_t ShouldCallExit; + + uint64_t ModuleHandle; + uint64_t Result; +}__attribute__((packed)); + +int LoadSPRX(const char* ProcessName, const char* Path, bool ShouldCallEntry = true); +int UnloadSPRX(const char* ProcessName, int Handle, bool ShouldCallExit = true); +int UnloadSPRX(const char* ProcessName, const char* Name, bool ShouldCallExit = true); \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/System.cpp b/Playstation/Kernel/Kernel/source/Util/System.cpp new file mode 100644 index 0000000..82951b1 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/System.cpp @@ -0,0 +1,402 @@ +#include "../Common.hpp" +#include "System.hpp" +#include "../Util/ShellCode/SPRXShellCode.hpp" + +char* strrchr(const char *cp, int ch) +{ + char *save; + char c; + + for (save = (char *) 0; (c = *cp); cp++) { + if (c == ch) + save = (char *) cp; + } + + return save; +} + +char* strchr(const char *s, int c) +{ + do { + if (*s == c) + { + return (char*)s; + } + } while (*s++); + return (0); +} + +char* basename(const char *filename) +{ + char *p = strrchr(filename, '/'); + return p ? p + 1 : (char *)filename; +} + +// Shamelessly yoinked from MIRA +// Credits: flatz +proc* FindProcessByName(const char* p_Name) +{ + sx* allproclock = (sx*)allproc_lock; + proclist* _allproc = (proclist*)*(uint64_t*)(allproc); + + proc* s_FoundProc = nullptr; + + if (!p_Name) + return NULL; + + _sx_slock(allproclock, 0, __FILE__, __LINE__); + + do + { + proc* s_Proc = nullptr; + + FOREACH_PROC_IN_SYSTEM(s_Proc) + { + //PROC_LOCK(s_Proc); + + if (strncmp(p_Name, s_Proc->p_comm, strlen(p_Name)) == 0) { + s_FoundProc = s_Proc; + //PROC_UNLOCK(s_Proc); + break; + } + + //PROC_UNLOCK(s_Proc); + } + } while (false); + + _sx_sunlock(allproclock, __FILE__, __LINE__); + + return s_FoundProc; +} + +proc* FindProcessByPID(pid_t pid) +{ + sx* allproclock = (sx*)allproc_lock; + proclist* _allproc = (proclist*)*(uint64_t*)(allproc); + + proc* s_FoundProc = nullptr; + + _sx_slock(allproclock, 0, __FILE__, __LINE__); + + do + { + proc* s_Proc = nullptr; + + FOREACH_PROC_IN_SYSTEM(s_Proc) + { + //PROC_LOCK(s_Proc); + + if (s_Proc->p_pid == pid) { + s_FoundProc = s_Proc; + //PROC_UNLOCK(s_Proc); + break; + } + + //PROC_UNLOCK(s_Proc); + } + } while (false); + + _sx_sunlock(allproclock, __FILE__, __LINE__); + + return s_FoundProc; +} + +uint8_t* AllocateProcessMemory(proc* Process, uint32_t Size, uint32_t Protection) +{ + if (Process == nullptr) + return nullptr; + + klog("Requested Size: (%x).", Size); + Size = round_page(Size); + klog("Adjusted Size (%x).", Size); + + vm_offset_t s_Address = 0; + + // Get the vmspace + auto s_VmSpace = Process->p_vmspace; + if (s_VmSpace == nullptr) + { + klog("invalid vmspace."); + return nullptr; + } + + // Get the vmmap + vm_map_t s_VmMap = &s_VmSpace->vm_map; + + // Lock the vmmap + vm_map_lock(s_VmMap, __FILE__, __LINE__); + + do + { + // Find some free space to allocate memory + auto s_Result = vm_map_findspace(s_VmMap, s_VmMap->header.start, Size, &s_Address); + if (s_Result != 0) + { + klog("vm_map_findspace returned (%d).", s_Result); + break; + } + + klog("_vm_map_findspace returned address (%p).", s_Address); + + // Validate the address + if (s_Address == 0) + { + klog("allocated address is invalid (%p).", s_Address); + break; + } + + // Insert the new stuff map + s_Result = vm_map_insert(s_VmMap, NULL, 0, s_Address, s_Address + Size, Protection, Protection, 0); + if (s_Result != 0) + { + klog("vm_map_insert returned (%d).", s_Result); + break; + } + + } while (false); + + vm_map_unlock(s_VmMap); + + return reinterpret_cast(s_Address); +} + +void FreeProcessMemory(struct proc* p_Process, void* p_Pointer, uint32_t p_Size) +{ + struct vmspace* s_VmSpace = p_Process->p_vmspace; + if (s_VmSpace == nullptr) + { + klog("could not get vmspace."); + return; + } + + struct vm_map* s_VmMap = &s_VmSpace->vm_map; + + vm_map_lock(s_VmMap, __FILE__, __LINE__); + + auto s_Ret = vm_map_delete(s_VmMap, reinterpret_cast(p_Pointer), p_Size); + + vm_map_unlock(s_VmMap); + + if (s_Ret != 0) + klog("could not delete from vm map (%d).", s_Ret); +} + +bool ReadWriteProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength, bool p_Write) +{ + // Validate process + if (p_TargetProcess == nullptr) + { + klog("invalid process."); + return false; + } + + thread* s_ProcMainThread = p_TargetProcess->p_singlethread ? p_TargetProcess->p_singlethread : p_TargetProcess->p_threads.tqh_first; + if (s_ProcMainThread == nullptr) + { + klog("could not get process main thread."); + return false; + } + + // Validate the target address + if (p_TargetAddress == nullptr) + { + klog("invalid target address."); + return false; + } + + // Validate the data + if (p_Data == nullptr || + p_DataLength == 0) + { + klog("invalid data."); + return false; + } + + struct iovec s_Vec; + memset(&s_Vec, 0, sizeof(s_Vec)); + s_Vec.iov_base = p_Data; + s_Vec.iov_len = p_DataLength; + + struct uio s_Uio; + memset(&s_Uio, 0, sizeof(s_Uio)); + s_Uio.uio_iov = &s_Vec; + s_Uio.uio_iovcnt = 1; + s_Uio.uio_offset = (uint64_t)p_TargetAddress; + s_Uio.uio_resid = (uint64_t)p_DataLength; + s_Uio.uio_segflg = UIO_SYSSPACE; + s_Uio.uio_rw = p_Write ? UIO_WRITE : UIO_READ; + s_Uio.uio_td = s_ProcMainThread; + + auto s_Ret = proc_rwmem(p_TargetProcess, &s_Uio); + if (s_Ret != 0) + { + klog("could not proc_rwmem (%d).", s_Ret); + return false; + } + + return true; +} + +bool ReadProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength) +{ + return ReadWriteProcessMemory(p_TargetProcess, p_TargetAddress, p_Data, p_DataLength, false); +} + +bool WriteProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength) +{ + return ReadWriteProcessMemory(p_TargetProcess, p_TargetAddress, p_Data, p_DataLength, true); +} + +int MountNullFS(char* where, char* what, int flags) +{ + struct mntarg* ma = NULL; + + ma = mount_argf(ma, "fstype", "%s", "nullfs"); + ma = mount_argf(ma, "fspath", "%s", where); + ma = mount_argf(ma, "target", "%s", what); + + if (ma == NULL) { + klog("Something is wrong, ma value is null after argument\n"); + return 50; + } + + return kern_mount(ma, flags); +} + +bool MountDir(thread* td, char* Sandbox, char* what, int flags) +{ + if(!td) + { + klog("Thread was NULL..."); + return false; + } + + char s_fulldir[0x200]; + snprintf(s_fulldir, sizeof(s_fulldir), "%s%s", Sandbox, what); + + klog("Mount: %s -> %s", s_fulldir, what); + + if(kern_mkdir(td, s_fulldir, 0, 0777) != 0) + return false; + + if(MountNullFS(s_fulldir, what, flags) != 0) + return false; + + return true; +} + +bool UnMountDir(thread* td, char* Sandbox, char* what, int flags) +{ + if(!td) + { + klog("Thread was NULL..."); + return false; + } + + char s_fulldir[0x200]; + snprintf(s_fulldir, sizeof(s_fulldir), "%s%s", Sandbox, what); + + klog("Un-Mount: %s -> %s", s_fulldir, what); + + if(kunmount(s_fulldir, flags, td) != 0) + return false; + + if(kern_rmdir(td, s_fulldir, 0) != 0) + return false; + + return true; +} + +bool MountShellUIDirs(proc* p, vnode* jdir, bool Mount) +{ + klog("%s dirs { system, data, host, hostapp } on process %s", Mount ? "Mounting" : "Un-Mounting", p->p_comm); + + //Get first thread in proc. + thread* td = curthread();//p->p_threads.tqh_first; + + //Get the sandbox path. + char* s_SandboxPath = nullptr; + char* s_Freepath = nullptr; + vn_fullpath(td, jdir, &s_SandboxPath, &s_Freepath); + klog("%s -> %s\n", p->p_comm, s_SandboxPath); + + if(Mount) + { + if(!MountDir(td, s_SandboxPath, "/system", MNT_SYNCHRONOUS)) + { + klog("Failed to Mount /System."); + return false; + } + if(!MountDir(td, s_SandboxPath, "/data", MNT_SYNCHRONOUS)) + { + klog("Failed to Mount /data."); + return false; + } + if(!MountDir(td, s_SandboxPath, "/host", MNT_SYNCHRONOUS)) + { + klog("Failed to Mount /host."); + return false; + } + if(!MountDir(td, s_SandboxPath, "/hostapp", MNT_SYNCHRONOUS)) + { + klog("Failed to Mount /hostapp."); + return false; + } + + return true; + } + else + { + if(!UnMountDir(td, s_SandboxPath, "/system", MNT_FORCE)) + { + klog("Failed to Un-Mount /system."); + return false; + } + if(!UnMountDir(td, s_SandboxPath, "/data", MNT_FORCE)) + { + klog("Failed to Un-Mount /data."); + return false; + } + if(!UnMountDir(td, s_SandboxPath, "/host", MNT_FORCE)) + { + klog("Failed to Un-Mount /host."); + return false; + } + if(!UnMountDir(td, s_SandboxPath, "/hostapp", MNT_FORCE)) + { + klog("Failed to Un-Mount /hostapp."); + return false; + } + + return true; + } +} + +bool DoShellUIMount(proc* p, bool Mount) +{ + if(!strcmp(p->titleId, "NPXS20001") && (!strcmp(p->p_comm, "SecureUIProcess.self") || !strcmp(p->p_comm, "SceShellUI"))) + { + // Jailbreak the process. + Backup_Jail bkJail; + proc_Jailbreak(p, &bkJail); + + // Un-Mount the dirs for ShellUI + bool res = MountShellUIDirs(p, bkJail.fd_jdir, Mount); + + // Restore previous jail. + proc_RestoreJail(p, bkJail); + + if(!strcmp(p->p_comm, "SecureUIProcess.self")) + { + while(FindProcessByName("SceShellUI") == nullptr) { Sleep(10); } + + Sleep(3000); + + LoadSPRX("SceShellUI", "/data/Orbis Toolbox/Orbis Toolbox.sprx"); + } + + return res; + } + + return false; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/System.hpp b/Playstation/Kernel/Kernel/source/Util/System.hpp new file mode 100644 index 0000000..a47f667 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/System.hpp @@ -0,0 +1,17 @@ +#pragma once + +char* basename(const char *filename); +proc* FindProcessByName(const char* p_Name); +proc* FindProcessByPID(pid_t pid) ; +uint8_t* AllocateProcessMemory(proc* Process, uint32_t Size, uint32_t Protection); +void FreeProcessMemory(struct proc* p_Process, void* p_Pointer, uint32_t p_Size); + +bool ReadWriteProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength, bool p_Write); +bool ReadProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength); +bool WriteProcessMemory(struct proc* p_TargetProcess, void* p_TargetAddress, void* p_Data, uint32_t p_DataLength); + +int MountNullFS(char* where, char* what, int flags); +bool MountDir(thread* td, char* Sandbox, char* what, int flags); +bool UnMountDir(thread* td, char* Sandbox, char* what, int flags); +bool MountShellUIDirs(proc* p, vnode* jdir, bool Mount); +bool DoShellUIMount(proc* p, bool Mount); \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/Types.hpp b/Playstation/Kernel/Kernel/source/Util/Types.hpp new file mode 100644 index 0000000..bb9a74b --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/Types.hpp @@ -0,0 +1,25 @@ +#pragma once +#include "sys/types.h" + +#ifndef NULL +#define NULL 0 +#endif + +#ifndef true +#define true 1 +#endif + +#ifndef false +#define false 0 +#endif + +enum Auth_ID +{ + JitBase = 0x3100000000000000, + CoreDump = 0x3800000000000006, + SysCore = 0x3800000000000007, + ShellUI = 0x380000000000000F, + Shell3D = 0x3800000000000009, + ShellCore = 0x3800000000000010, + DECID = 0x3800000000010003, +}; \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/kproc.cpp b/Playstation/Kernel/Kernel/source/Util/kproc.cpp new file mode 100644 index 0000000..6a5bd61 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/kproc.cpp @@ -0,0 +1,42 @@ +#include "../Common.hpp" +#include "kproc.hpp" + +kproc::kproc(void(*Entry)(void*), void* Args, const char* Proc_Name, const char* Title_ID, int Flags, int Pages) +{ + //Create new Process. + int ret = kproc_create(Entry, Args, &this->Process, Flags, Pages, Proc_Name); + if( ret != 0 || this->Process == nullptr ) + { + kprintf("Failed to create new Process.\n"); + return; + } + + //Copy Title ID Text. + strcpy(this->Process->titleId, (char*)Title_ID); + + //Help with graceful shutdown. + Proc_Should_Run = true; + + kprintf("Created New Process Sucessfully.\n%s(%i) %s", this->Process->p_comm, this->Process->p_pid, this->Process->titleId); +} + +kproc::~kproc() +{ + +} + +thread* kproc::Add_Thread(void(*Thread)(void*), void *Args, int Flags, int Pages, const char* Thread_Name) +{ + thread* NewThread = nullptr; + int ret = kproc_kthread_add(Thread, Args, &this->Process, &NewThread, Flags, Pages, this->Process->p_comm, Thread_Name); + + if(ret != 0 || NewThread == nullptr) + { + kprintf("Failed to Create New Thread (%s) on Proc %s(%i) %s", Thread_Name, this->Process->p_comm, this->Process->p_pid, this->Process->titleId); + return nullptr; + } + + kprintf("New Thread (%s) on Proc %s(%i) %s", Thread_Name, this->Process->p_comm, this->Process->p_pid, this->Process->titleId); + + return NewThread; +} \ No newline at end of file diff --git a/Playstation/Kernel/Kernel/source/Util/kproc.hpp b/Playstation/Kernel/Kernel/source/Util/kproc.hpp new file mode 100644 index 0000000..d245478 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/Util/kproc.hpp @@ -0,0 +1,17 @@ +#pragma once +#include "../Common.hpp" + +class kproc +{ +private: + bool Proc_Should_Run = false; + +public: + proc* Process = nullptr; + thread* Main_Thread = nullptr; + + kproc(void(*Entry)(void*), void* Args, const char* Proc_Name, const char* Title_ID, int Flags, int Pages); + ~kproc(); + + thread* Add_Thread(void(*Thread)(void*), void *Args, int Flags, int Pages, const char* Thread_Name); +}; diff --git a/Playstation/Kernel/Kernel/source/main.cpp b/Playstation/Kernel/Kernel/source/main.cpp new file mode 100644 index 0000000..a41c7d7 --- /dev/null +++ b/Playstation/Kernel/Kernel/source/main.cpp @@ -0,0 +1,49 @@ +#include "Common.hpp" +#include "OrbisLib/OrbisLib.hpp" +#include "Util/Patches/Patches.hpp" + +KDriver_Info* KDriverInfo = nullptr; +OrbisLib* OrbisLibInstance = nullptr; + +extern "C" int _Shutdown() +{ + klog("!!! SHUTDOWN SHUTDOWN SHUTDOWN !!!"); + + KDriverInfo->Running = false; + + delete OrbisLibInstance; + + Sleep(2000); + + klog("!!! BYE !!!"); + + return 0; +} + +extern "C" int _main(uint64_t* p) +{ + ResolveFunctions(); + Install_Patches(); + + KDriverInfo = new KDriver_Info(); + + // Copy in our start up info. + if(p != nullptr) + memcpy(KDriverInfo, p, sizeof(KDriver_Info)); + + // Set up Driver info. + KDriverInfo->MajorVersion = KDRIVER_MAJOR_VERSION; + KDriverInfo->MinorVersion = KDRIVER_MINOR_VERSION; + KDriverInfo->BuildVersion = KDRIVER_BUILD_VERSION; + KDriverInfo->Shutdown = &_Shutdown; + + // Start up main Kdriver Class. + OrbisLibInstance = new OrbisLib(); + + klog("Hello from Kernel\nKDriver %s v%d.%d.%d", SOFTWARE_VERSION_STR, KDRIVER_MAJOR_VERSION, KDRIVER_MINOR_VERSION, KDRIVER_BUILD_VERSION); + + // Set our running state. + KDriverInfo->Running = true; + + return 0; +} diff --git a/Playstation/Kernel/Kernel/temp.txt b/Playstation/Kernel/Kernel/temp.txt new file mode 100644 index 0000000..a0cc013 --- /dev/null +++ b/Playstation/Kernel/Kernel/temp.txt @@ -0,0 +1,4 @@ +open 192.168.0.55 2121 +user anonymous anonymous +put "/mnt/c/Users/grego/source/repos/Orbis-Suite-2.0/Playstation/Kernel/Kernel/Kernel.elf" "/data/Orbis Suite/Kernel.505.ELF" +bye diff --git a/Playstation/Kernel/Makefile b/Playstation/Kernel/Makefile new file mode 100644 index 0000000..ad5356f --- /dev/null +++ b/Playstation/Kernel/Makefile @@ -0,0 +1,42 @@ +SHELL=/bin/bash + +none: + printf "\e[1m\e[31mPlease Choose a firmware!! EG. \"make 505\" \033[37m\n" + +build: + cmd.exe /C Increment.bat + + +$(MAKE) -C ShellCode clean + +$(MAKE) -C ShellCode + +$(MAKE) -C Kernel clean + +$(MAKE) -C Kernel + +$(MAKE) -C Kernel copy + printf "\e[1m\e[32m[%0.2f Build Sucess!]\033[37m\n" "$$(($(VERSION) * 1))e-2" + +505: + +$(MAKE) build VERSION=505 + +672: + +$(MAKE) build VERSION=672 + +702: + +$(MAKE) build VERSION=702 + +755: + +$(MAKE) build VERSION=755 + +900: + +$(MAKE) build VERSION=900 + +all: + +$(MAKE) build VERSION=505 + +$(MAKE) build VERSION=672 + +$(MAKE) build VERSION=702 + +$(MAKE) build VERSION=755 + +$(MAKE) build VERSION=900 + + @/bin/echo -e "\e[1m\e[32m[All Build Sucess!]\033[37m" + +clean: + +$(MAKE) -C ShellCode clean + +$(MAKE) -C Kernel clean diff --git a/Playstation/Kernel/README.md b/Playstation/Kernel/README.md new file mode 100644 index 0000000..b26bb8b --- /dev/null +++ b/Playstation/Kernel/README.md @@ -0,0 +1,3 @@ +# Orbis Suite Kernel Driver + +This project is a bit of a mess since I never really have the time to hash out the build process. I will eventually upload the dependancies as another repo though even they are pretty hacked up to make things work :lol: dont judge I am lazy and just want things to do their things. \ No newline at end of file diff --git a/Playstation/Kernel/ShellCode/LoaderShellCode.s b/Playstation/Kernel/ShellCode/LoaderShellCode.s new file mode 100644 index 0000000..298cecf --- /dev/null +++ b/Playstation/Kernel/ShellCode/LoaderShellCode.s @@ -0,0 +1,221 @@ +BITS 64 +DEFAULT REL + +magic: db 'SHEL' +entry: dq shellcode + +thr_initial: dq 0 +ShellCodeComplete: db 0 +ShouldCallEntry: db 0 + +; sceKernelLoadStartModule Variables +ModulePath: db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +ModuleHandle: dq 0 + +; Addresses / Misc +sceKernelUsleep: dq 0 +asceKernelLoadStartModule: dq 0 +libkernel: dq 0 +str_libkernel: db 'libkernel.sprx', 0 +str_libkernelweb: db 'libkernel_web.sprx', 0 +str_libkernelsys: db 'libkernel_sys.sprx', 0 +str_sceKernelSleep: db 'sceKernelUsleep', 0 +str_sceKernelLoadStartModule: db 'sceKernelLoadStartModule', 0 + +str_scePthreadCreate: db 'scePthreadCreate', 0 +scePthreadCreate: dq 0 +str_scePthreadAttrSetstacksize: db 'scePthreadAttrSetstacksize', 0 +scePthreadAttrSetstacksize: dq 0 +str_scePthreadAttrInit: db 'scePthreadAttrInit', 0 +scePthreadAttrInit: dq 0 + +hthread: dq 0 +scePthreadAttr: dq 0 +str_threadName: db 'Orbis SPRX Loader', 0 + +; Work around for oosdk +amodule_start: dq 0 +str_module_start: db 'module_start', 0 + +; Main shellcode function. +shellcode: + ; load thread into fs + mov rdi, qword [thr_initial] + mov rsi, qword [rdi] + mov rdi, qword [rsi + 0x1E0] + call amd64_set_fsbase + + ; get libkernel handle + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernel] + call sys_dynlib_load_prx + test rax, rax + je resolve + + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernelweb] + call sys_dynlib_load_prx + test rax, rax + je resolve + + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernelsys] + call sys_dynlib_load_prx + +resolve: + ; resolve sceKernelUsleep + lea rdx, [sceKernelUsleep] + lea rsi, [str_sceKernelSleep] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve sceKernelLoadStartModule + lea rdx, [asceKernelLoadStartModule] + lea rsi, [str_sceKernelLoadStartModule] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadCreate + lea rdx, [scePthreadCreate] + lea rsi, [str_scePthreadCreate] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadAttrSetstacksize + lea rdx, [scePthreadAttrSetstacksize] + lea rsi, [str_scePthreadAttrSetstacksize] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadAttrInit + lea rdx, [scePthreadAttrInit] + lea rsi, [str_scePthreadAttrInit] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + call sceKernelLoadStartModule + + ; Check if the module loaded and if it did call the entry. + cmp dword[ModuleHandle], 0 + jle didntload + + ; Check to see if we shouldnt call the entry manually. + cmp byte[ShouldCallEntry], 0 + je didntload + + ; Manually calling Entry. + call module_start + +didntload: + ; Set the Flag we are done. + mov byte [ShellCodeComplete], 1 + + ; Shutdown the thread. + mov rdi, 0 + call sys_thr_exit + retn + + +; Sub function +module_start: + lea rdx, [amodule_start] + lea rsi, [str_module_start] + mov rdi, qword [ModuleHandle] + call sys_dynlib_dlsym + + cmp dword[amodule_start], 0 + ja found_start + + xor eax, eax + retn + +; Sub function +found_start: + ; create attr + lea rdi, [scePthreadAttr] + mov r12, qword [scePthreadAttrInit] + call r12 + + ; set stack size + mov rsi, 0x80000 ; 512 kb + lea rdi, [scePthreadAttr] + mov r12, qword [scePthreadAttrSetstacksize] + call r12 + + ; create thread + lea r8, [str_threadName] + mov rcx, 0 + mov rdx, qword [amodule_start] + lea rsi, [scePthreadAttr] + lea rdi, [hthread] + mov r12, qword [scePthreadCreate] + call r12 + + xor eax, eax + retn + +; Sub function +sceKernelLoadStartModule: + xor r9, r9 + xor r8, r8 + xor rcx, rcx + xor rdx, rdx + xor rsi, rsi + lea rdi, [ModulePath] + mov r12, qword [asceKernelLoadStartModule] + call r12 + mov qword [ModuleHandle], rax + xor eax, eax + retn + +; Sub function +sys_dynlib_load_prx: + mov rax, 594 + mov r10, rcx + syscall + retn + +; Sub function +sys_dynlib_dlsym: + mov rax, 591 + mov r10, rcx + syscall + retn + +; Sub function +sys_thr_exit: + mov rax, 431 + mov r10, rcx + syscall + retn + +; Sub function +sys_sysarch: + mov rax, 165 + mov r10, rcx + syscall + retn + +; Sub function +amd64_set_fsbase: + push rbp + mov rbp, rsp + push rbx + sub rsp, 0x18 + + mov [rbp - 0x18], rdi + + lea rsi, [rbp - 0x18] + mov edi, 129 + call sys_sysarch + + add rsp, 0x18 + pop rbx + pop rbp + retn \ No newline at end of file diff --git a/Playstation/Kernel/ShellCode/Makefile b/Playstation/Kernel/ShellCode/Makefile new file mode 100644 index 0000000..373b194 --- /dev/null +++ b/Playstation/Kernel/ShellCode/Makefile @@ -0,0 +1,18 @@ +LoaderShellCode = ../Kernel/Resources/LoaderShellCode.bin +LoaderShellCodes = LoaderShellCode.s +UnloaderShellCode = ../Kernel/Resources/UnLoaderShellCode.bin +UnloaderShellCodes = UnLoaderShellCode.s + +all: clean $(LoaderShellCode) +all: clean $(UnloaderShellCode) + +$(LoaderShellCode): + nasm -f bin -o $(LoaderShellCode) $(LoaderShellCodes) + +$(UnloaderShellCode): + nasm -f bin -o $(UnloaderShellCode) $(UnloaderShellCodes) + +.PHONY: clean +clean: + rm -f $(LoaderShellCode) + rm -f $(UnloaderShellCode) \ No newline at end of file diff --git a/Playstation/Kernel/ShellCode/UnLoaderShellCode.s b/Playstation/Kernel/ShellCode/UnLoaderShellCode.s new file mode 100644 index 0000000..d0e3d11 --- /dev/null +++ b/Playstation/Kernel/ShellCode/UnLoaderShellCode.s @@ -0,0 +1,191 @@ +BITS 64 +DEFAULT REL + +magic: db 'SHEL' +entry: dq shellcode + +thr_initial: dq 0 +ShellCodeComplete: db 0 +ShouldCallExit: db 0 + +ModuleHandle: dq 0 +Result: dq 0 + +; Addresses / Misc +sceKernelUsleep: dq 0 +asceKernelStopUnloadModule: dq 0 +libkernel: dq 0 +str_libkernel: db 'libkernel.sprx', 0 +str_libkernelweb: db 'libkernel_web.sprx', 0 +str_libkernelsys: db 'libkernel_sys.sprx', 0 +str_sceKernelSleep: db 'sceKernelUsleep', 0 +str_sceKernelStopUnloadModule: db 'sceKernelStopUnloadModule', 0 + +str_scePthreadCreate: db 'scePthreadCreate', 0 +scePthreadCreate: dq 0 +str_scePthreadAttrSetstacksize: db 'scePthreadAttrSetstacksize', 0 +scePthreadAttrSetstacksize: dq 0 +str_scePthreadAttrInit: db 'scePthreadAttrInit', 0 +scePthreadAttrInit: dq 0 + +hthread: dq 0 +scePthreadAttr: dq 0 +str_threadName: db 'Orbis SPRX UnLoader', 0 + +; Work around for oosdk +amodule_stop: dq 0 +str_module_stop: db 'module_stop', 0 + +; Main shellcode function. +shellcode: + ; load thread into fs + mov rdi, qword [thr_initial] + mov rsi, qword [rdi] + mov rdi, qword [rsi + 0x1E0] + call amd64_set_fsbase + + ; get libkernel handle + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernel] + call sys_dynlib_load_prx + test rax, rax + je resolve + + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernelweb] + call sys_dynlib_load_prx + test rax, rax + je resolve + + mov rcx, 0 + lea rdx, [libkernel] + mov rsi, 0 + lea rdi, [str_libkernelsys] + call sys_dynlib_load_prx + +resolve: + ; resolve sceKernelUsleep + lea rdx, [sceKernelUsleep] + lea rsi, [str_sceKernelSleep] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve sceKernelStopUnloadModule + lea rdx, [asceKernelStopUnloadModule] + lea rsi, [str_sceKernelStopUnloadModule] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadCreate + lea rdx, [scePthreadCreate] + lea rsi, [str_scePthreadCreate] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadAttrSetstacksize + lea rdx, [scePthreadAttrSetstacksize] + lea rsi, [str_scePthreadAttrSetstacksize] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + ; resolve scePthreadAttrInit + lea rdx, [scePthreadAttrInit] + lea rsi, [str_scePthreadAttrInit] + mov rdi, qword [libkernel] + call sys_dynlib_dlsym + + call StopModule + call sceKernelStopUnloadModule + + ; Set the Flag we are done. + mov byte [ShellCodeComplete], 1 + + ; Shutdown the thread. + mov rdi, 0 + call sys_thr_exit + retn + +StopModule: + ; Check to see if we shouldnt call the exit manually. + cmp byte[ShouldCallExit], 0 + je EndofModuleStop + + ; Manually calling Exit. + lea rdx, [amodule_stop] + lea rsi, [str_module_stop] + mov rdi, qword [ModuleHandle] + call sys_dynlib_dlsym + + cmp dword[amodule_stop], 0 + jle EndofModuleStop + + mov r12, qword [amodule_stop] + call r12 + +EndofModuleStop: + xor eax, eax + retn + +; Sub function +sceKernelStopUnloadModule: + xor r9, r9 + xor r8, r8 + xor rcx, rcx + xor rdx, rdx + xor rsi, rsi + mov rdi, [ModuleHandle] + mov r12, qword [asceKernelStopUnloadModule] + call r12 + mov qword [Result], rax + xor eax, eax + retn + +; Sub function +sys_dynlib_load_prx: + mov rax, 594 + mov r10, rcx + syscall + retn + +; Sub function +sys_dynlib_dlsym: + mov rax, 591 + mov r10, rcx + syscall + retn + +; Sub function +sys_thr_exit: + mov rax, 431 + mov r10, rcx + syscall + retn + +; Sub function +sys_sysarch: + mov rax, 165 + mov r10, rcx + syscall + retn + +; Sub function +amd64_set_fsbase: + push rbp + mov rbp, rsp + push rbx + sub rsp, 0x18 + + mov [rbp - 0x18], rdi + + lea rsi, [rbp - 0x18] + mov edi, 129 + call sys_sysarch + + add rsp, 0x18 + pop rbx + pop rbp + retn \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Build_Overlay.cpp b/Playstation/Orbis Toolbox/Build_Overlay.cpp new file mode 100644 index 0000000..9c9a233 --- /dev/null +++ b/Playstation/Orbis Toolbox/Build_Overlay.cpp @@ -0,0 +1,46 @@ +#include "Common.h" +#include "Build_Overlay.h" + +bool Build_Overlay::Draw = false; +Widget* Build_Overlay::Root_Widget = nullptr; + +void Build_Overlay::Update() +{ + if (Draw) + { + if (Root_Widget->Has_Child("BUILDPANEL")) + return; + + //Create new Label for the build string. + Label* BuildLabel = new Label("BUILDLABEL", 20.0f, 36.0f, ORBIS_TOOLBOX_BUILDSTRING, 20, Label::fsItalic, + Label::fwBold, Label::VerticalAlignment::vCenter, Label::HorizontalAlignment::hCenter, 1.0f, 1.0f, 1.0f, 1.0f); + + //Create new panel for the build Panel. + Panel* BuildPanel = new Panel("BUILDPANEL", UI::Utilities::ScreenWidth() - (BuildLabel->Get_Text_Width() + 30.0f), 20.0f, 440.0f, 100.0f, + 0.92f, 0.2f, 0.16f, 0.8f, Panel::RenderingOrder::Last, UI::Utilities::Adjust_Content(Panel::Vertical, 4, 4, 4, 4)); + + //Append the Text to the Build Panel. + BuildPanel->Append_Child("BUILDLABEL", BuildLabel); + + //Append the Label to the root widget. + Root_Widget->Append_Child("BUILDPANEL", BuildPanel); + } + else + Root_Widget->Remove_Child("BUILDPANEL"); +} + +void Build_Overlay::Init() +{ + //Init the local widget class with our new root widget. + Root_Widget = new Widget(); + Root_Widget->Instance = UI::Utilities::Get_root_Widget(); +} + +void Build_Overlay::Term() +{ + //Remove the build panel for destruction. + Root_Widget->Remove_Child("BUILDPANEL"); + + //Clean up alocated classses. + delete Root_Widget; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Build_Overlay.h b/Playstation/Orbis Toolbox/Build_Overlay.h new file mode 100644 index 0000000..ac5aea2 --- /dev/null +++ b/Playstation/Orbis Toolbox/Build_Overlay.h @@ -0,0 +1,16 @@ +#pragma once +#include "Common.h" +#include "Widget.h" + +class Build_Overlay +{ +public: + static bool Draw; + + static void Update(); + static void Init(); + static void Term(); + +private: + static Widget* Root_Widget; +}; diff --git a/Playstation/Orbis Toolbox/Common.h b/Playstation/Orbis Toolbox/Common.h new file mode 100644 index 0000000..6ec581c --- /dev/null +++ b/Playstation/Orbis Toolbox/Common.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Version.h" +#include "Utilities.h" +#include "Mono.h" +#include "Detour.h" +#include "Patcher.h" +#include "UI.h" +#include "Menu.h" + +#include "Widget.h" +#include "Label.h" +#include "Panel.h" + +#define ORBIS_TOOLBOX_NOTIFY ("Orbis Toolbox Alpha: " stringify(ORBIS_TOOLBOX_MAJOR) "." stringify(ORBIS_TOOLBOX_MINOR) " Loaded!") \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Config.cpp b/Playstation/Orbis Toolbox/Config.cpp new file mode 100644 index 0000000..59fe756 --- /dev/null +++ b/Playstation/Orbis Toolbox/Config.cpp @@ -0,0 +1,266 @@ +#include "Common.h" +#include "Config.h" + +#include "Settings_Menu.h" +#include "Debug_Features.h" +#include "LncUtil.h" +#include "Game_Overlay.h" +#include "Build_Overlay.h" +#include "Config.h" + +/*bool Config::Parse(const char* File) +{ + //Clear the previous data. + Config_Data.clear(); + + //Check if file is already open. + if (RFile_Handle.is_open()) + { + RFile_Handle.close(); + + klog("Failed to open File (%s) - File already open\n", File); + return false; + } + + //Open file. + RFile_Handle = std::fstream(File, std::ios::in); + + //Make sure file actually opened. + if (!RFile_Handle.is_open()) + { + klog("Failed to open File (%s)\n", File); + return false; + } + + //Global Vars for parsing the config file. + std::map Current_Members; + std::string Current_Line; + std::string Current_Section; + int Current_Line_Number = 0; + + //Loop through all lines of file. + while (std::getline(RFile_Handle, Current_Line)) + { + //Increment Line count. + Current_Line_Number++; + + //If the line starts with the comment block or is an empty line ignore this line. + if ((strstr((Current_Line.substr(0, 1)).c_str(), ";")) || Current_Line.empty()) { + klog("Found Comment / Empty Line at %i\n", Current_Line_Number); + continue; + } + + //If Line is a Section Block set current Section we are in. + if (strstr((Current_Line.substr(0, 1)).c_str(), "[")) + { + //If were entering a new section store the previous section to the map. + if ((Current_Section.c_str() != NULL && Current_Section.empty() == false) && Config_Data.find(Current_Section.c_str()) == Config_Data.end()) { + klog("Storing Section \"%s\" to map.\n", Current_Section.c_str()); + Config_Data.insert(std::make_pair(Current_Section, Current_Members)); + } + + //clear the temporary stored data. + Current_Members.clear(); + + //Get the index of the open and close delimiter and set the string between them as our current section. + unsigned first = Current_Line.find('[') + 1; + unsigned last = Current_Line.find(']'); + Current_Section = Current_Line.substr(first, last - first); + + klog("Section \"%s\" Found at line %i\n", Current_Section.c_str(), Current_Line_Number); + + //Go to next line to start parsing section. + continue; + } + + std::string Member_Name = ""; + std::string Member_Data = ""; + + //Parse member name from before '=' and the data to EOL after '='. + Member_Name = Current_Line.substr(0, Current_Line.find('=')); + Member_Data = Current_Line.substr(Current_Line.find('=') + 1, (Current_Line.length() - (Current_Line.find('=') + 1) - 1)); + + //Insert member into temporary map. + Current_Members.insert(std::make_pair(Member_Name, Member_Data)); + } + + //Store The last Section. + if (Config_Data.find(Current_Section.c_str()) == Config_Data.end()) { + klog("Storing Section \"%s\" to map.\n", Current_Section.c_str()); + Config_Data.insert(std::make_pair(Current_Section, Current_Members)); + } + + if (!RFile_Handle.is_open()) { + return false; + } + + RFile_Handle.close(); + + return true; +} + +bool Config::Does_Member_Exist(const char* Section, const char* Member) +{ + if (Config_Data.find(Section) == Config_Data.end()) + { + klog("Failed to find Section \"%s\".\n", Section); + return false; + } + + if (Config_Data[Section].find(Member) == Config_Data[Section].end()) + { + klog("Failed to find Member \"%s\" in Section \"%s\".\n", Member, Section); + return false; + } + + return true; +} + +bool Config::Read_Bool(const char* Section, const char* Member) +{ + if (!Does_Member_Exist(Section, Member)) + return false; + + std::string Data = Config_Data[Section][Member]; + + if (Data.compare("true") || Data.compare("yes") || Data.compare("1")) + return true; + else + return false; +} + +int Config::Read_Int(const char* Section, const char* Member) +{ + if (!Does_Member_Exist(Section, Member)) + return -1; + + return atoi(Config_Data[Section][Member].c_str()); +} + +float Config::Read_Float(const char* Section, const char* Member) +{ + if (!Does_Member_Exist(Section, Member)) + return -1.0f; + + return atof(Config_Data[Section][Member].c_str()); +} + +std::string Config::Read_String(const char* Section, const char* Member) +{ + if (!Does_Member_Exist(Section, Member)) + return ""; + + return Config_Data[Section][Member]; +}*/ + +Config::Data_s* Config::Data; +#define CFG_VERSION 1 + +bool Config::Read(const char* File) +{ + int fd = sceKernelOpen(File, SCE_KERNEL_O_RDONLY, 0511); + + if (fd) + { + //Reade the data then close the file handle. + sceKernelRead(fd, (void*)Data, sizeof(Data_s)); + sceKernelClose(fd); + + //Make sure the version matches. + if (Data->Version != CFG_VERSION) + { + klog("[Config] CFG Version miss match (%i != %i)...\nConfig Could be corrupt...\n", CFG_VERSION, Data->Version); + + return false; + } + + //Could be a good idea to take a digest here to see if things have changed and compare with the digest at 0x4. + + + klog("[Config] Read Config Sucessfully.\n"); + + return true; + } + else + { + klog("[Config] File: %s Does not exist.\n", File); + return false; + } +} + +bool Config::Parse(const char* File) +{ + if (Read(File)) + { + //Parse data out. + Menu::Auto_Load_Settings = Data->Auto_Load_Settings; + Debug_Feature::DebugTitleIdLabel::ShowLabels = Data->Show_DebugTitleIdLabel; + Debug_Feature::DevkitPanel::ShowPanel = Data->Show_DevkitPanel; + Debug_Feature::Custom_Content::Show_Debug_Settings = Data->Show_Debug_Settings; + Debug_Feature::Custom_Content::Show_App_Home = Data->Show_App_Home; + + Build_Overlay::Draw = Data->Show_Build_Overlay; + + strcpy(Game_Overlay::Location, Data->Game_Overlay_Location); + Game_Overlay::Show_CPU_Usage = Data->Show_CPU_Usage; + Game_Overlay::Show_Thread_Count = Data->Show_Thread_Count; + Game_Overlay::Show_ram = Data->Show_ram; + Game_Overlay::Show_vram = Data->Show_vram; + Game_Overlay::Show_CPU_Temp = Data->Show_CPU_Temp; + Game_Overlay::Show_SOC_Temp = Data->Show_SOC_Temp; + + return true; + } + + return false; +} + +bool Config::Write(const char* File) +{ + int fd = sceKernelOpen(File, SCE_KERNEL_O_CREAT | SCE_KERNEL_O_WRONLY, 0777); + + if (fd) + { + //Build new cfg file. + Data->Version = CFG_VERSION; + + Data->Auto_Load_Settings = Menu::Auto_Load_Settings; + Data->Show_DebugTitleIdLabel = Debug_Feature::DebugTitleIdLabel::ShowLabels; + Data->Show_DevkitPanel = Debug_Feature::DevkitPanel::ShowPanel; + Data->Show_Debug_Settings = Debug_Feature::Custom_Content::Show_Debug_Settings; + Data->Show_App_Home = Debug_Feature::Custom_Content::Show_App_Home; + + Data->Show_Build_Overlay = Build_Overlay::Draw; + + strcpy(Data->Game_Overlay_Location, Game_Overlay::Location); + Data->Show_CPU_Usage = Game_Overlay::Show_CPU_Usage; + Data->Show_Thread_Count = Game_Overlay::Show_Thread_Count; + Data->Show_ram = Game_Overlay::Show_ram; + Data->Show_vram = Game_Overlay::Show_vram; + Data->Show_CPU_Temp = Game_Overlay::Show_CPU_Temp; + Data->Show_SOC_Temp = Game_Overlay::Show_SOC_Temp; + + //Take digest and write it. + + //Write Data + sceKernelWrite(fd, (void*)Data, sizeof(Data_s)); + sceKernelClose(fd); + + return true; + } + else + { + klog("[Config] File: %s Does not exist & Could not be created.\n", File); + return false; + } +} + +void Config::Init() +{ + Data = new Data_s(); +} + +void Config::Term() +{ + delete Data; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Config.h b/Playstation/Orbis Toolbox/Config.h new file mode 100644 index 0000000..cb8651a --- /dev/null +++ b/Playstation/Orbis Toolbox/Config.h @@ -0,0 +1,62 @@ +/*#pragma once + +#include +#include +#include +#include +#include + +class Config +{ +public: + bool Parse(const char* File); + + bool Read_Bool(const char* Section, const char* Member); + int Read_Int(const char* Section, const char* Member); + float Read_Float(const char* Section, const char* Member); + std::string Read_String(const char* Section, const char* Member); + +private: + std::fstream RFile_Handle; + std::fstream WFile_Handle; + + std::map> Config_Data; + + bool Does_Member_Exist(const char* Section, const char* Member); +};*/ +#pragma once + +class Config +{ +private: + struct Data_s + { + int Version; + + bool Auto_Load_Settings; + bool Show_DebugTitleIdLabel; + bool Show_DevkitPanel; + bool Show_Debug_Settings; + bool Show_App_Home; + + bool Show_Build_Overlay; + + char Game_Overlay_Location[0x100]; + bool Show_CPU_Usage; + bool Show_Thread_Count; + bool Show_ram; + bool Show_vram; + bool Show_CPU_Temp; + bool Show_SOC_Temp; + }; + +public: + static Data_s* Data; + + static bool Read(const char* File); + static bool Parse(const char* File); + static bool Write(const char* File); + + static void Init(); + static void Term(); +}; diff --git a/Playstation/Orbis Toolbox/Custom_Content.cpp b/Playstation/Orbis Toolbox/Custom_Content.cpp new file mode 100644 index 0000000..09db1f5 --- /dev/null +++ b/Playstation/Orbis Toolbox/Custom_Content.cpp @@ -0,0 +1,111 @@ +#include "Common.h" +#include "Debug_Features.h" + +Detour* Debug_Feature::Custom_Content::Detour_ExecuteSelectQuery = nullptr; +Detour* Debug_Feature::Custom_Content::Detour_ExecuteCountQuery = nullptr; +Detour* Debug_Feature::Custom_Content::Detour_StartDebugSettings = nullptr; +Detour* Debug_Feature::Custom_Content::Detour_GetIconPath = nullptr; +Detour* Debug_Feature::Custom_Content::Detour_IsInstalled = nullptr; + +bool Debug_Feature::Custom_Content::Show_App_Home; +bool Debug_Feature::Custom_Content::Show_Debug_Settings; + +MonoObject* Debug_Feature::Custom_Content::ExecuteSelectQuery_Hook(MonoObject* Instance, int offset, int limit) +{ + //System.Collections.Generic List + MonoClass* List = Mono::Get_Class(Mono::mscorlib, "System.Collections.Generic", "List`1"); + + MonoObject* List_Instance = Detour_ExecuteSelectQuery->Stub(Instance, offset, limit); + if (Mono::Get_Field(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemAccessor", Instance, "exclusionFilterTypeAppHome") == 0) + { + if (Show_Debug_Settings) + Mono::Invoke(Mono::Accessor_Db, List, List_Instance, "Insert", 0, UI::Utilities::AppBrowseItem("NPXS20993", "★Orbis Toolbox")); + + if (Show_App_Home) + { + Mono::Invoke(Mono::Accessor_Db, List, List_Instance, "Insert", 0, UI::Utilities::AppBrowseItem("NPXS29998", "★APP_HOME(data)")); + Mono::Invoke(Mono::Accessor_Db, List, List_Instance, "Insert", 0, UI::Utilities::AppBrowseItem("NPXS29999", "★APP_HOME(host)")); + } + + } + + return List_Instance; +} + +int Debug_Feature::Custom_Content::ExecuteCountQuery_Hook(MonoObject* Instance) +{ + int Count = Detour_ExecuteCountQuery->Stub(Instance); + + if (Mono::Get_Field(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemAccessor", Instance, "exclusionFilterTypeAppHome") == 0) + { + if (Show_Debug_Settings) + Count += 1; + + if (Show_App_Home) + Count += 2; + } + + return Count; +} + +void Debug_Feature::Custom_Content::StartDebugSettings_Hook(MonoObject* Instance) +{ + MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager"); + MonoClass* SettingsApplication = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI", "SettingsApplication"); + Mono::Invoke(Mono::App_exe, UIManager, Mono::Get_Field(SettingsApplication, Instance, "uiManager"), "Push", Mono::New_String("orbis_toolbox.xml"), Mono::New_String("id_orbis_toolbox"), 3); +} + +MonoString* GetTexture(const char* texId) +{ + // /Application/resource/Sce.Vsh.ShellUI.Base.rco + return Mono::New_String("cxml://BasePlugin/%s", texId); +} + +MonoString* Debug_Feature::Custom_Content::GetIconPath_Hook(MonoObject* item, bool withTheme) +{ + MonoString* IconPath = Detour_GetIconPath->Stub(item, withTheme); + + char* TitleId = mono_string_to_utf8(Mono::Get_Property(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemLite", item, "TitleId")); + if (!strcmp(TitleId, "NPXS29999")) + return GetTexture("tex_app_home"); + else if (!strcmp(TitleId, "NPXS29998")) + return GetTexture("tex_app_home_data"); + else if (!strcmp(TitleId, "NPXS20993")) + return GetTexture("tex_debug_settings"); + else + return IconPath; +} + +bool Debug_Feature::Custom_Content::IsInstalled_Hook(MonoString* titleId) +{ + char* ctitleId = mono_string_to_utf8(titleId); + + // Kinda ghetto but the detour stub was brokie. + return strstr(ctitleId, "NPXS20") != nullptr || (!strcmp(ctitleId, "NPXS21008") || !strcmp(ctitleId, "NPXS27003")) || !strcmp(ctitleId, "NPXS27009") || !strcmp(ctitleId, "NPXS29998") || !strcmp(ctitleId, "NPXS29999"); +} + +void Debug_Feature::Custom_Content::Init() +{ + Detour_ExecuteSelectQuery = new Detour(); + Detour_ExecuteCountQuery = new Detour(); + Detour_StartDebugSettings = new Detour(); + Detour_GetIconPath = new Detour(); + Detour_IsInstalled = new Detour(); + + + + Detour_ExecuteSelectQuery->DetourMethod(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemAccessor", "ExecuteSelectQuery", 2, (void*)ExecuteSelectQuery_Hook); + Detour_ExecuteCountQuery->DetourMethod(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemAccessor", "ExecuteCountQuery", 0, (void*)ExecuteCountQuery_Hook); + Detour_StartDebugSettings->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI", "SettingsApplication", "StartDebugSettings", 0, (void*)StartDebugSettings_Hook); + Detour_GetIconPath->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "AppBrowseItemMethodExteneder", "GetIconPath", 2, (void*)GetIconPath_Hook); + Detour_IsInstalled->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "ApplicationMonitor/AppConfig", "IsLaunchable", 1, (void*)IsInstalled_Hook); +} + +void Debug_Feature::Custom_Content::Term() +{ + delete Detour_ExecuteSelectQuery; + delete Detour_ExecuteCountQuery; + delete Detour_StartDebugSettings; + delete Detour_GetIconPath; + delete Detour_IsInstalled; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Daemons.cpp b/Playstation/Orbis Toolbox/Daemons.cpp new file mode 100644 index 0000000..8d11174 --- /dev/null +++ b/Playstation/Orbis Toolbox/Daemons.cpp @@ -0,0 +1,131 @@ +#include "Common.h" +#include "Daemons.h" + +#include "SysfileUtilWrapper.h" +#include "LncUtil.h" + +bool Start_Daemon(char* TitleId) +{ + if (!Is_Daemon_Running(TitleId)) + { + LncUtil::LaunchAppParam p = { sizeof(LncUtil::LaunchAppParam), -1, 0, 0, LncUtil::Flag_None }; + LncUtil::LaunchApp(TitleId, 0, 0, &p); + + if (!Is_Daemon_Running(TitleId)) + return false; + } + + return true; +} + +bool Stop_Daemon(char* TitleId) +{ + int AppId = LncUtil::GetAppId(TitleId); + if (AppId > 0) + { + LncUtil::KillApp(AppId); + + if (Is_Daemon_Running(TitleId)) + return false; + } + + return true; +} + +bool Is_Daemon_Running(char* TitleId) +{ + return (LncUtil::GetAppId(TitleId) > 0); +} + +/* + Will start or stop a Daemon depending on its state. + + TitleId - A string representing the Daemons title Index usually in form of XXXX##### + Restart - If the Daemon is already running will stop and restart it. +*/ +bool Start_Stop_Daemon(char* TitleId, bool Restart) +{ + int AppId = LncUtil::GetAppId(TitleId); + if (AppId > 0) + { + LncUtil::KillApp(AppId); + + if ((LncUtil::GetAppId(TitleId) <= 0) && Restart) + return Start_Stop_Daemon(TitleId, false); + else if (LncUtil::GetAppId(TitleId) <= 0) + return true; + else + return false; + } + else + { + LncUtil::LaunchAppParam p = { sizeof(LncUtil::LaunchAppParam), -1, 0, 0, LncUtil::Flag_None }; + LncUtil::LaunchApp(TitleId, 0, 0, &p); + + return (LncUtil::GetAppId(TitleId) > 0); + } +} + +void Add_Daemon(char* dent) +{ + char TitleId[10]; + char Id_Name[0x100]; + char Icon_Path[PATH_MAX]; + char SFO_Path[PATH_MAX]; + + strcpy(TitleId, dent); + sprintf(Id_Name, "id_%s", TitleId); + sprintf(Icon_Path, "file://system/vsh/app/%s/sce_sys/icon0.png", TitleId); + sprintf(SFO_Path, "/system/vsh/app/%s/sce_sys/param.sfo", TitleId); + + //Adds a custom button to the current drawing stack with the name and desc. of the daemon from the param.sfo + UI::Utilities::AddMenuItem(UI::Utilities::ElementData(Id_Name, SysfileUtilWrapper::GetTitle(SFO_Path), SysfileUtilWrapper::GetDescription(SFO_Path), Icon_Path)); + + //Remove Menu Option if already Exists. + if (Menu::Has_Option(Id_Name)) + Menu::Remove_Option(Id_Name); + + //Add Menu Option with call back to load Daemon. + Menu::Add_Option(Id_Name, [TitleId, Id_Name]() -> void { + + int AppId = LncUtil::GetAppId(TitleId); + if (AppId > 0) //App is Currently Running. + { + UI::Utilities::Set_Value(Id_Name, "Stopping"); + UI::Utilities::ResetMenuItem(Id_Name); + + //Kill the app. + LncUtil::KillApp(AppId); + + //Check to see if it worked. + UI::Utilities::Set_Value(Id_Name, (LncUtil::GetAppId(TitleId) > 0) ? "Running" : "Stopped"); + UI::Utilities::ResetMenuItem(Id_Name); + } + else + { + UI::Utilities::Set_Value(Id_Name, "Starting"); + UI::Utilities::ResetMenuItem(Id_Name); + + LncUtil::LaunchAppParam p = { sizeof(LncUtil::LaunchAppParam), -1, 0, 0, LncUtil::Flag_None }; + LncUtil::LaunchApp(TitleId, 0, 0, &p); + + //Check to see if it worked. + UI::Utilities::Set_Value(Id_Name, (LncUtil::GetAppId(TitleId) > 0) ? "Running" : "Stopped"); + UI::Utilities::ResetMenuItem(Id_Name); + } + + }); + + //Shows the current status of the daemon. + UI::Utilities::Set_Value(Id_Name, (LncUtil::GetAppId(TitleId) > 0) ? "Running" : "Stopped"); + UI::Utilities::ResetMenuItem(Id_Name); +} + +void Remove_Daemon(char* dent) +{ + char Id_Name[0x100]; + sprintf(Id_Name, "id_%s", dent); + + UI::Utilities::RemoveMenuItem(Id_Name); + Menu::Remove_Option(Id_Name); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Daemons.h b/Playstation/Orbis Toolbox/Daemons.h new file mode 100644 index 0000000..c54db6b --- /dev/null +++ b/Playstation/Orbis Toolbox/Daemons.h @@ -0,0 +1,8 @@ +#pragma once +bool Start_Daemon(char* TitleId); +bool Stop_Daemon(char* TitleId); +bool Is_Daemon_Running(char* TitleId); +bool Start_Stop_Daemon(char* TitleId, bool Restart = false); + +void Add_Daemon(char* dent); +void Remove_Daemon(char* dent); \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/DebugTitleIdLabel.cpp b/Playstation/Orbis Toolbox/DebugTitleIdLabel.cpp new file mode 100644 index 0000000..8c0daab --- /dev/null +++ b/Playstation/Orbis Toolbox/DebugTitleIdLabel.cpp @@ -0,0 +1,130 @@ +#include "Common.h" +#include "Debug_Features.h" + +void(*Debug_Feature::DebugTitleIdLabel::CreateDebugTitleIdLabel)(MonoObject* Instance); +Detour* Debug_Feature::DebugTitleIdLabel::Detour_ContentDecoratorBase_Constructor = nullptr; + +Patcher* Debug_Feature::DebugTitleIdLabel::Patch_createDevKitPanel = nullptr; + +bool Debug_Feature::DebugTitleIdLabel::ShowLabels = false; + +uint64_t Debug_Feature::DebugTitleIdLabel::ContentDecoratorBase_Constructor_Hook(MonoObject* Instance, uint64_t param) +{ + uint64_t res = Detour_ContentDecoratorBase_Constructor->Stub(Instance, param); + + if (ShowLabels) + CreateDebugTitleIdLabel(Instance); + + return res; +} + +void Debug_Feature::DebugTitleIdLabel::AddTitleId(MonoObject* m_contentsGridList) +{ + MonoClass* ReadOnlyCollection = Mono::Get_Class(Mono::mscorlib, "System.Collections.ObjectModel", "ReadOnlyCollection`1"); + + if (m_contentsGridList) + { + MonoObject* ActiveItems = Mono::Get_Property(Mono::UI_dll, Mono::PUI_UI2, "ListPanelBase", m_contentsGridList, "ActiveItems"); + + for (int i = 0; i < Mono::Get_Property(ReadOnlyCollection, ActiveItems, "Count"); i++) + { + MonoObject* Member = Mono::Invoke(Mono::mscorlib, ReadOnlyCollection, ActiveItems, "get_Item", i); + MonoObject* ListVisualizer = Mono::Get_Property(Mono::Vsh_Lx, "Sce.Vsh.Lx", "ListItem", Member, "ListVisualizer"); + MonoObject* m_decorator = Mono::Get_Field(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentVisualizer", ListVisualizer, "m_decorator"); + CreateDebugTitleIdLabel(m_decorator); + } + } +} + +void Debug_Feature::DebugTitleIdLabel::RemoveTitleId(MonoObject* m_contentsGridList) +{ + MonoClass* ReadOnlyCollection = Mono::Get_Class(Mono::mscorlib, "System.Collections.ObjectModel", "ReadOnlyCollection`1"); + + if (m_contentsGridList) + { + MonoObject* ActiveItems = Mono::Get_Property(Mono::UI_dll, Mono::PUI_UI2, "ListPanelBase", m_contentsGridList, "ActiveItems"); + + for (int i = 0; i < Mono::Get_Property(ReadOnlyCollection, ActiveItems, "Count"); i++) + { + MonoObject* Member = Mono::Invoke(Mono::mscorlib, ReadOnlyCollection, ActiveItems, "get_Item", i); + MonoObject* ListVisualizer = Mono::Get_Property(Mono::Vsh_Lx, "Sce.Vsh.Lx", "ListItem", Member, "ListVisualizer"); + MonoObject* m_decorator = Mono::Get_Field(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentVisualizer", ListVisualizer, "m_decorator"); + MonoObject* m_iconImageBox = Mono::Get_Field(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentDecoratorBase", m_decorator, "m_iconImageBox"); + + if (m_iconImageBox) + { + MonoArray* Children = Mono::Invoke(Mono::App_exe, Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Node`1"), m_iconImageBox, "GetChildrenArray"); + + for (int i = 0; i < mono_array_length(Children); i++) + { + MonoObject* Instance = mono_array_get(Children, MonoObject*, i); + + if (!Instance) + continue; + + if (!Instance->vtable) + continue; + + if (!Instance->vtable->klass) + continue; + + if (strcmp(Instance->vtable->klass->name, "Label")) + continue; + + Mono::Invoke(Mono::App_exe, Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Widget"), Instance, "RemoveFromParent"); + } + } + } + } +} + +void Debug_Feature::DebugTitleIdLabel::Update() +{ + Debug_Feature::DebugTitleIdLabel::ShowLabels ? Show() : Hide(); +} + +void Debug_Feature::DebugTitleIdLabel::Show() +{ + MonoClass* ContentsAreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentsAreaManager"); + MonoObject* m_scene = Mono::Get_Field(ContentsAreaManager, Mono::Get_Instance(ContentsAreaManager, "Instance"), "m_scene"); + MonoArray* m_contentsGridList = Mono::Get_Field(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentAreaScene", m_scene, "m_contentsGridList"); + + AddTitleId(mono_array_get(m_contentsGridList, MonoObject*, 0)); + AddTitleId(mono_array_get(m_contentsGridList, MonoObject*, 1)); + + ShowLabels = true; +} + +void Debug_Feature::DebugTitleIdLabel::Hide() +{ + MonoClass* ContentsAreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentsAreaManager"); + MonoObject* m_scene = Mono::Get_Field(ContentsAreaManager, Mono::Get_Instance(ContentsAreaManager, "Instance"), "m_scene"); + MonoArray* m_contentsGridList = Mono::Get_Field(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentAreaScene", m_scene, "m_contentsGridList"); + + RemoveTitleId(mono_array_get(m_contentsGridList, MonoObject*, 0)); + RemoveTitleId(mono_array_get(m_contentsGridList, MonoObject*, 1)); + + ShowLabels = false; +} + +void Debug_Feature::DebugTitleIdLabel::Init() +{ + uint64_t CreateDebugTitleIdLabel_addr = Mono::Get_Address_of_Method(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentDecoratorBase", "CreateDebugTitleIdLabel", 0); + CreateDebugTitleIdLabel = decltype(CreateDebugTitleIdLabel)(CreateDebugTitleIdLabel_addr); + + //Patch RegMgr Check + Patch_createDevKitPanel = new Patcher(); + Patch_createDevKitPanel->Install_Method_Patch(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentDecoratorBase", "CreateDebugTitleIdLabel", 0, 0x2C, "\x90\x90\x90\x90\x90\x90", 6); + + Detour_ContentDecoratorBase_Constructor = new Detour(); + Detour_ContentDecoratorBase_Constructor->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Library", "ContentDecoratorBase", ".ctor", 1, (void*)ContentDecoratorBase_Constructor_Hook); +} + +void Debug_Feature::DebugTitleIdLabel::Term() +{ + //Clean up Patches + delete Patch_createDevKitPanel; + + //Clean up Detours + delete Detour_ContentDecoratorBase_Constructor; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Debug_Features.h b/Playstation/Orbis Toolbox/Debug_Features.h new file mode 100644 index 0000000..72a2860 --- /dev/null +++ b/Playstation/Orbis Toolbox/Debug_Features.h @@ -0,0 +1,71 @@ +#pragma once + +class Debug_Feature +{ +public: + class Custom_Content + { + private: + static Detour* Detour_ExecuteSelectQuery; + static Detour* Detour_ExecuteCountQuery; + static Detour* Detour_StartDebugSettings; + static Detour* Detour_GetIconPath; + static Detour* Detour_IsInstalled; + + static MonoObject* ExecuteSelectQuery_Hook(MonoObject* Instance, int offset, int limit); + static int ExecuteCountQuery_Hook(MonoObject* Instance); + static void StartDebugSettings_Hook(MonoObject* Instance); + static MonoString* GetIconPath_Hook(MonoObject* item, bool withTheme); + static bool IsInstalled_Hook(MonoString* titleId); + + public: + static bool Show_App_Home; + static bool Show_Debug_Settings; + + static void Init(); + static void Term(); + }; + + class DebugTitleIdLabel + { + private: + static void(*CreateDebugTitleIdLabel)(MonoObject* Instance); + static Detour* Detour_ContentDecoratorBase_Constructor; + static uint64_t ContentDecoratorBase_Constructor_Hook(MonoObject* Instance, uint64_t param); + + static Patcher* Patch_createDevKitPanel; + + static void AddTitleId(MonoObject* m_contentsGridList); + static void RemoveTitleId(MonoObject* m_contentsGridList); + + public: + static bool ShowLabels; + + static void Update(); + static void Show(); + static void Hide(); + static void Init(); + static void Term(); + }; + + class DevkitPanel + { + private: + static void(*createDevKitPanel)(MonoObject* Instance); + static Detour* Detour_AreaManager_Constructor; + static uint64_t AreaManager_Constructor_Hook(MonoObject* Instance); + + public: + static bool ShowPanel; + + static void Update(); + static void Show(); + static void Hide(); + static bool GetState(); + static void Init(); + static void Term(); + }; + +private: + +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Detour.cpp b/Playstation/Orbis Toolbox/Detour.cpp new file mode 100644 index 0000000..54aa9b2 --- /dev/null +++ b/Playstation/Orbis Toolbox/Detour.cpp @@ -0,0 +1,109 @@ +#include "Common.h" +#include "Detour.h" +#include "Mono.h" +#include "hde64.h" + +void Detour::WriteJump(void* Address, void* Destination) +{ + uint8_t JumpInstructions[] = { + 0xFF, 0x25, 0x00, 0x00, 0x00, 0x00, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, // jmp QWORD PTR[Address] + }; + + //Write the address of our hook to the instruction. + *(uint64_t*)(JumpInstructions + 6) = (uint64_t)Destination; + + sceKernelMprotect((void*)Address, sizeof(JumpInstructions), VM_PROT_ALL); + memcpy(Address, JumpInstructions, sizeof(JumpInstructions)); +} + +void* Detour::DetourFunction(uint64_t FunctionPtr, void* HookPtr) +{ + if (FunctionPtr == NULL || HookPtr == NULL) + { + klog("[Detour] DetourFunction: FunctionPtr or HookPtr NULL (%llX -> %llX)\n", FunctionPtr, HookPtr); + return (void*)0; + } + uint32_t InstructionSize = 0; + + while (InstructionSize < 14) + { + hde64s hs; + uint32_t temp = hde64_disasm((void*)(FunctionPtr + InstructionSize), &hs); + + if (hs.flags & F_ERROR) + return (void*)0; + + InstructionSize += temp; + } + + klog("InstructionSize: %i\n", InstructionSize); + + if (InstructionSize < 14) + { + klog("[Detour] DetourFunction: Hooking Requires a minimum of 14 bytes to write jump!\n"); + return (void*)0; + } + + //Save Pointers for later + this->FunctionPtr = (void*)FunctionPtr; + this->HookPtr = HookPtr; + + //Set protection. + sceKernelMprotect((void*)FunctionPtr, InstructionSize, VM_PROT_ALL); + + //Allocate Executable memory for stub and write instructions to stub and a jump back to original execution. + this->StubSize = (InstructionSize + 14); + int res = sceKernelMmap(0, this->StubSize, VM_PROT_ALL, 0x1000 | 0x2, -1, 0, &this->StubPtr); + if (res < 0 || this->StubPtr == 0) + { + klog("[Detour] sceKernelMmap Failed: 0x%llX\n", res); + return 0; + } + + memcpy(StubPtr, (void*)FunctionPtr, InstructionSize); + WriteJump((void*)((uint64_t)StubPtr + InstructionSize), (void*)(FunctionPtr + InstructionSize)); + + //Write jump from function to hook. + WriteJump((void*)FunctionPtr, HookPtr); + + klog("[Detour] DetourFunction: Detour (%llX -> %llX) Written Successfully!\n", FunctionPtr, this->HookPtr); + + return this->StubPtr; +} + +void* Detour::DetourMethod(MonoImage* Assembly_Image, const char* Namespace, const char* Klass, const char* Method, int Param_Count, void* HookPtr) +{ + uint64_t Method_addr = Mono::Get_Address_of_Method(Assembly_Image, Namespace, Klass, Method, Param_Count); + + if (Method_addr == NULL) + { + klog("[Detour] DetourMethod: Method address returned null!\n"); + return (void*)0; + } + + return DetourFunction(Method_addr, HookPtr); +} + +void Detour::RestoreFunction() +{ + if (this->StubPtr) + { + sceKernelMprotect((void*)this->FunctionPtr, this->StubSize - 14, VM_PROT_ALL); + memcpy((void*)this->FunctionPtr, this->StubPtr, this->StubSize - 14); + + klog("[Detour] RestoreFunction: (%llX) has been Restored Successfully!\n", this->FunctionPtr); + } +} + +Detour::Detour() +{ + +} + +Detour::~Detour() +{ + RestoreFunction(); + + //Clean up + sceKernelMunmap(this->StubPtr, this->StubSize); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Detour.h b/Playstation/Orbis Toolbox/Detour.h new file mode 100644 index 0000000..d33ee71 --- /dev/null +++ b/Playstation/Orbis Toolbox/Detour.h @@ -0,0 +1,28 @@ +#pragma once + +class Detour +{ +private: + + void* StubPtr = 0; + size_t StubSize = 0; + + void* FunctionPtr = 0; + void* HookPtr = 0; + +public: + template + result Stub(Args... args) + { + result(*Stub_internal)(Args... args) = decltype(Stub_internal)(StubPtr); + return Stub_internal(args...); + } + + void WriteJump(void* Address, void* Destination); + void* DetourFunction(uint64_t FunctionPtr, void* HookPtr); + void* DetourMethod(MonoImage* Assembly_Image, const char* Namespace, const char* Klass, const char* Method, int Param_Count, void* HookPtr); + void RestoreFunction(); + + Detour(); + ~Detour(); +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/DevkitPanel.cpp b/Playstation/Orbis Toolbox/DevkitPanel.cpp new file mode 100644 index 0000000..f93ceac --- /dev/null +++ b/Playstation/Orbis Toolbox/DevkitPanel.cpp @@ -0,0 +1,109 @@ +#include "Common.h" +#include "Debug_Features.h" + +void(*Debug_Feature::DevkitPanel::createDevKitPanel)(MonoObject* Instance) = nullptr; +Detour* Debug_Feature::DevkitPanel::Detour_AreaManager_Constructor = nullptr; + +bool Debug_Feature::DevkitPanel::ShowPanel = false; + +uint64_t Debug_Feature::DevkitPanel::AreaManager_Constructor_Hook(MonoObject* Instance) +{ + uint64_t res = Detour_AreaManager_Constructor->Stub(Instance); + + if (ShowPanel) + createDevKitPanel(Instance); + + return res; +} + +void Debug_Feature::DevkitPanel::Update() +{ + Debug_Feature::DevkitPanel::ShowPanel ? Show() : Hide(); +} + +void Debug_Feature::DevkitPanel::Show() +{ + MonoClass* AreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager"); + MonoObject* AreaManager_Instance = Mono::Get_Instance(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", "Instance"); + MonoObject* m_devKitPanel = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_devKitPanel"); + MonoClass* Widget = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Widget"); + + // AreaManager.Instance.m_devKitPanel + // If m_devKitPanel is null we must create the panel first. + if (!m_devKitPanel) + { + createDevKitPanel(Mono::Get_Instance(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", "Instance")); + } + else + { + MonoClass* UITimer = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UITimer"); + MonoObject* m_updatePanelTimer = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_updatePanelTimer"); + + // AreaManager.Instance.m_updatePanelTimer.Start() + // If the m_updatePanelTimer is initialized start the timer. + if (m_updatePanelTimer) + Mono::Invoke(Mono::UI_dll, UITimer, m_updatePanelTimer, "Start"); + + // AreaManager.Instance.m_devKitPanel.Show() + // Show the panel. + MonoClass* UINode = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UINode"); + Mono::Invoke(Mono::UI_dll, UINode, m_devKitPanel, "Show"); + } + + ShowPanel = true; +} + +void Debug_Feature::DevkitPanel::Hide() +{ + MonoClass* AreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager"); + MonoObject* AreaManager_Instance = Mono::Get_Instance(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", "Instance"); + + MonoClass* UITimer = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UITimer"); + MonoObject* m_updatePanelTimer = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_updatePanelTimer"); + + // AreaManager.Instance.m_updatePanelTimer.Stop() + // If the m_updatePanelTimer is initialized stop the timer. + if (m_updatePanelTimer) + Mono::Invoke(Mono::UI_dll, UITimer, m_updatePanelTimer, "Stop"); + + // AreaManager.Instance.m_devKitPanel.Hide() + // Hide the panel. + MonoObject* m_devKitPanel = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_devKitPanel"); + if (m_devKitPanel) + { + MonoClass* UINode = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UINode"); + Mono::Invoke(Mono::UI_dll, UINode, m_devKitPanel, "Hide"); + } + + ShowPanel = false; +} + +bool Debug_Feature::DevkitPanel::GetState() +{ + MonoClass* FrameTask = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "FrameTask"); + MonoClass* AreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager"); + MonoObject* AreaManager_Instance = Mono::Get_Instance(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", "Instance"); + MonoObject* m_devKitPanel = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_devKitPanel"); + MonoObject* m_updatePanelTimer = Mono::Get_Field(AreaManager, AreaManager_Instance, "m_updatePanelTimer"); + + if (m_devKitPanel && m_updatePanelTimer) + return !Mono::Get_Property(FrameTask, m_updatePanelTimer, "IsStopped"); + else + return false; +} + +void Debug_Feature::DevkitPanel::Init() +{ + //Get Method to make devkit panel + uint64_t createDevKitPanel_addr = Mono::Get_Address_of_Method(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", "createDevKitPanel", 0); + createDevKitPanel = decltype(createDevKitPanel)(createDevKitPanel_addr); + + //Hook AreaManager Constructor + Detour_AreaManager_Constructor = new Detour(); + Detour_AreaManager_Constructor->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager", ".ctor", 0, (void*)AreaManager_Constructor_Hook); +} + +void Debug_Feature::DevkitPanel::Term() +{ + delete Detour_AreaManager_Constructor; +} diff --git a/Playstation/Orbis Toolbox/Embed.s b/Playstation/Orbis Toolbox/Embed.s new file mode 100644 index 0000000..f5596ce --- /dev/null +++ b/Playstation/Orbis Toolbox/Embed.s @@ -0,0 +1,37 @@ +.section .rodata + .global settings_root + .type settings_root, @object + .align 4 + .global orbis_toolbox + .type orbis_toolbox, @object + .align 4 + .global external_hdd + .type external_hdd, @object + .align 4 + +settings_root: + .incbin "settings_root.xml" +settings_root_End: + .global settings_root_Size + .type settings_root_Size, @object + .align 4 +settings_root_Size: + .int settings_root_End - settings_root + +orbis_toolbox: + .incbin "orbis_toolbox.xml" +orbis_toolbox_End: + .global orbis_toolbox_Size + .type orbis_toolbox_Size, @object + .align 4 +orbis_toolbox_Size: + .int orbis_toolbox_End - orbis_toolbox + +external_hdd: + .incbin "external_hdd.xml" +external_hdd_End: + .global external_hdd_Size + .type external_hdd_Size, @object + .align 4 +external_hdd_Size: + .int external_hdd_End - external_hdd \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/GamePad.cpp b/Playstation/Orbis Toolbox/GamePad.cpp new file mode 100644 index 0000000..4593004 --- /dev/null +++ b/Playstation/Orbis Toolbox/GamePad.cpp @@ -0,0 +1,7 @@ +#include "Common.h" +#include "GamePad.h" + +bool GamePad::IsDown(int button) +{ + return Mono::Invoke(Mono::App_exe, Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.DebugSystem", "KeyMonitorTask"), NULL, "IsButtonDown", button); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/GamePad.h b/Playstation/Orbis Toolbox/GamePad.h new file mode 100644 index 0000000..4b46b6a --- /dev/null +++ b/Playstation/Orbis Toolbox/GamePad.h @@ -0,0 +1,31 @@ +#pragma once + +class GamePad +{ +private: + +public: + enum Buttons + { + Left = 1U, + Up, + Right = 4U, + Down = 8U, + Square = 16U, + Triangle = 32U, + Circle = 64U, + Cross = 128U, + Start = 256U, + Select = 512U, + L = 1024U, + R = 2048U, + L2 = 4096U, + R2 = 8192U, + L3 = 16384U, + R3 = 32768U, + Enter = 65536U, + Back = 131072U + }; + + static bool IsDown(int button); +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Game_Overlay.cpp b/Playstation/Orbis Toolbox/Game_Overlay.cpp new file mode 100644 index 0000000..5a1936b --- /dev/null +++ b/Playstation/Orbis Toolbox/Game_Overlay.cpp @@ -0,0 +1,259 @@ +#include "Common.h" +#include "Game_Overlay.h" +#include "System_Monitor.h" + +float Game_Overlay::X, Game_Overlay::Y; +bool Game_Overlay::Show_CPU_Usage = false; +bool Game_Overlay::Show_Thread_Count = false; +bool Game_Overlay::Show_ram = false; +bool Game_Overlay::Show_vram = false; +bool Game_Overlay::Show_CPU_Temp = false; +bool Game_Overlay::Show_SOC_Temp = false; +char Game_Overlay::Location[0x100] = { "Left" }; + +float Game_Overlay::Text_Height = 0.0f; +Widget* Game_Overlay::Game_Widget = nullptr; +std::map* Game_Overlay::Updater; +bool Game_Overlay::Shutdown = false; + +/* + Init_Overlay(const char* Name, CALL_BACK_TYPE_D) + This will push each of our labels made and their call backs for data updates + to a std::map. Currently it has issues with ordering **Needs refactor**. +*/ + +void Game_Overlay::Init_Overlay(const char* Name, CALL_BACK_TYPE_D) +{ + Label* Temp = new Label(Name, 10.0f, 10.0f, "", 20, Label::fsNormal, Label::fwMedium, Label::vBottom, Label::hLeft, 1.0f, 1.0f, 1.0f, 1.0f); + Game_Widget->Append_Child(Name, Temp); + Text_Height = Temp->Get_Text_Height(); + + Updater->insert(Updater->begin(), std::make_pair(Name, CallBack)); +} + +/* + Update_Location() + This will update the global vars for X and Y depending on where the user + decides to draw the overlay which is stored in the text Location. + + Currenttly supporting Left, Right and Center. May Impliment a vertical + location to this in the future. +*/ + +void Game_Overlay::Update_Location() +{ + if (!strcmp(Location, "Left")) + { + X = 10.0f, Y = 5.0f; + for (std::map::iterator it = Updater->begin(); it != Updater->end(); it++) + { + Label* Instance = (Label*)Game_Widget->Get_Child(it->first); + Instance->hAlign = Label::hLeft; + } + } + else if (!strcmp(Location, "Right")) + { + X = UI::Utilities::ScreenWidth() - 10.0f, Y = 5.0f; + for (std::map::iterator it = Updater->begin(); it != Updater->end(); it++) + { + Label* Instance = (Label*)Game_Widget->Get_Child(it->first); + Instance->hAlign = Label::hRight; + } + } + else if (!strcmp(Location, "Center")) + { + X = UI::Utilities::ScreenWidth() / 2.0f, Y = 5.0f; + for (std::map::iterator it = Updater->begin(); it != Updater->end(); it++) + { + Label* Instance = (Label*)Game_Widget->Get_Child(it->first); + Instance->hAlign = Label::hCenter; + } + } + + Update(); +} + +/* + OnRender() + Anything called in this function will be called in the main mono render + loop. + + Checks for Game_Widget pointer and boolean Shutdown for safety. + + Here we will iterate through all of the overlays supported and decide + which to draw and their location. +*/ + +void Game_Overlay::OnRender() +{ + if (!Game_Widget || Shutdown) + return; + + static int Waiter = 0; + + if (Waiter <= 0) + { + for (std::map::iterator it = Updater->begin(); it != Updater->end(); it++) + { + Label* Instance = (Label*)Game_Widget->Get_Child(it->first); + it->second(Instance); + } + + Waiter = 100; + } + else + Waiter--; +} + +void inline Game_Overlay::Update_Label(int* Location, const char* Name) +{ + Label* Instance = (Label*)Game_Widget->Get_Child(Name); + if ((*Updater)[Name](Instance)) + { + Instance->Set_Location(X, Y + (*Location * 25.0f)); + Instance->Set_Colour(1.0f, 1.0f, 1.0f, 1.0f); + *Location += 1; + } + else + Instance->Set_Colour(1.0f, 1.0f, 1.0f, 0.0f); +} + +void Game_Overlay::Update() +{ + klog("Update...\n"); + + int Count = 0; + Update_Label(&Count, "CPUUSAGE"); + Update_Label(&Count, "CPUUSAGEAVG"); + Update_Label(&Count, "THREADCOUNT"); + Update_Label(&Count, "RAMUSAGE"); + Update_Label(&Count, "VRAMUSAGE"); + Update_Label(&Count, "CPUTEMP"); + Update_Label(&Count, "SOCTEMP"); +} + +void Game_Overlay::Init() +{ + //Get Relevent Classes. + MonoClass* LayerManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "LayerManager"); + MonoClass* ContainerScene = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "ContainerScene"); + + //Initialize Game Scene widget + Game_Widget = new Widget(); + MonoObject* Game = Mono::Invoke(Mono::App_exe, LayerManager, nullptr, "FindContainerSceneByPath", Mono::New_String("Game")); + Game_Widget->Instance = Mono::Get_Property(Mono::UI_dll, Mono::PUI_UI2, "Scene", Game, "RootWidget"); + + //Set location to left. + strcpy(Location, "Left"); + X = 10.0f, Y = 5.0f; + + //Init map: For somereason doesnt work with out being allocated. + Updater = new std::map(); + + //Initialize call back for updating overlay types. + Init_Overlay("CPUTEMP", [](Label* Instance) -> bool { + + if (Show_CPU_Temp) + { + Instance->Set_Text("CPU Temp: %i C", System_Monitor::CPU_Temp); + + return true; + } + else + return false; + + }); + + Init_Overlay("SOCTEMP", [](Label* Instance) -> bool { + + if (Show_SOC_Temp) + { + Instance->Set_Text("SOC Temp: %i C", System_Monitor::SOC_Temp); + + return true; + } + else + return false; + + }); + + Init_Overlay("THREADCOUNT", [](Label* Instance) -> bool { + + if (Show_Thread_Count) + { + Instance->Set_Text("Thread Count: %i", System_Monitor::Thread_Count); + + return true; + } + else + return false; + + }); + + Init_Overlay("CPUUSAGE", [](Label* Instance) -> bool { + + if (Show_CPU_Usage) + { + Instance->Set_Text("CPU Usage: %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%%", + System_Monitor::Usage[0], System_Monitor::Usage[1], System_Monitor::Usage[2], System_Monitor::Usage[3], + System_Monitor::Usage[4], System_Monitor::Usage[5], System_Monitor::Usage[6], System_Monitor::Usage[7]); + + return true; + } + else + return false; + }); + + Init_Overlay("CPUUSAGEAVG", [](Label* Instance) -> bool { + + if (Show_CPU_Usage) + { + Instance->Set_Text("CPU Usage Average: %2.0f%%", System_Monitor::Average_Usage); + + return true; + } + else + return false; + }); + + + + Init_Overlay("RAMUSAGE", [](Label* Instance) -> bool { + + if (Show_ram) + { + Instance->Set_Text("RAM: %2.0f%% %u MB / %u MB", System_Monitor::RAM.Percentage, System_Monitor::RAM.Used, System_Monitor::RAM.Total); + + return true; + } + else + return false; + + }); + + Init_Overlay("VRAMUSAGE", [](Label* Instance) -> bool { + + if (Show_vram) + { + Instance->Set_Text("VRAM: %2.0f%% %u MB / %u MB", System_Monitor::VRAM.Percentage, System_Monitor::VRAM.Used, System_Monitor::VRAM.Total); + + return true; + } + else + return false; + + }); +} + +void Game_Overlay::Term() +{ + Shutdown = true; + + if (Game_Widget) + { + for (std::map::iterator it = Updater->begin(); it != Updater->end(); it++) + Game_Widget->Remove_Child(it->first); + + delete Game_Widget; + } +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Game_Overlay.h b/Playstation/Orbis Toolbox/Game_Overlay.h new file mode 100644 index 0000000..65af64b --- /dev/null +++ b/Playstation/Orbis Toolbox/Game_Overlay.h @@ -0,0 +1,36 @@ +#pragma once +#include "Widget.h" +#include "Common.h" + +#define CALL_BACK_TYPE bool(*)(Label*) +#define CALL_BACK_TYPE_D bool(*CallBack)(Label*) + +class Game_Overlay +{ +public: + static bool Show_CPU_Usage; + static bool Show_Thread_Count; + static bool Show_ram; + static bool Show_vram; + static bool Show_CPU_Temp; + static bool Show_SOC_Temp; + static char Location[0x100]; + + static void Update_Location(); + static void OnRender(); + + static void Update(); + static void Init(); + static void Term(); + +private: + static float X, Y; + static float Text_Height; + static Widget* Game_Widget; + + static std::map* Updater; + static bool Shutdown; + + static void Update_Label(int* Location, const char* Name); + static void Init_Overlay(const char* Name, CALL_BACK_TYPE_D); +}; diff --git a/Playstation/Orbis Toolbox/Increment.bat b/Playstation/Orbis Toolbox/Increment.bat new file mode 100644 index 0000000..b8abbf5 --- /dev/null +++ b/Playstation/Orbis Toolbox/Increment.bat @@ -0,0 +1,66 @@ +echo off +REM you need this to set and read a variable inside +REM a parethetical structure such as a FOR loop +setlocal enabledelayedexpansion + +REM This is the file we are going to alter +set filepath=%1 +set filename=%~n1%~x1 + +REM Use temp file +REM delete if already exists +REM so we can use append operator for all output +if exist "%filepath%.temp" del "%filepath%.temp" + +REM For each line in the file... +REM ...using FOR alone to parse the file skips blank lines so we... +REM ...parse the output (note single quotes) of... +REM running TYPE on the file and piping the output through FINDSTR... +REM ...with the /n switch (this adds a line number and a colon at the start of each line) +REM the FINDSTR search string is ".*" (find any characters including cr/lf) +REM Split into 2* tokens, the asterisk means %%R is the entire remainder of the line +REM delimiter being the colon thus... +REM The number is token 1, %%Q (discarded, along with the colon) +REM The original source file line is token 2, %%R +REM note we escape the pipe character with a caret ^ in the FOR dataset block +for /f "tokens=1,2* delims=:" %%Q in ('type "%filepath%" ^| findstr /n ".*"') do ( + + REM if token 2 is null then the line is blank so we echo a blank line to the temp output file + if "%%R"=="" echo. >> "%filepath%.temp" + + REM This flag gets set to 1 if we have a line that needs changing + set incflag=0 + + REM Split the line into 3 tokens with white space the delimiter + for /f "tokens=1-3 delims= " %%A in ("%%R") do ( + + REM test if an increment needs to happen and set the flag if it does + if "%%B"==%2 set incflag=1 + REM %%C is the number + + REM If the line contains a number to increment... + if !incflag! equ 1 ( + REM do it... + set /a num=%%C+1 + + REM info msg to console + echo Incrementing %%B from %%C to !num! + + REM write the altered line to file + echo %%A %%B !num! >>"%filepath%.temp" + + REM the line is a nonblank one that simply needs copying + ) else ( + + echo %%R >> "%filepath%.temp" + + REM Match those parentheses! + ) + ) +) + +REM delete original file +del "%filepath%" + +REM rename temp file to original file name +ren "%filepath%.temp" "%filename%" \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/KDriver.cpp b/Playstation/Orbis Toolbox/KDriver.cpp new file mode 100644 index 0000000..2be3a80 --- /dev/null +++ b/Playstation/Orbis Toolbox/KDriver.cpp @@ -0,0 +1,147 @@ +#include "Common.h" +#include "KDriver.h" + +bool KDriver::TestDriver() +{ + int fd = sceKernelOpen("/dev/OrbisSuite", SCE_KERNEL_O_RDONLY, 0); + if (fd > 0) + { + klog("Driver Installed...\n"); + sceKernelClose(fd); + return true; + } + + klog("Driver Not Installed...\n"); + return false; +} + +bool KDriver::GetDriverInfo(KDriver_Info* Info) +{ + int fd = sceKernelOpen("/dev/OrbisSuite", 0, 0); + if (fd > 0) + { + int res = ioctl(fd, KDRIVER_INFO, Info); + + if (res != 0) + { + klog("KDRIVER_INFO failed with %d\n", res); + + sceKernelClose(fd); + + return false; + } + + sceKernelClose(fd); + + return true; + } + else + klog("Where kernel??\n"); + + return false; +} + +int KDriver::GetProcessList(int ProcessCount, ProcInfo* ProcList) +{ + auto fd = sceKernelOpen("/dev/OrbisSuite", 0, 0); + if (fd > 0) + { + auto Info = new KDriver_ProcList(); + Info->UserlandAddr = (uint64_t)ProcList; + Info->UserlandSize = ((sizeof(ProcInfo) * ProcessCount)); + Info->ProcCount = ProcessCount; + + auto res = ioctl(fd, PROC_LIST, Info); + + if (res != 0) + { + delete Info; + + sceKernelClose(fd); + + return res; + } + + sceKernelClose(fd); + + delete Info; + + return Info->ProcCount; + } + else + klog("Where kernel??\n"); + + return -1; +} + +int KDriver::LoadSPRX(const char* ProccessName, const char* Path, bool ShouldCallEntry) +{ + klog("OrbisDriver::LoadSPRX\n"); + auto fd = sceKernelOpen("/dev/OrbisSuite", 0, 0); + if (fd > 0) + { + KDriver_ProcSPRX ProcSPRX; + ProcSPRX.CallType = 0; + strcpy(ProcSPRX.ProcName, ProccessName); + strcpy(ProcSPRX.Path, Path); + ProcSPRX.CallEntryExit = ShouldCallEntry; + + auto res = ioctl(fd, PROC_SPRX, &ProcSPRX); + + sceKernelClose(fd); + + return res; + } + else + klog("Where kernel??\n"); + + return -1; +} + +int KDriver::UnLoadSPRX(const char* ProccessName, const char* Name, bool ShouldCallExit) +{ + klog("OrbisDriver::UnLoadSPRX\n"); + auto fd = sceKernelOpen("/dev/OrbisSuite", 0, 0); + if (fd > 0) + { + KDriver_ProcSPRX ProcSPRX; + ProcSPRX.CallType = 1; + strcpy(ProcSPRX.ProcName, ProccessName); + strcpy(ProcSPRX.Path, Name); + ProcSPRX.CallEntryExit = ShouldCallExit; + + auto res = ioctl(fd, PROC_SPRX, &ProcSPRX); + + sceKernelClose(fd); + + return res; + } + else + klog("Where kernel??\n"); + + return -1; +} + +int KDriver::UnLoadSPRX(const char* ProccessName, int ModuleHandle, bool ShouldCallExit) +{ + klog("OrbisDriver::UnLoadSPRX\n"); + auto fd = sceKernelOpen("/dev/OrbisSuite", 0, 0); + if (fd > 0) + { + KDriver_ProcSPRX ProcSPRX; + ProcSPRX.CallType = 2; + strcpy(ProcSPRX.ProcName, ProccessName); + ProcSPRX.Handle = ModuleHandle; + ProcSPRX.CallEntryExit = ShouldCallExit; + + auto res = ioctl(fd, PROC_SPRX, &ProcSPRX); + + sceKernelClose(fd); + + return res; + } + else + klog("Where kernel??\n"); + + return -1; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/KDriver.h b/Playstation/Orbis Toolbox/KDriver.h new file mode 100644 index 0000000..3713ef0 --- /dev/null +++ b/Playstation/Orbis Toolbox/KDriver.h @@ -0,0 +1,25 @@ +#pragma once +#include "../../Misc/DriverDefinitions.h" + +class KDriver +{ +public: + // Driver + static bool TestDriver(); + static bool GetDriverInfo(KDriver_Info* Info); + + // Proc + static int GetProcessList(int ProcessCount, ProcInfo* ProcList); + // AttachtoProcess + // DetachfromProcess + // ReadProcessMemory + // WriteProcessMemory + // GetProcessInfo + // GetModuleList + static int LoadSPRX(const char* ProccessName, const char* Path, bool ShouldCallEntry = true); + static int UnLoadSPRX(const char* ProccessName, const char* Name, bool ShouldCallExit = true); + static int UnLoadSPRX(const char* ProccessName, int ModuleHandle, bool ShouldCallExit = true); + +private: + +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Label.cpp b/Playstation/Orbis Toolbox/Label.cpp new file mode 100644 index 0000000..35b2e8c --- /dev/null +++ b/Playstation/Orbis Toolbox/Label.cpp @@ -0,0 +1,107 @@ +#include "Common.h" +#include "UI.h" +#include "Widget.h" +#include "Label.h" + +void Label::Set_Location(float X, float Y) +{ + this->X = X; this->Y = Y; + + if (hAlign == HorizontalAlignment::hRight) + X -= Get_Text_Width(); + else if (hAlign == HorizontalAlignment::hCenter) + X -= (Get_Text_Width() / 2.0f); + + Mono::Set_Property(Label_Class, Instance, "X", X); + Mono::Set_Property(Label_Class, Instance, "Y", Y); +} + +void Label::Set_Font(int Size, FontStyle Style, FontWeight Weight) +{ + Mono::Set_Property_Invoke(Label_Class, Instance, "Font", UI::Utilities::IUFont(Size, Style, Weight)); +} + +void Label::Set_Alignment(VerticalAlignment Vertical_Align, HorizontalAlignment Horizontal_Align) +{ + vAlign = Vertical_Align; + hAlign = Horizontal_Align; + Set_Location(X, Y); + + Mono::Set_Property(Label_Class, Instance, "VerticalAlignment", Vertical_Align); + Mono::Set_Property(Label_Class, Instance, "HorizontalAlignment", Horizontal_Align); +} + +void Label::Set_Colour(float R, float G, float B, float A) +{ + if (this->R == R && this->G == G && this->B == B && this->A == A) + return; + + this->R = R; this->G = G; this->B = B; this->A = A; + Mono::Set_Property_Invoke(Label_Class, Instance, "TextColor", UI::Utilities::UIColor(R, G, B, A)); +} + +float Label::Get_Text_Width() +{ + return Mono::Invoke(Mono::App_exe, Label_Class, Instance, "GetTextWidth"); +} + +float Label::Get_Text_Height() +{ + return Mono::Invoke(Mono::App_exe, Label_Class, Instance, "GetTextHeight"); +} + +Label::Label(const char* Name) +{ + Label_Class = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Label"); + + //Allocates memory for our new instance of a class. + Instance = Mono::New_Object(Label_Class); + + //Call Constructor. + mono_runtime_object_init(Instance); + + //Set Panel Name + Mono::Set_Property(Label_Class, Instance, "Name", Mono::New_String(Name)); +} + +MonoObject* NewTextShadowSettings(float R, float G, float B) +{ + MonoClass* TextShadowSettings = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "TextShadowSettings"); + + MonoObject* TextShadow_Instance = Mono::New_Object(TextShadowSettings); + mono_runtime_object_init(TextShadow_Instance); + Mono::Set_Property_Invoke(TextShadowSettings, TextShadow_Instance, "Color", UI::Utilities::UIColor(R, G, B)); + + return TextShadow_Instance; +} + +Label::Label(const char* Name, float X, float Y, const char* Text, int Size, FontStyle Style, FontWeight Weight, VerticalAlignment Vertical_Align, HorizontalAlignment Horizontal_Align, float R, float G, float B, float A) +{ + Label_Class = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Label"); + //TODO: Add checks to see if it got the class. + + //Allocates memory for our new instance of a class. + Instance = Mono::New_Object(Label_Class); + + //Call Constructor. + mono_runtime_object_init(Instance); + + //Set Panel Name + Mono::Set_Property(Label_Class, Instance, "Name", Mono::New_String(Name)); + + //Set Values + Set_Location(X, Y); + Set_Text(Text); + Set_Font(Size, Style, Weight); + Set_Alignment(Vertical_Align, Horizontal_Align); + Set_Colour(R, G, B, A); + Mono::Set_Property(Label_Class, Instance, "FitWidthToText", true); + Mono::Set_Property(Label_Class, Instance, "FitHeightToText", true); + + Mono::Set_Property(Label_Class, Instance, "TextShadow", NewTextShadowSettings(0.0f, 0.0f, 0.0f)); +} + +Label::~Label() +{ + +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Label.h b/Playstation/Orbis Toolbox/Label.h new file mode 100644 index 0000000..0d617ff --- /dev/null +++ b/Playstation/Orbis Toolbox/Label.h @@ -0,0 +1,59 @@ +#pragma once + +class Label : public Widget +{ +public: + enum VerticalAlignment + { + vTop, + vBottom, + vCenter + }; + + enum HorizontalAlignment + { + hLeft, + hCenter, + hRight + }; + + enum FontStyle + { + fsNormal, + fsItalic = 2U + }; + + enum FontWeight + { + fwNormal, //Obsolete: This value is not used for Orbis. Use 'Light' or 'Medium'. + fwBold, //Obsolete: Use 'Medium' instead of Bold. + fwLight, + fwMedium, + fwLegacyBold = 1000U //Obsolete: This value is for GLS. Use 'Medium' instead of LegacyBold. + }; + + void Set_Location(float X, float Y); + template + void Set_Text(const char* Text, pack... Args) + { + Mono::Set_Property(Label_Class, Instance, "Text", Mono::New_String(Text, Args...)); + Set_Location(X, Y); + } + void Set_Font(int Size, FontStyle Style, FontWeight Weight); + void Set_Alignment(VerticalAlignment Vertical_Align, HorizontalAlignment Horizontal_Align); + void Set_Colour(float R, float G, float B, float A); + + float X, Y; + VerticalAlignment vAlign; + HorizontalAlignment hAlign; + float R, G, B, A; + float Get_Text_Width(); + float Get_Text_Height(); + + Label(const char* Name); + Label(const char* Name, float X, float Y, const char* Text, int Size, FontStyle Style, FontWeight Weight, VerticalAlignment Vertical_Align, HorizontalAlignment Horizontal_Align, float R, float G, float B, float A); + ~Label(); + +private: + MonoClass* Label_Class; +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/LncUtil.cpp b/Playstation/Orbis Toolbox/LncUtil.cpp new file mode 100644 index 0000000..62d464c --- /dev/null +++ b/Playstation/Orbis Toolbox/LncUtil.cpp @@ -0,0 +1,97 @@ +#include "Common.h" +#include "LncUtil.h" + +int LncUtil::GetAppStatus(AppStatus* Status) +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + MonoClass* AppStatus = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil/AppStatus"); + + MonoObject* AppStatus_Instance = Mono::New_Object(AppStatus); + if (AppStatus_Instance) + { + Mono::Invoke(Mono::platform_dll, AppStatus, (MonoObject*)mono_object_unbox(AppStatus_Instance), ".ctor", Status->appId, Status->launchRequestAppId, Status->appType); + + int res = Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "GetAppStatus", mono_object_unbox(AppStatus_Instance)); + + memcpy(Status, (void*)mono_object_unbox(AppStatus_Instance), sizeof(AppStatus)); + + return res; + } + + return 0; +} + +//int SuspendApp(int appId, Flag flag = Flag_None); +//int ResumeApp(int appId, Flag flag = Flag_None); + +//static int SetControllerFocus(int appId); +//static int SetAppFocus(int appId, Flag flag = Flag_None); + +int LncUtil::GetAppId(const char* titleId) +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + return Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "GetAppId", Mono::New_String(titleId)); +} + +int LncUtil::LaunchApp(const char* titleId, char* args, int argsSize, LaunchAppParam* param) +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + + // + // Init Launch Param + // + MonoClass* LaunchAppParam_class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil/LaunchAppParam"); + + MonoObject* LaunchAppParam_Instance = Mono::New_Object(LaunchAppParam_class); + MonoObject* LaunchAppParam_Instance_real = (MonoObject*)mono_object_unbox(LaunchAppParam_Instance); + + Mono::Set_Field(LaunchAppParam_Instance, "size", param->size); + Mono::Set_Field(LaunchAppParam_Instance, "userId", param->userId); + Mono::Set_Field(LaunchAppParam_Instance, "appAttr", param->appAttr); + Mono::Set_Field(LaunchAppParam_Instance, "enableCrashReport", param->enableCrashReport); + Mono::Set_Field(LaunchAppParam_Instance, "checkFlag", param->checkFlag); + + //LaunchAppParam* p = (LaunchAppParam*)mono_object_unbox(LaunchAppParam_Instance); + //memcpy(p, param, sizeof(LaunchAppParam)); + + // + // Init Byte Class. + // + MonoArray* Array = Mono::New_Array(mono_get_byte_class(), argsSize); + char* Array_addr = mono_array_addr_with_size(Array, sizeof(char), 0); + + if(args && argsSize > 0) + memcpy(Array_addr, args, argsSize); + + klog("Calling Launch...\n"); + + return Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "LaunchApp", Mono::New_String(titleId), Array, argsSize, LaunchAppParam_Instance_real); +} + +int LncUtil::KillApp(int appId, int userId) +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + return Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "KillApp", appId, userId, 0, 0); +} + +//static int ForceKillApp(int appId, int userId = -1); +//static int KillLocalProcess(int appId, int appLocalPid); + +void LncUtil::SystemShutdown(Boot flag) +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "SystemShutdown", flag); +} + +void LncUtil::SystemReboot() +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "SystemReboot"); +} + +void LncUtil::SystemSuspend() +{ + MonoClass* LncUtil_Class = Mono::Get_Class(Mono::platform_dll, "Sce.Vsh.ShellUI.Lnc", "LncUtil"); + Mono::Invoke(Mono::platform_dll, LncUtil_Class, nullptr, "SystemSuspend"); +} + diff --git a/Playstation/Orbis Toolbox/LncUtil.h b/Playstation/Orbis Toolbox/LncUtil.h new file mode 100644 index 0000000..2fd0567 --- /dev/null +++ b/Playstation/Orbis Toolbox/LncUtil.h @@ -0,0 +1,71 @@ +#pragma once + +class LncUtil +{ +public: + enum Boot + { + None = 0, + Eap = 1 + }; + + enum Flag : unsigned long + { + Flag_None = 0UL, + SkipLaunchCheck = 1UL, + SkipResumeCheck = 1UL, + SkipSystemUpdateCheck = 2UL, + RebootPatchInstall = 4UL, + VRMode = 8UL, + NonVRMode = 16UL + }; + + struct LaunchAppParam + { + unsigned int size; + int userId; + int appAttr; + int enableCrashReport; + Flag checkFlag; + }; + + enum AppType + { + Invalid = -1, + Unknown, + ShellUI, + Daemon, + CDLG, + MiniApp, + BigApp, + ShellCore, + ShellApp + }; + + struct AppStatus + { + int appId; + int launchRequestAppId; + char appType; + }; + + static int GetAppStatus(AppStatus* Status); + static int SuspendApp(int appId, Flag flag = Flag_None); + static int ResumeApp(int appId, Flag flag = Flag_None); + + static int SetControllerFocus(int appId); + static int SetAppFocus(int appId, Flag flag = Flag_None); + + static int GetAppId(const char* titleId); + static int LaunchApp(const char* titleId, char* args, int argsSize, LaunchAppParam* param); + static int KillApp(int appId, int userId = -1); + static int ForceKillApp(int appId, int userId = -1); + static int KillLocalProcess(int appId, int appLocalPid); + + static void SystemShutdown(Boot flag); + static void SystemReboot(); + static void SystemSuspend(); + +private: + +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Menu.cpp b/Playstation/Orbis Toolbox/Menu.cpp new file mode 100644 index 0000000..e648515 --- /dev/null +++ b/Playstation/Orbis Toolbox/Menu.cpp @@ -0,0 +1,204 @@ +#include "Common.h" +#include "Menu.h" + +#include "Settings_Menu.h" +#include "Debug_Features.h" +#include "Game_Overlay.h" +#include "Build_Overlay.h" +#include "Config.h" +#include "LncUtil.h" +#include "Daemons.h" +#include "KDriver.h" + +std::map* Menu::Options; +bool Menu::Auto_Load_Settings; + +void Menu::Init() +{ + Options = new std::map(); + + /* + ★Orbis Toolbox + */ + + // Power Options + Add_Option("id_reload_shellui", []() -> void { Notify("%s", __FUNCTION__); })->Visible = false; + Add_Option("id_reboot", []() -> void { LncUtil::SystemReboot(); }); + Add_Option("id_shutdown", []() -> void { LncUtil::SystemShutdown(LncUtil::None); }); + Add_Option("id_suspend", []() -> void { LncUtil::SystemShutdown(LncUtil::Eap); }); + + // Note: Package Installer does not need to be done here + // because of the fact its managed by the system. + + // Daemon Manager + Add_Option("id_daemons", nullptr, nullptr, []() -> void { + + int fd; + OrbisKernelStat stats; + char* Dent_Buffer; + OrbisKernelDirents *dent; + int bpos; + + //Open a file descriptor on the directory where daemons are stored. + fd = sceKernelOpen(DAEMON_DIR, 0, 0511); + if (fd) + { + //Get the size of the directory and allocate space to read the contents. + sceKernelFstat(fd, &stats); + Dent_Buffer = (char*)malloc((size_t)stats.st_blksize); + + + //Read the directory contents and if the number of byte sread returned less than or equal to zero return. + int nread = sceKernelGetdents(fd, Dent_Buffer, (size_t)stats.st_blksize); + if (nread <= 0) + goto End; + + //Loop through all the directory contents by position in the buffer insuring we dont go over the number of read bytes. + for (bpos = 0; bpos < nread;) + { + //dent is our curent directory. + dent = (OrbisKernelDirents*) (Dent_Buffer + bpos); + + //Find any daemons that arent system. Making sure the type is directory and its name doesnt contain NPXS. + if (dent->d_type == DT_DIR && !strstr(dent->d_name, "NPXS") && !strstr(dent->d_name, ".") && !strstr(dent->d_name, PAYLOAD_DAEMON)) + Add_Daemon(dent->d_name); + + //Increase the position we are going to read by the size of the current directory entry. + bpos += dent->d_reclen; + } + + //make sure to close file descriptor when we are done. + sceKernelClose(fd); + } + + End: + free(Dent_Buffer); + + }); + + Add_Option("id_option_daemon_refresh", []() -> void { + + klog("id_option_daemon_refresh\n"); + + int fd; + OrbisKernelStat stats; + char* Dent_Buffer; + OrbisKernelDirents *dent; + int bpos; + + //Open a file descriptor on the directory where daemons are stored. + fd = sceKernelOpen(DAEMON_DIR, 0, 0511); + if (fd) + { + //Get the size of the directory and allocate space to read the contents. + sceKernelFstat(fd, &stats); + Dent_Buffer = (char*)malloc((size_t)stats.st_blksize); + + + //Read the directory contents and if the number of byte sread returned less than or equal to zero return. + int nread = sceKernelGetdents(fd, Dent_Buffer, (size_t)stats.st_blksize); + if (nread <= 0) + goto End; + + //Loop through all the directory contents by position in the buffer insuring we dont go over the number of read bytes. + for (bpos = 0; bpos < nread;) + { + //dent is our curent directory. + dent = (OrbisKernelDirents*)(Dent_Buffer + bpos); + + //Find any daemons that arent system. Making sure the type is directory and its name doesnt contain NPXS. + if (dent->d_type == DT_DIR && !strstr(dent->d_name, "NPXS") && !strstr(dent->d_name, ".") && !strstr(dent->d_name, PAYLOAD_DAEMON)) + { + Remove_Daemon(dent->d_name); + Add_Daemon(dent->d_name); + } + + //Increase the position we are going to read by the size of the current directory entry. + bpos += dent->d_reclen; + } + + //make sure to close file descriptor when we are done. + sceKernelClose(fd); + } + + End: + free(Dent_Buffer); + + }); + + // ShellUI Plugin Manager + Add_Option("id_plugins")->Visible = false; + + // Payload Loader + Add_Option("id_payloads", nullptr, nullptr, []() -> void { + + + + })->Visible = false; + + Add_Option("id_Custom_Loader", []() -> void { + + if (Is_Daemon_Running(PAYLOAD_DAEMON)) + { + if (!Stop_Daemon(PAYLOAD_DAEMON) && !Start_Daemon(PAYLOAD_DAEMON)) + Notify("Payload Loader: Failed to start Payload Daemon."); + } + else + { + if (!Start_Daemon(PAYLOAD_DAEMON)) + Notify("Payload Loader: Failed to start Payload Daemon."); + } + + }); + + // Note: System settings does not need to be done here + // because of the fact its managed by the system. + + //Orbis Toolbox Settings + Add_Option("id_load_cfg_on_start", &Auto_Load_Settings, Type_Boolean); + Add_Option("id_system_disp_titleid", &Debug_Feature::DebugTitleIdLabel::ShowLabels, Type_Boolean, Debug_Feature::DebugTitleIdLabel::Update); + Add_Option("id_system_disp_devkit_panel", &Debug_Feature::DevkitPanel::ShowPanel, Type_Boolean, Debug_Feature::DevkitPanel::Update); + Add_Option("id_system_disp_debug_settings_panel", &Debug_Feature::Custom_Content::Show_Debug_Settings, Type_Boolean, UI::Utilities::ReloadItemList); + Add_Option("id_system_disp_app_home_panel", &Debug_Feature::Custom_Content::Show_App_Home, Type_Boolean, UI::Utilities::ReloadItemList); + + //Debug Overlay + Add_Option("id_overlay_dbg", &Build_Overlay::Draw, Type_Boolean, Build_Overlay::Update); + + //Game Overlay + Add_Option("id_overlay_loc", &Game_Overlay::Location, Type_String, Game_Overlay::Update_Location); + Add_Option("id_overlay_cpu_usage", &Game_Overlay::Show_CPU_Usage, Type_Boolean, Game_Overlay::Update); + Add_Option("id_overlay_thr_count", &Game_Overlay::Show_Thread_Count, Type_Boolean, Game_Overlay::Update); + Add_Option("id_overlay_ram", &Game_Overlay::Show_ram, Type_Boolean, Game_Overlay::Update); + Add_Option("id_overlay_vram", &Game_Overlay::Show_vram, Type_Boolean, Game_Overlay::Update); + Add_Option("id_overlay_cpu", &Game_Overlay::Show_CPU_Temp, Type_Boolean, Game_Overlay::Update); + Add_Option("id_overlay_soc", &Game_Overlay::Show_SOC_Temp, Type_Boolean, Game_Overlay::Update); + Add_Option("id_load_settings", []() -> void { + + if (Config::Parse(SETTIN_DIR)) + { + UI::Utilities::ResetMenuItem("id_load_cfg_on_start"); + UI::Utilities::ResetMenuItem("id_system_disp_titleid"); + UI::Utilities::ResetMenuItem("id_system_disp_devkit_panel"); + UI::Utilities::ResetMenuItem("id_system_disp_debug_settings_panel"); + UI::Utilities::ResetMenuItem("id_system_disp_app_home_panel"); + UI::Utilities::ResetMenuItem("id_overlay_dbg"); + + Debug_Feature::DebugTitleIdLabel::Update(); + Debug_Feature::DevkitPanel::Update(); + UI::Utilities::ReloadItemList(); + Build_Overlay::Update(); + Game_Overlay::Update_Location(); + Game_Overlay::Update(); + + Notify("Orbis Toolbox: Loaded Settings Sucessfully!"); + } + else + Notify("Orbis Toolbox: Failed to Load Settings..."); + }); + Add_Option("id_save_settings", []() -> void { Config::Write(SETTIN_DIR) ? Notify("Orbis Toolbox: Saved Settings Sucessfully!") : Notify("Orbis Toolbox: Failed to Save Settings..."); }); +} + +void Menu::Term() +{ + //TODO: clear menu map +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Menu.h b/Playstation/Orbis Toolbox/Menu.h new file mode 100644 index 0000000..6cd742f --- /dev/null +++ b/Playstation/Orbis Toolbox/Menu.h @@ -0,0 +1,117 @@ +#pragma once +#include "Common.h" + +enum Data_Type +{ + Type_None, + Type_Boolean, + Type_Integer, + Type_Float, + Type_String, +}; + +class MenuOption +{ +public: + char Id[0x100]; + Data_Type Type; + uint64_t* Data; + bool Visible; + std::function OnPreCreate; + std::function OnPageActivating; + std::function OnPress; + + MenuOption() { } + ~MenuOption() { } + +private: + +}; + +struct CompareFirst { + template + bool operator()(T const& t, U const& u) const { return !strcmp(t.first, u.first); } +}; + +class Menu +{ +public: + template + static MenuOption* Add_Option(const char* Option_Id, Value* Data, Data_Type Type, std::function OnPress = nullptr, std::function OnPreCreate = nullptr, std::function OnPageActivating = nullptr) + { + //klog("Add_Option(): %s\n", Option_Id); + MenuOption* Temp = new MenuOption(); + strcpy(Temp->Id, Option_Id); + Temp->Data = (uint64_t*)Data; + Temp->Type = Type; + Temp->Visible = true; + Temp->OnPreCreate = OnPreCreate; + Temp->OnPageActivating = OnPageActivating; + Temp->OnPress = OnPress; + + Options->insert(std::pair(Temp->Id, Temp)); + + return Temp; + } + + static MenuOption* Add_Option(const char* Option_Id, std::function OnPress = nullptr, std::function OnPreCreate = nullptr, std::function OnPageActivating = nullptr) + { + //klog("Add_Option(): %s\n", Option_Id); + MenuOption* Temp = new MenuOption(); + strcpy(Temp->Id, Option_Id); + Temp->Type = Type_None; + Temp->Visible = true; + Temp->OnPreCreate = OnPreCreate; + Temp->OnPageActivating = OnPageActivating; + Temp->OnPress = OnPress; + + Options->insert(std::pair(Temp->Id, Temp)); + + return Temp; + } + + static bool Has_Option(char* Option_Id) + { + return std::find_if(Options->begin(), Options->end(), [Option_Id](auto a1) -> bool { return !strcmp(a1.first, Option_Id); }) != Options->end(); + } + + static MenuOption* Get_Option(char* Option_Id) + { + std::map::iterator it = std::find_if(Options->begin(), Options->end(), [Option_Id](auto a1) -> bool { return !strcmp(a1.first, Option_Id); }); + if (it != Options->end()) + return it->second; + else + { + //klog("[Menu] Get_Option(): Option \"%s\" Does not exist.\n", Option_Id); + return nullptr; + } + } + + static void Remove_Option(char* Option_Id) + { + std::map::iterator it = std::find_if(Options->begin(), Options->end(), [Option_Id](auto a1) -> bool { return !strcmp(a1.first, Option_Id); }); + if (it != Options->end()) + { + Options->erase(it); + + klog("[Menu] Remove_Option(): Removed Option \"%s\"\n", Option_Id); + } + else + klog("[Menu] Remove_Option(): Option \"%s\" Does not exist.\n", Option_Id); + } + + static std::map* Options; + static bool Auto_Load_Settings; + + static void Init(); + static void Term(); + +private: + +}; + +#define DAEMON_DIR "/system/vsh/app/" +#define PLUGIN_DIR "/user/data/Orbis Toolbox/Plugins" +#define SETTIN_DIR "/user/data/Orbis Toolbox/Settings.cfg" +#define PAYLOAD_DIR "/user/data/Orbis Toolbox/Payloads" +#define PAYLOAD_DAEMON (char*)"PLDR00000" diff --git a/Playstation/Orbis Toolbox/Mono.cpp b/Playstation/Orbis Toolbox/Mono.cpp new file mode 100644 index 0000000..eac5932 --- /dev/null +++ b/Playstation/Orbis Toolbox/Mono.cpp @@ -0,0 +1,274 @@ +#include "Common.h" +#include "Mono.h" + +MonoDomain* Mono::Root_Domain; +MonoImage* Mono::PlayStation_Core; +MonoImage* Mono::App_exe; +MonoImage* Mono::platform_dll; +MonoImage* Mono::UI_dll; +MonoImage* Mono::KernelSysWrapper; +MonoImage* Mono::mscorlib; +MonoImage* Mono::Accessor_Db; +MonoImage* Mono::Vsh_Lx; +MonoImage* Mono::SysfileUtilWrapper; + +int Mono::Software_Version; +const char* Mono::PUI; +const char* Mono::PUI_UI2; +const char* Mono::PUI_UI3; + +bool Mono::Init() +{ + MonoLog("Init"); + + Root_Domain = mono_get_root_domain(); + mono_thread_attach(Root_Domain); + + if (Root_Domain == nullptr) + { + MonoLog("Mono: Failed to get root domain."); + return false; + } + + MonoLog("Get Images"); + + UI_dll = Get_Image("/%s/common/lib/Sce.PlayStation.PUI.dll", sceKernelGetFsSandboxRandomWord()); + if (!UI_dll) + { + klog("Using Highlevel.UI2...\n"); + UI_dll = Get_Image("/%s/common/lib/Sce.PlayStation.HighLevel.UI2.dll", sceKernelGetFsSandboxRandomWord()); + } + else + klog("Using PUI...\n"); + + App_exe = Get_Image("/app0/psm/Application/app.exe"); + platform_dll = Get_Image("/app0/psm/Application/platform.dll"); + PlayStation_Core = Get_Image("/%s/common/lib/Sce.PlayStation.Core.dll", sceKernelGetFsSandboxRandomWord()); + KernelSysWrapper = Get_Image("/%s/common/lib/Sce.Vsh.KernelSysWrapper.dll", sceKernelGetFsSandboxRandomWord()); + mscorlib = Get_Image("/%s/common/lib/mscorlib.dll", sceKernelGetFsSandboxRandomWord()); + Accessor_Db = Get_Image("/%s/common/lib/Sce.Vsh.Accessor.Db.dll", sceKernelGetFsSandboxRandomWord()); + Vsh_Lx = Get_Image("/%s/common/lib/Sce.Vsh.Lx.dll", sceKernelGetFsSandboxRandomWord()); + SysfileUtilWrapper = Get_Image("/%s/common/lib/Sce.Vsh.SysfileUtilWrapper.dll", sceKernelGetFsSandboxRandomWord()); + + SceKernelSystemSwVersion Version; + Version.Size = sizeof(SceKernelSystemSwVersion); + sceKernelGetSystemSwVersion(&Version); + char Version_Short[] = { Version.info[1], Version.info[3], Version.info[4] }; + Software_Version = atoi(Version_Short); + klog("Software Version: %s %i\n", Version.info, Software_Version); + + switch (Software_Version) + { + default: + klog("Unsuported Software Version!! \"%s\"(%i)\n", Version.info, Software_Version); + break; + + case 505: + PUI = "Sce.PlayStation.HighLevel.UI2"; + PUI_UI2 = "Sce.PlayStation.HighLevel.UI2"; + PUI_UI3 = "Sce.PlayStation.HighLevel.UI2"; + break; + + case 672: + case 702: + case 755: + case 900: + PUI = "Sce.PlayStation.PUI"; + PUI_UI2 = "Sce.PlayStation.PUI.UI2"; + PUI_UI3 = "Sce.PlayStation.PUI.UI3"; + break; + } + + MonoLog("Init Complete"); + + return true; +} + +void Mono::MonoLog(const char* fmt, ...) +{ + char va_Buffer[0x200]; + + //Create full string from va list. + va_list args; + va_start(args, fmt); + vsprintf(va_Buffer, fmt, args); + va_end(args); + + klog("[Mono] %s\n", va_Buffer); +} + +MonoImage* Mono::Get_Image(const char* Assembly_Name, ...) +{ + char va_Buffer[0x200]; + + //Create full string from va list. + va_list args; + va_start(args, Assembly_Name); + vsprintf(va_Buffer, Assembly_Name, args); + va_end(args); + + MonoAssembly* Assembly = mono_domain_assembly_open(Root_Domain, va_Buffer); + if (Assembly == nullptr) + { + MonoLog("GetImage: Failed to open \"%s\" assembly.", va_Buffer); + return nullptr; + } + + MonoImage* Assembly_Image = mono_assembly_get_image(Assembly); + if (Assembly_Image == nullptr) + { + MonoLog("GetImage: Failed to open \"%s\" Image.", va_Buffer); + return nullptr; + } + + return Assembly_Image; +} + +// +// Classes +// + +MonoClass* Mono::Get_Class(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name) +{ + MonoClass* klass = mono_class_from_name(Assembly_Image, Namespace, Class_Name); + if (klass == nullptr) + MonoLog("Get_Class: Failed to open \"%s\" class from \"%s\" Namespace.", Class_Name, Namespace); + + return klass; +} + +// +// Objects +// + +MonoObject* Mono::New_Object(MonoClass* Klass) +{ + if (Klass == nullptr) + { + MonoLog("New_Object: Klass pointer was null."); + return nullptr; + } + + MonoObject* Obj = mono_object_new(Root_Domain, Klass); + + if (Obj == nullptr) + MonoLog("New_Object: Failed to Create new object \"%s\".", Klass->name); + + return Obj; +} + +MonoObject* Mono::New_Object(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name) +{ + MonoClass* klass = Get_Class(Assembly_Image, Namespace, Class_Name); + + if (klass != nullptr) + return New_Object(klass); + else + return nullptr; +} + +MonoString* Mono::New_String(const char* str, ...) +{ + char va_Buffer[0x200]; + + //Create full string from va list. + va_list args; + va_start(args, str); + vsprintf(va_Buffer, str, args); + va_end(args); + + return mono_string_new(Root_Domain, va_Buffer); +} + +MonoArray* Mono::New_Array(MonoClass* eclass, int size) +{ + return mono_array_new(Root_Domain, eclass, size); +} + +// +// Methods +// + +uint64_t Mono::Get_Address_of_Method(MonoImage* Assembly_Image, const char* Name_Space, const char* Class_Name, const char* Method_Name, int Param_Count) +{ + MonoClass* klass = Get_Class(Assembly_Image, Name_Space, Class_Name); + + if (!klass) + { + MonoLog("Get_Address_of_Method: failed to open class \"%s\" in namespace \"%s\"", Class_Name, Name_Space); + return 0; + } + + MonoMethod* Method = mono_class_get_method_from_name(klass, Method_Name, Param_Count); + + if (!Method) + { + MonoLog("Get_Address_of_Method: failed to find method \"%s\" in class \"%s\"", Method_Name, Class_Name); + return 0; + } + + return (uint64_t)mono_aot_get_method(Root_Domain, Method); +} + +uint64_t Mono::Get_Address_of_Method(MonoImage* Assembly_Image, MonoClass* klass, const char* Method_Name, int Param_Count) +{ + if (!klass) + { + MonoLog("Get_Address_of_Method: klass was null."); + return 0; + } + + MonoMethod* Method = mono_class_get_method_from_name(klass, Method_Name, Param_Count); + + if (!Method) + { + MonoLog("Get_Address_of_Method: failed to find method \"%s\" in class \"%s\"", Method_Name, klass->name); + return 0; + } + + return (uint64_t)mono_aot_get_method(mono_get_root_domain(), Method); +} + +// +// Properties +// + +MonoObject* Mono::Get_Instance(MonoClass* Klass, const char* Instance) +{ + if (Klass == nullptr) + { + MonoLog("Get_Instance: Klass was null."); + return nullptr; + } + + MonoProperty* inst_prop = mono_class_get_property_from_name(Klass, Instance); + + if (inst_prop == nullptr) + { + MonoLog("Failed to find Instance property \"%s\" in Class \"%s\".", Instance, Klass->name); + return nullptr; + } + + MonoMethod* inst_get_method = mono_property_get_get_method(inst_prop); + + if (inst_get_method == nullptr) + { + MonoLog("Failed to find get method for \"%s\" in Class \"%s\".", Instance, Klass->name); + return nullptr; + } + + MonoObject* inst = mono_runtime_invoke(inst_get_method, 0, 0, 0); + + if (inst == nullptr) + { + MonoLog("Failed to find get Instance \"%s\" in Class \"%s\".", Instance, Klass->name); + return nullptr; + } + + return inst; +} + +MonoObject* Mono::Get_Instance(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, const char* Instance) +{ + return Get_Instance(Get_Class(Assembly_Image, Namespace, Class_Name), Instance); +} diff --git a/Playstation/Orbis Toolbox/Mono.h b/Playstation/Orbis Toolbox/Mono.h new file mode 100644 index 0000000..e7d5830 --- /dev/null +++ b/Playstation/Orbis Toolbox/Mono.h @@ -0,0 +1,458 @@ +#pragma once + +class Mono +{ +private: + static MonoDomain* Root_Domain; + +public: + static MonoImage* App_exe; + static MonoImage* PlayStation_Core; + static MonoImage* platform_dll; + static MonoImage* UI_dll; + static MonoImage* KernelSysWrapper; + static MonoImage* mscorlib; + static MonoImage* Accessor_Db; + static MonoImage* Vsh_Lx; + static MonoImage* SysfileUtilWrapper; + + static int Software_Version; + static const char* PUI; + static const char* PUI_UI2; + static const char* PUI_UI3; + + static bool Init(); + static void MonoLog(const char* fmt, ...); + static MonoImage* Get_Image(const char* MonoAssembly, ...); + + // + // Classes + // + static MonoClass* Get_Class(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name); + + // + // Objects + // + static MonoObject* New_Object(MonoClass* Klass); + static MonoObject* New_Object(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name); + static MonoString* New_String(const char* str, ...); + static MonoArray* New_Array(MonoClass* eclass, int size); + + // + // Methods + // + static uint64_t Get_Address_of_Method(MonoImage* Assembly_Image, const char* Name_Space, const char* Class_Name, const char* Method_Name, int Param_Count); + static uint64_t Get_Address_of_Method(MonoImage* Assembly_Image, MonoClass* klass, const char* Method_Name, int Param_Count); + + template + static result Invoke(MonoImage* Assembly_Image, MonoClass* klass, MonoObject* Instance, const char* Method_Name, Args... args) + { + void* Argsv[] = { &args... }; + uint64_t ThunkAddress = Get_Address_of_Method(Assembly_Image, klass, Method_Name, ARRAY_COUNT(Argsv)); + + if (!ThunkAddress) + { + MonoLog("Invoke: Failed to get thunk address for \"%s\".", Method_Name); + return (result)NULL; + } + + if (Instance) + { + result(*Method)(MonoObject* Instance, Args... args) = decltype(Method)(ThunkAddress); + return Method(Instance, args...); + } + else //Static Call. + { + result(*Method)(Args... args) = decltype(Method)(ThunkAddress); + return Method(args...); + } + } + + // + // Properties + // + static MonoObject* Get_Instance(MonoClass* Klass, const char* Instance); + static MonoObject* Get_Instance(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, const char* Instance); + + template + static result Get_Property(MonoClass* Klass, MonoObject* Instance, const char* Property_Name) + { + if (Klass == nullptr) + { + MonoLog("Get_Property: Klass was null."); + return (result)0; + } + + /*if (Instance == nullptr) + { + MonoLog("Get_Property: Instance was null."); + return (result)0; + }*/ + + MonoProperty* Prop = mono_class_get_property_from_name(Klass, Property_Name); + + if (Prop == nullptr) + { + MonoLog("Get_Property: Property \"%s\" could not be found on class \"%s\".", Property_Name, Klass->name); + return (result)NULL; + } + + MonoMethod* Get_Method = mono_property_get_get_method(Prop); + + if (Get_Method == nullptr) + { + MonoLog("Get_Property: Could not find Get Method for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return (result)NULL; + } + + uint64_t Get_Method_Thunk = (uint64_t)mono_aot_get_method(Root_Domain, Get_Method); + + if (Get_Method_Thunk == NULL) + { + MonoLog("Get_Property: Could not get thunk address for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return (result)NULL; + } + + if (Instance != nullptr) + { + result(*Method)(MonoObject* Instance) = decltype(Method)(Get_Method_Thunk); + return Method(Instance); + } + else + { + result(*Method)() = decltype(Method)(Get_Method_Thunk); + return Method(); + } + } + + template + static result Get_Property_Invoke(MonoClass* Klass, MonoObject* Instance, const char* Property_Name) + { + if (Klass == nullptr) + { + MonoLog("Set_Property: Klass was null."); + return (result)0; + } + + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return (result)0; + } + + MonoProperty* Prop = mono_class_get_property_from_name(Klass, Property_Name); + + if (Prop == nullptr) + { + MonoLog("Get_Property: Property \"%s\" could not be found on class \"%s\".", Property_Name, Klass->name); + return (result)NULL; + } + + MonoMethod* Get_Method = mono_property_get_get_method(Prop); + + if (Get_Method == nullptr) + { + MonoLog("Get_Property: Could not find Get Method for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return (result)NULL; + } + + uint64_t obj = (uint64_t)mono_runtime_invoke(Get_Method, Instance, nullptr, NULL); + + if (std::is_pointer::value) + return (result)obj; + else + return *(result*)mono_object_unbox((MonoObject*)obj); + } + + template + static result Get_Property(MonoObject* Instance, const char* Property_Name) + { + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return (result)0; + } + + if (Instance->vtable == nullptr) + { + MonoLog("Set_Property: Instance->vtable was null."); + return (result)0; + } + + if (Instance->vtable->klass == nullptr) + { + MonoLog("Set_Property: Instance->vtable->klass was null."); + return (result)0; + } + + return Get_Property(Instance->vtable->klass, Instance, Property_Name); + } + + template + static result Get_Property(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, MonoObject* Instance, const char* Property_Name) + { + return Get_Property(Mono::Get_Class(Assembly_Image, Namespace, Class_Name), Instance, Property_Name); + } + + template + static void Set_Property(MonoClass* Klass, MonoObject* Instance, const char* Property_Name, Param Value) + { + if (Klass == nullptr) + { + MonoLog("Set_Property: Klass was null."); + return; + } + + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return; + } + + MonoProperty* Prop = mono_class_get_property_from_name(Klass, Property_Name); + + if (Prop == nullptr) + { + MonoLog("Set_Property: Property \"%s\" could not be found on class \"%s\".", Property_Name, Klass->name); + return; + } + + MonoMethod* Set_Method = mono_property_get_set_method(Prop); + + if (Set_Method == nullptr) + { + MonoLog("Set_Property: Could not find Set Method for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return; + } + + uint64_t Set_Method_Thunk = (uint64_t)mono_aot_get_method(Root_Domain, Set_Method); + + if (Set_Method_Thunk == NULL) + { + MonoLog("Set_Property: Could not get thunk address for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return; + } + + void(*Method)(MonoObject* Instance, Param Value) = decltype(Method)(Set_Method_Thunk); + Method(Instance, Value); + } + + template + static void Set_Property_Invoke(MonoClass* Klass, MonoObject* Instance, const char* Property_Name, Param Value) + { + if (Klass == nullptr) + { + MonoLog("Set_Property: Klass was null."); + return; + } + + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return; + } + + MonoProperty* Prop = mono_class_get_property_from_name(Klass, Property_Name); + + if (Prop == nullptr) + { + MonoLog("Set_Property: Property \"%s\" could not be found on class \"%s\".", Property_Name, Klass->name); + return; + } + + MonoMethod* Set_Method = mono_property_get_set_method(Prop); + + if (Set_Method == nullptr) + { + MonoLog("Set_Property: Could not find Set Method for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return; + } + + mono_runtime_invoke(Set_Method, Instance, (void**)&Value, NULL); + } + + template + static void Set_Property_test(MonoClass* Klass, MonoObject* Instance, const char* Property_Name, Param Value) + { + if (Klass == nullptr) + { + MonoLog("Set_Property: Klass was null."); + return; + } + + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return; + } + + MonoProperty* Prop = mono_class_get_property_from_name(Klass, Property_Name); + + if (Prop == nullptr) + { + MonoLog("Set_Property: Property \"%s\" could not be found on class \"%s\".", Property_Name, Klass->name); + return; + } + + MonoMethod* Set_Method = mono_property_get_set_method(Prop); + + if (Set_Method == nullptr) + { + MonoLog("Set_Property: Could not find Set Method for \"%s\" in class \"%s\".", Property_Name, Klass->name); + return; + } + void* Argsv[] = { &Value }; + mono_runtime_invoke(Set_Method, Instance, Argsv, NULL); + } + + template + static void Set_Property(MonoObject* Instance, const char* Property_Name, Param Value) + { + + if (Instance == nullptr) + { + MonoLog("Set_Property: Instance was null."); + return; + } + + if (Instance->vtable == nullptr) + { + MonoLog("Set_Property: Instance->vtable was null."); + return; + } + + if (Instance->vtable->klass == nullptr) + { + MonoLog("Set_Property: Instance->vtable->klass was null."); + return; + } + + MonoClass* Klass = Instance->vtable->klass; + + Set_Property(Instance->vtable->klass, Instance, Property_Name, Value); + } + + template + static void Set_Property(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, MonoObject* Instance, const char* Property_Name, Param Value) + { + Set_Property(Mono::Get_Class(Assembly_Image, Namespace, Class_Name), Instance, Property_Name, Value); + } + + // + // Fields + // + template + static result Get_Field(MonoClass* Klass, MonoObject* Instance, const char* Field_Name) + { + if (Klass == nullptr) + { + MonoLog("Get_Field: Klass was null."); + return (result)0; + } + + /*if (Instance == nullptr) + { + MonoLog("Get_Field: Instance was null."); + return (result)0; + }*/ + + MonoClassField* Field = mono_class_get_field_from_name(Klass, Field_Name); + + if (Field == nullptr) + { + MonoLog("Get_Field: Failed to find get Field \"%s\" in Class \"%s\".", Field_Name, Klass->name); + return (result)0; + } + + result Value; + mono_field_get_value(Instance, Field, &Value); + + return Value; + } + + template + static result Get_Field(MonoObject* Instance, const char* Field_Name) + { + if (Instance == nullptr) + { + MonoLog("Get_Field: Instance was null."); + return (result)0; + } + + if (Instance->vtable == nullptr) + { + MonoLog("Get_Field: Instance->vtable was null."); + return (result)0; + } + + if (Instance->vtable->klass == nullptr) + { + MonoLog("Get_Field: Instance->vtable->klass was null."); + return (result)0; + } + + return Get_Field(Instance->vtable->klass, Instance, Field_Name); + } + + template + static result Get_Field(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, MonoObject* Instance, const char* Field_Name) + { + return Get_Field(Mono::Get_Class(Assembly_Image, Namespace, Class_Name), Instance, Field_Name); + } + + template + static void Set_Field(MonoClass* Klass, MonoObject* Instance, const char* Field_Name, Param Value) + { + if (Klass == nullptr) + { + MonoLog("Set_Field: Klass was null."); + return; + } + + if (Instance == nullptr) + { + MonoLog("Set_Field: Instance was null."); + return; + } + + MonoClassField* Field = mono_class_get_field_from_name(Klass, Field_Name); + + if (Field == nullptr) + { + MonoLog("Set_Field: Failed to find get Field \"%s\" in Class \"%s\".", Field_Name, Klass->name); + return; + } + + mono_field_set_value(Instance, Field, &Value); + } + + template + static void Set_Field(MonoObject* Instance, const char* Field_Name, Param Value) + { + if (Instance == nullptr) + { + MonoLog("Set_Field: Instance was null."); + return; + } + + if (Instance->vtable == nullptr) + { + MonoLog("Set_Field: Instance->vtable was null."); + return; + } + + if (Instance->vtable->klass == nullptr) + { + MonoLog("Set_Field: Instance->vtable->klass was null."); + return; + } + + Set_Field(Instance->vtable->klass, Instance, Field_Name, Value); + } + + template + static void Set_Field(MonoImage* Assembly_Image, const char* Namespace, const char* Class_Name, MonoObject* Instance, const char* Field_Name, Param Value) + { + Set_Field(Mono::Get_Class(Assembly_Image, Namespace, Class_Name), Instance, Field_Name, Value); + } +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj b/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj new file mode 100644 index 0000000..4b2027f --- /dev/null +++ b/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj @@ -0,0 +1,133 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {ced79d48-621a-4076-81e8-11f77de1e41b} + Win32Proj + + + + Makefile + true + v141 + + + Makefile + false + v141 + + + + + + + + + + + + + + + WIN32;_DEBUG;$(NMakePreprocessorDefinitions) + + + _DEBUG;$(NMakePreprocessorDefinitions) + call Increment.bat "Version.h" "ORBIS_TOOLBOX_BUILDVERSION" +call build.bat $(IntDir) "$(TargetName)" "$(SolutionDir)" + + + del /s /q /f $(IntDir)\*.o +del /s /q /f $(IntDir)\*.elf +del /s /q /f $(IntDir)\*.oelf + $(SolutionDir) + $(OO_PS4_TOOLCHAIN)\include;$(NMakeIncludeSearchPath) + C:\OpenOrbis\PS4Toolchain\include\c++\v1;$(IncludePath) + + + WIN32;NDEBUG;$(NMakePreprocessorDefinitions) + + + NDEBUG;$(NMakePreprocessorDefinitions) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Designer + + + + + + \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj.filters b/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj.filters new file mode 100644 index 0000000..b30f168 --- /dev/null +++ b/Playstation/Orbis Toolbox/Orbis Toolbox.vcxproj.filters @@ -0,0 +1,227 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {f1752ec3-b45e-4e4c-b804-774b1b28112e} + + + {2c699a39-de1f-4f58-b238-56cfc5082064} + + + {812b535b-b5e1-4d31-afe7-1cc246cf24da} + + + {1aa11fd0-d68e-4ce6-9fa5-59186b8731fa} + + + {68203726-db97-4725-a8c6-54f63e09737c} + + + {78337306-cc53-400a-b0b4-c4a77ee99f2c} + + + {d2e2dc0a-9c64-4f86-84de-4d21d89bf2b8} + + + {5d91de35-6a6e-42df-8e6f-6dc9b30f31f4} + + + {4bee9374-872a-40dc-9a05-08a3eda8765e} + + + {cca5b923-678d-4f6c-95d1-9f6611c115af} + + + {3852b1fe-ad73-4e53-bc1d-d67375602f65} + + + {7f2735e6-1583-43ce-9998-e7216d23365d} + + + {552f02a8-0753-4459-8e06-dd0c40336741} + + + + + + Source Files\XML + + + Source Files\Utilites + + + + + Source Files + + + Source Files\Debug Features + + + Source Files\Debug Features + + + Source Files\Utilites + + + Source Files\Debug Features + + + Source Files\UI\Elements + + + Source Files\Menu + + + Source Files\Utilites + + + Source Files\UI\Elements + + + Source Files\Utilites + + + Source Files\Menu + + + Source Files\UI + + + Source Files\Utilites + + + Source Files\UI\Elements + + + Source Files\Utilites + + + Source Files\Utilites + + + Source Files\Utilites + + + Source Files\UI + + + Source Files\UI + + + Source Files\Utilites + + + Source Files\Utilites + + + Source Files\Menu\Sub Menus + + + Source Files\Utilites + + + Source Files\Utilites + + + + + Header Files + + + Header Files\Debug Features + + + Header Files\Utilities + + + Header Files\UI\Elements + + + Header Files\Menu + + + Header Files\Utilities + + + Header Files\UI\Elements + + + Header Files\Utilities + + + Header Files\Menu + + + Header Files\Utilities + + + Header Files\Utilities + + + Header Files\UI\Elements + + + Header Files\Utilities + + + Header Files\Utilities + + + Header Files\Utilities + + + Header Files\Utilities + + + Header Files\UI + + + Header Files\UI + + + Header Files\UI + + + Header Files\UI + + + Header Files\Utilities + + + Header Files\Utilities + + + Header Files\Menu\Sub Menus + + + Header Files\Utilities + + + Header Files\Utilities + + + + + Source Files\XML + + + Source Files\XML + + + Source Files\XML + + + \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Orbis_Toolbox.cpp b/Playstation/Orbis Toolbox/Orbis_Toolbox.cpp new file mode 100644 index 0000000..b291a59 --- /dev/null +++ b/Playstation/Orbis Toolbox/Orbis_Toolbox.cpp @@ -0,0 +1,46 @@ +#include "Common.h" +#include "Settings_Menu.h" +#include "System_Monitor.h" +#include "GamePad.h" + +extern "C" +{ + int module_start() + { + klog("!! Hello World !!\n"); + + Mono::Init(); + + if (GamePad::IsDown(GamePad::Buttons::Left | GamePad::Buttons::Triangle)) + { + Notify("Orbis Toolbox: Aborting Launch!!"); + return 0; + } + + System_Monitor::Init(); + Settings_Menu::Init(); + //Title_Menu::Init(); + + Notify(ORBIS_TOOLBOX_NOTIFY); + + return 0; + } + + int module_stop() + { + klog("!! BYE !!\n"); + + Settings_Menu::Term(); + System_Monitor::Term(); + //Title_Menu::Term(); + + sceKernelSleep(4); + + return 0; + } + + void _start() + { + + } +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Panel.cpp b/Playstation/Orbis Toolbox/Panel.cpp new file mode 100644 index 0000000..931d796 --- /dev/null +++ b/Playstation/Orbis Toolbox/Panel.cpp @@ -0,0 +1,71 @@ +#include "Common.h" +#include "UI.h" +#include "Widget.h" +#include "Panel.h" + +void Panel::Set_Position(float X, float Y) +{ + Mono::Set_Property(Panel_Class, Instance, "X", X); + Mono::Set_Property(Panel_Class, Instance, "Y", Y); +} + +void Panel::Set_Size(float Width, float Height) +{ + Mono::Set_Property(Panel_Class, Instance, "Width", Width); + Mono::Set_Property(Panel_Class, Instance, "Height", Height); +} + +void Panel::Set_Colour(float R, float G, float B, float A) +{ + Mono::Set_Property_Invoke(Panel_Class, Instance, "BackgroundColor", UI::Utilities::UIColor(R, G, B, A)); +} + +void Panel::Set_Rendering_Order(RenderingOrder Order) +{ + Mono::Set_Property(Panel_Class, Instance, "RenderingOrder", Order); +} + +void Panel::Set_Layout_Rule(MonoObject* Rule) +{ + Mono::Set_Property(Panel_Class, Instance, "LayoutRule", Rule); +} + +Panel::Panel(const char* Name) +{ + Panel_Class = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Panel"); + + //Allocates memory for our new instance of a class. + Instance = Mono::New_Object(Panel_Class); + + //Call Constructor. + mono_runtime_object_init(Instance); + + //Set Panel Name + Mono::Set_Property(Panel_Class, Instance, "Name", Mono::New_String(Name)); +} + +Panel::Panel(const char* Name, float X, float Y, float Width, float Height, float R, float G, float B, float A, RenderingOrder Order, MonoObject* Rule) +{ + Panel_Class = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Panel"); + + //Allocates memory for our new instance of a class. + Instance = Mono::New_Object(Panel_Class); + + //Call Constructor. + mono_runtime_object_init(Instance); + + //Set Panel Name + Mono::Set_Property(Panel_Class, Instance, "Name", Mono::New_String(Name)); + + //Set Values + Set_Position(X, Y); + Set_Size(Width, Height); + Set_Colour(R, G, B, A); + Set_Rendering_Order(Order); + Set_Layout_Rule(Rule); +} + +Panel::~Panel() +{ + +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Panel.h b/Playstation/Orbis Toolbox/Panel.h new file mode 100644 index 0000000..b9d8c2e --- /dev/null +++ b/Playstation/Orbis Toolbox/Panel.h @@ -0,0 +1,33 @@ +#pragma once +#include "Widget.h" + +class Panel : public Widget +{ +public: + enum Orientation + { + Horizontal, + Vertical + }; + + enum RenderingOrder + { + First = -1, + DontCare, + Last + }; + + void Set_Position(float X, float Y); + void Set_Size(float Width, float Height); + void Set_Colour(float R, float G, float B, float A); + void Set_Rendering_Order(RenderingOrder Order); + void Set_Layout_Rule(MonoObject* Rule); + + Panel(const char* Name); + Panel(const char* Name, float X, float Y, float W, float H, float R, float G, float B, float A, RenderingOrder Order, MonoObject* Rule); + ~Panel(); + +private: + MonoClass* Panel_Class; + +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Patcher.cpp b/Playstation/Orbis Toolbox/Patcher.cpp new file mode 100644 index 0000000..9ac9c72 --- /dev/null +++ b/Playstation/Orbis Toolbox/Patcher.cpp @@ -0,0 +1,68 @@ +#include "Common.h" +#include "Patcher.h" + +void Patcher::Install_Patch(uint64_t Address, const void* Data, size_t Length) +{ + //Backup Params. + this->Address = Address; + this->Length = Length; + + //Set protection to all + sceKernelMprotect((void*)Address, Length, VM_PROT_ALL); + + //Backup data. + int res = sceKernelMmap(0, Length, VM_PROT_ALL, 0x1000 | 0x2, -1, 0, &OriginalData); + if (res < 0) + { + klog("[Patcher] sceKernelMmap Failed: 0x%llX\n", res); + return; + } + memcpy(OriginalData, Data, Length); + + //Write Patch. + memcpy((void*)Address, Data, Length); + + klog("[Patcher] Install_Patch: Patch (%llX) Written Successfully!\n", Address); +} + +void Patcher::Install_Method_Patch(MonoImage* Assembly_Image, const char* Namespace, const char* Klass, const char* Method, int Param_Count, size_t Offset, const void* Data, size_t Length) +{ + uint64_t Method_Address = Mono::Get_Address_of_Method(Assembly_Image, Namespace, Klass, Method, Param_Count); + + if (Method_Address == NULL) + { + klog("[Patcher] Install_Method_Patch: Method address returned null!\n"); + return; + } + + Install_Patch(Method_Address + Offset, Data, Length); +} + +void Patcher::Restore_Patch() +{ + if (this->OriginalData) + { + //Set protection to all + sceKernelMprotect((void*)this->Address, this->Length, VM_PROT_ALL); + + //Write original Data back. + memcpy((void*)this->Address, this->OriginalData, this->Length); + + klog("[Patcher] Restore_Patch: Patch (%llX) Restored Successfully!\n", this->Address); + } + else + klog("[Patcher] Patch not installed.\n"); +} + +Patcher::Patcher() +{ + +} + +Patcher::~Patcher() +{ + Restore_Patch(); + + //Clean up + sceKernelMunmap(this->OriginalData, this->Length); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Patcher.h b/Playstation/Orbis Toolbox/Patcher.h new file mode 100644 index 0000000..af48d63 --- /dev/null +++ b/Playstation/Orbis Toolbox/Patcher.h @@ -0,0 +1,17 @@ +#pragma once + +class Patcher +{ +public: + void Install_Patch(uint64_t Address, const void* Data, size_t Length); + void Install_Method_Patch(MonoImage* Assembly_Image, const char* Namespace, const char* Klass, const char* Method, int Param_Count, size_t Offset, const void* Data, size_t Length); + void Restore_Patch(); + + Patcher(); + ~Patcher(); + +private: + uint64_t Address; + void* OriginalData; + size_t Length; +}; diff --git a/Playstation/Orbis Toolbox/Settings_Menu.cpp b/Playstation/Orbis Toolbox/Settings_Menu.cpp new file mode 100644 index 0000000..d5e8e66 --- /dev/null +++ b/Playstation/Orbis Toolbox/Settings_Menu.cpp @@ -0,0 +1,310 @@ +#include "Common.h" +#include "Settings_Menu.h" + +#include "UI.h" +#include "Debug_Features.h" +#include "Game_Overlay.h" +#include "Build_Overlay.h" +#include "Config.h" + +//Embedded xmls +extern uint8_t settings_root[]; +extern int32_t settings_root_Size; +extern uint8_t orbis_toolbox[]; +extern int32_t orbis_toolbox_Size; +extern uint8_t external_hdd[]; +extern int32_t external_hdd_Size; + +//Detours +Detour* Settings_Menu::Detour_GetManifestResourceStream = nullptr; +Detour* Settings_Menu::Detour_OnCheckVisible = nullptr; +Detour* Settings_Menu::Detour_OnPreCreate = nullptr; +Detour* Settings_Menu::Detour_OnPageActivating = nullptr; +Detour* Settings_Menu::Detour_OnPress = nullptr; +Detour* Settings_Menu::Detour_OnRender = nullptr; + +//Patches +Patcher* Settings_Menu::Patch_IsDevkit; +Patcher* Settings_Menu::Patch_IsDebugMenuEnable; +Patcher* Settings_Menu::Patch_AllowDebugMenu; +Patcher* Settings_Menu::Patch_MainThreadCheck; + +/* + GetManifestResourceStream: + This is the method I hook that loads internal packed resources + from the mono UI. I intercept the uri and force it to return a + new memory stream of the bytes for our custom xml. +*/ + +uint64_t Settings_Menu::GetManifestResourceStream_Hook(uint64_t inst, MonoString* FileName) +{ + char* str = mono_string_to_utf8(FileName); + //klog("****\nFileName: %s\n****\n", str); + + if (!strcmp(str, "Sce.Vsh.ShellUI.src.Sce.Vsh.ShellUI.Settings.Plugins.SettingsRoot.data.settings_root.xml")) + return (uint64_t)UI::Utilities::MemoryStream(settings_root, settings_root_Size); + else if (!strcmp(str, "Sce.Vsh.ShellUI.src.Sce.Vsh.ShellUI.Settings.Plugins.orbis_toolbox.xml")) + return (uint64_t)UI::Utilities::MemoryStream(orbis_toolbox, orbis_toolbox_Size); + else if (!strcmp(str, "Sce.Vsh.ShellUI.src.Sce.Vsh.ShellUI.Settings.Plugins.external_hdd.xml")) + return (uint64_t)UI::Utilities::MemoryStream(external_hdd, external_hdd_Size); + else + return Detour_GetManifestResourceStream->Stub(inst, FileName); +} + +/* + Settings Root Hooks: + I set my custom menu as the plugin of the root settings page + this allows me to hook all the call backs from inside this + page and run my own code. + + Note: in the xml "plugin="settings_root_plugin"" +*/ + +/* + OnCheckVisible: + This could allow us to show and hide elements on each page + much like the id_message which is a loading symbol. +*/ + +void Settings_Menu::OnCheckVisible_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e) +{ + if (Instance && element) + { + char* Id = mono_string_to_utf8(Mono::Get_Property(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement", element, "Id")); + MenuOption* Cur = Menu::Get_Option(Id); + + if (Cur) + { + //Show or hide Menu Options on the fly. + Mono::Set_Property(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement", element, "Visible", Cur->Visible); + } + } + Detour_OnCheckVisible->Stub(Instance, element, e); +} + +/* + OnPreCreate: + This Hook allows us to set values of each menu element + depending on what is set prior. For example I use this + to set the check boxes to match the previously selected + values. +*/ + +void Settings_Menu::OnPreCreate_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e) +{ + if (Instance && element) + { + MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement"); + char* Id = mono_string_to_utf8(Mono::Get_Property(SettingElement, element, "Id")); + MenuOption* Cur = Menu::Get_Option(Id); + + if (Cur) + { + //Update the shown value of the option. + if (Cur->Type == Type_Boolean) + Mono::Set_Property(SettingElement, element, "Value", (*(bool*)Cur->Data) ? Mono::New_String("1") : Mono::New_String("0")); + /*else if (Cur->Type == Type_Integer) + Mono::Set_Property(SettingElement, element, "Value", Mono::New_String(std::to_string(*(int*)Cur->Data).c_str())); + else if (Cur->Type == Type_Float) + Mono::Set_Property(SettingElement, element, "Value", Mono::New_String(std::to_string(*(float*)Cur->Data).c_str()));*/ + else if (Cur->Type == Type_String) + Mono::Set_Property(SettingElement, element, "Value", Mono::New_String((const char*)Cur->Data)); + + //Call the OnPreCreate call back. + if (Cur->OnPreCreate != nullptr) + Cur->OnPreCreate(); + } + } + Detour_OnPreCreate->Stub(Instance, element, e); +} + +/* + OnPageActivating: + Hooking this allows us to add custom elements when a + page is loading like for example how I will be using + it to parse the payloads from the HDD and display + them to be loaded. +*/ + +void Settings_Menu::OnPageActivating_Hook(MonoObject* Instance, MonoObject* page, MonoObject* e) +{ + if (Instance && page) + { + MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement"); + char* Id = mono_string_to_utf8(Mono::Get_Property(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingPage", page, "Id")); + + MenuOption* Cur = Menu::Get_Option(Id); + + if (Cur) + { + if(Cur->OnPageActivating != nullptr) + Cur->OnPageActivating(); + } + } + Detour_OnPageActivating->Stub(Instance, page, e); +} + +/* + OnPress: + This Hook allows us to catch when a element is selected + or its value is changed. +*/ + +void Settings_Menu::OnPress_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e) +{ + if (Instance && element) + { + MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement"); + char* Id = mono_string_to_utf8(Mono::Get_Property(SettingElement, element, "Id")); + char* Value = mono_string_to_utf8(Mono::Get_Property(SettingElement, element, "Value")); + + if (!strcmp(Id, "_option")) + Id = Value; + + MenuOption* Cur = Menu::Get_Option(Id); + + if (Cur) + { + //Update the local value of the option. + if (Cur->Type == Type_Boolean) + *(bool*)Cur->Data = (atoi(Value) >= 1); + else if (Cur->Type == Type_Integer) + *Cur->Data = atoi(Value); + else if (Cur->Type == Type_Float) + *Cur->Data = atof(Value); + else if (Cur->Type == Type_String) + strcpy((char*)Cur->Data, Value); + + //Call the OnPress call back. + if (Cur->OnPress != nullptr) + Cur->OnPress(); + } + } + + Detour_OnPress->Stub(Instance, element, e); +} + +void Settings_Menu::OnRender_Hook(MonoObject* Instance) +{ + static bool Do_Once = false; + if (!Do_Once) + { + Log("Init Game Overlay"); + Game_Overlay::Init(); + + Log("Init Build Overlay"); + Build_Overlay::Init(); + + if (Config::Read(SETTIN_DIR) && Config::Data->Auto_Load_Settings) + { + Config::Parse(SETTIN_DIR); + + //Call functions to reflect update + Debug_Feature::DebugTitleIdLabel::Update(); + Debug_Feature::DevkitPanel::Update(); + UI::Utilities::ReloadItemList(); + Build_Overlay::Update(); + Game_Overlay::Update_Location(); + Game_Overlay::Update(); + } + else + { + Build_Overlay::Draw = true; + Build_Overlay::Update(); + } + + Do_Once = true; + } + + Game_Overlay::OnRender(); + + Detour_OnRender->Stub(Instance); +} + +void Settings_Menu::Log(const char* fmt, ...) +{ + char va_Buffer[0x200]; + + //Create full string from va list. + va_list args; + va_start(args, fmt); + vsprintf(va_Buffer, fmt, args); + va_end(args); + + klog("[Settings Menu] %s\n", va_Buffer); +} + +void Settings_Menu::Init() +{ + Log("Init"); + + Log(ORBIS_TOOLBOX_BUILDSTRING); + + Config::Init(); + + //Debug Settings Patch + Patch_IsDevkit = new Patcher(); + Patch_IsDebugMenuEnable = new Patcher(); + Patch_AllowDebugMenu = new Patcher(); + Patch_MainThreadCheck = new Patcher(); + + Log("Install Patches"); + Patch_IsDevkit->Install_Method_Patch(Mono::KernelSysWrapper, "Sce.Vsh", "KernelSysWrapper", "IsDevKit", 0, 0, "\x48\xc7\xc0\x01\x00\x00\x00\xC3", 8); + Patch_IsDebugMenuEnable->Install_Method_Patch(Mono::App_exe, "Sce.Vsh.ShellUI.DebugSystem", "KeyMonitorTask", "IsDebugMenuEnable", 0, 0, "\x48\xc7\xc0\x01\x00\x00\x00\xC3", 8); + Patch_AllowDebugMenu->Install_Method_Patch(Mono::platform_dll, "Sce.Vsh.ShellUI.Settings.Sbl", "SblWrapper", "SblRcMgrIsAllowDebugMenuForSettings", 0, 0, "\x48\xc7\xc0\x01\x00\x00\x00\xC3", 8); + Patch_MainThreadCheck->Install_Method_Patch(Mono::PlayStation_Core, "Sce.PlayStation.Core.Runtime", "Diagnostics", "CheckRunningOnMainThread", 0, 0, "\xC3", 1); + + Debug_Feature::DevkitPanel::Init(); + Debug_Feature::DebugTitleIdLabel::Init(); + Debug_Feature::Custom_Content::Init(); + + Log("Init Menu"); + Menu::Init(); + + Log("Init Detours"); + Detour_GetManifestResourceStream = new Detour(); + Detour_OnCheckVisible = new Detour(); + Detour_OnPreCreate = new Detour(); + Detour_OnPageActivating = new Detour(); + Detour_OnPress = new Detour(); + Detour_OnRender = new Detour(); + + Log("Detour Methods"); + Detour_GetManifestResourceStream->DetourMethod(Mono::mscorlib, "System.Reflection", "Assembly", "GetManifestResourceStream", 1, (void*)GetManifestResourceStream_Hook); + Detour_OnCheckVisible->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.SettingsRoot", "SettingsRootHandler", "OnCheckVisible", 2, (void*)OnCheckVisible_Hook); + Detour_OnPreCreate->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.SettingsRoot", "SettingsRootHandler", "OnPreCreate", 2, (void*)OnPreCreate_Hook); + Detour_OnPageActivating->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.SettingsRoot", "SettingsRootHandler", "OnPageActivating", 2, (void*)OnPageActivating_Hook); + Detour_OnPress->DetourMethod(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.SettingsRoot", "SettingsRootHandler", "OnPress", 2, (void*)OnPress_Hook); + Detour_OnRender->DetourMethod(Mono::UI_dll, Mono::PUI, "Application", "Update", 0, (void*)OnRender_Hook); + + Log("Init Complete"); +} + +void Settings_Menu::Term() +{ + Config::Term(); + + Debug_Feature::DevkitPanel::Term(); + Debug_Feature::DebugTitleIdLabel::Term(); + Debug_Feature::Custom_Content::Term(); + + Game_Overlay::Term(); + Build_Overlay::Term(); + + //Remove Denug Settings Patch + delete Patch_IsDevkit; + delete Patch_IsDebugMenuEnable; + delete Patch_AllowDebugMenu; + delete Patch_MainThreadCheck; + + //Clean up detours + delete Detour_GetManifestResourceStream; + delete Detour_OnCheckVisible; + delete Detour_OnPreCreate; + delete Detour_OnPageActivating; + delete Detour_OnPress; + delete Detour_OnRender; + + //Clean up menu + Menu::Term(); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Settings_Menu.h b/Playstation/Orbis Toolbox/Settings_Menu.h new file mode 100644 index 0000000..0745f59 --- /dev/null +++ b/Playstation/Orbis Toolbox/Settings_Menu.h @@ -0,0 +1,34 @@ +#pragma once +#include "Widget.h" +class Widget; + +class Settings_Menu +{ +private: + //Detours + static Detour* Detour_GetManifestResourceStream; + static Detour* Detour_OnCheckVisible; + static Detour* Detour_OnPreCreate; + static Detour* Detour_OnPageActivating; + static Detour* Detour_OnPress; + static Detour* Detour_OnRender; + + static uint64_t GetManifestResourceStream_Hook(uint64_t inst, MonoString* FileName); + static void OnCheckVisible_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e); + static void OnPreCreate_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e); + static void OnPageActivating_Hook(MonoObject* Instance, MonoObject* page, MonoObject* e); + static void OnPress_Hook(MonoObject* Instance, MonoObject* element, MonoObject* e); + static void OnRender_Hook(MonoObject* Instance); + + //Patches + static Patcher* Patch_IsDevkit; + static Patcher* Patch_IsDebugMenuEnable; + static Patcher* Patch_AllowDebugMenu; + static Patcher* Patch_MainThreadCheck; + +public: + static void Log(const char* fmt, ...); + static void Init(); + static void Term(); + +}; diff --git a/Playstation/Orbis Toolbox/SysfileUtilWrapper.cpp b/Playstation/Orbis Toolbox/SysfileUtilWrapper.cpp new file mode 100644 index 0000000..48e0974 --- /dev/null +++ b/Playstation/Orbis Toolbox/SysfileUtilWrapper.cpp @@ -0,0 +1,68 @@ +#include "Common.h" +#include "SysfileUtilWrapper.h" + +void Print_Bytes(char* Bytes, size_t len) +{ + int Counter = 0; + for (size_t n = 0; n < len; n++) + { + printf("%02X ", Bytes[n]); + + if (Counter >= 20) + { + printf("\n"); + Counter = 0; + } + + Counter++; + } + printf("\n"); +} + +char* SysfileUtilWrapper::GetString(const char* FilePath, const char* Key, unsigned int Size) +{ + int fd = sceKernelOpen(FilePath, 0, 0511); + if (!fd) + { + klog("File doesnt exist %s\n", FilePath); + return (char*)""; + } + else + { + MonoClass* SysfileUtilWrapper_Util = Mono::Get_Class(Mono::SysfileUtilWrapper, "Sce.Vsh", "SysfileUtilWrapper/Util"); + + MonoString* str = Mono::Invoke(Mono::SysfileUtilWrapper, SysfileUtilWrapper_Util, nullptr, "GetString", Mono::New_String(FilePath), Mono::New_String(Key), Size); + + if (str) + return mono_string_to_utf8(str); + else + return (char*)""; + } +} + +int SysfileUtilWrapper::GetAttribute(const char* FilePath) +{ + MonoClass* SysfileUtilWrapper_Util = Mono::Get_Class(Mono::SysfileUtilWrapper, "Sce.Vsh", "SysfileUtilWrapper/Util"); + + return Mono::Invoke(Mono::SysfileUtilWrapper, SysfileUtilWrapper_Util, nullptr, "GetAttribute", Mono::New_String(FilePath)); +} + +char* SysfileUtilWrapper::GetTitleId(const char* FilePath) +{ + return GetString(FilePath, "TITLE_ID", 12U); +} + +char* SysfileUtilWrapper::GetContentId(const char* FilePath) +{ + return GetString(FilePath, "CONTENT_ID", 48U); +} + +char* SysfileUtilWrapper::GetTitle(const char* FilePath) +{ + return GetString(FilePath, "TITLE", 128U); +} + +char* SysfileUtilWrapper::GetDescription(const char* FilePath) +{ + return GetString(FilePath, "PROVIDER", 128U); +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/SysfileUtilWrapper.h b/Playstation/Orbis Toolbox/SysfileUtilWrapper.h new file mode 100644 index 0000000..a0e7f16 --- /dev/null +++ b/Playstation/Orbis Toolbox/SysfileUtilWrapper.h @@ -0,0 +1,16 @@ +#pragma once + +class SysfileUtilWrapper +{ +public: + static char* GetString(const char* FilePath, const char* Key, unsigned int Size); + + static int GetAttribute(const char* FilePath); + static char* GetTitleId(const char* FilePath); + static char* GetContentId(const char* FilePath); + static char* GetTitle(const char* FilePath); + static char* GetDescription(const char* FilePath); + +private: + +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/System_Monitor.cpp b/Playstation/Orbis Toolbox/System_Monitor.cpp new file mode 100644 index 0000000..9233843 --- /dev/null +++ b/Playstation/Orbis Toolbox/System_Monitor.cpp @@ -0,0 +1,181 @@ +#include "Common.h" +#include "System_Monitor.h" +#include "Game_Overlay.h" + +int System_Monitor::Thread_Count = 0; +float System_Monitor::Usage[8] = { 0 }; +float System_Monitor::Average_Usage; +int System_Monitor::CPU_Temp; +int System_Monitor::SOC_Temp; +System_Monitor::Memory System_Monitor::RAM; +System_Monitor::Memory System_Monitor::VRAM; + +bool System_Monitor::Should_Run_Thread = true; +Proc_Stats System_Monitor::Stat_Data[3072]; +System_Monitor::thread_usages System_Monitor::gThread_Data[2]; + +void System_Monitor::calc_usage(unsigned int idle_tid[8], thread_usages* cur, thread_usages* prev, float usage_out[8]) +{ + if (cur->Thread_Count <= 0 || prev->Thread_Count <= 0) //Make sure our banks have threads + return; + + //Calculate the Current time difference from the last bank to the current bank. + float Current_Time_Total = ((prev->current_time.tv_sec + (prev->current_time.tv_nsec / 1000000000.0f)) - (cur->current_time.tv_sec + (cur->current_time.tv_nsec / 1000000000.0f))); + + //Here this could use to be improved but essetially what its doing is finding the thread information for the idle threads using their thread Index stored from before. + struct Data_s + { + Proc_Stats* Cur; + Proc_Stats* Prev; + }Data[8]; + + for (int i = 0; i < cur->Thread_Count; i++) + { + for (int j = 0; j < 8; j++) + { + if (idle_tid[j] == cur->Threads[i].td_tid) + Data[j].Cur = &cur->Threads[i]; + } + } + + for (int i = 0; i < prev->Thread_Count; i++) + { + for (int j = 0; j < 8; j++) + { + if (idle_tid[j] == prev->Threads[i].td_tid) + Data[j].Prev = &prev->Threads[i]; + } + } + + //Here we loop through each core to calculate the total usage time as its split into user/sustem + for (int i = 0; i < 8; i++) + { + float Prev_Usage_Time = (Data[i].Prev->system_cpu_usage_time.tv_sec + (Data[i].Prev->system_cpu_usage_time.tv_nsec / 1000000.0f)); + Prev_Usage_Time += (Data[i].Prev->user_cpu_usage_time.tv_sec + (Data[i].Prev->user_cpu_usage_time.tv_nsec / 1000000.0f)); + + float Cur_Usage_Time = (Data[i].Cur->system_cpu_usage_time.tv_sec + (Data[i].Cur->system_cpu_usage_time.tv_nsec / 1000000.0f)); + Cur_Usage_Time += (Data[i].Cur->user_cpu_usage_time.tv_sec + (Data[i].Cur->user_cpu_usage_time.tv_nsec / 1000000.0f)); + + //We calculate the usage using usage time difference between the two samples divided by the current time difference. + float Idle_Usage = ((Prev_Usage_Time - Cur_Usage_Time) / Current_Time_Total); + + if (Idle_Usage > 1.0f) + Idle_Usage = 1.0f; + + if (Idle_Usage < 0.0f) + Idle_Usage = 0.0f; + + //Get inverse of idle percentage and express in percent. + usage_out[i] = (1.0f - Idle_Usage) * 100.0f; + } +} + +void* System_Monitor::Monitor_Thread(void* args) +{ + //klog("[System Monitor] Thread Started\n"); + + unsigned int Idle_Thread_ID[8]; + + int Thread_Count = 3072; + if (!sceKernelGetCpuUsage((Proc_Stats*)&Stat_Data, (int*)&Thread_Count) && Thread_Count > 0) + { + char Thread_Name[0x40]; + int Core_Count = 0; + for (int i = 0; i < Thread_Count; i++) + { + if (!sceKernelGetThreadName(Stat_Data[i].td_tid, Thread_Name) && sscanf(Thread_Name, "SceIdleCpu%d", &Core_Count) == 1 && Core_Count <= 7) + { + //klog("[System Monitor][SceIdleCpu%d] -> %i\n", Core_Count, Stat_Data[i].td_tid); + + Idle_Thread_ID[Core_Count] = Stat_Data[i].td_tid; + } + } + } + + //klog("[System Monitor] Starting Monitor...\n"); + int Current_Bank = 0; + while (Should_Run_Thread) + { + //klog("Getting Bank %i\n", Current_Bank); + if (Game_Overlay::Show_CPU_Usage || Game_Overlay::Show_Thread_Count) + { + //grab thread data with max threads of 3072. + gThread_Data[Current_Bank].Thread_Count = 3072; + if (!sceKernelGetCpuUsage((Proc_Stats*)&gThread_Data[Current_Bank].Threads, &gThread_Data[Current_Bank].Thread_Count)) + { + //Store the thread count. + System_Monitor::Thread_Count = gThread_Data[Current_Bank].Thread_Count; + + //klog("ThreadCount[%i] = %i\n", Current_Bank, gThread_Data[Current_Bank].Thread_Count); + + //Set the current time. + sceKernelClockGettime(4, &gThread_Data[Current_Bank].current_time); + + //flip to other bank. + Current_Bank = !Current_Bank; + + //make sure bank has threads + if (gThread_Data[Current_Bank].Thread_Count <= 0) + continue; + + //Calculate usage using thread data. + calc_usage(Idle_Thread_ID, &gThread_Data[!Current_Bank], &gThread_Data[Current_Bank], Usage); + + /*klog("CPU Utilization: %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%% %2.0f%%\n", + Usage[0], Usage[1], Usage[2], Usage[3], + Usage[4], Usage[5], Usage[6], Usage[7]);*/ + + System_Monitor::Average_Usage = ((Usage[0] + Usage[1] + Usage[2] + Usage[3] + Usage[4] + Usage[5] + Usage[6] + Usage[7]) / 8.0f); + } + } + + if (Game_Overlay::Show_CPU_Temp) + { + sceKernelGetCpuTemperature(&CPU_Temp); + } + + if (Game_Overlay::Show_SOC_Temp) + { + sceKernelGetSocSensorTemperature(0, &SOC_Temp); + } + + if (Game_Overlay::Show_ram) + { + Get_Page_Table_Stats(1, 1, &RAM.Used, &RAM.Free, &RAM.Total); + RAM.Percentage = (((float)RAM.Used / (float)RAM.Total) * 100.0f); + } + + if (Game_Overlay::Show_vram) + { + Get_Page_Table_Stats(1, 2, &VRAM.Used, &VRAM.Free, &VRAM.Total); + VRAM.Percentage = (((float)VRAM.Used / (float)VRAM.Total) * 100.0f); + } + + sceKernelSleep(2); + } + + Should_Run_Thread = true; + klog("[System Monitor] Thread Shutdown.\n"); + void* res; + scePthreadExit(res); + return res; +} + +void System_Monitor::Init() +{ + klog("[System Monitor] Starting System Monitor Thread...\n"); + + OrbisPthreadAttr attr; + scePthreadAttrInit(&attr); + + scePthreadAttrSetstacksize(&attr, 0x80000); + + OrbisPthread* id; + scePthreadCreate(&id, &attr, Monitor_Thread, NULL, "System Monitor Thread"); +} + +void System_Monitor::Term() +{ + Should_Run_Thread = false; + while (!Should_Run_Thread) { sceKernelUsleep(1000 * 10); } +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/System_Monitor.h b/Playstation/Orbis Toolbox/System_Monitor.h new file mode 100644 index 0000000..889d8e4 --- /dev/null +++ b/Playstation/Orbis Toolbox/System_Monitor.h @@ -0,0 +1,42 @@ +#pragma once +#include "Common.h" + +class System_Monitor +{ +public: + struct Memory + { + int Used; + int Free; + int Total; + float Percentage; + }; + + static int Thread_Count; + static float Usage[8]; + static float Average_Usage; + static int CPU_Temp; + static int SOC_Temp; + static Memory RAM; + static Memory VRAM; + + static void Init(); + static void Term(); + +private: + struct thread_usages + { + OrbisKernelTimespec current_time; //0x00 + int Thread_Count; //0x10 + char padding0[0x4]; //0x14 + Proc_Stats Threads[3072]; //0x18 + }; + + static bool Should_Run_Thread; + static Proc_Stats Stat_Data[3072]; + static thread_usages gThread_Data[2]; + + static void calc_usage(unsigned int idle_tid[8], thread_usages* cur, thread_usages* prev, float usage_out[8]); + static void* Monitor_Thread(void* args); + +}; diff --git a/Playstation/Orbis Toolbox/UI.h b/Playstation/Orbis Toolbox/UI.h new file mode 100644 index 0000000..91bc7f5 --- /dev/null +++ b/Playstation/Orbis Toolbox/UI.h @@ -0,0 +1,7 @@ +#pragma once + +#include "UI_Utilities.h" + +#include "Widget.h" +#include "Label.h" +#include "Panel.h" \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/UI_Utilities.cpp b/Playstation/Orbis Toolbox/UI_Utilities.cpp new file mode 100644 index 0000000..163ef83 --- /dev/null +++ b/Playstation/Orbis Toolbox/UI_Utilities.cpp @@ -0,0 +1,226 @@ +#include "Common.h" +#include "UI_Utilities.h" + +char* UI::Utilities::Get_Version_String() +{ + MonoClass* SystemSoftwareVersionInfo = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "SystemSoftwareVersionInfo"); + return mono_string_to_utf8(Mono::Get_Property(SystemSoftwareVersionInfo, Mono::Get_Instance(SystemSoftwareVersionInfo, "Instance"), "DisplayVersion")); +} + +void UI::Utilities::SetVersionString(const char* str) +{ + MonoClass* SystemSoftwareVersionInfo = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "SystemSoftwareVersionInfo"); + Mono::Set_Property(SystemSoftwareVersionInfo, Mono::Get_Instance(SystemSoftwareVersionInfo, "Instance"), "DisplayVersion", Mono::New_String(str)); +} + +void UI::Utilities::ReloadItemList() +{ + MonoClass* ContentsAreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentsAreaManager"); + MonoClass* ContentsList = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentsList"); + + MonoObject* m_scene = Mono::Get_Field(ContentsAreaManager, Mono::Get_Instance(ContentsAreaManager, "Instance"), "m_scene"); + MonoArray* m_contentsList = Mono::Get_Field(Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "ContentAreaScene"), m_scene, "m_contentsList"); + MonoObject* m_contentsList_0 = mono_array_get(m_contentsList, MonoObject*, 0); + + if (m_contentsList_0) + Mono::Invoke(Mono::App_exe, ContentsList, m_contentsList_0, "ReloadItemSource"); +} + +MonoObject* UI::Utilities::AppBrowseItem(const char* TitleId, const char* TitleName) +{ + MonoObject* Instance = Mono::New_Object(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItem"); + mono_runtime_object_init(Instance); + + Mono::Set_Property(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemLite", Instance, "TitleId", Mono::New_String(TitleId)); + Mono::Set_Property(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemBase", Instance, "TitleName", Mono::New_String(TitleName)); + Mono::Set_Property(Mono::Accessor_Db, "Sce.Vsh.Accessor.Db", "AppBrowseItemBase", Instance, "MetaDataPath", 0); + + return Instance; +} + +MonoObject* UI::Utilities::Get_Top_Scene() +{ + MonoClass* AreaManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.TopMenu", "AreaManager"); + return Mono::Invoke(Mono::App_exe, AreaManager, Mono::Get_Instance(AreaManager, "Instance"), "GetTopScene"); +} + +MonoObject* UI::Utilities::Get_root_Widget() +{ + return Mono::Get_Property(Mono::UI_dll, Mono::PUI_UI2, "Scene", Get_Top_Scene(), "RootWidget"); +} + +MonoObject* UI::Utilities::Adjust_Content(int AlignOrientation, float PaddingLeft, float PaddingRight, float PaddingTop, float PaddingBottom) +{ + MonoClass* AdjustContent = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "AdjustContent"); + + //Allocates memory for our new instance of a class. + MonoObject* AdjustContent_Instance = Mono::New_Object(AdjustContent); + + //Call the default no param constructor. + mono_runtime_object_init(AdjustContent_Instance); + + //Add Properties. + Mono::Set_Property(AdjustContent, AdjustContent_Instance, "AlignOrientation", AlignOrientation); + Mono::Set_Property(AdjustContent, AdjustContent_Instance, "PaddingLeft", PaddingLeft); + Mono::Set_Property(AdjustContent, AdjustContent_Instance, "PaddingRight", PaddingRight); + Mono::Set_Property(AdjustContent, AdjustContent_Instance, "PaddingTop", PaddingTop); + Mono::Set_Property(AdjustContent, AdjustContent_Instance, "PaddingBottom", PaddingBottom); + + return AdjustContent_Instance; +} + +MonoObject* UI::Utilities::Fit_To_Children() +{ + MonoClass* FitToChildren = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "FitToChildren"); + + MonoObject* FitToChildren_Instance = Mono::New_Object(FitToChildren); + mono_runtime_object_init(FitToChildren_Instance); + + return FitToChildren_Instance; +} + +MonoObject* UI::Utilities::IUFont(int size, int style, int weight) +{ + //Somewhere between 6.72 and 7.02 UIFont was moved to UI2. + MonoClass* UIFont = Mono::Get_Class(Mono::UI_dll, (Mono::Software_Version <= 672) ? Mono::PUI : Mono::PUI_UI2, "UIFont"); + + //Allocates memory for our new instance of a class. + MonoObject* UIFont_Instance = Mono::New_Object(UIFont); + Mono::Invoke(Mono::App_exe, UIFont, (MonoObject*)mono_object_unbox(UIFont_Instance), ".ctor", size, style, weight); + + return (MonoObject*)mono_object_unbox(UIFont_Instance); +} + +MonoObject* UI::Utilities::MemoryStream(void* Buffer, int Buffer_Size) +{ + MonoArray* Array = Mono::New_Array(mono_get_byte_class(), Buffer_Size); + char* Array_addr = mono_array_addr_with_size(Array, sizeof(char), 0); + memcpy(Array_addr, Buffer, Buffer_Size); + + MonoClass* MemoryStream = Mono::Get_Class(Mono::mscorlib, "System.IO", "MemoryStream"); + MonoObject* MemoryStream_Instance = Mono::New_Object(MemoryStream); + Mono::Invoke(Mono::mscorlib, MemoryStream, MemoryStream_Instance, ".ctor", Array, true); + + return MemoryStream_Instance; +} + +void UI::Utilities::ResetMenuItem(const char* Menu) +{ + MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager"); + Mono::Invoke(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "ResetMenuItem", Mono::New_String(Menu)); +} + +void UI::Utilities::RemoveMenuItem(const char* Menu) +{ + MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager"); + Mono::Invoke(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "RemoveMenuItem", Mono::New_String(Menu)); +} + +void UI::Utilities::AddMenuItem(MonoObject* ElementData) +{ + MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager"); + Mono::Invoke(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "AddMenuItem", ElementData, Mono::New_String("")); +} + +MonoObject* UI::Utilities::GetElement(const char* Id) +{ + MonoClass* UIManager = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "UIManager"); + return Mono::Invoke(Mono::App_exe, UIManager, Mono::Get_Instance(UIManager, "Instance"), "GetElement", Mono::New_String(Id)); +} + +void UI::Utilities::Set_Value(const char* Id, const char* Value) +{ + MonoClass* SettingElement = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "SettingElement"); + + MonoObject* Elem = GetElement(Id); + if(Elem) + Mono::Set_Property(SettingElement, Elem, "Value", Mono::New_String(Value)); +} + +MonoObject* UI::Utilities::ElementData(const char* Id, const char* Title, const char* Title2, const char* Icon) +{ + MonoClass* ButtonElementData = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "ButtonElementData"); + MonoClass* ElementData = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.Settings.Core", "ElementData"); + MonoObject* Instance = Mono::New_Object(ButtonElementData); + mono_runtime_object_init(Instance); + + Mono::Set_Property(ElementData, Instance, "Id", Mono::New_String(Id)); + Mono::Set_Property(ElementData, Instance, "Title", Mono::New_String(Title)); + Mono::Set_Property(ElementData, Instance, "SecondTitle", Mono::New_String(Title2)); + Mono::Set_Property(ElementData, Instance, "Icon", Mono::New_String(Icon)); + + return Instance; +} + +MonoObject* UI::Utilities::UIColor(float R, float G, float B, float A) +{ + MonoClass* UIColor = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UIColor"); + + //Allocates memory for our new instance of a class. + MonoObject* UIColor_Instance = Mono::New_Object(UIColor); + + // Calling the constructor for the struct** Notice that for structs we have to unbox the + // Object first before calling the constructor. + MonoObject* Real_Instance = (MonoObject*)mono_object_unbox(UIColor_Instance); + Mono::Invoke(Mono::UI_dll, UIColor, Real_Instance, ".ctor", R, G, B, A); + + return Real_Instance; +} + +MonoObject* UI::Utilities::UIColor(float R, float G, float B) +{ + MonoClass* UIColor = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UIColor"); + + //Allocates memory for our new instance of a class. + MonoObject* UIColor_Instance = Mono::New_Object(UIColor); + + // Calling the constructor for the struct** Notice that for structs we have to unbox the + // Object first before calling the constructor. + MonoObject* Real_Instance = (MonoObject*)mono_object_unbox(UIColor_Instance); + Mono::Invoke(Mono::UI_dll, UIColor, Real_Instance, ".ctor", R, G, B); + + return Real_Instance; +} + +float UI::Utilities::ScreenHeight() +{ + MonoClass* UISystem = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UISystem"); + return Mono::Get_Property(UISystem, nullptr, "ScreenHeight"); +} + +float UI::Utilities::ScreenWidth() +{ + MonoClass* UISystem = Mono::Get_Class(Mono::UI_dll, Mono::PUI, "UISystem"); + return Mono::Get_Property(UISystem, nullptr, "ScreenWidth"); +} + +//Sce.Vsh.ShellUI.Library OptionMenuFactory IsAppRunning +bool UI::Utilities::IsAppRunning(const char* TitleId) +{ + MonoClass* ApplicationMonitor = Mono::Get_Class(Mono::App_exe, "Sce.Vsh.ShellUI.AppSystem", "ApplicationMonitor"); + + if (ApplicationMonitor == nullptr) + { + klog("IsAppRunning: ApplicationMonitor was null."); + return false; + } + + MonoMethod* Method = mono_class_get_method_from_name(ApplicationMonitor, "GetAppEvent", 1); + + if (!Method) + { + klog("Get_Address_of_Method: failed to find method \"%s\" in class \"%s\"", "GetAppEvent", "ApplicationMonitor"); + return false; + } + + void* Args[] = { Mono::New_String(TitleId) }; + + uint64_t obj = (uint64_t)mono_runtime_invoke(Method, nullptr, Args, NULL); + + //MonoObject* Res = Mono::Invoke(Mono::App_exe, ApplicationMonitor, nullptr, "GetAppEvent", Mono::New_String(TitleId)); + + klog("obj = %llX\n", obj); + return (obj != NULL); + + return true; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/UI_Utilities.h b/Playstation/Orbis Toolbox/UI_Utilities.h new file mode 100644 index 0000000..d078be0 --- /dev/null +++ b/Playstation/Orbis Toolbox/UI_Utilities.h @@ -0,0 +1,32 @@ +#pragma once + +namespace UI +{ + class Utilities + { + public: + static char* Get_Version_String(); + static void SetVersionString(const char* str); + static void ReloadItemList(); + static MonoObject* AppBrowseItem(const char* TitleId, const char* TitleName); + static MonoObject* Get_Top_Scene(); + static MonoObject* Get_root_Widget(); + static MonoObject* Adjust_Content(int AlignOrientation, float PaddingLeft, float PaddingRight, float PaddingTop, float PaddingBottom); + static MonoObject* Fit_To_Children(); + static MonoObject* IUFont(int size, int style, int weight); + static MonoObject* MemoryStream(void* Buffer, int Buffer_Size); + static void ResetMenuItem(const char* Menu); + static void RemoveMenuItem(const char* Menu); + static MonoObject* GetElement(const char* Id); + static void Set_Value(const char* Id, const char* Value); + static void AddMenuItem(MonoObject* ElementData); + static MonoObject* ElementData(const char* Id, const char* Title, const char* Title2, const char* Icon); + static MonoObject* UIColor(float R, float G, float B, float A); + static MonoObject* UIColor(float R, float G, float B); + static float ScreenHeight(); + static float ScreenWidth(); + static bool IsAppRunning(const char* TitleId); + private: + + }; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Utilities.cpp b/Playstation/Orbis Toolbox/Utilities.cpp new file mode 100644 index 0000000..da4a174 --- /dev/null +++ b/Playstation/Orbis Toolbox/Utilities.cpp @@ -0,0 +1,112 @@ +#include "Common.h" +#include "Utilities.h" + +void klog(const char* fmt, ...) +{ + char Buffer[0x200]; + + //Create full string from va list. + va_list args; + va_start(args, fmt); + vsprintf(Buffer, fmt, args); + va_end(args); + + sceKernelDebugOutText(0, Buffer); +} + +void Notify(const char* MessageFMT, ...) +{ + NotifyBuffer Buffer; + + //Create full string from va list. + va_list args; + va_start(args, MessageFMT); + vsprintf(Buffer.Message, MessageFMT, args); + va_end(args); + + //Populate the notify buffer. + Buffer.Type = NotifyType::NotificationRequest; //this one is just a standard one and will print what ever is stored at the buffer.Message. + Buffer.unk3 = 0; + Buffer.UseIconImageUri = 1; //Bool to use a custom uri. + Buffer.TargetId = -1; //Not sure if name is correct but is always set to -1. + strcpy(Buffer.Uri, "https://i.imgur.com/SJPIBGG.png"); //Copy the uri to the buffer. + + //From user land we can call int64_t sceKernelSendNotificationRequest(int64_t unk1, char* Buffer, size_t size, int64_t unk2) which is a libkernel import. + sceKernelSendNotificationRequest(0, (char*)&Buffer, 3120, 0); + + //What sceKernelSendNotificationRequest is doing is opening the device "/dev/notification0" or "/dev/notification1" + // and writing the NotifyBuffer we created to it. Somewhere in ShellUI it is read and parsed into a json which is where + // I found some clues on how to build the buffer. +} + +struct Myiovec +{ + void* iov_base; + size_t iov_len; +}; + +void build_iovec(Myiovec** iov, int* iovlen, const char* name, const void* val, size_t len) +{ + int i; + + if (*iovlen < 0) + return; + + i = *iovlen; + *iov = (Myiovec*)realloc(*iov, sizeof **iov * (i + 2)); + if (*iov == NULL) { + *iovlen = -1; + return; + } + + (*iov)[i].iov_base = strdup(name); + (*iov)[i].iov_len = strlen(name) + 1; + ++i; + + (*iov)[i].iov_base = (void*)val; + if (len == (size_t)-1) { + if (val != NULL) + len = strlen((const char*)val) + 1; + else + len = 0; + } + (*iov)[i].iov_len = (int)len; + + *iovlen = ++i; +} + + +/* + +vm: +1 - Seems to be system +2 - seems to be app specific. + +type: +1 - System, +2 - VRAM + + System, + Video, + SharedVideoSystemAsset, + SharedVideoHighResoAsset +*/ + +void Get_Page_Table_Stats(int vm, int type, int* Used, int* Free, int* Total) +{ + int _Total = 0, _Free = 0; + + if (get_page_table_stats(vm, type, &_Total, &_Free) == -1) { + klog("get_page_table_stats() Failed.\n"); + return; + } + + if (Used) + *Used = (_Total - _Free); + + if (Free) + *Free = _Free; + + if (Total) + *Total = _Total; +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Utilities.h b/Playstation/Orbis Toolbox/Utilities.h new file mode 100644 index 0000000..c11d0a8 --- /dev/null +++ b/Playstation/Orbis Toolbox/Utilities.h @@ -0,0 +1,69 @@ +#pragma once + +enum NotifyType +{ + NotificationRequest = 0, + SystemNotification = 1, + SystemNotificationWithUserId = 2, + SystemNotificationWithDeviceId = 3, + SystemNotificationWithDeviceIdRelatedToUser = 4, + SystemNotificationWithText = 5, + SystemNotificationWithTextRelatedToUser = 6, + SystemNotificationWithErrorCode = 7, + SystemNotificationWithAppId = 8, + SystemNotificationWithAppName = 9, + SystemNotificationWithAppInfo = 9, + SystemNotificationWithAppNameRelatedToUser = 10, + SystemNotificationWithParams = 11, + SendSystemNotificationWithUserName = 12, + SystemNotificationWithUserNameInfo = 13, + SendAddressingSystemNotification = 14, + AddressingSystemNotificationWithDeviceId = 15, + AddressingSystemNotificationWithUserName = 16, + AddressingSystemNotificationWithUserId = 17, + + UNK_1 = 100, + TrcCheckNotificationRequest = 101, + NpDebugNotificationRequest = 102, + UNK_2 = 102, +}; + +struct NotifyBuffer +{ //Naming may be incorrect. + NotifyType Type; //0x00 + int ReqId; //0x04 + int Priority; //0x08 + int MsgId; //0x0C + int TargetId; //0x10 + int UserId; //0x14 + int unk1; //0x18 + int unk2; //0x1C + int AppId; //0x20 + int ErrorNum; //0x24 + int unk3; //0x28 + char UseIconImageUri; //0x2C + char Message[1024]; //0x2D + char Uri[1024]; //0x42D + char unkstr[1024]; //0x82D +}; //Size = 0xC30 + +#define ARRAY_COUNT(arry) sizeof(arry) / sizeof(arry[0]) + +typedef unsigned char vm_prot_t; /* protection codes */ + +#define VM_PROT_NONE ((vm_prot_t) 0x00) +#define VM_PROT_READ ((vm_prot_t) 0x01) +#define VM_PROT_WRITE ((vm_prot_t) 0x02) +#define VM_PROT_EXECUTE ((vm_prot_t) 0x04) +#define VM_PROT_COPY ((vm_prot_t) 0x08) /* copy-on-read */ + +#define VM_PROT_ALL (VM_PROT_READ|VM_PROT_WRITE|VM_PROT_EXECUTE) +#define VM_PROT_RW (VM_PROT_READ|VM_PROT_WRITE) +#define VM_PROT_DEFAULT VM_PROT_ALL + +#define MNT_UPDATE 0x0000000000010000ULL /* not real mount, just update */ + +void klog(const char* fmt, ...); +void Notify(const char* MessageFMT, ...); + +void Get_Page_Table_Stats(int vm, int type, int* Used, int* Free, int* Total); \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Version.h b/Playstation/Orbis Toolbox/Version.h new file mode 100644 index 0000000..07bc852 --- /dev/null +++ b/Playstation/Orbis Toolbox/Version.h @@ -0,0 +1,11 @@ +#pragma once +#define ORBIS_TOOLBOX_MAJOR 1 +#define ORBIS_TOOLBOX_MINOR 0 +#define ORBIS_TOOLBOX_BUILDVERSION 1225 +#define stringify(a) stringify_(a) +#define stringify_(a) #a +#if defined(ORBIS_TOOLBOX_DEBUG) +#define ORBIS_TOOLBOX_BUILDSTRING ("[Orbis Toolbox Alpha Version " stringify(ORBIS_TOOLBOX_MAJOR) "." stringify(ORBIS_TOOLBOX_MINOR) "] Dev Build " stringify(ORBIS_TOOLBOX_BUILDVERSION) " " __DATE__ " " __TIME__) +#else +#define ORBIS_TOOLBOX_BUILDSTRING ("[Orbis Toolbox Alpha Version " stringify(ORBIS_TOOLBOX_MAJOR) "." stringify(ORBIS_TOOLBOX_MINOR) "] Build " stringify(ORBIS_TOOLBOX_BUILDVERSION) " " __DATE__ " " __TIME__) +#endif diff --git a/Playstation/Orbis Toolbox/Widget.cpp b/Playstation/Orbis Toolbox/Widget.cpp new file mode 100644 index 0000000..17af1b2 --- /dev/null +++ b/Playstation/Orbis Toolbox/Widget.cpp @@ -0,0 +1,58 @@ +#include "Common.h" +#include "UI.h" +#include "Panel.h" +#include "Label.h" +#include "Widget.h" + +void Widget::Remove_Child(const char* Child_Name) +{ + if (Instance) + { + if (Has_Child(Child_Name)) + { + MonoObject* ChildWidget = Mono::Invoke(Mono::App_exe, Widget_Class, Instance, "FindWidgetByName", Mono::New_String(Child_Name)); + Mono::Invoke(Mono::App_exe, Widget_Class, ChildWidget, "RemoveFromParent"); + + Children.erase(Children.find(Child_Name)); + } + else + klog("[Widget] %s(): Child \"%s\" does not exist in Family.\n", __FUNCTION__, Child_Name); + } + else + klog("[Widget] %s(): Instance is not set.\n", __FUNCTION__); +} + +void* Widget::Get_Child(const char* Child_Name) +{ + if (Has_Child(Child_Name)) + { + Children[Child_Name]->Instance = Mono::Invoke(Mono::App_exe, Widget_Class, this->Instance, "FindWidgetByName", Mono::New_String(Child_Name)); + return Children[Child_Name]; + } + else + klog("[Widget] %s(): Child \"%s\" Does not exist on Parent.\n", __FUNCTION__, Child_Name); + return 0; +} + +bool Widget::Has_Child(const char* Child_Name) +{ + return (Children.find(Child_Name) != Children.end()); +} + +void Widget::Set_Clip_Children(bool Value) +{ + if (Instance) + Mono::Set_Property(Widget_Class, Instance, "ClipChildren", Value); + else + klog("[Widget] %s(): Instance is not set.\n", __FUNCTION__); +} + +Widget::Widget() +{ + this->Widget_Class = Mono::Get_Class(Mono::UI_dll, Mono::PUI_UI2, "Widget"); +} + +Widget::~Widget() +{ + +} \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/Widget.h b/Playstation/Orbis Toolbox/Widget.h new file mode 100644 index 0000000..1815c5d --- /dev/null +++ b/Playstation/Orbis Toolbox/Widget.h @@ -0,0 +1,41 @@ +#pragma once +class Panel; +class Label; + +class Widget +{ +protected: + + +public: + MonoObject* Instance; + std::map Children; + + template + void Append_Child(const char* Child_Name, ChildClass* Child_Class) + { + if (Instance) + { + if (Children.find(Child_Name) == Children.end()) + { + Children.insert(std::pair(Child_Name, (Widget*)Child_Class)); + + Mono::Invoke(Mono::App_exe, Widget_Class, Instance, "AppendChild", Child_Class->Instance); + } + else + klog("[Widget] %s(): Child \"%s\" already exists in Family.\n", __FUNCTION__, Child_Name); + } + else + klog("[Widget] %s(): Instance is not set.\n", __FUNCTION__); + } + void Remove_Child(const char* Child_Name); + void* Get_Child(const char* Child_Name); + bool Has_Child(const char* Child_Name); + void Set_Clip_Children(bool Value); + + Widget(); + ~Widget(); + +private: + MonoClass* Widget_Class; +}; \ No newline at end of file diff --git a/Playstation/Orbis Toolbox/build.bat b/Playstation/Orbis Toolbox/build.bat new file mode 100644 index 0000000..2dacfe1 --- /dev/null +++ b/Playstation/Orbis Toolbox/build.bat @@ -0,0 +1,63 @@ +SETLOCAL EnableDelayedExpansion + +Rem Libraries to link in +set libraries=-lSceLibcInternal -lSceLibcInternalExt -lkernel -lmonosgen -lSceSystemService -lSceLncUtil + +Rem Read the script arguments into local vars +set intdir=%1 +set targetname=%~2 +set outputPath=%~3 + +set outputElf=%intdir%%targetname%.elf +set outputOelf=%intdir%%targetname%.oelf +set outputPrx=%intdir%%targetname%.prx +set outputStub=%intdir%%targetname%_stub.so + +Rem Compile object files for all the source files -DORBIS_TOOLBOX_DEBUG +for %%f in (*.cpp) do ( + clang++ -cc1 -triple x86_64-scei-ps4-elf -munwind-tables -I"%OO_PS4_TOOLCHAIN%\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" -emit-obj -o %intdir%\%%~nf.o %%~nf.cpp +) + +Rem Compile object files for all the assembly files +for %%f in (*.s) do ( + clang -m64 -nodefaultlibs -nostdlib --target=x86_64-scei-ps4-elf -c -o %intdir%\%%~nf.o %%~nf.s +) + +Rem Get a list of object files for linking +set obj_files= +for %%f in (%intdir%\\*.o) do set obj_files=!obj_files! .\%%f + +Rem Link the input ELF +ld.lld -m elf_x86_64 -pie --script "%OO_PS4_TOOLCHAIN%\link.x" --eh-frame-hdr -o "%outputElf%" "-L%OO_PS4_TOOLCHAIN%\lib" %libraries% --verbose "%OO_PS4_TOOLCHAIN%\lib\crtlib.o" %obj_files% + +Rem Create stub shared libraries +for %%f in (*.cpp) do ( + clang++ -target x86_64-pc-linux-gnu -ffreestanding -nostdlib -fno-builtin -fPIC -c -I"%OO_PS4_TOOLCHAIN%\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" -o %intdir%\%%~nf.o.stub %%~nf.cpp +) + +set stub_obj_files= +for %%f in (%intdir%\\*.o.stub) do set stub_obj_files=!stub_obj_files! .\%%f + +clang++ -target x86_64-pc-linux-gnu -shared -fuse-ld=lld -ffreestanding -nostdlib -fno-builtin "-L%OO_PS4_TOOLCHAIN%\lib" %libraries% %stub_obj_files% -o "%outputStub%" + +Rem Create the prx +%OO_PS4_TOOLCHAIN%\bin\windows\create-lib.exe -in "%outputElf%" --out "%outputOelf%" --paid 0x3800000000010003 + +Rem Cleanup +copy "%outputPrx%" "%outputPath%\Playstation\Build\pkg\Orbis Toolbox\%targetname%.sprx" +del "%outputPrx%" + +REM Generate the script. Will overwrite any existing temp.txt +REM echo open 192.168.0.55 1337> temp.txt +echo open 192.168.0.55 2121> temp.txt +echo anonymous>> temp.txt +echo anonymous>> temp.txt +echo cd "/data/Orbis Toolbox/">> temp.txt +echo send "%outputPath%Playstation\Build\pkg\Orbis Toolbox\%targetname%.sprx">> temp.txt +echo quit>> temp.txt + +REM Launch FTP and pass it the script +ftp -s:temp.txt + +REM Clean up. +del temp.txt diff --git a/Playstation/Orbis Toolbox/external_hdd.xml b/Playstation/Orbis Toolbox/external_hdd.xml new file mode 100644 index 0000000..6369b29 --- /dev/null +++ b/Playstation/Orbis Toolbox/external_hdd.xml @@ -0,0 +1,28 @@ + + + + + + + +