diff --git a/native/CMakeLists.txt b/native/CMakeLists.txt index 1e59da5..4b90b83 100644 --- a/native/CMakeLists.txt +++ b/native/CMakeLists.txt @@ -110,7 +110,7 @@ if (MSVC) foreach(CompilerFlag ${CompilerFlags}) string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}") endforeach() - add_compile_options("/EHa") #We require exception handling + add_compile_options("/EHsc") #We require exception handling else() #This is a bad thing here! function(resolve_library VARIABLE FALLBACK PATHS) diff --git a/native/crash_handler/src/crash_handler.cpp b/native/crash_handler/src/crash_handler.cpp index b1e516f..e4d2cb9 100644 --- a/native/crash_handler/src/crash_handler.cpp +++ b/native/crash_handler/src/crash_handler.cpp @@ -8,6 +8,7 @@ #include #include +#include #include "base64.h" using namespace std; @@ -151,12 +152,12 @@ bool crash_callback(const fs::path& source_file, CrashContext* context, const st return succeeded; } -bool signal::setup(std::unique_ptr& context) { +extern void create_minidump(struct _EXCEPTION_POINTERS* apExceptionInfo); +bool signal::setup(std::unique_ptr& context) { #ifndef WIN32 global_crash_handler = make_unique(google_breakpad::MinidumpDescriptor("/tmp"), nullptr, breakpad_crash_callback, nullptr, true, -1); #else - //SetUnhandledExceptionFilter(unhandled_handler); global_crash_handler = AddVectoredExceptionHandler(0, unhandled_handler); /* this only works! */ #endif crash_context = move(context); @@ -173,6 +174,7 @@ void signal::finalize() { #else if(global_crash_handler) RemoveVectoredExceptionHandler(global_crash_handler); + global_crash_handler = nullptr; #endif crash_context.reset(); diff --git a/native/crash_handler/src/win_crash_generator.cpp b/native/crash_handler/src/win_crash_generator.cpp index 212c809..4cb30b2 100644 --- a/native/crash_handler/src/win_crash_generator.cpp +++ b/native/crash_handler/src/win_crash_generator.cpp @@ -85,6 +85,25 @@ void create_minidump(struct _EXCEPTION_POINTERS* apExceptionInfo) } LONG WINAPI unhandled_handler(struct _EXCEPTION_POINTERS* apExceptionInfo) { + auto code = apExceptionInfo->ExceptionRecord->ExceptionCode; + auto crash = false; + switch(code) { + case EXCEPTION_ACCESS_VIOLATION: + case EXCEPTION_ILLEGAL_INSTRUCTION: + case EXCEPTION_STACK_OVERFLOW: + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + case EXCEPTION_INT_DIVIDE_BY_ZERO: + case EXCEPTION_IN_PAGE_ERROR: + case EXCEPTION_NONCONTINUABLE_EXCEPTION: + crash = true; + break; + default: + crash = false; + } + + if(!crash) + return EXCEPTION_CONTINUE_SEARCH; + create_minidump(apExceptionInfo); exit(1); return EXCEPTION_EXECUTE_HANDLER; diff --git a/native/serverconnection/src/connection/ProtocolHandler.cpp b/native/serverconnection/src/connection/ProtocolHandler.cpp index b5523d5..b19f95d 100644 --- a/native/serverconnection/src/connection/ProtocolHandler.cpp +++ b/native/serverconnection/src/connection/ProtocolHandler.cpp @@ -155,7 +155,7 @@ void ProtocolHandler::progress_packet(const pipes::buffer_view &buffer) { return; } - auto packet = std::make_shared(buffer); + auto packet = std::shared_ptr(ts::protocol::ServerPacket::from_buffer(buffer).release()); auto packet_type = packet->type(); auto packet_id = packet->packetId(); auto ordered = packet_type.type() == protocol::COMMAND || packet_type.type() == protocol::COMMAND_LOW; @@ -502,9 +502,10 @@ void ProtocolHandler::send_acknowledge(uint16_t packet_id, bool low) { char buffer[2]; le2be16(packet_id, buffer); auto packet = make_shared(low ? protocol::PacketTypeInfo::AckLow : protocol::PacketTypeInfo::Ack, 0, pipes::buffer_view{buffer, 2}); - if(this->connection_state >= connection_state::CONNECTING) - ;//packet->toggle(protocol::PacketFlag::NewProtocol, !low); - //LivingBots DDOS protection dont want a new protocol here! + if(this->connection_state >= connection_state::CONNECTING) { + ;//packet->toggle(protocol::PacketFlag::NewProtocol, !low); + //LivingBots DDOS protection dont want a new protocol here! + } this->send_packet(packet); } diff --git a/native/serverconnection/src/connection/ServerConnection.cpp b/native/serverconnection/src/connection/ServerConnection.cpp index ab0a1bb..f5e4980 100644 --- a/native/serverconnection/src/connection/ServerConnection.cpp +++ b/native/serverconnection/src/connection/ServerConnection.cpp @@ -553,7 +553,7 @@ static shared_ptr shuffle_cached_packet; #endif void ServerConnection::send_voice_data(const void *buffer, size_t buffer_length, uint8_t codec, bool head) { auto _buffer = pipes::buffer{ts::protocol::ClientPacket::META_SIZE + buffer_length + 3}; - auto packet = make_shared(_buffer); + auto packet = ts::protocol::ClientPacket::from_buffer(_buffer); memset(&_buffer[ts::protocol::ClientPacket::META_MAC_SIZE], 0, ts::protocol::ClientPacket::META_HEADER_SIZE); /* reset all header data */ packet->type(ts::protocol::PacketTypeInfo::Voice); @@ -581,7 +581,7 @@ void ServerConnection::send_voice_data(const void *buffer, size_t buffer_length, shuffle_cached_packet = packet; } #else - this->protocol_handler->send_packet(packet); + this->protocol_handler->send_packet(std::shared_ptr(packet.release())); #endif }