From f71f72106159036a11405a0b6312540463cd541f Mon Sep 17 00:00:00 2001 From: Greg Date: Thu, 19 Jan 2023 23:01:34 -0700 Subject: [PATCH] Add peek n poke. --- .gitmodules | 3 + External/Be.HexEditor | 1 + External/HexView | 2 +- External/SimpleUI | 2 +- Misc/General_IPC.h | 9 +- Orbis Suite 3.0.sln | 21 +- Playstation/OrbisLibAPI/API.cpp | 74 ++-- Playstation/OrbisLibAPI/APIPackets.h | 114 +++++- Playstation/OrbisLibAPI/Debug.cpp | 73 ++++ Playstation/OrbisLibAPI/Debug.h | 2 + Playstation/OrbisLibAPI/GeneralIPC.cpp | 105 ++++++ Playstation/OrbisLibAPI/GeneralIPC.h | 1 + Playstation/OrbisLibAPI/ShellUIIPC.cpp | 5 + Playstation/OrbisLibAPI/SocketListener.cpp | 4 +- Playstation/OrbisLibAPI/Sockets.cpp | 2 +- Playstation/OrbisLibAPI/Utilities.h | 3 +- Playstation/OrbisLibAPI/Version.h | 22 +- Playstation/OrbisLibGeneralHelper/Detour.cpp | 10 - .../LocalSocketListener.cpp | 3 +- .../OrbisLibGeneralHelper.cpp | 117 +++++- .../OrbisLibGeneralHelper.vcxproj | 2 +- .../OrbisLibGeneralHelper.vcxproj.filters | 2 +- .../{Socket.cpp => Sockets.cpp} | 23 ++ Playstation/OrbisLibGeneralHelper/Sockets.h | 2 +- .../OrbisLibGeneralHelper/Utilities.cpp | 41 +++ Playstation/OrbisLibGeneralHelper/Utilities.h | 16 +- Playstation/OrbisMonitor/OrbisMonitor.vcxproj | 68 ++++ .../OrbisMonitor/OrbisMonitor.vcxproj.filters | 19 + Playstation/OrbisMonitor/build.bat | 80 +++++ Playstation/OrbisMonitor/main.cpp | 7 + Windows/Installer/SetupBA/SetupBA.csproj | 5 +- Windows/Libraries/OrbisLib2/Common/API/API.cs | 2 +- .../OrbisLib2/Common/API/APIPackets.cs | 2 + Windows/Libraries/OrbisLib2/Common/Config.cs | 2 +- .../OrbisLib2/Common/Helpers/Sockets.cs | 27 +- Windows/Libraries/OrbisLib2/OrbisLib2.csproj | 2 +- Windows/Libraries/OrbisLib2/Targets/Debug.cs | 64 ++++ .../OrbisLibraryManager.csproj | 2 +- .../OrbisNeighborHood.csproj | 3 +- .../Resources/BuildNumber.txt | 2 +- .../Resources/BuildString.txt | 2 +- Windows/OrbisPeeknPoke/OrbisPeeknPoke.csproj | 13 +- Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml | 238 +++++++++---- Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml.cs | 333 ++++++++++++++---- Windows/OrbisSuiteService/Program.cs | 2 +- 45 files changed, 1296 insertions(+), 236 deletions(-) create mode 160000 External/Be.HexEditor rename Playstation/OrbisLibGeneralHelper/{Socket.cpp => Sockets.cpp} (63%) create mode 100644 Playstation/OrbisMonitor/OrbisMonitor.vcxproj create mode 100644 Playstation/OrbisMonitor/OrbisMonitor.vcxproj.filters create mode 100644 Playstation/OrbisMonitor/build.bat create mode 100644 Playstation/OrbisMonitor/main.cpp diff --git a/.gitmodules b/.gitmodules index 9ebc035..093ecbb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -15,3 +15,6 @@ [submodule "External/HexView"] path = External/HexView url = https://github.com/OSM-Made/HexView.Wpf +[submodule "External/Be.HexEditor"] + path = External/Be.HexEditor + url = https://github.com/OSM-Made/Be.HexEditor diff --git a/External/Be.HexEditor b/External/Be.HexEditor new file mode 160000 index 0000000..3f0ec50 --- /dev/null +++ b/External/Be.HexEditor @@ -0,0 +1 @@ +Subproject commit 3f0ec50cb701dc744d8d6bac8ab51ff6fb15ff37 diff --git a/External/HexView b/External/HexView index e7a373f..a6f43ec 160000 --- a/External/HexView +++ b/External/HexView @@ -1 +1 @@ -Subproject commit e7a373f06cf61548bf843bcbd20fa27b9a97b2d9 +Subproject commit a6f43ec0d8be2eb87d885608d192643098a9cd72 diff --git a/External/SimpleUI b/External/SimpleUI index 4fa9094..2e088ce 160000 --- a/External/SimpleUI +++ b/External/SimpleUI @@ -1 +1 @@ -Subproject commit 4fa90941c5b44d3a1b439aedb80b43214fe26392 +Subproject commit 2e088ce8139ae1b4b40b945386ffd66fdc56e2b7 diff --git a/Misc/General_IPC.h b/Misc/General_IPC.h index 0073e5b..6cd2c93 100644 --- a/Misc/General_IPC.h +++ b/Misc/General_IPC.h @@ -1,6 +1,6 @@ #pragma once -// Genreall IPC ADDRS should follow the GeneralIPC# pattern. +// Genreall IPC ADDRS should follow the GeneralIPC- pattern. #define GENERAL_IPC_ADDR "/system_tmp/GeneralIPC-%d" enum GeneralIPCCommands @@ -21,6 +21,13 @@ enum GeneralIPCResult GIPC_OK, }; +struct RWPacket +{ + bool Write; + uint64_t Address; + uint64_t Length; +}; + struct LibPacket { uint32_t Handle; diff --git a/Orbis Suite 3.0.sln b/Orbis Suite 3.0.sln index 95811b2..2bcdfb3 100644 --- a/Orbis Suite 3.0.sln +++ b/Orbis Suite 3.0.sln @@ -49,7 +49,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OrbisLibGeneralHelper", "Pl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisLib2", "Windows\Libraries\OrbisLib2\OrbisLib2.csproj", "{75BA171D-708A-40AA-A27D-57150E5DFB7B}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OrbisPeeknPoke", "Windows\OrbisPeeknPoke\OrbisPeeknPoke.csproj", "{90180080-9585-499C-99A8-6F4D1725CAF4}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OrbisPeeknPoke", "Windows\OrbisPeeknPoke\OrbisPeeknPoke.csproj", "{90180080-9585-499C-99A8-6F4D1725CAF4}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "OrbisMonitor", "Playstation\OrbisMonitor\OrbisMonitor.vcxproj", "{95716BEC-FF5A-4666-B8FE-547512CA38E0}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -255,6 +257,22 @@ Global {90180080-9585-499C-99A8-6F4D1725CAF4}.Release|x64.Build.0 = Release|Any CPU {90180080-9585-499C-99A8-6F4D1725CAF4}.Release|x86.ActiveCfg = Release|Any CPU {90180080-9585-499C-99A8-6F4D1725CAF4}.Release|x86.Build.0 = Release|Any CPU + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|Any CPU.ActiveCfg = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|Any CPU.Build.0 = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|Win32.ActiveCfg = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|Win32.Build.0 = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|x64.ActiveCfg = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|x64.Build.0 = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|x86.ActiveCfg = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Debug|x86.Build.0 = Debug|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|Any CPU.ActiveCfg = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|Any CPU.Build.0 = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|Win32.ActiveCfg = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|Win32.Build.0 = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|x64.ActiveCfg = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|x64.Build.0 = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|x86.ActiveCfg = Release|x64 + {95716BEC-FF5A-4666-B8FE-547512CA38E0}.Release|x86.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -274,6 +292,7 @@ Global {F0E3446E-D9D7-4F44-AC98-797C5124BE91} = {8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45} {75BA171D-708A-40AA-A27D-57150E5DFB7B} = {72E29C1E-8723-4885-A5ED-BD3A929D81B6} {90180080-9585-499C-99A8-6F4D1725CAF4} = {8F0E1457-FB1E-47A4-9DA8-74A6B757CAA4} + {95716BEC-FF5A-4666-B8FE-547512CA38E0} = {8E8E4C8D-E3E1-4CB9-BD78-7ADAB2F2CF45} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4B6EE1D0-5ADF-44A2-B6EE-E5C8E110EE47} diff --git a/Playstation/OrbisLibAPI/API.cpp b/Playstation/OrbisLibAPI/API.cpp index e81ee13..bcbb3ca 100644 --- a/Playstation/OrbisLibAPI/API.cpp +++ b/Playstation/OrbisLibAPI/API.cpp @@ -14,50 +14,58 @@ void API::ListenerCallback(void* tdParam, OrbisNetId s, OrbisNetInAddr sin_addr) // Deserialize the packet. auto Packet = RecievePacket(s); + // Did we recieve a packet? + if (Packet == nullptr) + { + return; + } + + // Validate Packet + if (strcmp(Packet->PacketMagic, "ORBIS_SUITE") && Packet->PacketVersion != PACKET_VERSION) + { + klog("Invalid Packet with Magic %s and Version %i\n", Packet->PacketMagic, Packet->PacketVersion); + + free(Packet); + + return; + } + + //if (Packet->Command > 0 && Packet->Command <= ARRAY_COUNT(CommandList)) + //{ + // klog("Recieved the Command %i(%s)\n", Packet->Command, CommandList[Packet->Command]); + //} + // Add host to the host list. Events::AddHost(sin_addr.s_addr); - if (Packet != nullptr) + // Send out the command to the right places. + switch (Packet->Command) { - // Make sure were getting the proper packet version. - if (Packet->PacketVersion != PACKET_VERSION) - { - //klog("Packet version %i does not match our expected %i version!\n", Packet->PacketVersion, PACKET_VERSION); + default: + klog("API: Invalid Command %i...\n", Packet->Command); + break; - free(Packet); + case APICommands::PROC_START ... APICommands::PROC_END: + Proc->HandleAPI(s, Packet); + break; - return; - } + case APICommands::APP_START ... APICommands::APP_END: + Apps->HandleAPI(s, Packet); + break; - // Send out the command to the right places. - switch (Packet->Command) - { - default: - klog("API: Invalid Command %i...\n", Packet->Command); - break; + case APICommands::DBG_START ... APICommands::DBG_END: + Debug->HandleAPI(s, Packet); + break; - case APICommands::PROC_START ... APICommands::PROC_END: - Proc->HandleAPI(s, Packet); - break; + case APICommands::KERN_START ... APICommands::KERN_END: + klog("Kernel API Call\n"); - case APICommands::APP_START ... APICommands::APP_END: - Apps->HandleAPI(s, Packet); - break; + break; - case APICommands::DBG_START ... APICommands::DBG_END: - Debug->HandleAPI(s, Packet); - break; + case APICommands::TARGET_START ... APICommands::TARGET_END: + Target->HandleAPI(s, Packet); + break; - case APICommands::KERN_START ... APICommands::KERN_END: - klog("Kernel API Call\n"); - - break; - - case APICommands::TARGET_START ... APICommands::TARGET_END: - Target->HandleAPI(s, Packet); - break; - - } } // Clean up. :) diff --git a/Playstation/OrbisLibAPI/APIPackets.h b/Playstation/OrbisLibAPI/APIPackets.h index 1056eec..d0897b3 100644 --- a/Playstation/OrbisLibAPI/APIPackets.h +++ b/Playstation/OrbisLibAPI/APIPackets.h @@ -1,7 +1,7 @@ #pragma once #include "Common.h" -#define PACKET_VERSION 2 +#define PACKET_VERSION 3 #pragma region Commands @@ -114,6 +114,117 @@ enum APICommands /* ############################## */ }; +constexpr const char* CommandList[] = { + "Invalid Command", + + /* ####### Proc functions ####### */ + "PROC_START", + + "API_PROC_GET_LIST", + "API_PROC_LOAD_ELF", + "API_PROC_CALL", /* RPC Call. */ + + "PROC_END", + /* ############################## */ + + /* ####### Apps functions ####### */ + "APP_START", + + "API_APPS_GET_LIST", + "API_APPS_GET_INFO_STR", + "API_APPS_STATUS", + "API_APPS_START", + "API_APPS_STOP", + "API_APPS_SUSPEND", + "API_APPS_RESUME", + "API_APPS_DELETE", + "API_APPS_SET_VISIBILITY", + "API_APPS_GET_VISIBILITY", + + "APP_END", + /* ############################## */ + + /* ##### Debugger functions ##### */ + "DBG_START", + + "API_DBG_ATTACH", /* Debugger attach to target */ + "API_DBG_DETACH", /* Debugger detach from target */ + "API_DBG_GET_CURRENT", + "API_DBG_READ", + "API_DBG_WRITE", + "API_DBG_KILL", + "API_DBG_BREAK", + "API_DBG_RESUME", + "API_DBG_SIGNAL", + "API_DBG_STEP", + "API_DBG_STEP_OVER", + "API_DBG_STEP_OUT", + "API_DBG_GET_CALLSTACK", + "API_DBG_GET_REG", + "API_DBG_SET_REG", + "API_DBG_GET_FREG", + "API_DBG_SET_FREG", + "API_DBG_GET_DBGREG", + "API_DBG_SET_DBGREG", + + /* Remote Library functions */ + "API_DBG_LOAD_LIBRARY", + "API_DBG_UNLOAD_LIBRARY", + "API_DBG_RELOAD_LIBRARY", + "API_DBG_LIBRARY_LIST", + + /* Thread Management */ + "API_DBG_THREAD_LIST", + "API_DBG_THREAD_STOP", + "API_DBG_THREAD_RESUME", + + /* Breakpoint functions */ + "API_DBG_BREAKPOINT_GETFREE", + "API_DBG_BREAKPOINT_SET", + "API_DBG_BREAKPOINT_UPDATE", + "API_DBG_BREAKPOINT_REMOVE", + "API_DBG_BREAKPOINT_GETINFO", + "API_DBG_BREAKPOINT_LIST", + + /* Watchpoint functions */ + "API_DBG_WATCHPOINT_SET", + "API_DBG_WATCHPOINT_UPDATE", + "API_DBG_WATCHPOINT_REMOVE", + "API_DBG_WATCHPOINT_GETINFO", + "API_DBG_WATCHPOINT_LIST", + + "DBG_END", + /* ############################## */ + + /* ###### Kernel functions ###### */ + "KERN_START", + + "API_KERN_BASE", + "API_KERN_READ", + "API_KERN_WRITE", + + "KERN_END", + /* ############################## */ + + /* ###### Target functions ###### */ + "TARGET_START", + + "API_TARGET_INFO", + "API_TARGET_RESTMODE", + "API_TARGET_SHUTDOWN", + "API_TARGET_REBOOT", + "API_TARGET_NOTIFY", + "API_TARGET_BUZZER", + "API_TARGET_SET_LED", + "API_TARGET_DUMP_PROC", + "API_TARGET_SET_SETTINGS", + "API_TARGET_GETFILE", + + "TARGET_END", + /* ############################## */ + +}; + #pragma endregion #pragma region Generic @@ -136,6 +247,7 @@ enum APIResults struct APIPacket { + char PacketMagic[10]; int PacketVersion; int Command; }; diff --git a/Playstation/OrbisLibAPI/Debug.cpp b/Playstation/OrbisLibAPI/Debug.cpp index 3a0d7ca..9fc3003 100644 --- a/Playstation/OrbisLibAPI/Debug.cpp +++ b/Playstation/OrbisLibAPI/Debug.cpp @@ -40,10 +40,14 @@ void Debug::HandleAPI(OrbisNetId Sock, APIPacket* Packet) case API_DBG_READ: + ReadWriteMemory(Sock, false); + break; case API_DBG_WRITE: + ReadWriteMemory(Sock, true); + break; case API_DBG_KILL: @@ -387,6 +391,75 @@ void Debug::GetLibraryList(OrbisNetId Sock) Sockets::SendLargeData(Sock, (unsigned char*)libraryList.data(), libraryList.size() * sizeof(LibraryPacket)); } +void Debug::ReadWriteMemory(OrbisNetId Sock, bool write) +{ + if (!IsDebugging || CurrentPID == -1) + { + return; + } + + // Get next packet. + auto Packet = (DbgRWPacket*)malloc(sizeof(DbgRWPacket)); + sceNetRecv(Sock, Packet, sizeof(DbgRWPacket), 0); + + if (write) + { + auto buffer = (unsigned char*)malloc(Packet->Length); + + if (!Sockets::RecvLargeData(Sock, buffer, Packet->Length)) + { + free(buffer); + + klog("Failed to recieve memory to write\n"); + + return; + } + + if (!GeneralIPC::ReadWriteMemory(CurrentPID, Packet->Address, buffer, Packet->Length, true)) + { + free(buffer); + + klog("Failed to write memory to process %i at %llX\n", CurrentPID, Packet->Address); + + Sockets::SendInt(Sock, 0); + + return; + } + + free(buffer); + + Sockets::SendInt(Sock, 1); + } + else + { + auto buffer = (unsigned char*)malloc(Packet->Length); + + if (!GeneralIPC::ReadWriteMemory(CurrentPID, Packet->Address, buffer, Packet->Length, false)) + { + free(buffer); + + klog("Failed to write memory to process %i at %llX\n", CurrentPID, Packet->Address); + + Sockets::SendInt(Sock, 0); + + return; + } + + Sockets::SendInt(Sock, 1); + + if (!Sockets::SendLargeData(Sock, buffer, Packet->Length)) + { + free(buffer); + + klog("Failed to send memory\n"); + + return; + } + + free(buffer); + } +} + Debug::Debug() { IsDebugging = false; diff --git a/Playstation/OrbisLibAPI/Debug.h b/Playstation/OrbisLibAPI/Debug.h index 6cdacc0..6476273 100644 --- a/Playstation/OrbisLibAPI/Debug.h +++ b/Playstation/OrbisLibAPI/Debug.h @@ -23,4 +23,6 @@ private: void UnloadLibrary(OrbisNetId Sock); void ReloadLibrary(OrbisNetId Sock); void GetLibraryList(OrbisNetId Sock); + + void ReadWriteMemory(OrbisNetId Sock, bool write); }; diff --git a/Playstation/OrbisLibAPI/GeneralIPC.cpp b/Playstation/OrbisLibAPI/GeneralIPC.cpp index de96d66..94ff0dd 100644 --- a/Playstation/OrbisLibAPI/GeneralIPC.cpp +++ b/Playstation/OrbisLibAPI/GeneralIPC.cpp @@ -13,6 +13,11 @@ OrbisNetId GeneralIPC::Connect(int pid) // Make new local Socket auto Socket = sceNetSocket("GeneralIPC Socket", ORBIS_NET_AF_LOCAL, ORBIS_NET_SOCK_STREAM, 0); + if (Socket < 0) + { + klog("Failed to get socket: %llX\n", Socket); + return NULL; + } auto res = sceNetConnect(Socket, (OrbisNetSockaddr*)&addr, SUN_LEN(&addr)); if (!res) @@ -351,5 +356,105 @@ bool GeneralIPC::Jail(int pid) // Close the socket. sceNetSocketClose(sock); + return result == GIPC_OK; +} + +bool GeneralIPC::ReadWriteMemory(int pid, uint64_t address, unsigned char* data, size_t length, bool write) +{ + // Open a new local socket connection for the process. + auto sock = Connect(pid); + if (!sock) + { + klog("[GeneralIPC] ReadWriteMemory(): Failed to connect to socket.\n"); + return false; + } + + // Send the command. + if (!SendCommand(sock, GIPC_RW)) + { + // Close the socket. + sceNetSocketClose(sock); + + klog("[GeneralIPC] ReadWriteMemory(): Failed to send command.\n"); + return false; + } + + // Create next packet. + auto Packet = (RWPacket*)malloc(sizeof(RWPacket)); + Packet->Address = address; + Packet->Length = length; + Packet->Write = write; + + // Send the packet. + if (sceNetSend(sock, Packet, sizeof(RWPacket), 0) < 0) + { + // Close the socket. + sceNetSocketClose(sock); + + // Cleanup + free(Packet); + + klog("[GeneralIPC] ReadWriteMemory(): Failed to send RWPacket.\n"); + + return false; + } + + // Cleanup + free(Packet); + + // Make sure the address was valid. + int result = 0; + if (!Sockets::RecvInt(sock, &result)) + { + // Close the socket. + sceNetSocketClose(sock); + + klog("[GeneralIPC] Failed to recv result.\n"); + return false; + } + + if (result == 0) + { + // Close the socket. + sceNetSocketClose(sock); + + klog("[GeneralIPC] ReadWriteMemory():Invalid Address %llX\n", address); + return false; + } + + // Recieve/Send Data + if (write) + { + if (!Sockets::SendLargeData(sock, data, length)) + { + klog("[GeneralIPC] ReadWriteMemory(): Failed to send the data."); + + return false; + } + } + else + { + if (!Sockets::RecvLargeData(sock, data, length)) + { + klog("[GeneralIPC] ReadWriteMemory(): Failed to recv the data."); + + return false; + } + } + + // Recieve the result. + result = 0; + if (!Sockets::RecvInt(sock, &result)) + { + // Close the socket. + sceNetSocketClose(sock); + + klog("[GeneralIPC] Failed to recv result.\n"); + return false; + } + + // Close the socket. + sceNetSocketClose(sock); + return result == GIPC_OK; } \ No newline at end of file diff --git a/Playstation/OrbisLibAPI/GeneralIPC.h b/Playstation/OrbisLibAPI/GeneralIPC.h index 4074a87..d10fa1c 100644 --- a/Playstation/OrbisLibAPI/GeneralIPC.h +++ b/Playstation/OrbisLibAPI/GeneralIPC.h @@ -14,4 +14,5 @@ public: static bool UnLoadLibrary(int pid, int Handle); static bool Jailbreak(int pid); static bool Jail(int pid); + static bool ReadWriteMemory(int pid, uint64_t address, unsigned char* data, size_t length, bool write); }; \ No newline at end of file diff --git a/Playstation/OrbisLibAPI/ShellUIIPC.cpp b/Playstation/OrbisLibAPI/ShellUIIPC.cpp index f81421a..a994f1d 100644 --- a/Playstation/OrbisLibAPI/ShellUIIPC.cpp +++ b/Playstation/OrbisLibAPI/ShellUIIPC.cpp @@ -10,6 +10,11 @@ OrbisNetId ShellUIIPC::Connect() // Make new local Socket auto Socket = sceNetSocket("GeneralIPC Socket", ORBIS_NET_AF_LOCAL, ORBIS_NET_SOCK_STREAM, 0); + if (Socket < 0) + { + klog("Failed to get socket: %llX\n", Socket); + return NULL; + } auto res = sceNetConnect(Socket, (OrbisNetSockaddr*)&addr, SUN_LEN(&addr)); if (!res) diff --git a/Playstation/OrbisLibAPI/SocketListener.cpp b/Playstation/OrbisLibAPI/SocketListener.cpp index 9e7cc93..2092bf0 100644 --- a/Playstation/OrbisLibAPI/SocketListener.cpp +++ b/Playstation/OrbisLibAPI/SocketListener.cpp @@ -11,7 +11,7 @@ void* SocketListener::ClientThread(void* tdParam) socketListener->ClientCallBack(socketListener->tdParam, Sock, sin_addr); sceNetSocketClose(Sock); - free(Params); + delete Params; // Kill our thread and exit. scePthreadDetach(scePthreadSelf()); @@ -86,7 +86,7 @@ void* SocketListener::DoWork() if (ClientSocket != -1) { - // klog("New Connection from %i.%i.%i.%i!\n", ClientAddr.sin_addr.s_addr & 0xFF, (ClientAddr.sin_addr.s_addr >> 8) & 0xFF, (ClientAddr.sin_addr.s_addr >> 16) & 0xFF, (ClientAddr.sin_addr.s_addr >> 24) & 0xFF); + //klog("New Connection from %i.%i.%i.%i!\n", ClientAddr.sin_addr.s_addr & 0xFF, (ClientAddr.sin_addr.s_addr >> 8) & 0xFF, (ClientAddr.sin_addr.s_addr >> 16) & 0xFF, (ClientAddr.sin_addr.s_addr >> 24) & 0xFF); int optval = 1; sceNetSetsockopt(ClientSocket, ORBIS_NET_SOL_SOCKET, ORBIS_NET_SO_NOSIGPIPE, &optval, sizeof(optval)); diff --git a/Playstation/OrbisLibAPI/Sockets.cpp b/Playstation/OrbisLibAPI/Sockets.cpp index bb92ee8..441d4d5 100644 --- a/Playstation/OrbisLibAPI/Sockets.cpp +++ b/Playstation/OrbisLibAPI/Sockets.cpp @@ -19,7 +19,7 @@ bool Sockets::RecvInt(OrbisNetId Sock, int* val) auto res = sceNetRecv(Sock, val, sizeof(int), 0); if (res <= 0) { - klog("RecvInt(): Failed to send %llX\n", res); + klog("RecvInt(): Failed to recv %llX\n", res); return false; } diff --git a/Playstation/OrbisLibAPI/Utilities.h b/Playstation/OrbisLibAPI/Utilities.h index 9ef27ca..5df6bc0 100644 --- a/Playstation/OrbisLibAPI/Utilities.h +++ b/Playstation/OrbisLibAPI/Utilities.h @@ -1,6 +1,6 @@ #pragma once - +#define ARRAY_COUNT(arry) sizeof(arry) / sizeof(arry[0]) // Misc bool LoadModules(); @@ -32,6 +32,7 @@ struct kinfo_proc { #define KERN_PROC 14 #define KERN_PROC_ALL 0 #define KERN_PROC_PROC 8 +#define KERN_PROC_PID 1 void hexdump(void* ptr, int buflen); int GetProcessList(std::vector& ProcessList); diff --git a/Playstation/OrbisLibAPI/Version.h b/Playstation/OrbisLibAPI/Version.h index dbbfea1..0bceb14 100644 --- a/Playstation/OrbisLibAPI/Version.h +++ b/Playstation/OrbisLibAPI/Version.h @@ -1,11 +1,11 @@ -#pragma once -#define ORBISLIB_MAJOR 3 -#define ORBISLIB_MINOR 0 -#define ORBISLIB_BUILDVERSION 995 -#define stringify(a) stringify_(a) -#define stringify_(a) #a -#if defined(_DEBUG) -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#else -#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) -#endif +#pragma once +#define ORBISLIB_MAJOR 3 +#define ORBISLIB_MINOR 0 +#define ORBISLIB_BUILDVERSION 1021 +#define stringify(a) stringify_(a) +#define stringify_(a) #a +#if defined(_DEBUG) +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Dev Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#else +#define ORBISLIB_BUILDSTRING ("[OrbisLib Daemon " stringify(ORBISLIB_MAJOR) "." stringify(ORBISLIB_MINOR) "] Build " stringify(ORBISLIB_BUILDVERSION) " " __DATE__ " " __TIME__) +#endif diff --git a/Playstation/OrbisLibGeneralHelper/Detour.cpp b/Playstation/OrbisLibGeneralHelper/Detour.cpp index 7f35186..f98d50d 100644 --- a/Playstation/OrbisLibGeneralHelper/Detour.cpp +++ b/Playstation/OrbisLibGeneralHelper/Detour.cpp @@ -2,16 +2,6 @@ #include "Detour.h" #include "hde64.h" -#define VM_PROT_NONE ((int) 0x00) -#define VM_PROT_READ ((int) 0x01) -#define VM_PROT_WRITE ((int) 0x02) -#define VM_PROT_EXECUTE ((int) 0x04) -#define VM_PROT_COPY ((int) 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 - void Detour::WriteJump(void* Address, void* Destination) { uint8_t JumpInstructions[] = { diff --git a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp index 3e742da..ac70e82 100644 --- a/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp +++ b/Playstation/OrbisLibGeneralHelper/LocalSocketListener.cpp @@ -11,9 +11,10 @@ void* LocalSocketListener::ClientThread(void* tdParam) localSocketListener->ClientCallBack(localSocketListener->tdParam, Sock); sceNetSocketClose(Sock); - free(Params); + delete Params; // Kill our thread and exit. + scePthreadDetach(scePthreadSelf()); scePthreadExit(NULL); return nullptr; } diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp index 9a910d2..90faadc 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.cpp @@ -59,6 +59,107 @@ void LoadUnloadLib(int Command, OrbisNetId Sock) free(Packet); } +void ReadWriteMemory(OrbisNetId Sock) +{ + int res = 0; + + // Get the packet for the info. + auto Packet = (RWPacket*)malloc(sizeof(RWPacket)); + if (sceNetRecv(Sock, Packet, sizeof(RWPacket), 0) < 0) + { + klog("ReadWriteMemory(): Failed to recieve packet\n"); + + free(Packet); + + return; + } + + // Make sure the address is valid. + OrbisKernelModuleInfo info; + if (Packet->Address == 0 || !GetModuleFromAddress(Packet->Address, &info) && !IsMemoryMapped(Packet->Address)) + { + Sockets::SendInt(Sock, 0); + + klog("ReadWriteMemory(): Failed to validate address.\n"); + + free(Packet); + + return; + } + + // Get the current protection of the memory. + int prot; + res = sceKernelQueryMemoryProtection((void*)Packet->Address, nullptr, nullptr, &prot); + if (res != 0) + { + Sockets::SendInt(Sock, 0); + + klog("ReadWriteMemory(): Failed to get memory prot: %llX\n", res); + + free(Packet); + + return; + } + + // Set the protection level so we can RW. + res = sceKernelMprotect((void* )Packet->Address, Packet->Length, VM_PROT_ALL); + if (res != 0) + { + Sockets::SendInt(Sock, 0); + + klog("ReadWriteMemory(): Failed to set memory prot: %llX\n", res); + + free(Packet); + + return; + } + + Sockets::SendInt(Sock, 1); + + // Read / Write the memory. + if (Packet->Write) + { + auto buffer = (unsigned char*)malloc(Packet->Length); + + if (!Sockets::RecvLargeData(Sock, buffer, Packet->Length)) + { + klog("ReadWriteMemory(): Failed to recieve the data.\n"); + + free(buffer); + + goto Exit; + } + + memcpy((void*)Packet->Address, buffer, Packet->Length); + + free(buffer); + } + else + { + auto buffer = (unsigned char*)malloc(Packet->Length); + memcpy(buffer, (void*)Packet->Address, Packet->Length); + + if (!Sockets::SendLargeData(Sock, buffer, Packet->Length)) + { + klog("ReadWriteMemory(): Failed to send memory.\n"); + } + + free(buffer); + } + +Exit: + // Reset the protection back. + res = sceKernelMprotect((void*)Packet->Address, Packet->Length, prot); + if (res != 0) + { + klog("ReadMemory(): Failed to restore memory prot: %llX\n", res); + } + + free(Packet); + + Sockets::SendInt(Sock, 1); +} + void ListenerClientThread(void* tdParam, OrbisNetId Sock) { int Command = 0; @@ -69,7 +170,7 @@ void ListenerClientThread(void* tdParam, OrbisNetId Sock) return; } - if (!Sockets::SendInt(Sock, GIPC_OK)) + if (!Sockets::SendInt(Sock, 1)) { klog("Failed to send confirm command.\n"); return; @@ -85,7 +186,7 @@ void ListenerClientThread(void* tdParam, OrbisNetId Sock) case GIPC_HELLO: - Sockets::SendInt(Sock, GIPC_OK); + Sockets::SendInt(Sock, 1); break; @@ -104,7 +205,7 @@ void ListenerClientThread(void* tdParam, OrbisNetId Sock) Jailbreak(); - Sockets::SendInt(Sock, GIPC_OK); + Sockets::SendInt(Sock, 1); break; @@ -112,12 +213,14 @@ void ListenerClientThread(void* tdParam, OrbisNetId Sock) RestoreJail(); - Sockets::SendInt(Sock, GIPC_OK); + Sockets::SendInt(Sock, 1); break; - case GIPC_RW: - // Might not really need this. + case GIPC_RW: + + ReadWriteMemory(Sock); + break; case GIPC_PROT: @@ -131,8 +234,6 @@ extern "C" { int __cdecl module_start(size_t argc, const void* args) { - klog("Hello from Helper!\n"); - klog("Helping with %d\n", getpid()); char serverAddress[0x200]; diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj index 8e072ec..c713fcb 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj @@ -68,7 +68,7 @@ del /s /q /f $(IntDir)\*.oelf - + diff --git a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters index 824c83c..625bd18 100644 --- a/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters +++ b/Playstation/OrbisLibGeneralHelper/OrbisLibGeneralHelper.vcxproj.filters @@ -32,7 +32,7 @@ Source Files\Utilities - + Source Files\Utilities diff --git a/Playstation/OrbisLibGeneralHelper/Socket.cpp b/Playstation/OrbisLibGeneralHelper/Sockets.cpp similarity index 63% rename from Playstation/OrbisLibGeneralHelper/Socket.cpp rename to Playstation/OrbisLibGeneralHelper/Sockets.cpp index dcc920d..0d45144 100644 --- a/Playstation/OrbisLibGeneralHelper/Socket.cpp +++ b/Playstation/OrbisLibGeneralHelper/Sockets.cpp @@ -32,5 +32,28 @@ bool Sockets::SendLargeData(OrbisNetId Sock, unsigned char* data, size_t dataLen CurrentPosition += res; } + return true; +} + +bool Sockets::RecvLargeData(OrbisNetId Sock, unsigned char* data, size_t dataLen) +{ + size_t DataLeft = dataLen; + int Received = 0; + int res = 0; + + while (DataLeft > 0) + { + size_t DataChunkSize = std::min((size_t)8192, DataLeft); + res = sceNetRecv(Sock, data + Received, DataChunkSize, 0); + + if (res < 0) + { + return false; + } + + Received += res; + DataLeft -= res; + } + return true; } \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/Sockets.h b/Playstation/OrbisLibGeneralHelper/Sockets.h index d31075d..1c203ed 100644 --- a/Playstation/OrbisLibGeneralHelper/Sockets.h +++ b/Playstation/OrbisLibGeneralHelper/Sockets.h @@ -6,7 +6,7 @@ public: static bool SendInt(OrbisNetId Sock, int val); static bool RecvInt(OrbisNetId Sock, int* val); static bool SendLargeData(OrbisNetId Sock, unsigned char* data, size_t dataLen); - + static bool RecvLargeData(OrbisNetId Sock, unsigned char* data, size_t dataLen); private: }; diff --git a/Playstation/OrbisLibGeneralHelper/Utilities.cpp b/Playstation/OrbisLibGeneralHelper/Utilities.cpp index 4706eca..87395f6 100644 --- a/Playstation/OrbisLibGeneralHelper/Utilities.cpp +++ b/Playstation/OrbisLibGeneralHelper/Utilities.cpp @@ -45,4 +45,45 @@ void RestoreJail() { jbc_set_cred(&BackupCred); } +} + +#define ModuleMax 200 +bool GetModuleFromAddress(uint64_t Address, OrbisKernelModuleInfo* out) +{ + OrbisKernelModule List[ModuleMax]; + size_t moduleCount; + auto res = sceKernelGetModuleList(List, sizeof(List), &moduleCount); + if (res != 0) + { + klog("GetModuleFromAddress(): Failed to get Module List: %llX\n", res); + + return false; + } + + for (int i = 0; i < ModuleMax; i++) + { + out->size = sizeof(OrbisKernelModuleInfo); + res = sceKernelGetModuleInfo(List[i], out); + + if (res == 0) + { + for (int j = 0; j < out->segmentCount; j++) + { + auto baseAddress = (uint64_t)out->segmentInfo[j].address; + auto segSize = out->segmentInfo[j].size; + if (Address >= baseAddress && Address < (baseAddress + segSize)) + { + return true; + } + } + } + } + + return false; +} + +bool IsMemoryMapped(uint64_t address) +{ + OrbisKernelVirtualQueryInfo info; + return sceKernelVirtualQuery((void*)address, 0, &info, sizeof(info)) == 0; } \ No newline at end of file diff --git a/Playstation/OrbisLibGeneralHelper/Utilities.h b/Playstation/OrbisLibGeneralHelper/Utilities.h index 1eb4871..9ada4bf 100644 --- a/Playstation/OrbisLibGeneralHelper/Utilities.h +++ b/Playstation/OrbisLibGeneralHelper/Utilities.h @@ -1,6 +1,20 @@ #pragma once +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 + // Misc void klog(const char* fmt, ...); void Jailbreak(); -void RestoreJail(); \ No newline at end of file +void RestoreJail(); +bool GetModuleFromAddress(uint64_t Address, OrbisKernelModuleInfo* out); +bool IsMemoryMapped(uint64_t address); \ No newline at end of file diff --git a/Playstation/OrbisMonitor/OrbisMonitor.vcxproj b/Playstation/OrbisMonitor/OrbisMonitor.vcxproj new file mode 100644 index 0000000..b383a7d --- /dev/null +++ b/Playstation/OrbisMonitor/OrbisMonitor.vcxproj @@ -0,0 +1,68 @@ + + + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {95716bec-ff5a-4666-b8fe-547512ca38e0} + 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/OrbisMonitor/OrbisMonitor.vcxproj.filters b/Playstation/OrbisMonitor/OrbisMonitor.vcxproj.filters new file mode 100644 index 0000000..1309513 --- /dev/null +++ b/Playstation/OrbisMonitor/OrbisMonitor.vcxproj.filters @@ -0,0 +1,19 @@ + + + + + {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 + + + + + Source Files + + + + \ No newline at end of file diff --git a/Playstation/OrbisMonitor/build.bat b/Playstation/OrbisMonitor/build.bat new file mode 100644 index 0000000..3e46feb --- /dev/null +++ b/Playstation/OrbisMonitor/build.bat @@ -0,0 +1,80 @@ +SETLOCAL EnableDelayedExpansion + +Rem Package information +set PKG_TITLE="My Homebrew" +set PKG_VERSION="1.00" +set PKG_ASSETS="assets" +set PKG_TITLE_ID="BREW00100" +set PKG_CONTENT_ID="IV0000-BREW00100_00-MYHOMEBREW000000" + +Rem Libraries to link in +set libraries=-lc -lkernel -lc++ + +Rem set extra_flags= + +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 + +@mkdir %intdir% + +Rem Compile object files for all the source files +for %%f in (*.c) do ( + clang --target=x86_64-pc-freebsd12-elf -fPIC -funwind-tables -I"%OO_PS4_TOOLCHAIN%\\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" %extra_flags% -c -o %intdir%\%%~nf.o %%~nf.c +) + +for %%f in (*.cpp) do ( + clang++ --target=x86_64-pc-freebsd12-elf -fPIC -funwind-tables -I"%OO_PS4_TOOLCHAIN%\\include" -I"%OO_PS4_TOOLCHAIN%\\include\\c++\\v1" %extra_flags% -c -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-fself.exe -in "%outputElf%" --out "%outputOelf%" --eboot "eboot.bin" --paid 0x3800000000000011 + +Rem Create param.sfo +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_new sce_sys/param.sfo +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo APP_TYPE --type Integer --maxsize 4 --value 1 +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo APP_VER --type Utf8 --maxsize 8 --value %PKG_VERSION% +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo ATTRIBUTE --type Integer --maxsize 4 --value 0 +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo CATEGORY --type Utf8 --maxsize 4 --value "gd" +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo CONTENT_ID --type Utf8 --maxsize 48 --value %PKG_CONTENT_ID% +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo DOWNLOAD_DATA_SIZE --type Integer --maxsize 4 --value 0 +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo SYSTEM_VER --type Integer --maxsize 4 --value 0 +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo TITLE --type Utf8 --maxsize 128 --value %PKG_TITLE% +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo TITLE_ID --type Utf8 --maxsize 12 --value %PKG_TITLE_ID% +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe sfo_setentry sce_sys/param.sfo VERSION --type Utf8 --maxsize 8 --value %PKG_VERSION% + +Rem Get a list of assets for packaging +set module_files= +for %%f in (sce_module\\*) do set module_files=!module_files! sce_module/%%~nxf + +set asset_audio_files= +for %%f in (assets\\audio\\*) do set asset_audio_files=!asset_audio_files! assets/audio/%%~nxf + +set asset_fonts_files= +for %%f in (assets\\fonts\\*) do set asset_fonts_files=!asset_fonts_files! assets/fonts/%%~nxf + +set asset_images_files= +for %%f in (assets\\images\\*) do set asset_images_files=!asset_images_files! assets/images/%%~nxf + +set asset_misc_files= +for %%f in (assets\\misc\\*) do set asset_misc_files=!asset_misc_files! assets/misc/%%~nxf + +set asset_videos_files= +for %%f in (assets\\videos\\*) do set asset_videos_files=!asset_videos_files! assets/videos/%%~nxf + +Rem Create gp4 +%OO_PS4_TOOLCHAIN%\bin\windows\create-gp4.exe -out pkg.gp4 --content-id=%PKG_CONTENT_ID% --files "eboot.bin sce_sys/about/right.sprx sce_sys/param.sfo sce_sys/icon0.png %module_files% %asset_audio_files% %asset_fonts_files% %asset_images_files% %asset_misc_files% %asset_videos_files%" + +Rem Create pkg +%OO_PS4_TOOLCHAIN%\bin\windows\PkgTool.Core.exe pkg_build pkg.gp4 .. diff --git a/Playstation/OrbisMonitor/main.cpp b/Playstation/OrbisMonitor/main.cpp new file mode 100644 index 0000000..ec1c64d --- /dev/null +++ b/Playstation/OrbisMonitor/main.cpp @@ -0,0 +1,7 @@ +#include + +int main() +{ + // Your code here... + return 0; +} \ No newline at end of file diff --git a/Windows/Installer/SetupBA/SetupBA.csproj b/Windows/Installer/SetupBA/SetupBA.csproj index cbc05b3..0c6fa9e 100644 --- a/Windows/Installer/SetupBA/SetupBA.csproj +++ b/Windows/Installer/SetupBA/SetupBA.csproj @@ -46,8 +46,9 @@ - - C:\Users\grego\source\repos\SimpleUI-Framework\SimpleUI-Framework\bin\Debug\SimpleUI.dll + + False + C:\Users\grego\source\repos\SimpleUI-Framework\SimpleUI-Framework\bin\Release\SimpleUI.dll diff --git a/Windows/Libraries/OrbisLib2/Common/API/API.cs b/Windows/Libraries/OrbisLib2/Common/API/API.cs index 2a7e289..8deffcc 100644 --- a/Windows/Libraries/OrbisLib2/Common/API/API.cs +++ b/Windows/Libraries/OrbisLib2/Common/API/API.cs @@ -43,7 +43,7 @@ namespace OrbisLib2.Common.API if (Connect(DesiredTarget.IPAddress, Settings.CreateInstance().APIPort, TimeOut, out Socket Sock)) { // Send Inital Packet. - var result = SendNextPacket(Sock, new APIPacket() { PacketVersion = Config.PacketVersion, Command = Command }); + var result = SendNextPacket(Sock, new APIPacket() { PacketMagic="ORBIS_SUITE", PacketVersion = Config.PacketVersion, Command = Command }); // Call lambda for additional calls. if (result == APIResults.API_OK && AdditionalCommunications != null) diff --git a/Windows/Libraries/OrbisLib2/Common/API/APIPackets.cs b/Windows/Libraries/OrbisLib2/Common/API/APIPackets.cs index a880c67..b3634c9 100644 --- a/Windows/Libraries/OrbisLib2/Common/API/APIPackets.cs +++ b/Windows/Libraries/OrbisLib2/Common/API/APIPackets.cs @@ -130,6 +130,8 @@ namespace OrbisLib2.Common.API [StructLayout(LayoutKind.Sequential, Pack = 4, CharSet = CharSet.Ansi, Size = 8), Serializable] public struct APIPacket { + [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)] + public string PacketMagic; public int PacketVersion; public APICommands Command; } diff --git a/Windows/Libraries/OrbisLib2/Common/Config.cs b/Windows/Libraries/OrbisLib2/Common/Config.cs index 50a0e5a..3262e0a 100644 --- a/Windows/Libraries/OrbisLib2/Common/Config.cs +++ b/Windows/Libraries/OrbisLib2/Common/Config.cs @@ -61,6 +61,6 @@ namespace OrbisLib2.Common /// /// The version of the packets used to communicate with the Target Console. /// - public static readonly int PacketVersion = 2; + public static readonly int PacketVersion = 3; } } diff --git a/Windows/Libraries/OrbisLib2/Common/Helpers/Sockets.cs b/Windows/Libraries/OrbisLib2/Common/Helpers/Sockets.cs index c2e18e1..1bc1907 100644 --- a/Windows/Libraries/OrbisLib2/Common/Helpers/Sockets.cs +++ b/Windows/Libraries/OrbisLib2/Common/Helpers/Sockets.cs @@ -1,4 +1,5 @@ -using System.Net.NetworkInformation; +using System.Data; +using System.Net.NetworkInformation; using System.Net.Sockets; using System.Text; @@ -20,7 +21,7 @@ namespace OrbisLib2.Common.Helpers while (Left > 0) { - var chunkSize = Math.Min(s.ReceiveBufferSize, Left); + var chunkSize = Math.Min(8192, Left); var res = s.Receive(data, Received, chunkSize, 0); Received += res; @@ -33,6 +34,28 @@ namespace OrbisLib2.Common.Helpers } } + public static void SendLarge(this Socket s, byte[] data) + { + try + { + int Left = data.Length; + int CurrentPosition = 0; + + while (Left > 0) + { + var chunkSize = Math.Min(8192, Left); + var res = s.Send(data, CurrentPosition, chunkSize, 0); + + Left -= res; + CurrentPosition += res; + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + /// /// Sends an object and its size to the socket. /// diff --git a/Windows/Libraries/OrbisLib2/OrbisLib2.csproj b/Windows/Libraries/OrbisLib2/OrbisLib2.csproj index 6c287c8..2d731f4 100644 --- a/Windows/Libraries/OrbisLib2/OrbisLib2.csproj +++ b/Windows/Libraries/OrbisLib2/OrbisLib2.csproj @@ -36,7 +36,7 @@ - ..\..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\SimpleUI.dll + ..\..\..\External\SimpleUI\SimpleUI\bin\Release\net6.0-windows\SimpleUI.dll diff --git a/Windows/Libraries/OrbisLib2/Targets/Debug.cs b/Windows/Libraries/OrbisLib2/Targets/Debug.cs index 032e62f..02ad0f1 100644 --- a/Windows/Libraries/OrbisLib2/Targets/Debug.cs +++ b/Windows/Libraries/OrbisLib2/Targets/Debug.cs @@ -10,6 +10,7 @@ using System.Runtime.InteropServices; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; +using System.Windows.Markup; using static SQLite.SQLite3; namespace OrbisLib2.Targets @@ -198,5 +199,68 @@ namespace OrbisLib2.Targets return libraryList; } + + + public byte[] ReadMemory(ulong Address, ulong Length) + { + if (!IsDebugging) + { + return new byte[0]; + } + + int readResult = 0; + var data = new byte[Length]; + var result = API.SendCommand(Target, 6, APICommands.API_DBG_READ, (Socket Sock, APIResults Result) => + { + var isDebugging = Sock.RecvInt32(); + if (isDebugging == 1) + { + var Packet = new DbgRWPacket(); + Packet.Address = Address; + Packet.Length = Length; + Sock.Send(Helper.StructToBytes(Packet)); + + // Status + readResult = Sock.RecvInt32(); + + // Recv the memory if the address was valid. + if (readResult == 1) + { + Sock.RecvLarge(data); + } + } + }); + + return readResult == 1 ? data : new byte[0]; + } + + public bool WriteMemory(ulong Address, byte[] Data) + { + if (!IsDebugging) + { + return false; + } + + int writeResult = 0; + var result = API.SendCommand(Target, 6, APICommands.API_DBG_WRITE, (Socket Sock, APIResults Result) => + { + var isDebugging = Sock.RecvInt32(); + if (isDebugging == 1) + { + var Packet = new DbgRWPacket(); + Packet.Address = Address; + Packet.Length = (ulong)Data.Length; + Sock.Send(Helper.StructToBytes(Packet)); + + // Send the memory to write. + Sock.SendLarge(Data); + + // Status + writeResult = Sock.RecvInt32(); + } + }); + + return writeResult == 1; + } } } diff --git a/Windows/OrbisLibraryManager/OrbisLibraryManager.csproj b/Windows/OrbisLibraryManager/OrbisLibraryManager.csproj index 17187d6..07a1407 100644 --- a/Windows/OrbisLibraryManager/OrbisLibraryManager.csproj +++ b/Windows/OrbisLibraryManager/OrbisLibraryManager.csproj @@ -41,7 +41,7 @@ ..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\Microsoft.Expression.Drawing.dll - ..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\SimpleUI.dll + ..\..\External\SimpleUI\SimpleUI\bin\Release\net6.0-windows\SimpleUI.dll diff --git a/Windows/OrbisNeighborHood/OrbisNeighborHood.csproj b/Windows/OrbisNeighborHood/OrbisNeighborHood.csproj index 31677f1..3327bc6 100644 --- a/Windows/OrbisNeighborHood/OrbisNeighborHood.csproj +++ b/Windows/OrbisNeighborHood/OrbisNeighborHood.csproj @@ -181,8 +181,7 @@ ..\..\External\SimpleUI\SimpleUI\Libraries\Microsoft.Expression.Drawing.dll - ..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\SimpleUI.dll - True + ..\..\External\SimpleUI\SimpleUI\bin\Release\net6.0-windows\SimpleUI.dll diff --git a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt index 3d212cf..91488bb 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildNumber.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildNumber.txt @@ -1 +1 @@ -2415 +2528 diff --git a/Windows/OrbisNeighborHood/Resources/BuildString.txt b/Windows/OrbisNeighborHood/Resources/BuildString.txt index 441d891..73358d1 100644 --- a/Windows/OrbisNeighborHood/Resources/BuildString.txt +++ b/Windows/OrbisNeighborHood/Resources/BuildString.txt @@ -1 +1 @@ -Version 3.0.2415 Debug Build Sunday January 15 2023 5:32 PM +Version 3.0.2528 Debug Build Thursday January 19 2023 10:59 PM diff --git a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.csproj b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.csproj index 38e1a81..90eea6c 100644 --- a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.csproj +++ b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.csproj @@ -1,10 +1,11 @@  - WinExe + Exe net6.0-windows enable true + true OrbisPeeknPoke.ico @@ -53,14 +54,14 @@ + + ..\..\External\Be.HexEditor\Be.Windows.Forms.HexBox\bin\Release\Be.Windows.Forms.HexBox.dll + ..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\Microsoft.Expression.Drawing.dll - ..\..\External\SimpleUI\SimpleUI\bin\Debug\net6.0-windows\SimpleUI.dll - - - C:\Users\grego\.nuget\packages\wpfhexaeditor\2.1.7\lib\net5.0-windows7.0\WPFHexaEditor.dll + ..\..\External\SimpleUI\SimpleUI\bin\Release\net6.0-windows\SimpleUI.dll @@ -69,7 +70,7 @@ - + diff --git a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml index 2b4ff62..929555f 100644 --- a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml +++ b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml @@ -6,12 +6,12 @@ xmlns:local="clr-namespace:OrbisPeeknPoke" xmlns:simpleControls="clr-namespace:SimpleUI.Controls;assembly=SimpleUI" xmlns:controls="clr-namespace:OrbisPeeknPoke.Controls" - xmlns:hv="clr-namespace:HexView.Wpf;assembly=HexView.Wpf" + xmlns:hv="clr-namespace:Be.Windows.Forms;assembly=Be.Windows.Forms.HexBox" mc:Ignorable="d" Title="Peek n' Poke" - Height="640" Width="980" - MinHeight="640" MinWidth="980" - MaxHeight="640" MaxWidth="980"> + Height="660" Width="837" + MinHeight="660" MinWidth="837" + MaxHeight="660" MaxWidth="837"> @@ -29,68 +29,19 @@ + + - - - - - - - - - - - - - - - - - - - - - - - - @@ -179,12 +130,126 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - Address: 0x400000 - + FontWeight="Bold" + Text="Address: "> + + + + + - + - Offset: 0x100 - - + FontWeight="Bold" + Text="Offset: "> + + + + + - - + + + + diff --git a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml.cs b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml.cs index ca66387..71369a3 100644 --- a/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml.cs +++ b/Windows/OrbisPeeknPoke/OrbisPeeknPoke.xaml.cs @@ -1,12 +1,23 @@ -using OrbisLib2.Common.Database.Types; +using Be.Windows.Forms; +using OrbisLib2.Common.Database.Types; using OrbisLib2.Common.Dispatcher; using OrbisLib2.Dialog; using OrbisLib2.General; using OrbisLib2.Targets; using SimpleUI.Controls; +using System; +using System.Collections.Generic; +using System.Globalization; using System.IO; +using System.Linq; +using System.Net; +using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Windows; -using WpfHexaEditor; +using System.Windows.Forms; +using System.Windows.Forms.Integration; +using System.Windows.Input; +using System.Windows.Shell; namespace OrbisPeeknPoke { @@ -15,8 +26,12 @@ namespace OrbisPeeknPoke /// public partial class MainWindow : SimpleWindow { + private List JumpList = new(); + public MainWindow() { + System.Windows.Forms.Application.EnableVisualStyles(); + InitializeComponent(); DispatcherClient.Subscribe(); @@ -27,56 +42,19 @@ namespace OrbisPeeknPoke Events.DBTouched += Events_DBTouched; Events.SelectedTargetChanged += Events_SelectedTargetChanged; - + HexBox.CurrentLineChanged += HexBox_CurrentLineChanged; + HexBox.CurrentPositionInLineChanged += HexBox_CurrentPositionInLineChanged; } - public byte[] testData = + private void HexBox_CurrentPositionInLineChanged(object? sender, EventArgs e) { - 0x2F, 0x6C, 0x69, 0x62, 0x65, 0x78, 0x65, 0x63, 0x2F, 0x6C, 0x64, 0x2D, - 0x65, 0x6C, 0x66, 0x2E, 0x73, 0x6F, 0x2E, 0x31, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x48, 0x89, 0xE5, - 0x41, 0x57, 0x41, 0x56, 0x53, 0x50, 0x48, 0x8D, 0x1D, 0x0F, 0x7E, 0x62, - 0x01, 0x4C, 0x8D, 0x35, 0xE8, 0x7D, 0x62, 0x01, 0x48, 0x3B, 0x1D, 0x59, - 0x08, 0x60, 0x01, 0x73, 0x33, 0x4C, 0x8D, 0x3D, 0xF8, 0x7D, 0x62, 0x01, - 0x0F, 0x1F, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x8B, 0x03, 0x48, - 0x85, 0xC0, 0x74, 0x02, 0xFF, 0xD0, 0x48, 0x83, 0xC3, 0x08, 0x4C, 0x39, - 0xFB, 0x72, 0xED, 0xEB, 0x0F, 0x66, 0x66, 0x2E, 0x0F, 0x1F, 0x84, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x49, 0x83, 0xC6, 0xF8, 0x49, 0x8B, 0x06, 0x48, - 0x85, 0xC0, 0x74, 0xF4, 0x48, 0x83, 0xF8, 0xFF, 0x74, 0x04, 0xFF, 0xD0, - 0xEB, 0xEA, 0x48, 0x83, 0xC4, 0x08, 0x5B, 0x41, 0x5E, 0x41, 0x5F, 0x5D, - 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, - 0x53, 0x50, 0x44, 0x8B, 0x37, 0x48, 0x89, 0xF3, 0x4C, 0x8D, 0x7F, 0x08, - 0xE8, 0xC7, 0xC7, 0x21, 0x01, 0x48, 0x89, 0xDF, 0xE8, 0xCF, 0xC7, 0x21, - 0x01, 0x48, 0x8D, 0x3D, 0xA8, 0xE2, 0x20, 0x01, 0xE8, 0xC3, 0xC7, 0x21, - 0x01, 0xE8, 0x4E, 0xFF, 0xFF, 0xFF, 0x31, 0xD2, 0x44, 0x89, 0xF7, 0x4C, - 0x89, 0xFE, 0xE8, 0x21, 0xB4, 0xEC, 0x00, 0x89, 0xC3, 0x89, 0xDF, 0xE8, - 0xB8, 0xC7, 0x21, 0x01, 0x89, 0xDF, 0xE8, 0x41, 0xB2, 0x21, 0x01, 0x0F, - 0x0B, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, 0x90, - 0x90, 0x90, 0x90, 0x90, 0x55, 0x48, 0x89, 0xE5, 0x48, 0x83, 0xEC, 0x10, - 0x89, 0x4C, 0x24, 0x08, 0x48, 0x89, 0x14, 0x24, 0xBA, 0x08, 0x00, 0x00, - 0x00, 0xB9, 0x0F, 0x00, 0x00, 0x00, 0x41, 0xB8, 0x08, 0x00, 0x00, 0x00, - 0x45, 0x31, 0xC9, 0xE8, 0x08, 0x00, 0x00, 0x00, 0x48, 0x83, 0xC4, 0x10, - 0x5D, 0xC3, 0x66, 0x90, 0x55, 0x48, 0x89, 0xE5, 0x41, 0x57, 0x41, 0x56, - 0x41, 0x55, 0x41, 0x54, 0x53, 0x48, 0x83, 0xEC, 0x18, 0x45, 0x89, 0xC4, - 0x49, 0x89, 0xFD, 0x48, 0x8B, 0x45, 0x10, 0x41, 0xBE, 0xFA, 0xFF, 0xFF, - 0xFF, 0x48, 0x85, 0xC0, 0x0F, 0x84, 0x17, 0x03, 0x00, 0x00, 0x0F, 0xB6, - 0x00, 0x83, 0xF8, 0x31, 0x0F, 0x85, 0x0B, 0x03, 0x00, 0x00, 0x83, 0x7D, - 0x18, 0x70, 0x0F, 0x85, 0x01, 0x03, 0x00, 0x00, 0x41, 0xBE, 0xFE, 0xFF, - 0xFF, 0xFF, 0x4D, 0x85, 0xED, 0x0F, 0x84, 0xF2, 0x02, 0x00, 0x00, 0x49, - 0xC7, 0x45, 0x30, 0x00, 0x00, 0x00, 0x00, 0x49, 0x8B, 0x45, 0x40, 0x48, - 0x85, 0xC0, 0x75, 0x13, 0x48, 0x8D, 0x05, 0x19, 0x84, 0x00, 0x00, 0x49, - 0x89, 0x45, 0x40, 0x49, 0xC7, 0x45, 0x50, 0x00, 0x00, 0x00, 0x00, 0x49, - 0x83, 0x7D, 0x48, 0x00, 0x75, 0x0B, 0x48, 0x8D, 0x3D, 0x0F, 0x84, 0x00, - 0x00, 0x49, 0x89, 0x7D, 0x48, 0x83, 0xFE, 0xFF, 0xBF, 0x06, 0x00, 0x00, - 0x00, 0x0F, 0x45, 0xFE, 0x85, 0xC9, 0x78, 0x15, 0x8D, 0x71, 0xF0, 0x83, - 0xF9, 0x0F, 0x0F, 0x9F, 0xC3, 0x0F, 0x4E, 0xF1, 0x0F, 0xB6, 0xDB, 0xFF, - 0xC3, 0x89, 0xF1, 0xEB, 0x04, 0xF7, 0xD9, 0x31, 0xDB, 0x41, 0x8D, 0x74, - 0x24, 0xFF, 0x83, 0xFE, 0x08, 0x0F, 0x87, 0x86, 0x02, 0x00, 0x00, 0x83, - 0xFA, 0x08, 0x0F, 0x85, 0x7D, 0x02, 0x00, 0x00, 0x83, 0xF9, 0x08, 0x0F, - 0x8C, 0x74, 0x02, 0x00, 0x00, 0x83, 0xF9, 0x0F - }; + OffsetValue.Text = $"0x{(((HexBox.CurrentLine - 1) * 0x10) + (HexBox.CurrentPositionInLine - 1)).ToString("X")}"; + } + private void HexBox_CurrentLineChanged(object? sender, EventArgs e) + { + OffsetValue.Text = $"0x{(((HexBox.CurrentLine - 1) * 0x10) + (HexBox.CurrentPositionInLine - 1)).ToString("X")}"; + } #region Events @@ -171,21 +149,109 @@ namespace OrbisPeeknPoke #region Buttons + private bool TryConvertStringToUlong(string str, out ulong val) + { + if (str.StartsWith("0x")) + { + if (!ulong.TryParse(str.Substring(2), NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val)) + { + return false; + } + } + else + { + if (!ulong.TryParse(str, out val) && !ulong.TryParse(str, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val)) + { + return false; + } + } + + return true; + } + + private bool GetPeekPokeInfo(out ulong address, out ulong length) + { + // Hex or decimal value of address + if (!TryConvertStringToUlong(BaseAddress.FieldText, out address)) + { + SimpleMessageBox.ShowError(this, "Failed to parse Base Address please ensure that it is a valid hex or decimal number.", "Failed to parse Base Address."); + length = 0; + return false; + } + + // Hex or decimal value of offset + ulong offset; + if (TryConvertStringToUlong(Offset.FieldText, out offset)) + { + address += offset; + } + + // Hex or decimal value of length + if (!TryConvertStringToUlong(Length.FieldText, out length)) + { + SimpleMessageBox.ShowError(this, "Failed to parse Length please ensure that it is a valid hex or decimal number.", "Failed to parse Length."); + return false; + } + + return true; + } + private void SelectBase_Click(object sender, RoutedEventArgs e) { + Task.Run(() => + { + var mainExecutable = TargetManager.SelectedTarget.Debug.GetLibraries().FirstOrDefault(); + if (mainExecutable != null) + { + Dispatcher.Invoke(() => BaseAddress.FieldText = $"0x{mainExecutable.Segments[0].Address.ToString("X")}"); + } + }); } private void Peek_Click(object sender, RoutedEventArgs e) { - HexBox.DataSource = new BinaryReader(new MemoryStream(testData)); - //HexBox.DataContext = new BinaryReader(new MemoryStream(testData)); - //HexBox.a = 0x400000; + GetPeekPokeInfo(out var address, out var length); + + Task.Run(() => + { + var data = TargetManager.SelectedTarget.Debug.ReadMemory(address, length); + + if (data != null && data.Length > 0) + { + // Clear the jump list if were reading new memory. + if (JumpList.Count > 0 && address != JumpList.Last()) + { + JumpList.Clear(); + Dispatcher.Invoke(() => ReturnPointer.IsEnabled = false); + } + + // Fill the hex box on the UI thread. + Dispatcher.Invoke(() => + { + HexBox.VScrollBarVisible = true; + HexBox.ByteProvider = new DynamicByteProvider(data); + HexBox.VScrollBarVisible = false; + }); + } + }); } private void Poke_Click(object sender, RoutedEventArgs e) { + if (HexBox.ByteProvider.Length <= 0) + return; + GetPeekPokeInfo(out var address, out var length); + + byte[] bytes = new byte[HexBox.ByteProvider.Length]; + + //Grab the bytes from the hex window + for (int i = 0; i < HexBox.ByteProvider.Length; i++) + bytes[i] = HexBox.ByteProvider.ReadByte(i); + + // Write bytes in task so we dont lock up the UI thread. + Task.Run(() => TargetManager.SelectedTarget.Debug.WriteMemory(address, bytes)); } private void AttachProcess_Click(object sender, RoutedEventArgs e) @@ -195,7 +261,7 @@ namespace OrbisPeeknPoke private void DetachProcess_Click(object sender, RoutedEventArgs e) { - TargetManager.SelectedTarget.Debug.Detach(); + Task.Run(() => TargetManager.SelectedTarget.Debug.Detach()); } private void LoadSomething_Click(object sender, RoutedEventArgs e) @@ -205,34 +271,169 @@ namespace OrbisPeeknPoke private void KillProcess_Click(object sender, RoutedEventArgs e) { - var currentTarget = TargetManager.SelectedTarget; - var processList = TargetManager.SelectedTarget.Process.GetList(); - var process = processList.Find(x => x.ProcessId == currentTarget.Debug.GetCurrentProcessId()); - if (process != null) + Task.Run(() => { - if (process.AppId > 0) + var currentTarget = TargetManager.SelectedTarget; + var processList = TargetManager.SelectedTarget.Process.GetList(); + var process = processList.Find(x => x.ProcessId == currentTarget.Debug.GetCurrentProcessId()); + if (process != null) { - currentTarget.Application.Stop(process.TitleId); + if (process.AppId > 0) + { + currentTarget.Application.Stop(process.TitleId); + } + else + { + SimpleMessageBox.ShowError(Window.GetWindow(this), $"Could not kill process \"{process.Name}\" because Orbis Suite doesnt currently support killing processes with out an appId.", "Error: Could not kill this process."); + } } - else - { - SimpleMessageBox.ShowError(Window.GetWindow(this), $"Could not kill process \"{process.Name}\" because Orbis Suite doesnt currently support killing processes with out an appId.", "Error: Could not kill this process."); - } - } + }); } private void RestartTarget_Click(object sender, RoutedEventArgs e) { - TargetManager.SelectedTarget.Reboot(); + Task.Run(() => TargetManager.SelectedTarget.Reboot()); } private void ShutdownTarget_Click(object sender, RoutedEventArgs e) { - TargetManager.SelectedTarget.Shutdown(); + Task.Run(() => TargetManager.SelectedTarget.Shutdown()); } #endregion - + #region Context Menu + + private void HexBox_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) + { + if (e.Button == MouseButtons.Right) + { + FormsHost.ContextMenu.IsOpen = true; + } + } + + private void CopyHex_Click(object sender, RoutedEventArgs e) + { + HexBox.CopyHex(); + } + + private void CopyText_Click(object sender, RoutedEventArgs e) + { + HexBox.Copy(); + } + private void PasteText_Click(object sender, RoutedEventArgs e) + { + try + { + HexBox.Paste(); + } + catch (Exception ex) + { + SimpleMessageBox.ShowError(this, $"Paste failed becase {ex.Message}", "Paste Failed."); + } + } + + private void PasteHex_Click(object sender, RoutedEventArgs e) + { + try + { + HexBox.PasteHex(); + } + catch (Exception ex) + { + SimpleMessageBox.ShowError(this, $"Paste failed becase {ex.Message}", "Paste Failed."); + } + } + + private void SelectAll_Click(object sender, RoutedEventArgs e) + { + HexBox.SelectAll(); + } + + private void FollowPointer_Click(object sender, RoutedEventArgs e) + { + GetPeekPokeInfo(out var lastAddress, out var length); + + byte[] RawJumpAddress = new byte[8]; + + //Grab 8 bytes + for (int i = 7; i >= 0; i--) + RawJumpAddress[i] = HexBox.ByteProvider.ReadByte(HexBox.SelectionStart + i); + + // Hex or decimal value of offset + ulong offset; + if (TryConvertStringToUlong(Offset.FieldText, out offset)) + { + lastAddress += offset; + } + + ulong address; + try + { + address = BitConverter.ToUInt64(RawJumpAddress, 0); + } + catch + { + SimpleMessageBox.ShowError(this, "The memory was not a Pointer.", "The memory was not a Pointer."); + return; + } + + Task.Run(() => + { + var data = TargetManager.SelectedTarget.Debug.ReadMemory(address, length); + + if (data != null && data.Length > 0) + { + // Add the last address to the list. + JumpList.Add(lastAddress); + + Dispatcher.Invoke(() => + { + ReturnPointer.IsEnabled = true; + + BaseAddress.FieldText = $"0x{address.ToString("X")}"; + Offset.FieldText = $"0x0"; + + HexBox.VScrollBarVisible = true; + HexBox.ByteProvider = new DynamicByteProvider(data); + HexBox.VScrollBarVisible = false; + }); + } + }); + } + + private void ReturnPointer_Click(object sender, RoutedEventArgs e) + { + if (JumpList.Count == 0) + ReturnPointer.IsEnabled = false; + + GetPeekPokeInfo(out var lastAddress, out var length); + Task.Run(() => + { + var data = TargetManager.SelectedTarget.Debug.ReadMemory(JumpList.Last(), length); + + if (data != null && data.Length > 0) + { + // Add the last address to the list. + JumpList.Remove(JumpList.Last()); + + Dispatcher.Invoke(() => + { + // Disable if we are back where we started. + if (JumpList.Count == 0) + ReturnPointer.IsEnabled = false; + + BaseAddress.FieldText = $"0x{lastAddress.ToString("X")}"; + Offset.FieldText = $"0x0"; + + HexBox.VScrollBarVisible = true; + HexBox.ByteProvider = new DynamicByteProvider(data); + HexBox.VScrollBarVisible = false; + }); + } + }); + } + + #endregion } } diff --git a/Windows/OrbisSuiteService/Program.cs b/Windows/OrbisSuiteService/Program.cs index e8c873a..030dbbb 100644 --- a/Windows/OrbisSuiteService/Program.cs +++ b/Windows/OrbisSuiteService/Program.cs @@ -17,7 +17,7 @@ class Service : ServiceBase Console.WriteLine("Starting"); var dp = new Dispatcher(); #if DEBUG - while (RunService) { Thread.Sleep(10); } + while (RunService) { Thread.Sleep(10); } #endif }