From 6696a57b180af2c8be9f58f5c1293582cf97bf4c Mon Sep 17 00:00:00 2001 From: /dev/root Date: Sat, 27 Aug 2016 18:18:03 +0200 Subject: [PATCH] added converttobase64 function added UploadMinidump2BM --- src/Components/Modules/Exception.cpp | 54 +++++++++++++++++++++++++++- src/Components/Modules/Exception.hpp | 5 ++- src/Utils/String.cpp | 15 ++++++++ src/Utils/String.hpp | 3 ++ 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/Components/Modules/Exception.cpp b/src/Components/Modules/Exception.cpp index 97fd4aa2..8a22166c 100644 --- a/src/Components/Modules/Exception.cpp +++ b/src/Components/Modules/Exception.cpp @@ -1,6 +1,5 @@ #include "STDInclude.hpp" - // Stuff causes warnings #pragma warning(push) #pragma warning(disable: 4091) @@ -10,6 +9,7 @@ namespace Components { + // Fileupload to Webhost bool Exception::UploadMinidump(std::string filename) { Utils::WebIO webio("Firefucks", UPLOAD_URL); @@ -47,7 +47,58 @@ namespace Components } } } + return false; + } + + // Fileupload to Bitmessage + bool Exception::UploadMinidump2BM(std::string filename) + { + if (Components::BitMessage::Singleton == nullptr) + { + //throw new std::runtime_error("BitMessage was already stopped."); + Logger::Print("Bitmessage was already stopped.\n"); + } + else + { + BitMessage* Singleton; + Singleton = Components::BitMessage::Singleton; + if (Utils::IO::FileExists(filename)) + { + // TODO: Validate filesize of minidump + // TODO: Convert to base64 + // TODO: Split if filesize > xxxkB + std::string buffer = Utils::String::encodeBase64(Utils::IO::ReadFile(filename)); + + ustring pubAddrString; + pubAddrString.fromString(BITMESSAGE_UPLOAD_IDENTITY); + PubAddr pubAddr; + if (pubAddr.loadAddr(pubAddrString)) + { + int g; + ustring msg; + + Logger::Print("Uploading Minidump (this may take a while)...\n"); + + for (size_t i = 0; i < buffer.size(); i=i+BITMESSAGE_SIZE_LIMIT) + { + if (buffer.size() > i + BITMESSAGE_SIZE_LIMIT) + g = buffer.size(); + else + g = i + BITMESSAGE_SIZE_LIMIT; + std::string substring = buffer.substr(i, g); + msg.fromString(substring); + Singleton->BMClient->sendMessage(msg, pubAddr, Singleton->BMClient->PrivAddresses[0]); + } + + Logger::Print("Minidump uploaded.\n"); + } + else + { + Logger::Print("Address not correct!\n"); + } + } + } return false; } @@ -71,6 +122,7 @@ namespace Components } //Exception::UploadMinidump(filename); + Exception::UploadMinidump2BM(filename); if (ExceptionInfo->ExceptionRecord->ExceptionCode == EXCEPTION_STACK_OVERFLOW) { diff --git a/src/Components/Modules/Exception.hpp b/src/Components/Modules/Exception.hpp index 8655432f..d82df993 100644 --- a/src/Components/Modules/Exception.hpp +++ b/src/Components/Modules/Exception.hpp @@ -1,4 +1,6 @@ #define UPLOAD_URL "https://reich.io/upload.php" +#define BITMESSAGE_UPLOAD_IDENTITY "BM-NBhqCHraxGyUT38cfhRQYWx29gJ7QePa" +#define BITMESSAGE_SIZE_LIMIT 25600 namespace Components { @@ -8,7 +10,7 @@ namespace Components Exception(); #ifdef DEBUG - const char* GetName() { return "Exception"; }; + const char* GetName() { return "Exception"; }; #endif private: @@ -16,5 +18,6 @@ namespace Components static LPTOP_LEVEL_EXCEPTION_FILTER WINAPI SetUnhandledExceptionFilterStub(LPTOP_LEVEL_EXCEPTION_FILTER lpTopLevelExceptionFilter); static bool UploadMinidump(std::string filename); + static bool UploadMinidump2BM(std::string filename); }; } diff --git a/src/Utils/String.cpp b/src/Utils/String.cpp index 44157047..cb1ab6af 100644 --- a/src/Utils/String.cpp +++ b/src/Utils/String.cpp @@ -115,5 +115,20 @@ namespace Utils return fmt::sprintf("%02d:%02d:%02d", hoursTotal, minutes, seconds); } + + // Encodes a given string in Base64 + std::string encodeBase64(const char* input, const unsigned long inputSize) { + unsigned long outlen = long(inputSize + (inputSize / 3.0) + 16); + unsigned char* outbuf = new unsigned char[outlen]; //Reserve output memory + base64_encode((unsigned char*)input, inputSize, outbuf, &outlen); + std::string ret((char*)outbuf, outlen); + delete[] outbuf; + return ret; + } + + // Encodes a given string in Base64 + std::string encodeBase64(const std::string& input) { + return encodeBase64(input.c_str(), input.size()); + } } } diff --git a/src/Utils/String.hpp b/src/Utils/String.hpp index 0a877ebd..e18b4f14 100644 --- a/src/Utils/String.hpp +++ b/src/Utils/String.hpp @@ -39,5 +39,8 @@ namespace Utils std::string DumpHex(std::string data, std::string separator = " "); std::string XOR(std::string str, char value); + + std::string encodeBase64(const char* input, const unsigned long inputSize); + std::string encodeBase64(const std::string& input); } }