diff --git a/Source/Core/Core/CMakeLists.txt b/Source/Core/Core/CMakeLists.txt index 8d7867d054..4137b8e23f 100644 --- a/Source/Core/Core/CMakeLists.txt +++ b/Source/Core/Core/CMakeLists.txt @@ -406,6 +406,8 @@ add_library(core NetPlayClient.h NetPlayServer.cpp NetPlayServer.h + NetworkCaptureLogger.cpp + NetworkCaptureLogger.h PatchEngine.cpp PatchEngine.h PowerPC/BreakPoints.cpp diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 88bb42579b..99e7624b55 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -534,6 +534,7 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi PatchEngine::Shutdown(); HLE::Clear(); + PowerPC::debug_interface.Clear(); }}; VideoBackendBase::PopulateBackendInfo(); diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.cpp b/Source/Core/Core/Debugger/PPCDebugInterface.cpp index 0ca90f52b4..44bdf0e3c7 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.cpp +++ b/Source/Core/Core/Debugger/PPCDebugInterface.cpp @@ -13,6 +13,7 @@ #include "Common/Align.h" #include "Common/GekkoDisassembler.h" +#include "Core/Config/MainSettings.h" #include "Core/Core.h" #include "Core/Debugger/OSThread.h" #include "Core/HW/DSP.h" @@ -383,10 +384,33 @@ void PPCDebugInterface::RunToBreakpoint() { } +std::shared_ptr PPCDebugInterface::NetworkLogger() +{ + const bool has_ssl = Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ) || + Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE); + const auto current_capture_type = + has_ssl ? Core::NetworkCaptureType::Raw : Core::NetworkCaptureType::None; + + if (m_network_logger && m_network_logger->GetCaptureType() == current_capture_type) + return m_network_logger; + + switch (current_capture_type) + { + case Core::NetworkCaptureType::Raw: + m_network_logger = std::make_shared(); + break; + case Core::NetworkCaptureType::None: + m_network_logger = std::make_shared(); + break; + } + return m_network_logger; +} + void PPCDebugInterface::Clear() { ClearAllBreakpoints(); ClearAllMemChecks(); ClearPatches(); ClearWatches(); + m_network_logger.reset(); } diff --git a/Source/Core/Core/Debugger/PPCDebugInterface.h b/Source/Core/Core/Debugger/PPCDebugInterface.h index bf17934f0e..8b9c265e84 100644 --- a/Source/Core/Core/Debugger/PPCDebugInterface.h +++ b/Source/Core/Core/Debugger/PPCDebugInterface.h @@ -5,11 +5,13 @@ #pragma once #include +#include #include #include "Common/Debug/MemoryPatches.h" #include "Common/Debug/Watches.h" #include "Common/DebugInterface.h" +#include "Core/NetworkCaptureLogger.h" class PPCPatches : public Common::Debug::MemoryPatches { @@ -82,9 +84,12 @@ public: u32 GetColor(u32 address) const override; std::string GetDescription(u32 address) const override; + std::shared_ptr NetworkLogger(); + void Clear() override; private: Common::Debug::Watches m_watches; PPCPatches m_patches; + std::shared_ptr m_network_logger; }; diff --git a/Source/Core/Core/IOS/Network/Socket.cpp b/Source/Core/Core/IOS/Network/Socket.cpp index b2f4429d55..d168da3709 100644 --- a/Source/Core/Core/IOS/Network/Socket.cpp +++ b/Source/Core/Core/IOS/Network/Socket.cpp @@ -20,10 +20,10 @@ #include "Common/FileUtil.h" #include "Common/IOFile.h" #include "Core/Config/MainSettings.h" -#include "Core/ConfigManager.h" #include "Core/Core.h" #include "Core/IOS/Device.h" #include "Core/IOS/IOS.h" +#include "Core/PowerPC/PowerPC.h" #ifdef _WIN32 #define ERRORCODE(name) WSA##name @@ -460,15 +460,10 @@ void WiiSocket::Update(bool read, bool write, bool except) int ret = mbedtls_ssl_write(&Device::NetSSL::_SSL[sslID].ctx, Memory::GetPointer(BufferOut2), BufferOutSize2); - if (Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE) && ret > 0) - { - std::string filename = File::GetUserPath(D_DUMPSSL_IDX) + - SConfig::GetInstance().GetGameID() + "_write.bin"; - File::IOFile(filename, "ab").WriteBytes(Memory::GetPointer(BufferOut2), ret); - } - if (ret >= 0) { + PowerPC::debug_interface.NetworkLogger()->LogWrite(Memory::GetPointer(BufferOut2), + ret); // Return bytes written or SSL_ERR_ZERO if none WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn); } @@ -498,15 +493,9 @@ void WiiSocket::Update(bool read, bool write, bool except) int ret = mbedtls_ssl_read(&Device::NetSSL::_SSL[sslID].ctx, Memory::GetPointer(BufferIn2), BufferInSize2); - if (Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ) && ret > 0) - { - std::string filename = File::GetUserPath(D_DUMPSSL_IDX) + - SConfig::GetInstance().GetGameID() + "_read.bin"; - File::IOFile(filename, "ab").WriteBytes(Memory::GetPointer(BufferIn2), ret); - } - if (ret >= 0) { + PowerPC::debug_interface.NetworkLogger()->LogRead(Memory::GetPointer(BufferIn2), ret); // Return bytes read or SSL_ERR_ZERO if none WriteReturnValue((ret == 0) ? SSL_ERR_ZERO : ret, BufferIn); } diff --git a/Source/Core/Core/NetworkCaptureLogger.cpp b/Source/Core/Core/NetworkCaptureLogger.cpp new file mode 100644 index 0000000000..b3fb6c69cc --- /dev/null +++ b/Source/Core/Core/NetworkCaptureLogger.cpp @@ -0,0 +1,52 @@ +// Copyright 2021 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#include "Core/NetworkCaptureLogger.h" + +#include "Common/FileUtil.h" +#include "Common/IOFile.h" +#include "Core/Config/MainSettings.h" +#include "Core/ConfigManager.h" + +namespace Core +{ +NetworkCaptureLogger::NetworkCaptureLogger() = default; +NetworkCaptureLogger::~NetworkCaptureLogger() = default; + +void DummyNetworkCaptureLogger::LogRead(const void* data, std::size_t length) +{ +} + +void DummyNetworkCaptureLogger::LogWrite(const void* data, std::size_t length) +{ +} + +NetworkCaptureType DummyNetworkCaptureLogger::GetCaptureType() const +{ + return NetworkCaptureType::None; +} + +void BinarySSLCaptureLogger::LogRead(const void* data, std::size_t length) +{ + if (!Config::Get(Config::MAIN_NETWORK_SSL_DUMP_READ)) + return; + const std::string filename = + File::GetUserPath(D_DUMPSSL_IDX) + SConfig::GetInstance().GetGameID() + "_read.bin"; + File::IOFile(filename, "ab").WriteBytes(data, length); +} + +void BinarySSLCaptureLogger::LogWrite(const void* data, std::size_t length) +{ + if (!Config::Get(Config::MAIN_NETWORK_SSL_DUMP_WRITE)) + return; + const std::string filename = + File::GetUserPath(D_DUMPSSL_IDX) + SConfig::GetInstance().GetGameID() + "_write.bin"; + File::IOFile(filename, "ab").WriteBytes(data, length); +} + +NetworkCaptureType BinarySSLCaptureLogger::GetCaptureType() const +{ + return NetworkCaptureType::Raw; +} +} // namespace Core diff --git a/Source/Core/Core/NetworkCaptureLogger.h b/Source/Core/Core/NetworkCaptureLogger.h new file mode 100644 index 0000000000..24c129e772 --- /dev/null +++ b/Source/Core/Core/NetworkCaptureLogger.h @@ -0,0 +1,48 @@ +// Copyright 2021 Dolphin Emulator Project +// Licensed under GPLv2+ +// Refer to the license.txt file included. + +#pragma once + +#include + +namespace Core +{ +enum class NetworkCaptureType +{ + None, + Raw, + PCAP, +}; + +class NetworkCaptureLogger +{ +public: + NetworkCaptureLogger(); + NetworkCaptureLogger(const NetworkCaptureLogger&) = delete; + NetworkCaptureLogger(NetworkCaptureLogger&&) = delete; + NetworkCaptureLogger& operator=(const NetworkCaptureLogger&) = delete; + NetworkCaptureLogger& operator=(NetworkCaptureLogger&&) = delete; + virtual ~NetworkCaptureLogger(); + + virtual void LogRead(const void* data, std::size_t length) = 0; + virtual void LogWrite(const void* data, std::size_t length) = 0; + virtual NetworkCaptureType GetCaptureType() const = 0; +}; + +class DummyNetworkCaptureLogger : public NetworkCaptureLogger +{ +public: + void LogRead(const void* data, std::size_t length) override; + void LogWrite(const void* data, std::size_t length) override; + NetworkCaptureType GetCaptureType() const override; +}; + +class BinarySSLCaptureLogger final : public NetworkCaptureLogger +{ +public: + void LogRead(const void* data, std::size_t length) override; + void LogWrite(const void* data, std::size_t length) override; + NetworkCaptureType GetCaptureType() const override; +}; +} // namespace Core diff --git a/Source/Core/DolphinLib.props b/Source/Core/DolphinLib.props index 9142fb1bc4..61688eb7b1 100644 --- a/Source/Core/DolphinLib.props +++ b/Source/Core/DolphinLib.props @@ -375,6 +375,7 @@ + @@ -943,6 +944,7 @@ +