NetworkCaptureLogger: Move SSL logging

This commit is contained in:
Sepalani 2017-08-24 19:45:26 +01:00
parent 3e66db2fd7
commit 289637f92f
8 changed files with 138 additions and 15 deletions

View File

@ -406,6 +406,8 @@ add_library(core
NetPlayClient.h
NetPlayServer.cpp
NetPlayServer.h
NetworkCaptureLogger.cpp
NetworkCaptureLogger.h
PatchEngine.cpp
PatchEngine.h
PowerPC/BreakPoints.cpp

View File

@ -534,6 +534,7 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
PatchEngine::Shutdown();
HLE::Clear();
PowerPC::debug_interface.Clear();
}};
VideoBackendBase::PopulateBackendInfo();

View File

@ -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<Core::NetworkCaptureLogger> 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<Core::BinarySSLCaptureLogger>();
break;
case Core::NetworkCaptureType::None:
m_network_logger = std::make_shared<Core::DummyNetworkCaptureLogger>();
break;
}
return m_network_logger;
}
void PPCDebugInterface::Clear()
{
ClearAllBreakpoints();
ClearAllMemChecks();
ClearPatches();
ClearWatches();
m_network_logger.reset();
}

View File

@ -5,11 +5,13 @@
#pragma once
#include <cstddef>
#include <memory>
#include <string>
#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<Core::NetworkCaptureLogger> NetworkLogger();
void Clear() override;
private:
Common::Debug::Watches m_watches;
PPCPatches m_patches;
std::shared_ptr<Core::NetworkCaptureLogger> m_network_logger;
};

View File

@ -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);
}

View File

@ -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

View File

@ -0,0 +1,48 @@
// Copyright 2021 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <cstddef>
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

View File

@ -375,6 +375,7 @@
<ClInclude Include="Core\NetPlayClient.h" />
<ClInclude Include="Core\NetPlayProto.h" />
<ClInclude Include="Core\NetPlayServer.h" />
<ClInclude Include="Core\NetworkCaptureLogger.h" />
<ClInclude Include="Core\PatchEngine.h" />
<ClInclude Include="Core\PowerPC\BreakPoints.h" />
<ClInclude Include="Core\PowerPC\CachedInterpreter\CachedInterpreter.h" />
@ -943,6 +944,7 @@
<ClCompile Include="Core\Movie.cpp" />
<ClCompile Include="Core\NetPlayClient.cpp" />
<ClCompile Include="Core\NetPlayServer.cpp" />
<ClCompile Include="Core\NetworkCaptureLogger.cpp" />
<ClCompile Include="Core\PatchEngine.cpp" />
<ClCompile Include="Core\PowerPC\BreakPoints.cpp" />
<ClCompile Include="Core\PowerPC\CachedInterpreter\CachedInterpreter.cpp" />