├── LICENSE ├── README.md ├── UwpDumper.sln ├── UwpDumper ├── UwpDumper.vcxproj ├── UwpDumper.vcxproj.filters ├── dllmain.cpp ├── engine │ ├── communications │ │ ├── communications.cpp │ │ └── communications.h │ └── dumper │ │ ├── address │ │ └── address.cpp │ │ ├── dumper.cpp │ │ ├── dumper.h │ │ ├── encryption │ │ └── encryption.cpp │ │ └── offsets │ │ └── offsets.cpp ├── global │ ├── global.cpp │ └── global.h ├── memory │ ├── scanner │ │ ├── scanner.cpp │ │ └── scanner.h │ └── zywrap │ │ ├── zywrap.cpp │ │ └── zywrap.h └── third-party │ ├── Zydis │ ├── LICENSE │ ├── Zydis.c │ └── Zydis.h │ ├── ixwebsocket │ ├── IXBase64.h │ ├── IXBench.cpp │ ├── IXBench.h │ ├── IXCancellationRequest.cpp │ ├── IXCancellationRequest.h │ ├── IXConnectionState.cpp │ ├── IXConnectionState.h │ ├── IXDNSLookup.cpp │ ├── IXDNSLookup.h │ ├── IXExponentialBackoff.cpp │ ├── IXExponentialBackoff.h │ ├── IXGetFreePort.cpp │ ├── IXGetFreePort.h │ ├── IXGzipCodec.cpp │ ├── IXGzipCodec.h │ ├── IXHttp.cpp │ ├── IXHttp.h │ ├── IXHttpClient.cpp │ ├── IXHttpClient.h │ ├── IXHttpServer.cpp │ ├── IXHttpServer.h │ ├── IXNetSystem.cpp │ ├── IXNetSystem.h │ ├── IXProgressCallback.h │ ├── IXSelectInterrupt.cpp │ ├── IXSelectInterrupt.h │ ├── IXSelectInterruptEvent.cpp │ ├── IXSelectInterruptEvent.h │ ├── IXSelectInterruptFactory.cpp │ ├── IXSelectInterruptFactory.h │ ├── IXSelectInterruptPipe.cpp │ ├── IXSelectInterruptPipe.h │ ├── IXSetThreadName.cpp │ ├── IXSetThreadName.h │ ├── IXSocket.cpp │ ├── IXSocket.h │ ├── IXSocketAppleSSL.cpp │ ├── IXSocketAppleSSL.h │ ├── IXSocketConnect.cpp │ ├── IXSocketConnect.h │ ├── IXSocketFactory.cpp │ ├── IXSocketFactory.h │ ├── IXSocketMbedTLS.cpp │ ├── IXSocketMbedTLS.h │ ├── IXSocketOpenSSL.cpp │ ├── IXSocketOpenSSL.h │ ├── IXSocketServer.cpp │ ├── IXSocketServer.h │ ├── IXSocketTLSOptions.cpp │ ├── IXSocketTLSOptions.h │ ├── IXStrCaseCompare.cpp │ ├── IXStrCaseCompare.h │ ├── IXUdpSocket.cpp │ ├── IXUdpSocket.h │ ├── IXUniquePtr.h │ ├── IXUrlParser.cpp │ ├── IXUrlParser.h │ ├── IXUserAgent.cpp │ ├── IXUserAgent.h │ ├── IXUtf8Validator.h │ ├── IXUuid.cpp │ ├── IXUuid.h │ ├── IXWebSocket.cpp │ ├── IXWebSocket.h │ ├── IXWebSocketCloseConstants.cpp │ ├── IXWebSocketCloseConstants.h │ ├── IXWebSocketCloseInfo.h │ ├── IXWebSocketErrorInfo.h │ ├── IXWebSocketHandshake.cpp │ ├── IXWebSocketHandshake.h │ ├── IXWebSocketHandshakeKeyGen.h │ ├── IXWebSocketHttpHeaders.cpp │ ├── IXWebSocketHttpHeaders.h │ ├── IXWebSocketInitResult.h │ ├── IXWebSocketMessage.h │ ├── IXWebSocketMessageType.h │ ├── IXWebSocketOpenInfo.h │ ├── IXWebSocketPerMessageDeflate.cpp │ ├── IXWebSocketPerMessageDeflate.h │ ├── IXWebSocketPerMessageDeflateCodec.cpp │ ├── IXWebSocketPerMessageDeflateCodec.h │ ├── IXWebSocketPerMessageDeflateOptions.cpp │ ├── IXWebSocketPerMessageDeflateOptions.h │ ├── IXWebSocketProxyServer.cpp │ ├── IXWebSocketProxyServer.h │ ├── IXWebSocketSendData.h │ ├── IXWebSocketSendInfo.h │ ├── IXWebSocketServer.cpp │ ├── IXWebSocketServer.h │ ├── IXWebSocketTransport.cpp │ ├── IXWebSocketTransport.h │ ├── IXWebSocketVersion.h │ └── LICENSE │ └── minhook │ ├── LICENSE │ ├── include │ └── MinHook.h │ └── src │ ├── buffer.c │ ├── buffer.h │ ├── hde │ ├── hde32.c │ ├── hde32.h │ ├── hde64.c │ ├── hde64.h │ ├── pstdint.h │ ├── table32.h │ └── table64.h │ ├── hook.c │ ├── trampoline.c │ └── trampoline.h └── UwpDumperConsole ├── App.config ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── UwpDumperConsole.csproj └── packages.config /README.md: -------------------------------------------------------------------------------- 1 | # MemoryAnalyzer 2 | 3 | MemoryAnalyzer was a tool written by myself and [@iDevastate](https://www.github.com/iDevastate) to analyze 32 bit UWP Roblox modules. The main reason for this tool was to help speed up the process of dumping and gathering shuffles, encryptions, addresses and offsets by hand by using a software like Ghidra. This is a runtime program and uses Zydis to analyze memory. 4 | 5 | # Disclaimer 6 | 7 | This is not meant to be used for malicious purposes and only works with 32 bit binaries. 8 | -------------------------------------------------------------------------------- /UwpDumper.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33403.182 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UwpDumper", "UwpDumper\UwpDumper.vcxproj", "{047CAF25-5012-4A37-B9E5-834842BCC959}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UwpDumperConsole", "UwpDumperConsole\UwpDumperConsole.csproj", "{7C380859-C28D-4102-91A0-9F055A270504}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|x64 = Debug|x64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|x64 = Release|x64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|Any CPU.ActiveCfg = Debug|x64 21 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|Any CPU.Build.0 = Debug|x64 22 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|x64.ActiveCfg = Debug|x64 23 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|x64.Build.0 = Debug|x64 24 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|x86.ActiveCfg = Debug|Win32 25 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Debug|x86.Build.0 = Debug|Win32 26 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|Any CPU.ActiveCfg = Release|x64 27 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|Any CPU.Build.0 = Release|x64 28 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|x64.ActiveCfg = Release|x64 29 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|x64.Build.0 = Release|x64 30 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|x86.ActiveCfg = Release|Win32 31 | {047CAF25-5012-4A37-B9E5-834842BCC959}.Release|x86.Build.0 = Release|Win32 32 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|x64.ActiveCfg = Debug|Any CPU 35 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|x64.Build.0 = Debug|Any CPU 36 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {7C380859-C28D-4102-91A0-9F055A270504}.Debug|x86.Build.0 = Debug|Any CPU 38 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|x64.ActiveCfg = Release|Any CPU 41 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|x64.Build.0 = Release|Any CPU 42 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|x86.ActiveCfg = Release|Any CPU 43 | {7C380859-C28D-4102-91A0-9F055A270504}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {A038F4FA-417B-4527-8A75-EFC28B11C0FF} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /UwpDumper/dllmain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "global/global.h" 4 | #include "memory/zywrap/zywrap.h" 5 | #include "engine/dumper/dumper.h" 6 | #include "memory/scanner/scanner.h" 7 | #include "engine/communications/communications.h" 8 | #include "third-party/minhook/include/MinHook.h" 9 | 10 | void entry() 11 | { 12 | auto func = ([]() -> void // Run before socket connects 13 | { 14 | auto start = std::chrono::high_resolution_clock::now(); 15 | 16 | scanner::init(); 17 | 18 | zywrap zywrap{}; 19 | 20 | engine::dumper::dumper_t dumper(zywrap); 21 | 22 | dumper.dump(); 23 | 24 | std::stringstream output_stream; 25 | output_stream << dumper.output().str() << "\n"; 26 | 27 | #if MULTI_THREADED 28 | while (comm_socket == nullptr) 29 | { 30 | volatile int a = 0; 31 | } // Wait for socket to connect 32 | #endif 33 | 34 | auto stop = std::chrono::high_resolution_clock::now(); 35 | 36 | ipc_write("Welcome to UWP Dumper!\n"); 37 | output_stream << "\nTook " << std::chrono::duration_cast(stop - start) << "!\n"; 38 | ipc_write(output_stream.str().c_str()); 39 | }); 40 | 41 | #if MULTI_THREADED 42 | std::thread(func).detach(); 43 | 44 | if (!engine::communications::start()) // Connect to socket 45 | ipc_write("Failed to setup socket!\n"); 46 | #else 47 | if (!engine::communications::start()) // Connect to socket 48 | ipc_write("Failed to setup socket!\n"); 49 | 50 | func(); 51 | #endif 52 | } 53 | 54 | BOOL APIENTRY DllMain(HMODULE hModule, 55 | DWORD ul_reason_for_call, 56 | LPVOID lpReserved 57 | ) 58 | { 59 | switch (ul_reason_for_call) 60 | { 61 | case DLL_PROCESS_ATTACH: 62 | std::thread(entry).detach(); 63 | break; 64 | case DLL_THREAD_ATTACH: 65 | case DLL_THREAD_DETACH: 66 | case DLL_PROCESS_DETACH: 67 | break; 68 | } 69 | return TRUE; 70 | } -------------------------------------------------------------------------------- /UwpDumper/engine/communications/communications.cpp: -------------------------------------------------------------------------------- 1 | #include "communications.h" 2 | 3 | bool engine::communications::start() 4 | { 5 | const auto web_sock_ = new ix::WebSocket(); 6 | 7 | web_sock_->setUrl(("ws://localhost:64609/dumper_ipc")); 8 | web_sock_->setOnMessageCallback([=](const ix::WebSocketMessagePtr& msg) {}); 9 | web_sock_->setPingInterval(1); 10 | web_sock_->disableAutomaticReconnection(); // turn off 11 | 12 | if (web_sock_->connect(30).success) 13 | { 14 | web_sock_->start(); 15 | 16 | comm_socket = web_sock_; 17 | 18 | return true; 19 | } 20 | 21 | return false; 22 | } 23 | -------------------------------------------------------------------------------- /UwpDumper/engine/communications/communications.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "../../global/global.h" 4 | 5 | namespace engine::communications 6 | { 7 | bool start(); 8 | } -------------------------------------------------------------------------------- /UwpDumper/engine/dumper/dumper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../../memory/zywrap/zywrap.h" 3 | #include "../../global/global.h" 4 | 5 | enum enc_types 6 | { 7 | none, // !< Encryption | Decryption 8 | add_pointer, // !< Struct + Pointer | *(TYPE*)(Struct) - Struct 9 | sub_pointer, // !< Struct - Pointer | Struct - *(TYPE*)(Struct) 10 | sub_offset, // !< Pointer - Struct | *(TYPE*)(Struct) + Struct 11 | xor_pointer // !< Struct ^ Pointer | *(TYPE*)(Struct) ^ Struct 12 | }; 13 | 14 | namespace engine::dumper 15 | { 16 | class dumper_t 17 | { 18 | public: 19 | std::map address_map{}; 20 | std::map offset_map{}; 21 | std::map encryption_map{}; 22 | 23 | int l_top_offset = 0; 24 | 25 | // Offset maps 26 | std::map lua_State_offset_map; 27 | std::map proto_offset_map; 28 | 29 | std::stringstream output_stream; 30 | 31 | zywrap zy; 32 | 33 | int total_address_count = 0; 34 | 35 | void dump(); 36 | [[nodiscard]] std::stringstream output(); 37 | 38 | /* 39 | * Addresses 40 | */ 41 | 42 | void dump_addresses(); 43 | [[nodiscard]] std::uintptr_t find_address(std::string_view); 44 | 45 | /* 46 | * Offsets 47 | */ 48 | void dump_freeproto(); // [[ DUMPS PROTO GROUP1/GROUP2 ENCRYPTIONS ]] && l->global, p->code, p->p, p->k, p->lineinfo, p->locvars, p->upvalues, p->debugins, p->typeinfo, p->sizecode, p->sizep, p->sizek, p->sizelineinfo, p->sizelocvars, p->sizeupvalues, p->sizecode 49 | void dump_dumpthread(); // p->source, p->linedefined, l->stack & l->ci 50 | void dump_math_max(); // locate l->top & l->base 51 | void dump_luavm_load(); // p->linegaplog2 52 | void dump_startrunningmodulescript(); // sc->loadedmodules 53 | void dump_cancollidewithlua(); // primative & world 54 | void dump_offsets(); 55 | 56 | void set_proto_offset(std::string_view, int); 57 | [[nodiscard]] std::string find_proto_offset(int); 58 | 59 | void set_lstate_offset(std::string_view, int); 60 | [[nodiscard]] std::string find_lstate_offset(int); 61 | 62 | /* 63 | * Encryptions 64 | * Note: Due to encryptions being used in different locations, each encryption location will need their own resolver. 65 | */ 66 | void dump_table_encryptions(disassembled_result, int); // Dumps table encryption via dumpthread 67 | void dump_udata_encryptions(); // Dumps udata encryption via dumpudata 68 | void dump_proto_encryptions(disassembled_result, int, std::string_view); // Dumps proto group1/group2 encryptions via luaF_freeproto 69 | void dump_proto_debugins_typeinfo_encryptions(disassembled_result, int, std::string_view); // Dumps proto debugins encryption via luaF_freeproto 70 | void dump_proto_debugname_encryptions(disassembled_result, int); // Dumps proto debugname encryotion via luavm::load//luau_load 71 | void dump_closure_debugname_encryptions(); // Dump closure debugname via dumpclosure 72 | void dump_closure_f_cont_encryptions(std::uintptr_t, std::string_view); // Dump closure f and closure cont via xref analysis 73 | void dump_ttname_encryptions(); // Dump global ttname via luaT_objtypenamestr 74 | void dump_global_encryptions(); // Dump lua_State global via luaM_freeproto 75 | 76 | // BRUTEFORCE SECTION 77 | void dump_hash_len_encryptions();// Dump tstring hash and tstring len via BRUTEFORCE 78 | 79 | [[nodiscard]] std::string encryption_to_string(enc_types enc); 80 | [[nodiscard]] enc_types find_encryption(std::string_view); 81 | 82 | dumper_t(zywrap& _zy) 83 | { 84 | zy = _zy; 85 | } 86 | }; 87 | } -------------------------------------------------------------------------------- /UwpDumper/global/global.cpp: -------------------------------------------------------------------------------- 1 | #include "global.h" 2 | 3 | ix::WebSocket* comm_socket = nullptr; -------------------------------------------------------------------------------- /UwpDumper/global/global.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | #include "IXWebSocket.h" 6 | 7 | #define MULTI_THREADED true 8 | 9 | extern ix::WebSocket* comm_socket; 10 | 11 | inline std::string s_str_format(const char* fmt, ...) 12 | { 13 | char buf[256]; 14 | 15 | va_list args; 16 | va_start(args, fmt); 17 | const auto r = std::vsnprintf(buf, sizeof buf, fmt, args); 18 | va_end(args); 19 | 20 | if (r < 0)// conversion failed 21 | return {}; 22 | 23 | const size_t len = r; 24 | if (len < sizeof buf) // we fit in the buffer 25 | return { buf, len }; 26 | 27 | #if __cplusplus >= 201703L 28 | // C++17: Create a string and write to its underlying array 29 | std::string s(len, '\0'); 30 | va_start(args, fmt); 31 | std::vsnprintf(s.data(), len + 1, fmt, args); 32 | va_end(args); 33 | 34 | return s; 35 | #else 36 | // C++11 or C++14: We need to allocate scratch memory 37 | const auto vbuf = std::unique_ptr(new char[len + 1]); 38 | va_start(args, fmt); 39 | std::vsnprintf(vbuf.get(), len + 1, fmt, args); 40 | va_end(args); 41 | 42 | return { vbuf.get(), len }; 43 | #endif 44 | } 45 | 46 | inline void ipc_write(std::string msg) 47 | { 48 | if (comm_socket != nullptr) 49 | comm_socket->send(msg); 50 | } -------------------------------------------------------------------------------- /UwpDumper/memory/scanner/scanner.cpp: -------------------------------------------------------------------------------- 1 | #include "scanner.h" 2 | #include 3 | #pragma comment( lib, "DbgHelp.lib" ) 4 | 5 | std::pair scanner::text_range{}; 6 | std::pair scanner::rdata_range{}; 7 | std::pair scanner::data_range{}; 8 | 9 | void scanner::init() 10 | { 11 | const auto handle = GetModuleHandle(nullptr); 12 | const auto nt = ImageNtHeader(handle); 13 | 14 | if (nt == nullptr) 15 | return; 16 | 17 | for (auto i = 0; i < nt->FileHeader.NumberOfSections; i++) 18 | { 19 | const auto section = IMAGE_FIRST_SECTION(nt) + i; 20 | 21 | if (std::strcmp(reinterpret_cast(section->Name), ".text") == 0) 22 | { 23 | text_range.first = reinterpret_cast(handle) + section->VirtualAddress; 24 | text_range.second = text_range.first + section->Misc.VirtualSize; 25 | } 26 | else if (std::strcmp(reinterpret_cast(section->Name), ".rdata") == 0) 27 | { 28 | rdata_range.first = reinterpret_cast(handle) + section->VirtualAddress; 29 | rdata_range.second = rdata_range.first + section->Misc.VirtualSize; 30 | } 31 | else if (std::strcmp(reinterpret_cast(section->Name), ".data") == 0) 32 | { 33 | data_range.first = reinterpret_cast(handle) + section->VirtualAddress; 34 | data_range.second = data_range.first + section->Misc.VirtualSize; 35 | } 36 | } 37 | } 38 | 39 | std::uintptr_t scanner::find_string(std::string_view str) 40 | { 41 | const auto start = reinterpret_cast(rdata_range.first); 42 | const auto end = reinterpret_cast(rdata_range.second); 43 | 44 | for (auto i = start; i < end; ++i) 45 | { 46 | if (*i == 0 || *i > 127 || *i < 33) //check if ascii 47 | continue; 48 | 49 | auto s = std::string_view{ reinterpret_cast(i) }; 50 | 51 | if (s.find(str) != std::string_view::npos && s.starts_with(str[0]) && s.ends_with(str[str.size() - 1])) 52 | return reinterpret_cast(i); 53 | 54 | i += s.length(); 55 | } 56 | return 0; 57 | } 58 | 59 | std::uintptr_t scanner::find_data(std::uintptr_t addr) 60 | { 61 | /* .data:0323EF20 D4 B3 EC 02 dd offset aScriptaccessca ; "ScriptAccessCaps" */ 62 | /* Addr example: 02ECB3D4 */ 63 | const auto target_bytes = reinterpret_cast(&addr); 64 | 65 | const auto start = reinterpret_cast(data_range.first); 66 | const auto end = reinterpret_cast(data_range.second); 67 | 68 | for (auto i = start; i < end; ++i) { 69 | // Match bytes with addr 70 | auto found = true; // Assume match initially 71 | 72 | for (std::size_t j = 0; j < sizeof(addr); ++j) { 73 | if (i + j >= end || *(i + j) != target_bytes[j]) { 74 | found = false; // Byte doesn't match 75 | break; 76 | } 77 | } 78 | 79 | if (found) { 80 | return reinterpret_cast(i); 81 | } 82 | } 83 | 84 | // Return a sentinel value (or handle not found case) 85 | return 0xFFFFFFFF; // Example sentinel value 86 | } -------------------------------------------------------------------------------- /UwpDumper/memory/scanner/scanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace scanner 12 | { 13 | extern std::pair text_range; 14 | extern std::pair rdata_range; 15 | extern std::pair data_range; 16 | 17 | void init(); 18 | 19 | std::uintptr_t find_string(std::string_view); 20 | std::uintptr_t find_data(std::uintptr_t); 21 | 22 | inline bool compare(std::uintptr_t address, const char* const pattern, const char* const mask) 23 | { 24 | for (auto i = 0; i < std::strlen(mask); i++) 25 | { 26 | if (mask[i] != '?' && static_cast(pattern[i]) != *reinterpret_cast(address + i)) 27 | return false; 28 | } 29 | 30 | return true; 31 | } 32 | 33 | inline std::uintptr_t find_pattern(std::uintptr_t alloc_base, const char* const pattern, const char* const mask) 34 | { 35 | MEMORY_BASIC_INFORMATION mbi; 36 | 37 | std::uintptr_t address = 0; 38 | while ((VirtualQuery)(reinterpret_cast(address), &mbi, sizeof(mbi))) 39 | { 40 | if (reinterpret_cast(mbi.AllocationBase) == alloc_base && mbi.State == MEM_COMMIT && mbi.Protect == PAGE_EXECUTE_READ) 41 | { 42 | const auto base = reinterpret_cast(mbi.BaseAddress); 43 | 44 | // If the BaseAddress is greater or equal to the start of the text range but lower or equal to the end 45 | if (base <= text_range.second && base >= text_range.first) 46 | { 47 | for (auto i = base; i < base + mbi.RegionSize; i++) 48 | { 49 | if (compare(i, pattern, mask)) 50 | return i; 51 | } 52 | } 53 | } 54 | 55 | address += mbi.RegionSize; 56 | } 57 | return 0; 58 | } 59 | 60 | template 61 | bool valid_pointer(T lpAddress) 62 | { 63 | MEMORY_BASIC_INFORMATION mbi; 64 | 65 | if (VirtualQuery(reinterpret_cast(lpAddress), &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0) 66 | return false; 67 | 68 | if (mbi.Protect & PAGE_NOACCESS) 69 | return false; 70 | 71 | if (mbi.Protect & PAGE_GUARD) 72 | return false; 73 | 74 | return true; 75 | } 76 | } -------------------------------------------------------------------------------- /UwpDumper/memory/zywrap/zywrap.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "../scanner/scanner.h" 9 | 10 | typedef std::map disassembled_result; 11 | 12 | class zywrap 13 | { 14 | private: 15 | ZydisDecoder decoder{}; 16 | ZydisFormatter formatter{}; 17 | std::uintptr_t base; 18 | public: 19 | template 20 | inline Ty rebase(const std::uintptr_t addr) 21 | { 22 | return Ty(addr - 0x400000 + base); 23 | } 24 | 25 | template 26 | inline Ty unbase(const std::uintptr_t addr) 27 | { 28 | return Ty(addr + 0x400000 - base); 29 | } 30 | 31 | [[nodiscard]] std::optional decode(std::uintptr_t) const; 32 | [[nodiscard]] disassembled_result decode_multiple(std::uintptr_t, int = -1) const; 33 | [[nodiscard]] disassembled_result decode_until(std::uintptr_t, std::uintptr_t) const; 34 | 35 | [[nodiscard]] std::uintptr_t find_start(std::uintptr_t) const; 36 | [[nodiscard]] std::uintptr_t find_end(std::uintptr_t) const; 37 | [[nodiscard]] std::uintptr_t function_size(std::uintptr_t) const; 38 | 39 | [[nodiscard]] std::uintptr_t get_absolute_address(std::uintptr_t) const; 40 | [[nodiscard]] std::vector find_xrefs(std::uintptr_t, std::size_t = 0) const; 41 | [[nodiscard]] std::vector get_calls(std::uintptr_t) const; 42 | 43 | std::optional scan(const char* const, const char* const) const; 44 | 45 | std::optional find_string(std::string_view); 46 | 47 | void debug_output(ZydisDisassembledInstruction& instruction) const; 48 | 49 | [[nodiscard]] std::uintptr_t get_base() const; 50 | 51 | zywrap() 52 | { 53 | ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_32, ZYDIS_STACK_WIDTH_32); 54 | ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL); 55 | base = reinterpret_cast(GetModuleHandle(nullptr)); 56 | } 57 | }; -------------------------------------------------------------------------------- /UwpDumper/third-party/Zydis/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Florian Bernd 4 | Copyright (c) 2014-2021 Joel Höner 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXBase64.h: -------------------------------------------------------------------------------- 1 | #ifndef _MACARON_BASE64_H_ 2 | #define _MACARON_BASE64_H_ 3 | 4 | /** 5 | * The MIT License (MIT) 6 | * Copyright (c) 2016 tomykaira 7 | * 8 | * Permission is hereby granted, free of charge, to any person obtaining 9 | * a copy of this software and associated documentation files (the 10 | * "Software"), to deal in the Software without restriction, including 11 | * without limitation the rights to use, copy, modify, merge, publish, 12 | * distribute, sublicense, and/or sell copies of the Software, and to 13 | * permit persons to whom the Software is furnished to do so, subject to 14 | * the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be 17 | * included in all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 23 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | namespace macaron { 32 | 33 | class Base64 { 34 | public: 35 | 36 | static std::string Encode(const std::string data) { 37 | static constexpr char sEncodingTable[] = { 38 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 39 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 40 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 41 | 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 42 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 43 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 44 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', 45 | '4', '5', '6', '7', '8', '9', '+', '/' 46 | }; 47 | 48 | size_t in_len = data.size(); 49 | size_t out_len = 4 * ((in_len + 2) / 3); 50 | std::string ret(out_len, '\0'); 51 | size_t i; 52 | char *p = const_cast(ret.c_str()); 53 | 54 | for (i = 0; i < in_len - 2; i += 3) { 55 | *p++ = sEncodingTable[(data[i] >> 2) & 0x3F]; 56 | *p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)]; 57 | *p++ = sEncodingTable[((data[i + 1] & 0xF) << 2) | ((int) (data[i + 2] & 0xC0) >> 6)]; 58 | *p++ = sEncodingTable[data[i + 2] & 0x3F]; 59 | } 60 | if (i < in_len) { 61 | *p++ = sEncodingTable[(data[i] >> 2) & 0x3F]; 62 | if (i == (in_len - 1)) { 63 | *p++ = sEncodingTable[((data[i] & 0x3) << 4)]; 64 | *p++ = '='; 65 | } 66 | else { 67 | *p++ = sEncodingTable[((data[i] & 0x3) << 4) | ((int) (data[i + 1] & 0xF0) >> 4)]; 68 | *p++ = sEncodingTable[((data[i + 1] & 0xF) << 2)]; 69 | } 70 | *p++ = '='; 71 | } 72 | 73 | return ret; 74 | } 75 | 76 | static std::string Decode(const std::string& input, std::string& out) { 77 | static constexpr unsigned char kDecodingTable[] = { 78 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 79 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 80 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 81 | 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 82 | 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 83 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 84 | 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 85 | 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 86 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 87 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 88 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 89 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 90 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 91 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 92 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 93 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 94 | }; 95 | 96 | size_t in_len = input.size(); 97 | if (in_len % 4 != 0) return "Input data size is not a multiple of 4"; 98 | 99 | size_t out_len = in_len / 4 * 3; 100 | if (input[in_len - 1] == '=') out_len--; 101 | if (input[in_len - 2] == '=') out_len--; 102 | 103 | out.resize(out_len); 104 | 105 | for (size_t i = 0, j = 0; i < in_len;) { 106 | uint32_t a = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast(input[i++])]; 107 | uint32_t b = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast(input[i++])]; 108 | uint32_t c = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast(input[i++])]; 109 | uint32_t d = input[i] == '=' ? 0 & i++ : kDecodingTable[static_cast(input[i++])]; 110 | 111 | uint32_t triple = (a << 3 * 6) + (b << 2 * 6) + (c << 1 * 6) + (d << 0 * 6); 112 | 113 | if (j < out_len) out[j++] = (triple >> 2 * 8) & 0xFF; 114 | if (j < out_len) out[j++] = (triple >> 1 * 8) & 0xFF; 115 | if (j < out_len) out[j++] = (triple >> 0 * 8) & 0xFF; 116 | } 117 | 118 | return ""; 119 | } 120 | 121 | }; 122 | 123 | } 124 | 125 | #endif /* _MACARON_BASE64_H_ */ 126 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXBench.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXBench.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXBench.h" 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | Bench::Bench(const std::string& description) 14 | : _description(description) 15 | { 16 | reset(); 17 | } 18 | 19 | Bench::~Bench() 20 | { 21 | if (!_reported) 22 | { 23 | report(); 24 | } 25 | } 26 | 27 | void Bench::reset() 28 | { 29 | _start = std::chrono::high_resolution_clock::now(); 30 | _reported = false; 31 | } 32 | 33 | void Bench::report() 34 | { 35 | auto now = std::chrono::high_resolution_clock::now(); 36 | auto microseconds = std::chrono::duration_cast(now - _start); 37 | 38 | _duration = microseconds.count(); 39 | std::cerr << _description << " completed in " << _duration << " us" << std::endl; 40 | 41 | setReported(); 42 | } 43 | 44 | void Bench::record() 45 | { 46 | auto now = std::chrono::high_resolution_clock::now(); 47 | auto microseconds = std::chrono::duration_cast(now - _start); 48 | 49 | _duration = microseconds.count(); 50 | } 51 | 52 | void Bench::setReported() 53 | { 54 | _reported = true; 55 | } 56 | 57 | uint64_t Bench::getDuration() const 58 | { 59 | return _duration; 60 | } 61 | } // namespace ix 62 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXBench.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXBench.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #pragma once 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | class Bench 15 | { 16 | public: 17 | Bench(const std::string& description); 18 | ~Bench(); 19 | 20 | void reset(); 21 | void record(); 22 | void report(); 23 | void setReported(); 24 | uint64_t getDuration() const; 25 | 26 | private: 27 | std::string _description; 28 | std::chrono::time_point _start; 29 | uint64_t _duration; 30 | bool _reported; 31 | }; 32 | } // namespace ix 33 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXCancellationRequest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXCancellationRequest.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXCancellationRequest.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | CancellationRequest makeCancellationRequestWithTimeout( 15 | int secs, std::atomic& requestInitCancellation) 16 | { 17 | assert(secs > 0); 18 | 19 | auto start = std::chrono::system_clock::now(); 20 | auto timeout = std::chrono::seconds(secs); 21 | 22 | auto isCancellationRequested = [&requestInitCancellation, start, timeout]() -> bool { 23 | // Was an explicit cancellation requested ? 24 | if (requestInitCancellation) return true; 25 | 26 | auto now = std::chrono::system_clock::now(); 27 | if ((now - start) > timeout) return true; 28 | 29 | // No cancellation request 30 | return false; 31 | }; 32 | 33 | return isCancellationRequested; 34 | } 35 | } // namespace ix 36 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXCancellationRequest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXCancellationRequest.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | using CancellationRequest = std::function; 15 | 16 | CancellationRequest makeCancellationRequestWithTimeout( 17 | int seconds, std::atomic& requestInitCancellation); 18 | } // namespace ix 19 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXConnectionState.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXConnectionState.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXConnectionState.h" 8 | 9 | namespace ix 10 | { 11 | std::atomic ConnectionState::_globalId(0); 12 | 13 | ConnectionState::ConnectionState() 14 | : _terminated(false) 15 | { 16 | computeId(); 17 | } 18 | 19 | void ConnectionState::computeId() 20 | { 21 | _id = std::to_string(_globalId++); 22 | } 23 | 24 | const std::string& ConnectionState::getId() const 25 | { 26 | return _id; 27 | } 28 | 29 | std::shared_ptr ConnectionState::createConnectionState() 30 | { 31 | return std::make_shared(); 32 | } 33 | 34 | void ConnectionState::setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback) 35 | { 36 | _onSetTerminatedCallback = callback; 37 | } 38 | 39 | bool ConnectionState::isTerminated() const 40 | { 41 | return _terminated; 42 | } 43 | 44 | void ConnectionState::setTerminated() 45 | { 46 | _terminated = true; 47 | 48 | if (_onSetTerminatedCallback) 49 | { 50 | _onSetTerminatedCallback(); 51 | } 52 | } 53 | 54 | const std::string& ConnectionState::getRemoteIp() 55 | { 56 | return _remoteIp; 57 | } 58 | 59 | int ConnectionState::getRemotePort() 60 | { 61 | return _remotePort; 62 | } 63 | 64 | void ConnectionState::setRemoteIp(const std::string& remoteIp) 65 | { 66 | _remoteIp = remoteIp; 67 | } 68 | 69 | void ConnectionState::setRemotePort(int remotePort) 70 | { 71 | _remotePort = remotePort; 72 | } 73 | } // namespace ix 74 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXConnectionState.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXConnectionState.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace ix 16 | { 17 | using OnSetTerminatedCallback = std::function; 18 | 19 | class ConnectionState 20 | { 21 | public: 22 | ConnectionState(); 23 | virtual ~ConnectionState() = default; 24 | 25 | virtual void computeId(); 26 | virtual const std::string& getId() const; 27 | 28 | void setTerminated(); 29 | bool isTerminated() const; 30 | 31 | const std::string& getRemoteIp(); 32 | int getRemotePort(); 33 | 34 | static std::shared_ptr createConnectionState(); 35 | 36 | private: 37 | void setOnSetTerminatedCallback(const OnSetTerminatedCallback& callback); 38 | 39 | void setRemoteIp(const std::string& remoteIp); 40 | void setRemotePort(int remotePort); 41 | 42 | protected: 43 | std::atomic _terminated; 44 | std::string _id; 45 | OnSetTerminatedCallback _onSetTerminatedCallback; 46 | 47 | static std::atomic _globalId; 48 | 49 | std::string _remoteIp; 50 | int _remotePort; 51 | 52 | friend class SocketServer; 53 | }; 54 | } // namespace ix 55 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXDNSLookup.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXDNSLookup.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | // 8 | // On Windows Universal Platform (uwp), gai_strerror defaults behavior is to returns wchar_t 9 | // which is different from all other platforms. We want the non unicode version. 10 | // See https://github.com/microsoft/vcpkg/pull/11030 11 | // We could do this in IXNetSystem.cpp but so far we are only using gai_strerror in here. 12 | // 13 | #ifdef _UNICODE 14 | #undef _UNICODE 15 | #endif 16 | #ifdef UNICODE 17 | #undef UNICODE 18 | #endif 19 | 20 | #include "IXDNSLookup.h" 21 | 22 | #include "IXNetSystem.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | // mingw build quirks 29 | #if defined(_WIN32) && defined(__GNUC__) 30 | #define AI_NUMERICSERV NI_NUMERICSERV 31 | #define AI_ADDRCONFIG LUP_ADDRCONFIG 32 | #endif 33 | 34 | namespace ix 35 | { 36 | const int64_t DNSLookup::kDefaultWait = 1; // ms 37 | 38 | DNSLookup::DNSLookup(const std::string& hostname, int port, int64_t wait) 39 | : _hostname(hostname) 40 | , _port(port) 41 | , _wait(wait) 42 | , _res(nullptr) 43 | , _done(false) 44 | { 45 | ; 46 | } 47 | 48 | DNSLookup::AddrInfoPtr DNSLookup::getAddrInfo(const std::string& hostname, 49 | int port, 50 | std::string& errMsg) 51 | { 52 | struct addrinfo hints; 53 | memset(&hints, 0, sizeof(hints)); 54 | hints.ai_flags = AI_ADDRCONFIG | AI_NUMERICSERV; 55 | hints.ai_family = AF_UNSPEC; 56 | hints.ai_socktype = SOCK_STREAM; 57 | 58 | std::string sport = std::to_string(port); 59 | 60 | struct addrinfo* res; 61 | int getaddrinfo_result = getaddrinfo(hostname.c_str(), sport.c_str(), &hints, &res); 62 | if (getaddrinfo_result) 63 | { 64 | errMsg = gai_strerror(getaddrinfo_result); 65 | res = nullptr; 66 | } 67 | return AddrInfoPtr{ res, freeaddrinfo }; 68 | } 69 | 70 | DNSLookup::AddrInfoPtr DNSLookup::resolve(std::string& errMsg, 71 | const CancellationRequest& isCancellationRequested, 72 | bool cancellable) 73 | { 74 | return cancellable ? resolveCancellable(errMsg, isCancellationRequested) 75 | : resolveUnCancellable(errMsg, isCancellationRequested); 76 | } 77 | 78 | DNSLookup::AddrInfoPtr DNSLookup::resolveUnCancellable( 79 | std::string& errMsg, const CancellationRequest& isCancellationRequested) 80 | { 81 | errMsg = "no error"; 82 | 83 | // Maybe a cancellation request got in before the background thread terminated ? 84 | if (isCancellationRequested()) 85 | { 86 | errMsg = "cancellation requested"; 87 | return nullptr; 88 | } 89 | 90 | return getAddrInfo(_hostname, _port, errMsg); 91 | } 92 | 93 | DNSLookup::AddrInfoPtr DNSLookup::resolveCancellable( 94 | std::string& errMsg, const CancellationRequest& isCancellationRequested) 95 | { 96 | errMsg = "no error"; 97 | 98 | // Can only be called once, otherwise we would have to manage a pool 99 | // of background thread which is overkill for our usage. 100 | if (_done) 101 | { 102 | return nullptr; // programming error, create a second DNSLookup instance 103 | // if you need a second lookup. 104 | } 105 | 106 | // 107 | // Good resource on thread forced termination 108 | // https://www.bo-yang.net/2017/11/19/cpp-kill-detached-thread 109 | // 110 | auto ptr = shared_from_this(); 111 | std::weak_ptr self(ptr); 112 | 113 | int port = _port; 114 | std::string hostname(_hostname); 115 | 116 | // We make the background thread doing the work a shared pointer 117 | // instead of a member variable, because it can keep running when 118 | // this object goes out of scope, in case of cancellation 119 | auto t = std::make_shared(&DNSLookup::run, this, self, hostname, port); 120 | t->detach(); 121 | 122 | while (!_done) 123 | { 124 | // Wait for 1 milliseconds, to see if the bg thread has terminated. 125 | // We do not use a condition variable to wait, as destroying this one 126 | // if the bg thread is alive can cause undefined behavior. 127 | std::this_thread::sleep_for(std::chrono::milliseconds(_wait)); 128 | 129 | // Were we cancelled ? 130 | if (isCancellationRequested()) 131 | { 132 | errMsg = "cancellation requested"; 133 | return nullptr; 134 | } 135 | } 136 | 137 | // Maybe a cancellation request got in before the bg terminated ? 138 | if (isCancellationRequested()) 139 | { 140 | errMsg = "cancellation requested"; 141 | return nullptr; 142 | } 143 | 144 | errMsg = getErrMsg(); 145 | return getRes(); 146 | } 147 | 148 | void DNSLookup::run(std::weak_ptr self, 149 | std::string hostname, 150 | int port) // thread runner 151 | { 152 | // We don't want to read or write into members variables of an object that could be 153 | // gone, so we use temporary variables (res) or we pass in by copy everything that 154 | // getAddrInfo needs to work. 155 | std::string errMsg; 156 | auto res = getAddrInfo(hostname, port, errMsg); 157 | 158 | if (auto lock = self.lock()) 159 | { 160 | // Copy result into the member variables 161 | setRes(res); 162 | setErrMsg(errMsg); 163 | 164 | _done = true; 165 | } 166 | } 167 | 168 | void DNSLookup::setErrMsg(const std::string& errMsg) 169 | { 170 | std::lock_guard lock(_errMsgMutex); 171 | _errMsg = errMsg; 172 | } 173 | 174 | const std::string& DNSLookup::getErrMsg() 175 | { 176 | std::lock_guard lock(_errMsgMutex); 177 | return _errMsg; 178 | } 179 | 180 | void DNSLookup::setRes(DNSLookup::AddrInfoPtr addr) 181 | { 182 | std::lock_guard lock(_resMutex); 183 | _res = std::move(addr); 184 | } 185 | 186 | DNSLookup::AddrInfoPtr DNSLookup::getRes() 187 | { 188 | std::lock_guard lock(_resMutex); 189 | return _res; 190 | } 191 | } // namespace ix 192 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXDNSLookup.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXDNSLookup.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | * 6 | * Resolve a hostname+port to a struct addrinfo obtained with getaddrinfo 7 | * Does this in a background thread so that it can be cancelled, since 8 | * getaddrinfo is a blocking call, and we don't want to block the main thread on Mobile. 9 | */ 10 | 11 | #pragma once 12 | 13 | #include "IXCancellationRequest.h" 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | struct addrinfo; 22 | 23 | namespace ix 24 | { 25 | class DNSLookup : public std::enable_shared_from_this 26 | { 27 | public: 28 | using AddrInfoPtr = std::shared_ptr; 29 | DNSLookup(const std::string& hostname, int port, int64_t wait = DNSLookup::kDefaultWait); 30 | ~DNSLookup() = default; 31 | 32 | AddrInfoPtr resolve(std::string& errMsg, 33 | const CancellationRequest& isCancellationRequested, 34 | bool cancellable = true); 35 | 36 | private: 37 | AddrInfoPtr resolveCancellable(std::string& errMsg, 38 | const CancellationRequest& isCancellationRequested); 39 | AddrInfoPtr resolveUnCancellable(std::string& errMsg, 40 | const CancellationRequest& isCancellationRequested); 41 | 42 | AddrInfoPtr getAddrInfo(const std::string& hostname, 43 | int port, 44 | std::string& errMsg); 45 | 46 | void run(std::weak_ptr self, std::string hostname, int port); // thread runner 47 | 48 | void setErrMsg(const std::string& errMsg); 49 | const std::string& getErrMsg(); 50 | 51 | void setRes(AddrInfoPtr addr); 52 | AddrInfoPtr getRes(); 53 | 54 | std::string _hostname; 55 | int _port; 56 | int64_t _wait; 57 | const static int64_t kDefaultWait; 58 | 59 | AddrInfoPtr _res; 60 | std::mutex _resMutex; 61 | 62 | std::string _errMsg; 63 | std::mutex _errMsgMutex; 64 | 65 | std::atomic _done; 66 | }; 67 | } // namespace ix 68 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXExponentialBackoff.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXExponentialBackoff.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXExponentialBackoff.h" 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | uint32_t calculateRetryWaitMilliseconds(uint32_t retryCount, 14 | uint32_t maxWaitBetweenReconnectionRetries, 15 | uint32_t minWaitBetweenReconnectionRetries) 16 | { 17 | // It's easy with a power function to go beyond 2^32, and then 18 | // have unexpected results, so prepare for that 19 | const uint32_t maxRetryCountWithoutOverflow = 26; 20 | 21 | uint32_t waitTime = 0; 22 | if (retryCount < maxRetryCountWithoutOverflow) 23 | { 24 | waitTime = std::pow(2, retryCount) * 100; 25 | } 26 | 27 | if (waitTime < minWaitBetweenReconnectionRetries) 28 | { 29 | waitTime = minWaitBetweenReconnectionRetries; 30 | } 31 | 32 | if (waitTime > maxWaitBetweenReconnectionRetries) 33 | { 34 | waitTime = maxWaitBetweenReconnectionRetries; 35 | } 36 | 37 | if (retryCount >= maxRetryCountWithoutOverflow) 38 | { 39 | waitTime = maxWaitBetweenReconnectionRetries; 40 | } 41 | 42 | return waitTime; 43 | } 44 | } // namespace ix 45 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXExponentialBackoff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXExponentialBackoff.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | uint32_t calculateRetryWaitMilliseconds(uint32_t retryCount, 14 | uint32_t maxWaitBetweenReconnectionRetries, 15 | uint32_t minWaitBetweenReconnectionRetries); 16 | } // namespace ix 17 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXGetFreePort.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXGetFreePort.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone. All rights reserved. 5 | */ 6 | 7 | // Using inet_addr will trigger an error on uwp without this 8 | // FIXME: use a different api 9 | #ifdef _WIN32 10 | #ifndef _WINSOCK_DEPRECATED_NO_WARNINGS 11 | #define _WINSOCK_DEPRECATED_NO_WARNINGS 12 | #endif 13 | #endif 14 | 15 | #include "IXGetFreePort.h" 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace ix 23 | { 24 | int getAnyFreePortRandom() 25 | { 26 | std::random_device rd; 27 | std::uniform_int_distribution dist(1024 + 1, 65535); 28 | 29 | return dist(rd); 30 | } 31 | 32 | int getAnyFreePort() 33 | { 34 | socket_t sockfd; 35 | if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) 36 | { 37 | return getAnyFreePortRandom(); 38 | } 39 | 40 | int enable = 1; 41 | if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char*) &enable, sizeof(enable)) < 0) 42 | { 43 | return getAnyFreePortRandom(); 44 | } 45 | 46 | // Bind to port 0. This is the standard way to get a free port. 47 | struct sockaddr_in server; // server address information 48 | server.sin_family = AF_INET; 49 | server.sin_port = htons(0); 50 | server.sin_addr.s_addr = inet_addr("127.0.0.1"); 51 | 52 | if (bind(sockfd, (struct sockaddr*) &server, sizeof(server)) < 0) 53 | { 54 | Socket::closeSocket(sockfd); 55 | return getAnyFreePortRandom(); 56 | } 57 | 58 | struct sockaddr_in sa; // server address information 59 | socklen_t len = sizeof(sa); 60 | if (getsockname(sockfd, (struct sockaddr*) &sa, &len) < 0) 61 | { 62 | Socket::closeSocket(sockfd); 63 | return getAnyFreePortRandom(); 64 | } 65 | 66 | int port = ntohs(sa.sin_port); 67 | Socket::closeSocket(sockfd); 68 | 69 | return port; 70 | } 71 | 72 | int getFreePort() 73 | { 74 | while (true) 75 | { 76 | #if defined(__has_feature) 77 | #if __has_feature(address_sanitizer) 78 | int port = getAnyFreePortRandom(); 79 | #else 80 | int port = getAnyFreePort(); 81 | #endif 82 | #else 83 | int port = getAnyFreePort(); 84 | #endif 85 | // 86 | // Only port above 1024 can be used by non root users, but for some 87 | // reason I got port 7 returned with macOS when binding on port 0... 88 | // 89 | if (port > 1024) 90 | { 91 | return port; 92 | } 93 | } 94 | 95 | return -1; 96 | } 97 | } // namespace ix 98 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXGetFreePort.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXGetFreePort.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | namespace ix 10 | { 11 | int getFreePort(); 12 | } // namespace ix 13 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXGzipCodec.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXGzipCodec.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXGzipCodec.h" 8 | 9 | #include "IXBench.h" 10 | #include 11 | #include 12 | 13 | #ifdef IXWEBSOCKET_USE_ZLIB 14 | #include 15 | #endif 16 | 17 | namespace ix 18 | { 19 | std::string gzipCompress(const std::string& str) 20 | { 21 | #ifndef IXWEBSOCKET_USE_ZLIB 22 | return std::string(); 23 | #else 24 | z_stream zs; // z_stream is zlib's control structure 25 | memset(&zs, 0, sizeof(zs)); 26 | 27 | // deflateInit2 configure the file format: request gzip instead of deflate 28 | const int windowBits = 15; 29 | const int GZIP_ENCODING = 16; 30 | 31 | deflateInit2(&zs, 32 | Z_DEFAULT_COMPRESSION, 33 | Z_DEFLATED, 34 | windowBits | GZIP_ENCODING, 35 | 8, 36 | Z_DEFAULT_STRATEGY); 37 | 38 | zs.next_in = (Bytef*) str.data(); 39 | zs.avail_in = (uInt) str.size(); // set the z_stream's input 40 | 41 | int ret; 42 | char outbuffer[32768]; 43 | std::string outstring; 44 | 45 | // retrieve the compressed bytes blockwise 46 | do 47 | { 48 | zs.next_out = reinterpret_cast(outbuffer); 49 | zs.avail_out = sizeof(outbuffer); 50 | 51 | ret = deflate(&zs, Z_FINISH); 52 | 53 | if (outstring.size() < zs.total_out) 54 | { 55 | // append the block to the output string 56 | outstring.append(outbuffer, zs.total_out - outstring.size()); 57 | } 58 | } while (ret == Z_OK); 59 | 60 | deflateEnd(&zs); 61 | 62 | return outstring; 63 | #endif // IXWEBSOCKET_USE_ZLIB 64 | } 65 | 66 | #ifdef IXWEBSOCKET_USE_DEFLATE 67 | static uint32_t loadDecompressedGzipSize(const uint8_t* p) 68 | { 69 | return ((uint32_t) p[0] << 0) | ((uint32_t) p[1] << 8) | ((uint32_t) p[2] << 16) | 70 | ((uint32_t) p[3] << 24); 71 | } 72 | #endif 73 | 74 | bool gzipDecompress(const std::string& in, std::string& out) 75 | { 76 | #ifndef IXWEBSOCKET_USE_ZLIB 77 | return false; 78 | #else 79 | z_stream inflateState; 80 | memset(&inflateState, 0, sizeof(inflateState)); 81 | 82 | inflateState.zalloc = Z_NULL; 83 | inflateState.zfree = Z_NULL; 84 | inflateState.opaque = Z_NULL; 85 | inflateState.avail_in = 0; 86 | inflateState.next_in = Z_NULL; 87 | 88 | if (inflateInit2(&inflateState, 16 + MAX_WBITS) != Z_OK) 89 | { 90 | return false; 91 | } 92 | 93 | inflateState.avail_in = (uInt) in.size(); 94 | inflateState.next_in = (unsigned char*) (const_cast(in.data())); 95 | 96 | const int kBufferSize = 1 << 14; 97 | std::array compressBuffer; 98 | 99 | do 100 | { 101 | inflateState.avail_out = (uInt) kBufferSize; 102 | inflateState.next_out = &compressBuffer.front(); 103 | 104 | int ret = inflate(&inflateState, Z_SYNC_FLUSH); 105 | 106 | if (ret == Z_NEED_DICT || ret == Z_DATA_ERROR || ret == Z_MEM_ERROR) 107 | { 108 | inflateEnd(&inflateState); 109 | return false; 110 | } 111 | 112 | out.append(reinterpret_cast(&compressBuffer.front()), 113 | kBufferSize - inflateState.avail_out); 114 | } while (inflateState.avail_out == 0); 115 | 116 | inflateEnd(&inflateState); 117 | return true; 118 | #endif // IXWEBSOCKET_USE_ZLIB 119 | } 120 | } // namespace ix 121 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXGzipCodec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXGzipCodec.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | std::string gzipCompress(const std::string& str); 14 | bool gzipDecompress(const std::string& in, std::string& out); 15 | } // namespace ix 16 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXHttp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXHttp.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXHttp.h" 8 | 9 | #include "IXCancellationRequest.h" 10 | #include "IXGzipCodec.h" 11 | #include "IXSocket.h" 12 | #include 13 | #include 14 | 15 | namespace ix 16 | { 17 | std::string Http::trim(const std::string& str) 18 | { 19 | std::string out; 20 | for (auto c : str) 21 | { 22 | if (c != ' ' && c != '\n' && c != '\r') 23 | { 24 | out += c; 25 | } 26 | } 27 | 28 | return out; 29 | } 30 | 31 | std::pair Http::parseStatusLine(const std::string& line) 32 | { 33 | // Request-Line = Method SP Request-URI SP HTTP-Version CRLF 34 | std::string token; 35 | std::stringstream tokenStream(line); 36 | std::vector tokens; 37 | 38 | // Split by ' ' 39 | while (std::getline(tokenStream, token, ' ')) 40 | { 41 | tokens.push_back(token); 42 | } 43 | 44 | std::string httpVersion; 45 | if (tokens.size() >= 1) 46 | { 47 | httpVersion = trim(tokens[0]); 48 | } 49 | 50 | int statusCode = -1; 51 | if (tokens.size() >= 2) 52 | { 53 | std::stringstream ss; 54 | ss << trim(tokens[1]); 55 | ss >> statusCode; 56 | } 57 | 58 | return std::make_pair(httpVersion, statusCode); 59 | } 60 | 61 | std::tuple Http::parseRequestLine( 62 | const std::string& line) 63 | { 64 | // Request-Line = Method SP Request-URI SP HTTP-Version CRLF 65 | std::string token; 66 | std::stringstream tokenStream(line); 67 | std::vector tokens; 68 | 69 | // Split by ' ' 70 | while (std::getline(tokenStream, token, ' ')) 71 | { 72 | tokens.push_back(token); 73 | } 74 | 75 | std::string method; 76 | if (tokens.size() >= 1) 77 | { 78 | method = trim(tokens[0]); 79 | } 80 | 81 | std::string requestUri; 82 | if (tokens.size() >= 2) 83 | { 84 | requestUri = trim(tokens[1]); 85 | } 86 | 87 | std::string httpVersion; 88 | if (tokens.size() >= 3) 89 | { 90 | httpVersion = trim(tokens[2]); 91 | } 92 | 93 | return std::make_tuple(method, requestUri, httpVersion); 94 | } 95 | 96 | std::tuple Http::parseRequest( 97 | std::unique_ptr& socket, int timeoutSecs) 98 | { 99 | HttpRequestPtr httpRequest; 100 | 101 | std::atomic requestInitCancellation(false); 102 | 103 | auto isCancellationRequested = 104 | makeCancellationRequestWithTimeout(timeoutSecs, requestInitCancellation); 105 | 106 | // Read first line 107 | auto lineResult = socket->readLine(isCancellationRequested); 108 | auto lineValid = lineResult.first; 109 | auto line = lineResult.second; 110 | 111 | if (!lineValid) 112 | { 113 | return std::make_tuple(false, "Error reading HTTP request line", httpRequest); 114 | } 115 | 116 | // Parse request line (GET /foo HTTP/1.1\r\n) 117 | auto requestLine = Http::parseRequestLine(line); 118 | auto method = std::get<0>(requestLine); 119 | auto uri = std::get<1>(requestLine); 120 | auto httpVersion = std::get<2>(requestLine); 121 | 122 | // Retrieve and validate HTTP headers 123 | auto result = parseHttpHeaders(socket, isCancellationRequested); 124 | auto headersValid = result.first; 125 | auto headers = result.second; 126 | 127 | if (!headersValid) 128 | { 129 | return std::make_tuple(false, "Error parsing HTTP headers", httpRequest); 130 | } 131 | 132 | std::string body; 133 | if (headers.find("Content-Length") != headers.end()) 134 | { 135 | int contentLength = 0; 136 | try 137 | { 138 | contentLength = std::stoi(headers["Content-Length"]); 139 | } 140 | catch (const std::exception&) 141 | { 142 | return std::make_tuple( 143 | false, "Error parsing HTTP Header 'Content-Length'", httpRequest); 144 | } 145 | 146 | if (contentLength < 0) 147 | { 148 | return std::make_tuple( 149 | false, "Error: 'Content-Length' should be a positive integer", httpRequest); 150 | } 151 | 152 | auto res = socket->readBytes(contentLength, nullptr, nullptr, isCancellationRequested); 153 | if (!res.first) 154 | { 155 | return std::make_tuple( 156 | false, std::string("Error reading request: ") + res.second, httpRequest); 157 | } 158 | body = res.second; 159 | } 160 | 161 | // If the content was compressed with gzip, decode it 162 | if (headers["Content-Encoding"] == "gzip") 163 | { 164 | #ifdef IXWEBSOCKET_USE_ZLIB 165 | std::string decompressedPayload; 166 | if (!gzipDecompress(body, decompressedPayload)) 167 | { 168 | return std::make_tuple( 169 | false, std::string("Error during gzip decompression of the body"), httpRequest); 170 | } 171 | body = decompressedPayload; 172 | #else 173 | std::string errorMsg("ixwebsocket was not compiled with gzip support on"); 174 | return std::make_tuple(false, errorMsg, httpRequest); 175 | #endif 176 | } 177 | 178 | httpRequest = std::make_shared(uri, method, httpVersion, body, headers); 179 | return std::make_tuple(true, "", httpRequest); 180 | } 181 | 182 | bool Http::sendResponse(HttpResponsePtr response, std::unique_ptr& socket) 183 | { 184 | // Write the response to the socket 185 | std::stringstream ss; 186 | ss << "HTTP/1.1 "; 187 | ss << response->statusCode; 188 | ss << " "; 189 | ss << response->description; 190 | ss << "\r\n"; 191 | 192 | if (!socket->writeBytes(ss.str(), nullptr)) 193 | { 194 | return false; 195 | } 196 | 197 | // Write headers 198 | ss.str(""); 199 | ss << "Content-Length: " << response->body.size() << "\r\n"; 200 | for (auto&& it : response->headers) 201 | { 202 | ss << it.first << ": " << it.second << "\r\n"; 203 | } 204 | ss << "\r\n"; 205 | 206 | if (!socket->writeBytes(ss.str(), nullptr)) 207 | { 208 | return false; 209 | } 210 | 211 | return response->body.empty() ? true : socket->writeBytes(response->body, nullptr); 212 | } 213 | } // namespace ix 214 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXHttp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXHttp.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXProgressCallback.h" 10 | #include "IXWebSocketHttpHeaders.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace ix 17 | { 18 | enum class HttpErrorCode : int 19 | { 20 | Ok = 0, 21 | CannotConnect = 1, 22 | Timeout = 2, 23 | Gzip = 3, 24 | UrlMalformed = 4, 25 | CannotCreateSocket = 5, 26 | SendError = 6, 27 | ReadError = 7, 28 | CannotReadStatusLine = 8, 29 | MissingStatus = 9, 30 | HeaderParsingError = 10, 31 | MissingLocation = 11, 32 | TooManyRedirects = 12, 33 | ChunkReadError = 13, 34 | CannotReadBody = 14, 35 | Cancelled = 15, 36 | Invalid = 100 37 | }; 38 | 39 | struct HttpResponse 40 | { 41 | int statusCode; 42 | std::string description; 43 | HttpErrorCode errorCode; 44 | WebSocketHttpHeaders headers; 45 | std::string body; 46 | std::string errorMsg; 47 | uint64_t uploadSize; 48 | uint64_t downloadSize; 49 | 50 | HttpResponse(int s = 0, 51 | const std::string& des = std::string(), 52 | const HttpErrorCode& c = HttpErrorCode::Ok, 53 | const WebSocketHttpHeaders& h = WebSocketHttpHeaders(), 54 | const std::string& b = std::string(), 55 | const std::string& e = std::string(), 56 | uint64_t u = 0, 57 | uint64_t d = 0) 58 | : statusCode(s) 59 | , description(des) 60 | , errorCode(c) 61 | , headers(h) 62 | , body(b) 63 | , errorMsg(e) 64 | , uploadSize(u) 65 | , downloadSize(d) 66 | { 67 | ; 68 | } 69 | }; 70 | 71 | using HttpResponsePtr = std::shared_ptr; 72 | using HttpParameters = std::unordered_map; 73 | using HttpFormDataParameters = std::unordered_map; 74 | using Logger = std::function; 75 | using OnResponseCallback = std::function; 76 | 77 | struct HttpRequestArgs 78 | { 79 | std::string url; 80 | std::string verb; 81 | WebSocketHttpHeaders extraHeaders; 82 | std::string body; 83 | std::string multipartBoundary; 84 | int connectTimeout = 60; 85 | int transferTimeout = 1800; 86 | bool followRedirects = true; 87 | int maxRedirects = 5; 88 | bool verbose = false; 89 | bool compress = true; 90 | bool compressRequest = false; 91 | Logger logger; 92 | OnProgressCallback onProgressCallback; 93 | OnChunkCallback onChunkCallback; 94 | std::atomic cancel; 95 | }; 96 | 97 | using HttpRequestArgsPtr = std::shared_ptr; 98 | 99 | struct HttpRequest 100 | { 101 | std::string uri; 102 | std::string method; 103 | std::string version; 104 | std::string body; 105 | WebSocketHttpHeaders headers; 106 | 107 | HttpRequest(const std::string& u, 108 | const std::string& m, 109 | const std::string& v, 110 | const std::string& b, 111 | const WebSocketHttpHeaders& h = WebSocketHttpHeaders()) 112 | : uri(u) 113 | , method(m) 114 | , version(v) 115 | , body(b) 116 | , headers(h) 117 | { 118 | } 119 | }; 120 | 121 | using HttpRequestPtr = std::shared_ptr; 122 | 123 | class Http 124 | { 125 | public: 126 | static std::tuple parseRequest( 127 | std::unique_ptr& socket, int timeoutSecs); 128 | static bool sendResponse(HttpResponsePtr response, std::unique_ptr& socket); 129 | 130 | static std::pair parseStatusLine(const std::string& line); 131 | static std::tuple parseRequestLine( 132 | const std::string& line); 133 | static std::string trim(const std::string& str); 134 | }; 135 | } // namespace ix 136 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXHttpClient.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXHttpClient.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXHttp.h" 10 | #include "IXSocket.h" 11 | #include "IXSocketTLSOptions.h" 12 | #include "IXWebSocketHttpHeaders.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace ix 24 | { 25 | class HttpClient 26 | { 27 | public: 28 | HttpClient(bool async = false); 29 | ~HttpClient(); 30 | 31 | HttpResponsePtr get(const std::string& url, HttpRequestArgsPtr args); 32 | HttpResponsePtr head(const std::string& url, HttpRequestArgsPtr args); 33 | HttpResponsePtr Delete(const std::string& url, HttpRequestArgsPtr args); 34 | 35 | HttpResponsePtr post(const std::string& url, 36 | const HttpParameters& httpParameters, 37 | const HttpFormDataParameters& httpFormDataParameters, 38 | HttpRequestArgsPtr args); 39 | HttpResponsePtr post(const std::string& url, 40 | const std::string& body, 41 | HttpRequestArgsPtr args); 42 | 43 | HttpResponsePtr put(const std::string& url, 44 | const HttpParameters& httpParameters, 45 | const HttpFormDataParameters& httpFormDataParameters, 46 | HttpRequestArgsPtr args); 47 | HttpResponsePtr put(const std::string& url, 48 | const std::string& body, 49 | HttpRequestArgsPtr args); 50 | 51 | HttpResponsePtr patch(const std::string& url, 52 | const HttpParameters& httpParameters, 53 | const HttpFormDataParameters& httpFormDataParameters, 54 | HttpRequestArgsPtr args); 55 | HttpResponsePtr patch(const std::string& url, 56 | const std::string& body, 57 | HttpRequestArgsPtr args); 58 | 59 | HttpResponsePtr request(const std::string& url, 60 | const std::string& verb, 61 | const std::string& body, 62 | HttpRequestArgsPtr args, 63 | int redirects = 0); 64 | 65 | HttpResponsePtr request(const std::string& url, 66 | const std::string& verb, 67 | const HttpParameters& httpParameters, 68 | const HttpFormDataParameters& httpFormDataParameters, 69 | HttpRequestArgsPtr args); 70 | 71 | void setForceBody(bool value); 72 | 73 | // Async API 74 | HttpRequestArgsPtr createRequest(const std::string& url = std::string(), 75 | const std::string& verb = HttpClient::kGet); 76 | 77 | bool performRequest(HttpRequestArgsPtr request, 78 | const OnResponseCallback& onResponseCallback); 79 | 80 | // TLS 81 | void setTLSOptions(const SocketTLSOptions& tlsOptions); 82 | 83 | std::string serializeHttpParameters(const HttpParameters& httpParameters); 84 | 85 | std::string serializeHttpFormDataParameters( 86 | const std::string& multipartBoundary, 87 | const HttpFormDataParameters& httpFormDataParameters, 88 | const HttpParameters& httpParameters = HttpParameters()); 89 | 90 | std::string generateMultipartBoundary(); 91 | 92 | std::string urlEncode(const std::string& value); 93 | 94 | const static std::string kPost; 95 | const static std::string kGet; 96 | const static std::string kHead; 97 | const static std::string kDelete; 98 | const static std::string kPut; 99 | const static std::string kPatch; 100 | 101 | private: 102 | void log(const std::string& msg, HttpRequestArgsPtr args); 103 | 104 | // Async API background thread runner 105 | void run(); 106 | // Async API 107 | bool _async; 108 | std::queue> _queue; 109 | mutable std::mutex _queueMutex; 110 | std::condition_variable _condition; 111 | std::atomic _stop; 112 | std::thread _thread; 113 | 114 | std::unique_ptr _socket; 115 | std::recursive_mutex _mutex; // to protect accessing the _socket (only one socket per 116 | // client) the mutex needs to be recursive as this function 117 | // might be called recursively to follow HTTP redirections 118 | 119 | SocketTLSOptions _tlsOptions; 120 | 121 | bool _forceBody; 122 | }; 123 | } // namespace ix 124 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXHttpServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXHttpServer.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXHttp.h" 10 | #include "IXWebSocket.h" 11 | #include "IXWebSocketServer.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include // pair 19 | 20 | namespace ix 21 | { 22 | class HttpServer final : public WebSocketServer 23 | { 24 | public: 25 | using OnConnectionCallback = 26 | std::function)>; 27 | 28 | HttpServer(int port = SocketServer::kDefaultPort, 29 | const std::string& host = SocketServer::kDefaultHost, 30 | int backlog = SocketServer::kDefaultTcpBacklog, 31 | size_t maxConnections = SocketServer::kDefaultMaxConnections, 32 | int addressFamily = SocketServer::kDefaultAddressFamily, 33 | int timeoutSecs = HttpServer::kDefaultTimeoutSecs, 34 | int handshakeTimeoutSecs = WebSocketServer::kDefaultHandShakeTimeoutSecs); 35 | 36 | void setOnConnectionCallback(const OnConnectionCallback& callback); 37 | 38 | void makeRedirectServer(const std::string& redirectUrl); 39 | 40 | void makeDebugServer(); 41 | 42 | int getTimeoutSecs(); 43 | 44 | private: 45 | // Member variables 46 | OnConnectionCallback _onConnectionCallback; 47 | 48 | const static int kDefaultTimeoutSecs; 49 | int _timeoutSecs; 50 | 51 | // Methods 52 | virtual void handleConnection(std::unique_ptr, 53 | std::shared_ptr connectionState) final; 54 | 55 | void setDefaultConnectionCallback(); 56 | }; 57 | } // namespace ix 58 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXNetSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXNetSystem.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | #ifdef __FreeBSD__ 12 | #include 13 | #endif 14 | 15 | #ifdef _WIN32 16 | 17 | #ifndef WIN32_LEAN_AND_MEAN 18 | #define WIN32_LEAN_AND_MEAN 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #undef EWOULDBLOCK 29 | #undef EAGAIN 30 | #undef EINPROGRESS 31 | #undef EBADF 32 | #undef EINVAL 33 | 34 | // map to WSA error codes 35 | #define EWOULDBLOCK WSAEWOULDBLOCK 36 | #define EAGAIN WSATRY_AGAIN 37 | #define EINPROGRESS WSAEINPROGRESS 38 | #define EBADF WSAEBADF 39 | #define EINVAL WSAEINVAL 40 | 41 | // Define our own poll on Windows, as a wrapper on top of select 42 | typedef unsigned long int nfds_t; 43 | 44 | // pollfd is not defined by some versions of mingw64 since _WIN32_WINNT is too low 45 | #if _WIN32_WINNT < 0x0600 46 | struct pollfd 47 | { 48 | int fd; /* file descriptor */ 49 | short events; /* requested events */ 50 | short revents; /* returned events */ 51 | }; 52 | 53 | #define POLLIN 0x001 /* There is data to read. */ 54 | #define POLLOUT 0x004 /* Writing now will not block. */ 55 | #define POLLERR 0x008 /* Error condition. */ 56 | #define POLLHUP 0x010 /* Hung up. */ 57 | #define POLLNVAL 0x020 /* Invalid polling request. */ 58 | #endif 59 | 60 | #else 61 | #include 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | #include 68 | #include 69 | #include 70 | #include 71 | #include 72 | #include 73 | #include 74 | #endif 75 | 76 | namespace ix 77 | { 78 | #ifdef _WIN32 79 | typedef SOCKET socket_t; 80 | #else 81 | typedef int socket_t; 82 | #endif 83 | 84 | bool initNetSystem(); 85 | bool uninitNetSystem(); 86 | 87 | int poll(struct pollfd* fds, nfds_t nfds, int timeout, void** event); 88 | 89 | const char* inet_ntop(int af, const void* src, char* dst, socklen_t size); 90 | int inet_pton(int af, const char* src, void* dst); 91 | 92 | unsigned short network_to_host_short(unsigned short value); 93 | } // namespace ix 94 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXProgressCallback.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXProgressCallback.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | using OnProgressCallback = std::function; 15 | using OnChunkCallback = std::function; 16 | } 17 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterrupt.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterrupt.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXSelectInterrupt.h" 8 | 9 | namespace ix 10 | { 11 | const uint64_t SelectInterrupt::kSendRequest = 1; 12 | const uint64_t SelectInterrupt::kCloseRequest = 2; 13 | 14 | SelectInterrupt::SelectInterrupt() 15 | { 16 | ; 17 | } 18 | 19 | SelectInterrupt::~SelectInterrupt() 20 | { 21 | ; 22 | } 23 | 24 | bool SelectInterrupt::init(std::string& /*errorMsg*/) 25 | { 26 | return true; 27 | } 28 | 29 | bool SelectInterrupt::notify(uint64_t /*value*/) 30 | { 31 | return true; 32 | } 33 | 34 | uint64_t SelectInterrupt::read() 35 | { 36 | return 0; 37 | } 38 | 39 | bool SelectInterrupt::clear() 40 | { 41 | return true; 42 | } 43 | 44 | int SelectInterrupt::getFd() const 45 | { 46 | return -1; 47 | } 48 | 49 | void* SelectInterrupt::getEvent() const 50 | { 51 | return nullptr; 52 | } 53 | } // namespace ix 54 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterrupt.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterrupt.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | class SelectInterrupt 16 | { 17 | public: 18 | SelectInterrupt(); 19 | virtual ~SelectInterrupt(); 20 | 21 | virtual bool init(std::string& errorMsg); 22 | 23 | virtual bool notify(uint64_t value); 24 | virtual bool clear(); 25 | virtual uint64_t read(); 26 | virtual int getFd() const; 27 | virtual void* getEvent() const; 28 | 29 | // Used as special codes for pipe communication 30 | static const uint64_t kSendRequest; 31 | static const uint64_t kCloseRequest; 32 | }; 33 | 34 | using SelectInterruptPtr = std::unique_ptr; 35 | } // namespace ix 36 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptEvent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptEvent.cpp 3 | */ 4 | 5 | // 6 | // On Windows we use a Windows Event to wake up ix::poll() (WSAWaitForMultipleEvents). 7 | // And on any other platform that doesn't support pipe file descriptors we 8 | // emulate the interrupt event by using a short timeout with ix::poll() and 9 | // read from the SelectInterrupt. (see Socket::poll() "Emulation mode") 10 | // 11 | #include 12 | #include "IXSelectInterruptEvent.h" 13 | 14 | namespace ix 15 | { 16 | SelectInterruptEvent::SelectInterruptEvent() 17 | { 18 | #ifdef _WIN32 19 | _event = CreateEvent(NULL, TRUE, FALSE, NULL); 20 | #endif 21 | } 22 | 23 | SelectInterruptEvent::~SelectInterruptEvent() 24 | { 25 | #ifdef _WIN32 26 | CloseHandle(_event); 27 | #endif 28 | } 29 | 30 | bool SelectInterruptEvent::init(std::string& /*errorMsg*/) 31 | { 32 | return true; 33 | } 34 | 35 | bool SelectInterruptEvent::notify(uint64_t value) 36 | { 37 | std::lock_guard lock(_valuesMutex); 38 | 39 | // WebSocket implementation detail: We only need one of the values in the queue 40 | if (std::find(_values.begin(), _values.end(), value) == _values.end()) 41 | _values.push_back(value); 42 | #ifdef _WIN32 43 | SetEvent(_event); // wake up 44 | #endif 45 | return true; 46 | } 47 | 48 | uint64_t SelectInterruptEvent::read() 49 | { 50 | std::lock_guard lock(_valuesMutex); 51 | 52 | if (_values.size() > 0) 53 | { 54 | uint64_t value = _values.front(); 55 | _values.pop_front(); 56 | #ifdef _WIN32 57 | // signal the event if there is still data in the queue 58 | if (_values.size() == 0) 59 | ResetEvent(_event); 60 | #endif 61 | return value; 62 | } 63 | return 0; 64 | } 65 | 66 | bool SelectInterruptEvent::clear() 67 | { 68 | std::lock_guard lock(_valuesMutex); 69 | _values.clear(); 70 | #ifdef _WIN32 71 | ResetEvent(_event); 72 | #endif 73 | return true; 74 | } 75 | 76 | void* SelectInterruptEvent::getEvent() const 77 | { 78 | #ifdef _WIN32 79 | return reinterpret_cast(_event); 80 | #else 81 | return nullptr; 82 | #endif 83 | } 84 | 85 | } // namespace ix 86 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptEvent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptEvent.h 3 | */ 4 | 5 | #pragma once 6 | 7 | #include "IXSelectInterrupt.h" 8 | #include 9 | #include 10 | #include 11 | #include 12 | #ifdef _WIN32 13 | #include 14 | #endif 15 | 16 | namespace ix 17 | { 18 | class SelectInterruptEvent final : public SelectInterrupt 19 | { 20 | public: 21 | SelectInterruptEvent(); 22 | virtual ~SelectInterruptEvent(); 23 | 24 | bool init(std::string& /*errorMsg*/) final; 25 | 26 | bool notify(uint64_t value) final; 27 | bool clear() final; 28 | uint64_t read() final; 29 | void* getEvent() const final; 30 | private: 31 | // contains every value only once, new values are inserted at the begin, nu 32 | std::deque _values; 33 | std::mutex _valuesMutex; 34 | #ifdef _WIN32 35 | // Windows Event to wake up the socket poll 36 | HANDLE _event; 37 | #endif 38 | }; 39 | } // namespace ix 40 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptFactory.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXSelectInterruptFactory.h" 8 | 9 | #include "IXUniquePtr.h" 10 | #if _WIN32 11 | #include "IXSelectInterruptEvent.h" 12 | #else 13 | #include "IXSelectInterruptPipe.h" 14 | #endif 15 | 16 | namespace ix 17 | { 18 | SelectInterruptPtr createSelectInterrupt() 19 | { 20 | #ifdef _WIN32 21 | return ix::make_unique(); 22 | #else 23 | return ix::make_unique(); 24 | #endif 25 | } 26 | } // namespace ix 27 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptFactory.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptFactory.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | class SelectInterrupt; 14 | using SelectInterruptPtr = std::unique_ptr; 15 | SelectInterruptPtr createSelectInterrupt(); 16 | } // namespace ix 17 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptPipe.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptPipe.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | // 8 | // On UNIX we use pipes to wake up select. There is no way to do that 9 | // on Windows so this file is compiled out on Windows. 10 | // 11 | #ifndef _WIN32 12 | 13 | #include "IXSelectInterruptPipe.h" 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include // for strerror 20 | #include // for write 21 | 22 | namespace ix 23 | { 24 | // File descriptor at index 0 in _fildes is the read end of the pipe 25 | // File descriptor at index 1 in _fildes is the write end of the pipe 26 | const int SelectInterruptPipe::kPipeReadIndex = 0; 27 | const int SelectInterruptPipe::kPipeWriteIndex = 1; 28 | 29 | SelectInterruptPipe::SelectInterruptPipe() 30 | { 31 | _fildes[kPipeReadIndex] = -1; 32 | _fildes[kPipeWriteIndex] = -1; 33 | } 34 | 35 | SelectInterruptPipe::~SelectInterruptPipe() 36 | { 37 | ::close(_fildes[kPipeReadIndex]); 38 | ::close(_fildes[kPipeWriteIndex]); 39 | _fildes[kPipeReadIndex] = -1; 40 | _fildes[kPipeWriteIndex] = -1; 41 | } 42 | 43 | bool SelectInterruptPipe::init(std::string& errorMsg) 44 | { 45 | std::lock_guard lock(_fildesMutex); 46 | 47 | // calling init twice is a programming error 48 | assert(_fildes[kPipeReadIndex] == -1); 49 | assert(_fildes[kPipeWriteIndex] == -1); 50 | 51 | if (pipe(_fildes) < 0) 52 | { 53 | std::stringstream ss; 54 | ss << "SelectInterruptPipe::init() failed in pipe() call" 55 | << " : " << strerror(errno); 56 | errorMsg = ss.str(); 57 | return false; 58 | } 59 | 60 | if (fcntl(_fildes[kPipeReadIndex], F_SETFL, O_NONBLOCK) == -1) 61 | { 62 | std::stringstream ss; 63 | ss << "SelectInterruptPipe::init() failed in fcntl(..., O_NONBLOCK) call" 64 | << " : " << strerror(errno); 65 | errorMsg = ss.str(); 66 | 67 | _fildes[kPipeReadIndex] = -1; 68 | _fildes[kPipeWriteIndex] = -1; 69 | return false; 70 | } 71 | 72 | if (fcntl(_fildes[kPipeWriteIndex], F_SETFL, O_NONBLOCK) == -1) 73 | { 74 | std::stringstream ss; 75 | ss << "SelectInterruptPipe::init() failed in fcntl(..., O_NONBLOCK) call" 76 | << " : " << strerror(errno); 77 | errorMsg = ss.str(); 78 | 79 | _fildes[kPipeReadIndex] = -1; 80 | _fildes[kPipeWriteIndex] = -1; 81 | return false; 82 | } 83 | 84 | #ifdef F_SETNOSIGPIPE 85 | if (fcntl(_fildes[kPipeWriteIndex], F_SETNOSIGPIPE, 1) == -1) 86 | { 87 | std::stringstream ss; 88 | ss << "SelectInterruptPipe::init() failed in fcntl(.... F_SETNOSIGPIPE) call" 89 | << " : " << strerror(errno); 90 | errorMsg = ss.str(); 91 | 92 | _fildes[kPipeReadIndex] = -1; 93 | _fildes[kPipeWriteIndex] = -1; 94 | return false; 95 | } 96 | 97 | if (fcntl(_fildes[kPipeWriteIndex], F_SETNOSIGPIPE, 1) == -1) 98 | { 99 | std::stringstream ss; 100 | ss << "SelectInterruptPipe::init() failed in fcntl(..., F_SETNOSIGPIPE) call" 101 | << " : " << strerror(errno); 102 | errorMsg = ss.str(); 103 | 104 | _fildes[kPipeReadIndex] = -1; 105 | _fildes[kPipeWriteIndex] = -1; 106 | return false; 107 | } 108 | #endif 109 | 110 | return true; 111 | } 112 | 113 | bool SelectInterruptPipe::notify(uint64_t value) 114 | { 115 | std::lock_guard lock(_fildesMutex); 116 | 117 | int fd = _fildes[kPipeWriteIndex]; 118 | if (fd == -1) return false; 119 | 120 | ssize_t ret = -1; 121 | do 122 | { 123 | ret = ::write(fd, &value, sizeof(value)); 124 | } while (ret == -1 && errno == EINTR); 125 | 126 | // we should write 8 bytes for an uint64_t 127 | return ret == 8; 128 | } 129 | 130 | // TODO: return max uint64_t for errors ? 131 | uint64_t SelectInterruptPipe::read() 132 | { 133 | std::lock_guard lock(_fildesMutex); 134 | 135 | int fd = _fildes[kPipeReadIndex]; 136 | 137 | uint64_t value = 0; 138 | 139 | ssize_t ret = -1; 140 | do 141 | { 142 | ret = ::read(fd, &value, sizeof(value)); 143 | } while (ret == -1 && errno == EINTR); 144 | 145 | return value; 146 | } 147 | 148 | bool SelectInterruptPipe::clear() 149 | { 150 | return true; 151 | } 152 | 153 | int SelectInterruptPipe::getFd() const 154 | { 155 | std::lock_guard lock(_fildesMutex); 156 | 157 | return _fildes[kPipeReadIndex]; 158 | } 159 | } // namespace ix 160 | 161 | #endif // !_WIN32 162 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSelectInterruptPipe.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSelectInterruptPipe.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXSelectInterrupt.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | namespace ix 16 | { 17 | class SelectInterruptPipe final : public SelectInterrupt 18 | { 19 | public: 20 | SelectInterruptPipe(); 21 | virtual ~SelectInterruptPipe(); 22 | 23 | bool init(std::string& errorMsg) final; 24 | 25 | bool notify(uint64_t value) final; 26 | bool clear() final; 27 | uint64_t read() final; 28 | int getFd() const final; 29 | 30 | private: 31 | // Store file descriptors used by the communication pipe. Communication 32 | // happens between a control thread and a background thread, which is 33 | // blocked on select. 34 | int _fildes[2]; 35 | mutable std::mutex _fildesMutex; 36 | 37 | // Used to identify the read/write idx 38 | static const int kPipeReadIndex; 39 | static const int kPipeWriteIndex; 40 | }; 41 | } // namespace ix 42 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSetThreadName.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSetThreadName.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #include "IXSetThreadName.h" 7 | 8 | // unix systems 9 | #if defined(__APPLE__) || defined(__linux__) || defined(BSD) 10 | #include 11 | #endif 12 | 13 | // freebsd needs this header as well 14 | #if defined(BSD) 15 | #include 16 | #endif 17 | 18 | // Windows 19 | #ifdef _WIN32 20 | #include 21 | #endif 22 | 23 | namespace ix 24 | { 25 | #ifdef _WIN32 26 | const DWORD MS_VC_EXCEPTION = 0x406D1388; 27 | 28 | #pragma pack(push, 8) 29 | typedef struct tagTHREADNAME_INFO 30 | { 31 | DWORD dwType; // Must be 0x1000. 32 | LPCSTR szName; // Pointer to name (in user addr space). 33 | DWORD dwThreadID; // Thread ID (-1=caller thread). 34 | DWORD dwFlags; // Reserved for future use, must be zero. 35 | } THREADNAME_INFO; 36 | #pragma pack(pop) 37 | 38 | void SetThreadName(DWORD dwThreadID, const char* threadName) 39 | { 40 | #ifndef __GNUC__ 41 | THREADNAME_INFO info; 42 | info.dwType = 0x1000; 43 | info.szName = threadName; 44 | info.dwThreadID = dwThreadID; 45 | info.dwFlags = 0; 46 | 47 | __try 48 | { 49 | RaiseException( 50 | MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR*) &info); 51 | } 52 | __except (EXCEPTION_EXECUTE_HANDLER) 53 | { 54 | } 55 | #endif 56 | } 57 | #endif 58 | 59 | void setThreadName(const std::string& name) 60 | { 61 | #if defined(__APPLE__) 62 | // 63 | // Apple reserves 16 bytes for its thread names 64 | // Notice that the Apple version of pthread_setname_np 65 | // does not take a pthread_t argument 66 | // 67 | pthread_setname_np(name.substr(0, 63).c_str()); 68 | #elif defined(__linux__) 69 | // 70 | // Linux only reserves 16 bytes for its thread names 71 | // See prctl and PR_SET_NAME property in 72 | // http://man7.org/linux/man-pages/man2/prctl.2.html 73 | // 74 | pthread_setname_np(pthread_self(), name.substr(0, 15).c_str()); 75 | #elif defined(_WIN32) 76 | SetThreadName(-1, name.c_str()); 77 | #elif defined(BSD) 78 | pthread_set_name_np(pthread_self(), name.substr(0, 15).c_str()); 79 | #else 80 | // ... assert here ? 81 | #endif 82 | } 83 | } // namespace ix 84 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSetThreadName.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSetThreadName.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #pragma once 7 | #include 8 | 9 | namespace ix 10 | { 11 | void setThreadName(const std::string& name); 12 | } 13 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocket.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #ifdef _WIN32 17 | #include 18 | #ifdef _MSC_VER 19 | typedef SSIZE_T ssize_t; 20 | #endif 21 | #endif 22 | 23 | #include "IXCancellationRequest.h" 24 | #include "IXProgressCallback.h" 25 | #include "IXSelectInterrupt.h" 26 | 27 | namespace ix 28 | { 29 | enum class PollResultType 30 | { 31 | ReadyForRead = 0, 32 | ReadyForWrite = 1, 33 | Timeout = 2, 34 | Error = 3, 35 | SendRequest = 4, 36 | CloseRequest = 5 37 | }; 38 | 39 | class Socket 40 | { 41 | public: 42 | Socket(int fd = -1); 43 | virtual ~Socket(); 44 | bool init(std::string& errorMsg); 45 | 46 | // Functions to check whether there is activity on the socket 47 | PollResultType poll(int timeoutMs = kDefaultPollTimeout); 48 | bool wakeUpFromPoll(uint64_t wakeUpCode); 49 | bool isWakeUpFromPollSupported(); 50 | 51 | PollResultType isReadyToWrite(int timeoutMs); 52 | PollResultType isReadyToRead(int timeoutMs); 53 | 54 | // Virtual methods 55 | virtual bool accept(std::string& errMsg); 56 | 57 | virtual bool connect(const std::string& host, 58 | int port, 59 | std::string& errMsg, 60 | const CancellationRequest& isCancellationRequested); 61 | virtual void close(); 62 | 63 | virtual ssize_t send(char* buffer, size_t length); 64 | ssize_t send(const std::string& buffer); 65 | virtual ssize_t recv(void* buffer, size_t length); 66 | 67 | // Blocking and cancellable versions, working with socket that can be set 68 | // to non blocking mode. Used during HTTP upgrade. 69 | bool readByte(void* buffer, const CancellationRequest& isCancellationRequested); 70 | bool writeBytes(const std::string& str, const CancellationRequest& isCancellationRequested); 71 | 72 | std::pair readLine(const CancellationRequest& isCancellationRequested); 73 | std::pair readBytes(size_t length, 74 | const OnProgressCallback& onProgressCallback, 75 | const OnChunkCallback& onChunkCallback, 76 | const CancellationRequest& isCancellationRequested); 77 | 78 | static int getErrno(); 79 | static bool isWaitNeeded(); 80 | static void closeSocket(int fd); 81 | 82 | static PollResultType poll(bool readyToRead, 83 | int timeoutMs, 84 | int sockfd, 85 | const SelectInterruptPtr& selectInterrupt); 86 | 87 | protected: 88 | std::atomic _sockfd; 89 | std::mutex _socketMutex; 90 | 91 | static bool readSelectInterruptRequest(const SelectInterruptPtr& selectInterrupt, 92 | PollResultType* pollResult); 93 | 94 | private: 95 | static const int kDefaultPollTimeout; 96 | static const int kDefaultPollNoTimeout; 97 | 98 | SelectInterruptPtr _selectInterrupt; 99 | }; 100 | } // namespace ix 101 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketAppleSSL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketAppleSSL.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #ifdef IXWEBSOCKET_USE_SECURE_TRANSPORT 7 | 8 | #pragma once 9 | 10 | #include "IXCancellationRequest.h" 11 | #include "IXSocket.h" 12 | #include "IXSocketTLSOptions.h" 13 | #include 14 | #include 15 | #include 16 | 17 | namespace ix 18 | { 19 | class SocketAppleSSL final : public Socket 20 | { 21 | public: 22 | SocketAppleSSL(const SocketTLSOptions& tlsOptions, int fd = -1); 23 | ~SocketAppleSSL(); 24 | 25 | virtual bool accept(std::string& errMsg) final; 26 | 27 | virtual bool connect(const std::string& host, 28 | int port, 29 | std::string& errMsg, 30 | const CancellationRequest& isCancellationRequested) final; 31 | virtual void close() final; 32 | 33 | virtual ssize_t send(char* buffer, size_t length) final; 34 | virtual ssize_t recv(void* buffer, size_t length) final; 35 | 36 | private: 37 | static std::string getSSLErrorDescription(OSStatus status); 38 | static OSStatus writeToSocket(SSLConnectionRef connection, const void* data, size_t* len); 39 | static OSStatus readFromSocket(SSLConnectionRef connection, void* data, size_t* len); 40 | 41 | OSStatus tlsHandShake(std::string& errMsg, 42 | const CancellationRequest& isCancellationRequested); 43 | 44 | SSLContextRef _sslContext; 45 | mutable std::mutex _mutex; // AppleSSL routines are not thread-safe 46 | 47 | SocketTLSOptions _tlsOptions; 48 | }; 49 | 50 | } // namespace ix 51 | 52 | #endif // IXWEBSOCKET_USE_SECURE_TRANSPORT 53 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketConnect.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketConnect.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXSocketConnect.h" 8 | 9 | #include "IXDNSLookup.h" 10 | #include "IXNetSystem.h" 11 | #include "IXSelectInterrupt.h" 12 | #include "IXSocket.h" 13 | #include "IXUniquePtr.h" 14 | #include 15 | #include 16 | #include 17 | 18 | // Android needs extra headers for TCP_NODELAY and IPPROTO_TCP 19 | #ifdef ANDROID 20 | #include 21 | #include 22 | #endif 23 | #include 24 | 25 | namespace ix 26 | { 27 | // 28 | // This function can be cancelled every 50 ms 29 | // This is important so that we don't block the main UI thread when shutting down a 30 | // connection which is already trying to reconnect, and can be blocked waiting for 31 | // ::connect to respond. 32 | // 33 | int SocketConnect::connectToAddress(const struct addrinfo* address, 34 | std::string& errMsg, 35 | const CancellationRequest& isCancellationRequested) 36 | { 37 | errMsg = "no error"; 38 | 39 | socket_t fd = socket(address->ai_family, address->ai_socktype, address->ai_protocol); 40 | if (fd < 0) 41 | { 42 | errMsg = "Cannot create a socket"; 43 | return -1; 44 | } 45 | 46 | // Set the socket to non blocking mode, so that slow responses cannot 47 | // block us for too long 48 | SocketConnect::configure(fd); 49 | 50 | int res = ::connect(fd, address->ai_addr, address->ai_addrlen); 51 | 52 | if (res == -1 && !Socket::isWaitNeeded()) 53 | { 54 | errMsg = strerror(Socket::getErrno()); 55 | Socket::closeSocket(fd); 56 | return -1; 57 | } 58 | 59 | for (;;) 60 | { 61 | if (isCancellationRequested && isCancellationRequested()) // Must handle timeout as well 62 | { 63 | Socket::closeSocket(fd); 64 | errMsg = "Cancelled"; 65 | return -1; 66 | } 67 | 68 | int timeoutMs = 10; 69 | bool readyToRead = false; 70 | SelectInterruptPtr selectInterrupt = ix::createSelectInterrupt(); 71 | PollResultType pollResult = Socket::poll(readyToRead, timeoutMs, fd, selectInterrupt); 72 | 73 | if (pollResult == PollResultType::Timeout) 74 | { 75 | continue; 76 | } 77 | else if (pollResult == PollResultType::Error) 78 | { 79 | Socket::closeSocket(fd); 80 | errMsg = std::string("Connect error: ") + strerror(Socket::getErrno()); 81 | return -1; 82 | } 83 | else if (pollResult == PollResultType::ReadyForWrite) 84 | { 85 | return fd; 86 | } 87 | else 88 | { 89 | Socket::closeSocket(fd); 90 | errMsg = std::string("Connect error: ") + strerror(Socket::getErrno()); 91 | return -1; 92 | } 93 | } 94 | } 95 | 96 | int SocketConnect::connect(const std::string& hostname, 97 | int port, 98 | std::string& errMsg, 99 | const CancellationRequest& isCancellationRequested) 100 | { 101 | // 102 | // First do DNS resolution 103 | // 104 | auto dnsLookup = std::make_shared(hostname, port); 105 | auto res = dnsLookup->resolve(errMsg, isCancellationRequested); 106 | if (res == nullptr) 107 | { 108 | return -1; 109 | } 110 | 111 | int sockfd = -1; 112 | 113 | // iterate through the records to find a working peer 114 | struct addrinfo* address; 115 | for (address = res.get(); address != nullptr; address = address->ai_next) 116 | { 117 | // 118 | // Second try to connect to the remote host 119 | // 120 | sockfd = connectToAddress(address, errMsg, isCancellationRequested); 121 | if (sockfd != -1) 122 | { 123 | break; 124 | } 125 | } 126 | 127 | return sockfd; 128 | } 129 | 130 | // FIXME: configure is a terrible name 131 | void SocketConnect::configure(int sockfd) 132 | { 133 | // 1. disable Nagle's algorithm 134 | int flag = 1; 135 | setsockopt(sockfd, IPPROTO_TCP, TCP_NODELAY, (char*) &flag, sizeof(flag)); 136 | 137 | // 2. make socket non blocking 138 | #ifdef _WIN32 139 | unsigned long nonblocking = 1; 140 | ioctlsocket(sockfd, FIONBIO, &nonblocking); 141 | #else 142 | fcntl(sockfd, F_SETFL, O_NONBLOCK); // make socket non blocking 143 | #endif 144 | 145 | // 3. (apple) prevent SIGPIPE from being emitted when the remote end disconnect 146 | #ifdef SO_NOSIGPIPE 147 | int value = 1; 148 | setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void*) &value, sizeof(value)); 149 | #endif 150 | } 151 | } // namespace ix 152 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketConnect.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketConnect.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXCancellationRequest.h" 10 | #include 11 | 12 | struct addrinfo; 13 | 14 | namespace ix 15 | { 16 | class SocketConnect 17 | { 18 | public: 19 | static int connect(const std::string& hostname, 20 | int port, 21 | std::string& errMsg, 22 | const CancellationRequest& isCancellationRequested); 23 | 24 | static void configure(int sockfd); 25 | 26 | private: 27 | static int connectToAddress(const struct addrinfo* address, 28 | std::string& errMsg, 29 | const CancellationRequest& isCancellationRequested); 30 | }; 31 | } // namespace ix 32 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketFactory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketFactory.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXSocketFactory.h" 8 | 9 | #include "IXUniquePtr.h" 10 | #ifdef IXWEBSOCKET_USE_TLS 11 | 12 | #ifdef IXWEBSOCKET_USE_MBED_TLS 13 | #include "IXSocketMbedTLS.h" 14 | #elif defined(IXWEBSOCKET_USE_OPEN_SSL) 15 | #include "IXSocketOpenSSL.h" 16 | #elif __APPLE__ 17 | #include "IXSocketAppleSSL.h" 18 | #endif 19 | 20 | #else 21 | 22 | #include "IXSocket.h" 23 | 24 | #endif 25 | 26 | namespace ix 27 | { 28 | std::unique_ptr createSocket(bool tls, 29 | int fd, 30 | std::string& errorMsg, 31 | const SocketTLSOptions& tlsOptions) 32 | { 33 | (void) tlsOptions; 34 | errorMsg.clear(); 35 | std::unique_ptr socket; 36 | 37 | if (!tls) 38 | { 39 | socket = ix::make_unique(fd); 40 | } 41 | else 42 | { 43 | #ifdef IXWEBSOCKET_USE_TLS 44 | #if defined(IXWEBSOCKET_USE_MBED_TLS) 45 | socket = ix::make_unique(tlsOptions, fd); 46 | #elif defined(IXWEBSOCKET_USE_OPEN_SSL) 47 | socket = ix::make_unique(tlsOptions, fd); 48 | #elif defined(__APPLE__) 49 | socket = ix::make_unique(tlsOptions, fd); 50 | #endif 51 | #else 52 | errorMsg = "TLS support is not enabled on this platform."; 53 | return nullptr; 54 | #endif 55 | } 56 | 57 | if (!socket->init(errorMsg)) 58 | { 59 | socket.reset(); 60 | } 61 | 62 | return socket; 63 | } 64 | } // namespace ix 65 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketFactory.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * IXSocketFactory.h 4 | * Author: Benjamin Sergeant 5 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 6 | */ 7 | 8 | #pragma once 9 | 10 | #include "IXSocketTLSOptions.h" 11 | #include 12 | #include 13 | 14 | namespace ix 15 | { 16 | class Socket; 17 | std::unique_ptr createSocket(bool tls, 18 | int fd, 19 | std::string& errorMsg, 20 | const SocketTLSOptions& tlsOptions); 21 | } // namespace ix 22 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketMbedTLS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketMbedTLS.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #ifdef IXWEBSOCKET_USE_MBED_TLS 7 | 8 | #pragma once 9 | 10 | #include "IXSocket.h" 11 | #include "IXSocketTLSOptions.h" 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | namespace ix 23 | { 24 | class SocketMbedTLS final : public Socket 25 | { 26 | public: 27 | SocketMbedTLS(const SocketTLSOptions& tlsOptions, int fd = -1); 28 | ~SocketMbedTLS(); 29 | 30 | virtual bool accept(std::string& errMsg) final; 31 | 32 | virtual bool connect(const std::string& host, 33 | int port, 34 | std::string& errMsg, 35 | const CancellationRequest& isCancellationRequested) final; 36 | virtual void close() final; 37 | 38 | virtual ssize_t send(char* buffer, size_t length) final; 39 | virtual ssize_t recv(void* buffer, size_t length) final; 40 | 41 | private: 42 | mbedtls_ssl_context _ssl; 43 | mbedtls_ssl_config _conf; 44 | mbedtls_entropy_context _entropy; 45 | mbedtls_ctr_drbg_context _ctr_drbg; 46 | mbedtls_x509_crt _cacert; 47 | mbedtls_x509_crt _cert; 48 | mbedtls_pk_context _pkey; 49 | 50 | std::mutex _mutex; 51 | SocketTLSOptions _tlsOptions; 52 | 53 | bool init(const std::string& host, bool isClient, std::string& errMsg); 54 | void initMBedTLS(); 55 | bool loadSystemCertificates(std::string& errMsg); 56 | }; 57 | 58 | } // namespace ix 59 | 60 | #endif // IXWEBSOCKET_USE_MBED_TLS 61 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketOpenSSL.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketOpenSSL.h 3 | * Author: Benjamin Sergeant, Matt DeBoer 4 | * Copyright (c) 2017-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #ifdef IXWEBSOCKET_USE_OPEN_SSL 7 | 8 | #pragma once 9 | 10 | #include "IXCancellationRequest.h" 11 | #include "IXSocket.h" 12 | #include "IXSocketTLSOptions.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace ix 21 | { 22 | class SocketOpenSSL final : public Socket 23 | { 24 | public: 25 | SocketOpenSSL(const SocketTLSOptions& tlsOptions, int fd = -1); 26 | ~SocketOpenSSL(); 27 | 28 | virtual bool accept(std::string& errMsg) final; 29 | 30 | virtual bool connect(const std::string& host, 31 | int port, 32 | std::string& errMsg, 33 | const CancellationRequest& isCancellationRequested) final; 34 | virtual void close() final; 35 | 36 | virtual ssize_t send(char* buffer, size_t length) final; 37 | virtual ssize_t recv(void* buffer, size_t length) final; 38 | 39 | private: 40 | void openSSLInitialize(); 41 | std::string getSSLError(int ret); 42 | SSL_CTX* openSSLCreateContext(std::string& errMsg); 43 | bool openSSLAddCARootsFromString(const std::string roots); 44 | bool openSSLClientHandshake(const std::string& hostname, 45 | std::string& errMsg, 46 | const CancellationRequest& isCancellationRequested); 47 | bool openSSLCheckServerCert(SSL* ssl, const std::string& hostname, std::string& errMsg); 48 | bool checkHost(const std::string& host, const char* pattern); 49 | bool handleTLSOptions(std::string& errMsg); 50 | bool openSSLServerHandshake(std::string& errMsg); 51 | 52 | // Required for OpenSSL < 1.1 53 | static void openSSLLockingCallback(int mode, int type, const char* /*file*/, int /*line*/); 54 | 55 | SSL* _ssl_connection; 56 | SSL_CTX* _ssl_context; 57 | const SSL_METHOD* _ssl_method; 58 | SocketTLSOptions _tlsOptions; 59 | 60 | mutable std::mutex _mutex; // OpenSSL routines are not thread-safe 61 | 62 | static std::once_flag _openSSLInitFlag; 63 | static std::atomic _openSSLInitializationSuccessful; 64 | }; 65 | 66 | } // namespace ix 67 | 68 | #endif // IXWEBSOCKET_USE_OPEN_SSL 69 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketServer.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXConnectionState.h" 10 | #include "IXNetSystem.h" 11 | #include "IXSelectInterrupt.h" 12 | #include "IXSocketTLSOptions.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include // pair 23 | 24 | namespace ix 25 | { 26 | class Socket; 27 | 28 | class SocketServer 29 | { 30 | public: 31 | using ConnectionStateFactory = std::function()>; 32 | 33 | // Each connection is handled by its own worker thread. 34 | // We use a list as we only care about remove and append operations. 35 | using ConnectionThreads = 36 | std::list, std::thread>>; 37 | 38 | SocketServer(int port = SocketServer::kDefaultPort, 39 | const std::string& host = SocketServer::kDefaultHost, 40 | int backlog = SocketServer::kDefaultTcpBacklog, 41 | size_t maxConnections = SocketServer::kDefaultMaxConnections, 42 | int addressFamily = SocketServer::kDefaultAddressFamily); 43 | virtual ~SocketServer(); 44 | virtual void stop(); 45 | 46 | // It is possible to override ConnectionState through inheritance 47 | // this method allows user to change the factory by returning an object 48 | // that inherits from ConnectionState but has its own methods. 49 | void setConnectionStateFactory(const ConnectionStateFactory& connectionStateFactory); 50 | 51 | const static int kDefaultPort; 52 | const static std::string kDefaultHost; 53 | const static int kDefaultTcpBacklog; 54 | const static size_t kDefaultMaxConnections; 55 | const static int kDefaultAddressFamily; 56 | 57 | void start(); 58 | std::pair listen(); 59 | void wait(); 60 | 61 | void setTLSOptions(const SocketTLSOptions& socketTLSOptions); 62 | 63 | int getPort(); 64 | std::string getHost(); 65 | int getBacklog(); 66 | std::size_t getMaxConnections(); 67 | int getAddressFamily(); 68 | protected: 69 | // Logging 70 | void logError(const std::string& str); 71 | void logInfo(const std::string& str); 72 | 73 | void stopAcceptingConnections(); 74 | 75 | private: 76 | // Member variables 77 | int _port; 78 | std::string _host; 79 | int _backlog; 80 | size_t _maxConnections; 81 | int _addressFamily; 82 | 83 | // socket for accepting connections 84 | socket_t _serverFd; 85 | 86 | std::atomic _stop; 87 | 88 | std::mutex _logMutex; 89 | 90 | // background thread to wait for incoming connections 91 | std::thread _thread; 92 | void run(); 93 | void onSetTerminatedCallback(); 94 | 95 | // background thread to cleanup (join) terminated threads 96 | std::atomic _stopGc; 97 | std::thread _gcThread; 98 | void runGC(); 99 | 100 | // the list of (connectionState, threads) for each connections 101 | ConnectionThreads _connectionsThreads; 102 | std::mutex _connectionsThreadsMutex; 103 | 104 | // used to have the main control thread for a server 105 | // wait for a 'terminate' notification without busy polling 106 | std::condition_variable _conditionVariable; 107 | std::mutex _conditionVariableMutex; 108 | 109 | // the factory to create ConnectionState objects 110 | ConnectionStateFactory _connectionStateFactory; 111 | 112 | virtual void handleConnection(std::unique_ptr, 113 | std::shared_ptr connectionState) = 0; 114 | virtual size_t getConnectedClientsCount() = 0; 115 | 116 | // Returns true if all connection threads are joined 117 | void closeTerminatedThreads(); 118 | size_t getConnectionsThreadsCount(); 119 | 120 | SocketTLSOptions _socketTLSOptions; 121 | 122 | // to wake up from select 123 | SelectInterruptPtr _acceptSelectInterrupt; 124 | 125 | // used by the gc thread, to know that a thread needs to be garbage collected 126 | // as a connection 127 | std::condition_variable _conditionVariableGC; 128 | std::mutex _conditionVariableMutexGC; 129 | bool _canContinueGC{ false }; 130 | }; 131 | } // namespace ix 132 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketTLSOptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketTLSOptions.h 3 | * Author: Matt DeBoer 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXSocketTLSOptions.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | const char* kTLSCAFileUseSystemDefaults = "SYSTEM"; 16 | const char* kTLSCAFileDisableVerify = "NONE"; 17 | const char* kTLSCiphersUseDefault = "DEFAULT"; 18 | const char* kTLSInMemoryMarker = "-----BEGIN CERTIFICATE-----"; 19 | 20 | bool SocketTLSOptions::isValid() const 21 | { 22 | if (!_validated) 23 | { 24 | if (!certFile.empty() && !std::ifstream(certFile)) 25 | { 26 | _errMsg = "certFile not found: " + certFile; 27 | return false; 28 | } 29 | if (!keyFile.empty() && !std::ifstream(keyFile)) 30 | { 31 | _errMsg = "keyFile not found: " + keyFile; 32 | return false; 33 | } 34 | if (!caFile.empty() && caFile != kTLSCAFileDisableVerify && 35 | caFile != kTLSCAFileUseSystemDefaults && !std::ifstream(caFile)) 36 | { 37 | _errMsg = "caFile not found: " + caFile; 38 | return false; 39 | } 40 | 41 | if (certFile.empty() != keyFile.empty()) 42 | { 43 | _errMsg = "certFile and keyFile must be both present, or both absent"; 44 | return false; 45 | } 46 | 47 | _validated = true; 48 | } 49 | return true; 50 | } 51 | 52 | bool SocketTLSOptions::hasCertAndKey() const 53 | { 54 | return !certFile.empty() && !keyFile.empty(); 55 | } 56 | 57 | bool SocketTLSOptions::isUsingSystemDefaults() const 58 | { 59 | return caFile == kTLSCAFileUseSystemDefaults; 60 | } 61 | 62 | bool SocketTLSOptions::isUsingInMemoryCAs() const 63 | { 64 | return caFile.find(kTLSInMemoryMarker) != std::string::npos; 65 | } 66 | 67 | bool SocketTLSOptions::isPeerVerifyDisabled() const 68 | { 69 | return caFile == kTLSCAFileDisableVerify; 70 | } 71 | 72 | bool SocketTLSOptions::isUsingDefaultCiphers() const 73 | { 74 | return ciphers.empty() || ciphers == kTLSCiphersUseDefault; 75 | } 76 | 77 | const std::string& SocketTLSOptions::getErrorMsg() const 78 | { 79 | return _errMsg; 80 | } 81 | 82 | std::string SocketTLSOptions::getDescription() const 83 | { 84 | std::stringstream ss; 85 | ss << "TLS Options:" << std::endl; 86 | ss << " certFile = " << certFile << std::endl; 87 | ss << " keyFile = " << keyFile << std::endl; 88 | ss << " caFile = " << caFile << std::endl; 89 | ss << " ciphers = " << ciphers << std::endl; 90 | ss << " tls = " << tls << std::endl; 91 | return ss.str(); 92 | } 93 | } // namespace ix 94 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXSocketTLSOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXSocketTLSOptions.h 3 | * Author: Matt DeBoer 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | struct SocketTLSOptions 14 | { 15 | public: 16 | // check validity of the object 17 | bool isValid() const; 18 | 19 | // the certificate presented to peers 20 | std::string certFile; 21 | 22 | // the key used for signing/encryption 23 | std::string keyFile; 24 | 25 | // the ca certificate (or certificate bundle) file containing 26 | // certificates to be trusted by peers; use 'SYSTEM' to 27 | // leverage the system defaults, use 'NONE' to disable peer verification 28 | std::string caFile = "SYSTEM"; 29 | 30 | // list of ciphers (rsa, etc...) 31 | std::string ciphers = "DEFAULT"; 32 | 33 | // whether tls is enabled, used for server code 34 | bool tls = false; 35 | 36 | // whether to skip validating the peer's hostname against the certificate presented 37 | bool disable_hostname_validation = false; 38 | 39 | bool hasCertAndKey() const; 40 | 41 | bool isUsingSystemDefaults() const; 42 | 43 | bool isUsingInMemoryCAs() const; 44 | 45 | bool isPeerVerifyDisabled() const; 46 | 47 | bool isUsingDefaultCiphers() const; 48 | 49 | const std::string& getErrorMsg() const; 50 | 51 | std::string getDescription() const; 52 | 53 | private: 54 | mutable std::string _errMsg; 55 | mutable bool _validated = false; 56 | }; 57 | } // namespace ix 58 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXStrCaseCompare.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXStrCaseCompare.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone. All rights reserved. 5 | */ 6 | 7 | #include "IXStrCaseCompare.h" 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | bool CaseInsensitiveLess::NocaseCompare::operator()(const unsigned char& c1, 15 | const unsigned char& c2) const 16 | { 17 | #if defined(_WIN32) && !defined(__GNUC__) 18 | return std::tolower(c1, std::locale()) < std::tolower(c2, std::locale()); 19 | #else 20 | return std::tolower(c1) < std::tolower(c2); 21 | #endif 22 | } 23 | 24 | bool CaseInsensitiveLess::cmp(const std::string& s1, const std::string& s2) 25 | { 26 | return std::lexicographical_compare(s1.begin(), 27 | s1.end(), // source range 28 | s2.begin(), 29 | s2.end(), // dest range 30 | NocaseCompare()); // comparison 31 | } 32 | 33 | bool CaseInsensitiveLess::operator()(const std::string& s1, const std::string& s2) const 34 | { 35 | return CaseInsensitiveLess::cmp(s1, s2); 36 | } 37 | } // namespace ix 38 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXStrCaseCompare.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXStrCaseCompare.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | struct CaseInsensitiveLess 14 | { 15 | // Case Insensitive compare_less binary function 16 | struct NocaseCompare 17 | { 18 | bool operator()(const unsigned char& c1, const unsigned char& c2) const; 19 | }; 20 | 21 | static bool cmp(const std::string& s1, const std::string& s2); 22 | 23 | bool operator()(const std::string& s1, const std::string& s2) const; 24 | }; 25 | } // namespace ix 26 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUdpSocket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUdpSocket.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXUdpSocket.h" 8 | 9 | #include "IXNetSystem.h" 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | UdpSocket::UdpSocket(int fd) 16 | : _sockfd(fd) 17 | { 18 | ; 19 | } 20 | 21 | UdpSocket::~UdpSocket() 22 | { 23 | close(); 24 | } 25 | 26 | void UdpSocket::close() 27 | { 28 | if (_sockfd == -1) return; 29 | 30 | closeSocket(_sockfd); 31 | _sockfd = -1; 32 | } 33 | 34 | int UdpSocket::getErrno() 35 | { 36 | int err; 37 | 38 | #ifdef _WIN32 39 | err = WSAGetLastError(); 40 | #else 41 | err = errno; 42 | #endif 43 | 44 | return err; 45 | } 46 | 47 | bool UdpSocket::isWaitNeeded() 48 | { 49 | int err = getErrno(); 50 | 51 | if (err == EWOULDBLOCK || err == EAGAIN || err == EINPROGRESS) 52 | { 53 | return true; 54 | } 55 | 56 | return false; 57 | } 58 | 59 | void UdpSocket::closeSocket(int fd) 60 | { 61 | #ifdef _WIN32 62 | closesocket(fd); 63 | #else 64 | ::close(fd); 65 | #endif 66 | } 67 | 68 | bool UdpSocket::init(const std::string& host, int port, std::string& errMsg) 69 | { 70 | _sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 71 | if (_sockfd < 0) 72 | { 73 | errMsg = "Could not create socket"; 74 | return false; 75 | } 76 | 77 | #ifdef _WIN32 78 | unsigned long nonblocking = 1; 79 | ioctlsocket(_sockfd, FIONBIO, &nonblocking); 80 | #else 81 | fcntl(_sockfd, F_SETFL, O_NONBLOCK); // make socket non blocking 82 | #endif 83 | 84 | memset(&_server, 0, sizeof(_server)); 85 | _server.sin_family = AF_INET; 86 | _server.sin_port = htons(port); 87 | 88 | // DNS resolution. 89 | struct addrinfo hints, *result = nullptr; 90 | memset(&hints, 0, sizeof(hints)); 91 | hints.ai_family = AF_INET; 92 | hints.ai_socktype = SOCK_DGRAM; 93 | 94 | int ret = getaddrinfo(host.c_str(), nullptr, &hints, &result); 95 | if (ret != 0) 96 | { 97 | errMsg = strerror(UdpSocket::getErrno()); 98 | freeaddrinfo(result); 99 | close(); 100 | return false; 101 | } 102 | 103 | struct sockaddr_in* host_addr = (struct sockaddr_in*) result->ai_addr; 104 | memcpy(&_server.sin_addr, &host_addr->sin_addr, sizeof(struct in_addr)); 105 | freeaddrinfo(result); 106 | 107 | return true; 108 | } 109 | 110 | ssize_t UdpSocket::sendto(const std::string& buffer) 111 | { 112 | return (ssize_t)::sendto( 113 | _sockfd, buffer.data(), buffer.size(), 0, (struct sockaddr*) &_server, sizeof(_server)); 114 | } 115 | 116 | ssize_t UdpSocket::recvfrom(char* buffer, size_t length) 117 | { 118 | #ifdef _WIN32 119 | int addressLen = (int) sizeof(_server); 120 | #else 121 | socklen_t addressLen = (socklen_t) sizeof(_server); 122 | #endif 123 | return (ssize_t)::recvfrom( 124 | _sockfd, buffer, length, 0, (struct sockaddr*) &_server, &addressLen); 125 | } 126 | } // namespace ix 127 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUdpSocket.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUdpSocket.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #ifdef _WIN32 14 | #include 15 | #ifdef _MSC_VER 16 | typedef SSIZE_T ssize_t; 17 | #endif 18 | #endif 19 | 20 | #include "IXNetSystem.h" 21 | 22 | namespace ix 23 | { 24 | class UdpSocket 25 | { 26 | public: 27 | UdpSocket(int fd = -1); 28 | ~UdpSocket(); 29 | 30 | // Virtual methods 31 | bool init(const std::string& host, int port, std::string& errMsg); 32 | ssize_t sendto(const std::string& buffer); 33 | ssize_t recvfrom(char* buffer, size_t length); 34 | 35 | void close(); 36 | 37 | static int getErrno(); 38 | static bool isWaitNeeded(); 39 | static void closeSocket(int fd); 40 | 41 | private: 42 | std::atomic _sockfd; 43 | struct sockaddr_in _server; 44 | }; 45 | } // namespace ix 46 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUniquePtr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUniquePtr.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | template 14 | std::unique_ptr make_unique(Args&&... args) 15 | { 16 | return std::unique_ptr(new T(std::forward(args)...)); 17 | } 18 | } // namespace ix 19 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUrlParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUrlParser.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | class UrlParser 14 | { 15 | public: 16 | static bool parse(const std::string& url, 17 | std::string& protocol, 18 | std::string& host, 19 | std::string& path, 20 | std::string& query, 21 | int& port); 22 | 23 | static bool parse(const std::string& url, 24 | std::string& protocol, 25 | std::string& host, 26 | std::string& path, 27 | std::string& query, 28 | int& port, 29 | bool& isProtocolDefaultPort); 30 | }; 31 | } // namespace ix 32 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUserAgent.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUserAgent.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXUserAgent.h" 8 | 9 | #include "IXWebSocketVersion.h" 10 | #include 11 | #ifdef IXWEBSOCKET_USE_ZLIB 12 | #include 13 | #endif 14 | 15 | // Platform name 16 | #if defined(_WIN32) 17 | #define PLATFORM_NAME "windows" // Windows 18 | #elif defined(_WIN64) 19 | #define PLATFORM_NAME "windows" // Windows 20 | #elif defined(__CYGWIN__) && !defined(_WIN32) 21 | #define PLATFORM_NAME "windows" // Windows (Cygwin POSIX under Microsoft Window) 22 | #elif defined(__ANDROID__) 23 | #define PLATFORM_NAME "android" // Android (implies Linux, so it must come first) 24 | #elif defined(__linux__) 25 | #define PLATFORM_NAME "linux" // Debian, Ubuntu, Gentoo, Fedora, openSUSE, RedHat, Centos and other 26 | #elif defined(__unix__) || !defined(__APPLE__) && defined(__MACH__) 27 | #include 28 | #if defined(BSD) 29 | #define PLATFORM_NAME "bsd" // FreeBSD, NetBSD, OpenBSD, DragonFly BSD 30 | #endif 31 | #elif defined(__hpux) 32 | #define PLATFORM_NAME "hp-ux" // HP-UX 33 | #elif defined(_AIX) 34 | #define PLATFORM_NAME "aix" // IBM AIX 35 | #elif defined(__APPLE__) && defined(__MACH__) // Apple OSX and iOS (Darwin) 36 | #include 37 | #if TARGET_IPHONE_SIMULATOR == 1 38 | #define PLATFORM_NAME "ios" // Apple iOS 39 | #elif TARGET_OS_IPHONE == 1 40 | #define PLATFORM_NAME "ios" // Apple iOS 41 | #elif TARGET_OS_MAC == 1 42 | #define PLATFORM_NAME "macos" // Apple OSX 43 | #endif 44 | #elif defined(__sun) && defined(__SVR4) 45 | #define PLATFORM_NAME "solaris" // Oracle Solaris, Open Indiana 46 | #else 47 | #define PLATFORM_NAME "unknown platform" 48 | #endif 49 | 50 | // SSL 51 | #ifdef IXWEBSOCKET_USE_MBED_TLS 52 | #include 53 | #elif defined(IXWEBSOCKET_USE_OPEN_SSL) 54 | #include 55 | #endif 56 | 57 | namespace ix 58 | { 59 | std::string userAgent() 60 | { 61 | std::stringstream ss; 62 | 63 | // IXWebSocket Version 64 | ss << "ixwebsocket/" << IX_WEBSOCKET_VERSION; 65 | 66 | // Platform 67 | ss << " " << PLATFORM_NAME; 68 | 69 | // TLS 70 | #ifdef IXWEBSOCKET_USE_TLS 71 | #ifdef IXWEBSOCKET_USE_MBED_TLS 72 | ss << " ssl/mbedtls " << MBEDTLS_VERSION_STRING; 73 | #elif defined(IXWEBSOCKET_USE_OPEN_SSL) 74 | ss << " ssl/OpenSSL " << OPENSSL_VERSION_TEXT; 75 | #elif __APPLE__ 76 | ss << " ssl/SecureTransport"; 77 | #endif 78 | #else 79 | ss << " nossl"; 80 | #endif 81 | 82 | #ifdef IXWEBSOCKET_USE_ZLIB 83 | // Zlib version 84 | ss << " zlib " << ZLIB_VERSION; 85 | #endif 86 | 87 | return ss.str(); 88 | } 89 | } // namespace ix 90 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUserAgent.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUserAgent.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ix 12 | { 13 | std::string userAgent(); 14 | } // namespace ix 15 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUuid.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUuid.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone. All rights reserved. 5 | */ 6 | 7 | /** 8 | * Generate a random uuid similar to the uuid python module 9 | * 10 | * >>> import uuid 11 | * >>> uuid.uuid4().hex 12 | * 'bec08155b37d4050a1f3c3fa0276bf12' 13 | * 14 | * Code adapted from https://github.com/r-lyeh-archived/sole 15 | */ 16 | 17 | #include "IXUuid.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | 26 | namespace ix 27 | { 28 | class Uuid 29 | { 30 | public: 31 | Uuid(); 32 | std::string toString() const; 33 | 34 | private: 35 | uint64_t _ab; 36 | uint64_t _cd; 37 | }; 38 | 39 | Uuid::Uuid() 40 | { 41 | static std::random_device rd; 42 | static std::uniform_int_distribution dist(0, (uint64_t)(~0)); 43 | 44 | _ab = dist(rd); 45 | _cd = dist(rd); 46 | 47 | _ab = (_ab & 0xFFFFFFFFFFFF0FFFULL) | 0x0000000000004000ULL; 48 | _cd = (_cd & 0x3FFFFFFFFFFFFFFFULL) | 0x8000000000000000ULL; 49 | } 50 | 51 | std::string Uuid::toString() const 52 | { 53 | std::stringstream ss; 54 | ss << std::hex << std::nouppercase << std::setfill('0'); 55 | 56 | uint32_t a = (_ab >> 32); 57 | uint32_t b = (_ab & 0xFFFFFFFF); 58 | uint32_t c = (_cd >> 32); 59 | uint32_t d = (_cd & 0xFFFFFFFF); 60 | 61 | ss << std::setw(8) << (a); 62 | ss << std::setw(4) << (b >> 16); 63 | ss << std::setw(4) << (b & 0xFFFF); 64 | ss << std::setw(4) << (c >> 16); 65 | ss << std::setw(4) << (c & 0xFFFF); 66 | ss << std::setw(8) << d; 67 | 68 | return ss.str(); 69 | } 70 | 71 | std::string uuid4() 72 | { 73 | Uuid id; 74 | return id.toString(); 75 | } 76 | } // namespace ix 77 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXUuid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXUuid.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017 Machine Zone. All rights reserved. 5 | */ 6 | #pragma once 7 | 8 | #include 9 | 10 | namespace ix 11 | { 12 | /** 13 | * Generate a random uuid 14 | */ 15 | std::string uuid4(); 16 | 17 | } // namespace ix 18 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketCloseConstants.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketCloseConstants.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXWebSocketCloseConstants.h" 8 | 9 | namespace ix 10 | { 11 | const uint16_t WebSocketCloseConstants::kNormalClosureCode(1000); 12 | const uint16_t WebSocketCloseConstants::kInternalErrorCode(1011); 13 | const uint16_t WebSocketCloseConstants::kAbnormalCloseCode(1006); 14 | const uint16_t WebSocketCloseConstants::kInvalidFramePayloadData(1007); 15 | const uint16_t WebSocketCloseConstants::kProtocolErrorCode(1002); 16 | const uint16_t WebSocketCloseConstants::kNoStatusCodeErrorCode(1005); 17 | 18 | const std::string WebSocketCloseConstants::kNormalClosureMessage("Normal closure"); 19 | const std::string WebSocketCloseConstants::kInternalErrorMessage("Internal error"); 20 | const std::string WebSocketCloseConstants::kAbnormalCloseMessage("Abnormal closure"); 21 | const std::string WebSocketCloseConstants::kPingTimeoutMessage("Ping timeout"); 22 | const std::string WebSocketCloseConstants::kProtocolErrorMessage("Protocol error"); 23 | const std::string WebSocketCloseConstants::kNoStatusCodeErrorMessage("No status code"); 24 | const std::string WebSocketCloseConstants::kProtocolErrorReservedBitUsed("Reserved bit used"); 25 | const std::string WebSocketCloseConstants::kProtocolErrorPingPayloadOversized( 26 | "Ping reason control frame with payload length > 125 octets"); 27 | const std::string WebSocketCloseConstants::kProtocolErrorCodeControlMessageFragmented( 28 | "Control message fragmented"); 29 | const std::string WebSocketCloseConstants::kProtocolErrorCodeDataOpcodeOutOfSequence( 30 | "Fragmentation: data message out of sequence"); 31 | const std::string WebSocketCloseConstants::kProtocolErrorCodeContinuationOpCodeOutOfSequence( 32 | "Fragmentation: continuation opcode out of sequence"); 33 | const std::string WebSocketCloseConstants::kInvalidFramePayloadDataMessage( 34 | "Invalid frame payload data"); 35 | const std::string WebSocketCloseConstants::kInvalidCloseCodeMessage("Invalid close code"); 36 | } // namespace ix 37 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketCloseConstants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketCloseConstants.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | struct WebSocketCloseConstants 15 | { 16 | static const uint16_t kNormalClosureCode; 17 | static const uint16_t kInternalErrorCode; 18 | static const uint16_t kAbnormalCloseCode; 19 | static const uint16_t kProtocolErrorCode; 20 | static const uint16_t kNoStatusCodeErrorCode; 21 | static const uint16_t kInvalidFramePayloadData; 22 | 23 | static const std::string kNormalClosureMessage; 24 | static const std::string kInternalErrorMessage; 25 | static const std::string kAbnormalCloseMessage; 26 | static const std::string kPingTimeoutMessage; 27 | static const std::string kProtocolErrorMessage; 28 | static const std::string kNoStatusCodeErrorMessage; 29 | static const std::string kProtocolErrorReservedBitUsed; 30 | static const std::string kProtocolErrorPingPayloadOversized; 31 | static const std::string kProtocolErrorCodeControlMessageFragmented; 32 | static const std::string kProtocolErrorCodeDataOpcodeOutOfSequence; 33 | static const std::string kProtocolErrorCodeContinuationOpCodeOutOfSequence; 34 | static const std::string kInvalidFramePayloadDataMessage; 35 | static const std::string kInvalidCloseCodeMessage; 36 | }; 37 | } // namespace ix 38 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketCloseInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketCloseInfo.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | struct WebSocketCloseInfo 15 | { 16 | uint16_t code; 17 | std::string reason; 18 | bool remote; 19 | 20 | WebSocketCloseInfo(uint16_t c = 0, const std::string& r = std::string(), bool rem = false) 21 | : code(c) 22 | , reason(r) 23 | , remote(rem) 24 | { 25 | ; 26 | } 27 | }; 28 | } // namespace ix 29 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketErrorInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketErrorInfo.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | struct WebSocketErrorInfo 15 | { 16 | uint32_t retries = 0; 17 | double wait_time = 0; 18 | int http_status = 0; 19 | std::string reason; 20 | bool decompressionError = false; 21 | }; 22 | } // namespace ix 23 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketHandshake.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketHandshake.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXCancellationRequest.h" 10 | #include "IXHttp.h" 11 | #include "IXSocket.h" 12 | #include "IXWebSocketHttpHeaders.h" 13 | #include "IXWebSocketInitResult.h" 14 | #include "IXWebSocketPerMessageDeflate.h" 15 | #include "IXWebSocketPerMessageDeflateOptions.h" 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | namespace ix 22 | { 23 | class WebSocketHandshake 24 | { 25 | public: 26 | WebSocketHandshake(std::atomic& requestInitCancellation, 27 | std::unique_ptr& _socket, 28 | WebSocketPerMessageDeflatePtr& perMessageDeflate, 29 | WebSocketPerMessageDeflateOptions& perMessageDeflateOptions, 30 | std::atomic& enablePerMessageDeflate); 31 | 32 | WebSocketInitResult clientHandshake(const std::string& url, 33 | const WebSocketHttpHeaders& extraHeaders, 34 | const std::string& protocol, 35 | const std::string& host, 36 | const std::string& path, 37 | int port, 38 | int timeoutSecs); 39 | 40 | WebSocketInitResult serverHandshake(int timeoutSecs, 41 | bool enablePerMessageDeflate, 42 | HttpRequestPtr request = nullptr); 43 | 44 | private: 45 | std::string genRandomString(const int len); 46 | 47 | // Parse HTTP headers 48 | WebSocketInitResult sendErrorResponse(int code, const std::string& reason); 49 | 50 | bool insensitiveStringCompare(const std::string& a, const std::string& b); 51 | 52 | std::atomic& _requestInitCancellation; 53 | std::unique_ptr& _socket; 54 | WebSocketPerMessageDeflatePtr& _perMessageDeflate; 55 | WebSocketPerMessageDeflateOptions& _perMessageDeflateOptions; 56 | std::atomic& _enablePerMessageDeflate; 57 | }; 58 | } // namespace ix 59 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketHttpHeaders.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketHttpHeaders.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXWebSocketHttpHeaders.h" 8 | 9 | #include "IXSocket.h" 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | std::pair parseHttpHeaders( 16 | std::unique_ptr& socket, const CancellationRequest& isCancellationRequested) 17 | { 18 | WebSocketHttpHeaders headers; 19 | 20 | char line[1024]; 21 | int i; 22 | 23 | while (true) 24 | { 25 | int colon = 0; 26 | 27 | for (i = 0; i < 2 || (i < 1023 && line[i - 2] != '\r' && line[i - 1] != '\n'); ++i) 28 | { 29 | if (!socket->readByte(line + i, isCancellationRequested)) 30 | { 31 | return std::make_pair(false, headers); 32 | } 33 | 34 | if (line[i] == ':' && colon == 0) 35 | { 36 | colon = i; 37 | } 38 | } 39 | if (line[0] == '\r' && line[1] == '\n') 40 | { 41 | break; 42 | } 43 | 44 | // line is a single header entry. split by ':', and add it to our 45 | // header map. ignore lines with no colon. 46 | if (colon > 0) 47 | { 48 | line[i] = '\0'; 49 | std::string lineStr(line); 50 | // colon is ':', usually colon+1 is ' ', and colon+2 is the start of the value. 51 | // some webservers do not put a space after the colon character, so 52 | // the start of the value might be farther than colon+2. 53 | // The spec says that space after the : should be discarded. 54 | // i is end of string (\0), i-colon is length of string minus key; 55 | // subtract 1 for '\0', 1 for '\n', 1 for '\r', 56 | // 1 for the ' ' after the ':', and total is -4 57 | // since we use an std::string later on and don't account for '\0', 58 | // plus the optional first space, total is -2 59 | int start = colon + 1; 60 | while (lineStr[start] == ' ') 61 | { 62 | start++; 63 | } 64 | 65 | std::string name(lineStr.substr(0, colon)); 66 | std::string value(lineStr.substr(start, lineStr.size() - start - 2)); 67 | 68 | headers[name] = value; 69 | } 70 | } 71 | 72 | return std::make_pair(true, headers); 73 | } 74 | } // namespace ix 75 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketHttpHeaders.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketHttpHeaders.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXCancellationRequest.h" 10 | #include "IXStrCaseCompare.h" 11 | #include 12 | #include 13 | #include 14 | 15 | namespace ix 16 | { 17 | class Socket; 18 | 19 | using WebSocketHttpHeaders = std::map; 20 | 21 | std::pair parseHttpHeaders( 22 | std::unique_ptr& socket, const CancellationRequest& isCancellationRequested); 23 | } // namespace ix 24 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketInitResult.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketInitResult.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXWebSocketHttpHeaders.h" 10 | 11 | namespace ix 12 | { 13 | struct WebSocketInitResult 14 | { 15 | bool success; 16 | int http_status; 17 | std::string errorStr; 18 | WebSocketHttpHeaders headers; 19 | std::string uri; 20 | std::string protocol; 21 | 22 | WebSocketInitResult(bool s = false, 23 | int status = 0, 24 | const std::string& e = std::string(), 25 | WebSocketHttpHeaders h = WebSocketHttpHeaders(), 26 | const std::string& u = std::string()) 27 | { 28 | success = s; 29 | http_status = status; 30 | errorStr = e; 31 | headers = h; 32 | uri = u; 33 | protocol = h["Sec-WebSocket-Protocol"]; 34 | } 35 | }; 36 | } // namespace ix 37 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketMessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketMessage.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXWebSocketCloseInfo.h" 10 | #include "IXWebSocketErrorInfo.h" 11 | #include "IXWebSocketMessageType.h" 12 | #include "IXWebSocketOpenInfo.h" 13 | #include 14 | #include 15 | 16 | namespace ix 17 | { 18 | struct WebSocketMessage 19 | { 20 | WebSocketMessageType type; 21 | const std::string& str; 22 | size_t wireSize; 23 | WebSocketErrorInfo errorInfo; 24 | WebSocketOpenInfo openInfo; 25 | WebSocketCloseInfo closeInfo; 26 | bool binary; 27 | 28 | WebSocketMessage(WebSocketMessageType t, 29 | const std::string& s, 30 | size_t w, 31 | WebSocketErrorInfo e, 32 | WebSocketOpenInfo o, 33 | WebSocketCloseInfo c, 34 | bool b = false) 35 | : type(t) 36 | , str(s) 37 | , wireSize(w) 38 | , errorInfo(e) 39 | , openInfo(o) 40 | , closeInfo(c) 41 | , binary(b) 42 | { 43 | ; 44 | } 45 | 46 | /** 47 | * @brief Deleted overload to prevent binding `str` to a temporary, which would cause 48 | * undefined behavior since class members don't extend lifetime beyond the constructor call. 49 | */ 50 | WebSocketMessage(WebSocketMessageType t, 51 | std::string&& s, 52 | size_t w, 53 | WebSocketErrorInfo e, 54 | WebSocketOpenInfo o, 55 | WebSocketCloseInfo c, 56 | bool b = false) = delete; 57 | }; 58 | 59 | using WebSocketMessagePtr = std::unique_ptr; 60 | } // namespace ix 61 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketMessageType.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketMessageType.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | namespace ix 10 | { 11 | enum class WebSocketMessageType 12 | { 13 | Message = 0, 14 | Open = 1, 15 | Close = 2, 16 | Error = 3, 17 | Ping = 4, 18 | Pong = 5, 19 | Fragment = 6 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketOpenInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketOpenInfo.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2017-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXWebSocketHttpHeaders.h" 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | struct WebSocketOpenInfo 16 | { 17 | std::string uri; 18 | WebSocketHttpHeaders headers; 19 | std::string protocol; 20 | 21 | WebSocketOpenInfo(const std::string& u = std::string(), 22 | const WebSocketHttpHeaders& h = WebSocketHttpHeaders(), 23 | const std::string& p = std::string()) 24 | : uri(u) 25 | , headers(h) 26 | , protocol(p) 27 | { 28 | ; 29 | } 30 | }; 31 | } // namespace ix 32 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketPerMessageDeflate.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * Author: Benjamin Sergeant 29 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 30 | * 31 | * Adapted from websocketpp/extensions/permessage_deflate/enabled.hpp 32 | * (same license as MZ: https://opensource.org/licenses/BSD-3-Clause) 33 | * 34 | * - Reused zlib compression + decompression bits. 35 | * - Refactored to have 2 class for compression and decompression, to allow multi-threading 36 | * and make sure that _compressBuffer is not shared between threads. 37 | * - Original code wasn't working for some reason, I had to add checks 38 | * for the presence of the kEmptyUncompressedBlock at the end of buffer so that servers 39 | * would start accepting receiving/decoding compressed messages. Original code was probably 40 | * modifying the passed in buffers before processing in enabled.hpp ? 41 | * - Added more documentation. 42 | * 43 | * Per message Deflate RFC: https://tools.ietf.org/html/rfc7692 44 | * Chrome websocket -> 45 | * https://github.com/chromium/chromium/tree/2ca8c5037021c9d2ecc00b787d58a31ed8fc8bcb/net/websockets 46 | * 47 | */ 48 | 49 | #include 50 | 51 | #include "IXWebSocketPerMessageDeflate.h" 52 | 53 | #include "IXUniquePtr.h" 54 | #include "IXWebSocketPerMessageDeflateCodec.h" 55 | #include "IXWebSocketPerMessageDeflateOptions.h" 56 | 57 | namespace ix 58 | { 59 | WebSocketPerMessageDeflate::WebSocketPerMessageDeflate() 60 | : _compressor(ix::make_unique()) 61 | , _decompressor(ix::make_unique()) 62 | { 63 | ; 64 | } 65 | 66 | WebSocketPerMessageDeflate::~WebSocketPerMessageDeflate() 67 | { 68 | ; 69 | } 70 | 71 | bool WebSocketPerMessageDeflate::init( 72 | const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions) 73 | { 74 | bool clientNoContextTakeover = perMessageDeflateOptions.getClientNoContextTakeover(); 75 | 76 | uint8_t deflateBits = perMessageDeflateOptions.getClientMaxWindowBits(); 77 | uint8_t inflateBits = perMessageDeflateOptions.getServerMaxWindowBits(); 78 | 79 | return _compressor->init(deflateBits, clientNoContextTakeover) && 80 | _decompressor->init(inflateBits, clientNoContextTakeover); 81 | } 82 | 83 | bool WebSocketPerMessageDeflate::compress(const IXWebSocketSendData& in, std::string& out) 84 | { 85 | return _compressor->compress(in, out); 86 | } 87 | 88 | bool WebSocketPerMessageDeflate::compress(const std::string& in, std::string& out) 89 | { 90 | return _compressor->compress(in, out); 91 | } 92 | 93 | bool WebSocketPerMessageDeflate::decompress(const std::string& in, std::string& out) 94 | { 95 | return _decompressor->decompress(in, out); 96 | } 97 | 98 | } // namespace ix 99 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketPerMessageDeflate.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, Peter Thorson. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions are met: 6 | * * Redistributions of source code must retain the above copyright 7 | * notice, this list of conditions and the following disclaimer. 8 | * * Redistributions in binary form must reproduce the above copyright 9 | * notice, this list of conditions and the following disclaimer in the 10 | * documentation and/or other materials provided with the distribution. 11 | * * Neither the name of the WebSocket++ Project nor the 12 | * names of its contributors may be used to endorse or promote products 13 | * derived from this software without specific prior written permission. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY 19 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | /* 28 | * Author: Benjamin Sergeant 29 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 30 | * 31 | * Adapted from websocketpp/extensions/permessage_deflate/enabled.hpp 32 | * (same license as MZ: https://opensource.org/licenses/BSD-3-Clause) 33 | */ 34 | 35 | #pragma once 36 | 37 | #include 38 | #include 39 | #include "IXWebSocketSendData.h" 40 | 41 | namespace ix 42 | { 43 | class WebSocketPerMessageDeflateOptions; 44 | class WebSocketPerMessageDeflateCompressor; 45 | class WebSocketPerMessageDeflateDecompressor; 46 | 47 | class WebSocketPerMessageDeflate 48 | { 49 | public: 50 | WebSocketPerMessageDeflate(); 51 | ~WebSocketPerMessageDeflate(); 52 | 53 | bool init(const WebSocketPerMessageDeflateOptions& perMessageDeflateOptions); 54 | bool compress(const IXWebSocketSendData& in, std::string& out); 55 | bool compress(const std::string& in, std::string& out); 56 | bool decompress(const std::string& in, std::string& out); 57 | 58 | private: 59 | std::unique_ptr _compressor; 60 | std::unique_ptr _decompressor; 61 | }; 62 | 63 | using WebSocketPerMessageDeflatePtr = std::unique_ptr; 64 | } // namespace ix 65 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketPerMessageDeflateCodec.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketPerMessageDeflateCodec.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018-2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #ifdef IXWEBSOCKET_USE_ZLIB 10 | #include "zlib.h" 11 | #endif 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include "IXWebSocketSendData.h" 17 | 18 | namespace ix 19 | { 20 | class WebSocketPerMessageDeflateCompressor 21 | { 22 | public: 23 | WebSocketPerMessageDeflateCompressor(); 24 | ~WebSocketPerMessageDeflateCompressor(); 25 | 26 | bool init(uint8_t deflateBits, bool clientNoContextTakeOver); 27 | bool compress(const IXWebSocketSendData& in, std::string& out); 28 | bool compress(const std::string& in, std::string& out); 29 | bool compress(const std::string& in, std::vector& out); 30 | bool compress(const std::vector& in, std::string& out); 31 | bool compress(const std::vector& in, std::vector& out); 32 | 33 | private: 34 | template 35 | bool compressData(const T& in, S& out); 36 | template 37 | bool endsWithEmptyUnCompressedBlock(const T& value); 38 | 39 | int _flush; 40 | std::array _compressBuffer; 41 | 42 | #ifdef IXWEBSOCKET_USE_ZLIB 43 | z_stream _deflateState; 44 | #endif 45 | }; 46 | 47 | class WebSocketPerMessageDeflateDecompressor 48 | { 49 | public: 50 | WebSocketPerMessageDeflateDecompressor(); 51 | ~WebSocketPerMessageDeflateDecompressor(); 52 | 53 | bool init(uint8_t inflateBits, bool clientNoContextTakeOver); 54 | bool decompress(const std::string& in, std::string& out); 55 | 56 | private: 57 | int _flush; 58 | std::array _compressBuffer; 59 | 60 | #ifdef IXWEBSOCKET_USE_ZLIB 61 | z_stream _inflateState; 62 | #endif 63 | }; 64 | 65 | } // namespace ix 66 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketPerMessageDeflateOptions.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketPerMessageDeflateOptions.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXWebSocketPerMessageDeflateOptions.h" 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | namespace ix 14 | { 15 | /// Default values as defined in the RFC 16 | const uint8_t WebSocketPerMessageDeflateOptions::kDefaultServerMaxWindowBits = 15; 17 | static const uint8_t minServerMaxWindowBits = 8; 18 | static const uint8_t maxServerMaxWindowBits = 15; 19 | 20 | const uint8_t WebSocketPerMessageDeflateOptions::kDefaultClientMaxWindowBits = 15; 21 | static const uint8_t minClientMaxWindowBits = 8; 22 | static const uint8_t maxClientMaxWindowBits = 15; 23 | 24 | WebSocketPerMessageDeflateOptions::WebSocketPerMessageDeflateOptions( 25 | bool enabled, 26 | bool clientNoContextTakeover, 27 | bool serverNoContextTakeover, 28 | uint8_t clientMaxWindowBits, 29 | uint8_t serverMaxWindowBits) 30 | { 31 | _enabled = enabled; 32 | _clientNoContextTakeover = clientNoContextTakeover; 33 | _serverNoContextTakeover = serverNoContextTakeover; 34 | _clientMaxWindowBits = clientMaxWindowBits; 35 | _serverMaxWindowBits = serverMaxWindowBits; 36 | 37 | sanitizeClientMaxWindowBits(); 38 | } 39 | 40 | // 41 | // Four extension parameters are defined for "permessage-deflate" to 42 | // help endpoints manage per-connection resource usage. 43 | // 44 | // - "server_no_context_takeover" 45 | // - "client_no_context_takeover" 46 | // - "server_max_window_bits" 47 | // - "client_max_window_bits" 48 | // 49 | // Server response could look like that: 50 | // 51 | // Sec-WebSocket-Extensions: permessage-deflate; client_no_context_takeover; 52 | // server_no_context_takeover 53 | // 54 | WebSocketPerMessageDeflateOptions::WebSocketPerMessageDeflateOptions(std::string extension) 55 | { 56 | extension = removeSpaces(extension); 57 | 58 | _enabled = false; 59 | _clientNoContextTakeover = false; 60 | _serverNoContextTakeover = false; 61 | _clientMaxWindowBits = kDefaultClientMaxWindowBits; 62 | _serverMaxWindowBits = kDefaultServerMaxWindowBits; 63 | 64 | #ifdef IXWEBSOCKET_USE_ZLIB 65 | // Split by ; 66 | std::string token; 67 | std::stringstream tokenStream(extension); 68 | 69 | while (std::getline(tokenStream, token, ';')) 70 | { 71 | if (token == "permessage-deflate") 72 | { 73 | _enabled = true; 74 | } 75 | 76 | if (token == "server_no_context_takeover") 77 | { 78 | _serverNoContextTakeover = true; 79 | } 80 | 81 | if (token == "client_no_context_takeover") 82 | { 83 | _clientNoContextTakeover = true; 84 | } 85 | 86 | if (startsWith(token, "server_max_window_bits=")) 87 | { 88 | uint8_t x = strtol(token.substr(token.find_last_of("=") + 1).c_str(), nullptr, 10); 89 | 90 | // Sanitize values to be in the proper range [8, 15] in 91 | // case a server would give us bogus values 92 | _serverMaxWindowBits = 93 | std::min(maxServerMaxWindowBits, std::max(x, minServerMaxWindowBits)); 94 | } 95 | 96 | if (startsWith(token, "client_max_window_bits=")) 97 | { 98 | uint8_t x = strtol(token.substr(token.find_last_of("=") + 1).c_str(), nullptr, 10); 99 | 100 | // Sanitize values to be in the proper range [8, 15] in 101 | // case a server would give us bogus values 102 | _clientMaxWindowBits = 103 | std::min(maxClientMaxWindowBits, std::max(x, minClientMaxWindowBits)); 104 | 105 | sanitizeClientMaxWindowBits(); 106 | } 107 | } 108 | #endif 109 | } 110 | 111 | void WebSocketPerMessageDeflateOptions::sanitizeClientMaxWindowBits() 112 | { 113 | // zlib/deflate has a bug with windowsbits == 8, so we silently upgrade it to 9 114 | // See https://bugs.chromium.org/p/chromium/issues/detail?id=691074 115 | if (_clientMaxWindowBits == 8) 116 | { 117 | _clientMaxWindowBits = 9; 118 | } 119 | } 120 | 121 | std::string WebSocketPerMessageDeflateOptions::generateHeader() 122 | { 123 | #ifdef IXWEBSOCKET_USE_ZLIB 124 | std::stringstream ss; 125 | ss << "Sec-WebSocket-Extensions: permessage-deflate"; 126 | 127 | if (_clientNoContextTakeover) ss << "; client_no_context_takeover"; 128 | if (_serverNoContextTakeover) ss << "; server_no_context_takeover"; 129 | 130 | ss << "; server_max_window_bits=" << static_cast(_serverMaxWindowBits); 131 | ss << "; client_max_window_bits=" << static_cast(_clientMaxWindowBits); 132 | 133 | ss << "\r\n"; 134 | 135 | return ss.str(); 136 | #else 137 | return std::string(); 138 | #endif 139 | } 140 | 141 | bool WebSocketPerMessageDeflateOptions::enabled() const 142 | { 143 | #ifdef IXWEBSOCKET_USE_ZLIB 144 | return _enabled; 145 | #else 146 | return false; 147 | #endif 148 | } 149 | 150 | bool WebSocketPerMessageDeflateOptions::getClientNoContextTakeover() const 151 | { 152 | return _clientNoContextTakeover; 153 | } 154 | 155 | bool WebSocketPerMessageDeflateOptions::getServerNoContextTakeover() const 156 | { 157 | return _serverNoContextTakeover; 158 | } 159 | 160 | uint8_t WebSocketPerMessageDeflateOptions::getClientMaxWindowBits() const 161 | { 162 | return _clientMaxWindowBits; 163 | } 164 | 165 | uint8_t WebSocketPerMessageDeflateOptions::getServerMaxWindowBits() const 166 | { 167 | return _serverMaxWindowBits; 168 | } 169 | 170 | bool WebSocketPerMessageDeflateOptions::startsWith(const std::string& str, 171 | const std::string& start) 172 | { 173 | return str.compare(0, start.length(), start) == 0; 174 | } 175 | 176 | std::string WebSocketPerMessageDeflateOptions::removeSpaces(const std::string& str) 177 | { 178 | std::string out(str); 179 | out.erase( 180 | std::remove_if(out.begin(), out.end(), [](unsigned char x) { return std::isspace(x); }), 181 | out.end()); 182 | 183 | return out; 184 | } 185 | } // namespace ix 186 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketPerMessageDeflateOptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketPerMessageDeflateOptions.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | 12 | namespace ix 13 | { 14 | class WebSocketPerMessageDeflateOptions 15 | { 16 | public: 17 | WebSocketPerMessageDeflateOptions( 18 | bool enabled = false, 19 | bool clientNoContextTakeover = false, 20 | bool serverNoContextTakeover = false, 21 | uint8_t clientMaxWindowBits = kDefaultClientMaxWindowBits, 22 | uint8_t serverMaxWindowBits = kDefaultServerMaxWindowBits); 23 | 24 | WebSocketPerMessageDeflateOptions(std::string extension); 25 | 26 | std::string generateHeader(); 27 | bool enabled() const; 28 | bool getClientNoContextTakeover() const; 29 | bool getServerNoContextTakeover() const; 30 | uint8_t getServerMaxWindowBits() const; 31 | uint8_t getClientMaxWindowBits() const; 32 | 33 | static bool startsWith(const std::string& str, const std::string& start); 34 | static std::string removeSpaces(const std::string& str); 35 | 36 | static uint8_t const kDefaultClientMaxWindowBits; 37 | static uint8_t const kDefaultServerMaxWindowBits; 38 | 39 | private: 40 | bool _enabled; 41 | bool _clientNoContextTakeover; 42 | bool _serverNoContextTakeover; 43 | uint8_t _clientMaxWindowBits; 44 | uint8_t _serverMaxWindowBits; 45 | 46 | void sanitizeClientMaxWindowBits(); 47 | }; 48 | } // namespace ix 49 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketProxyServer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketProxyServer.cpp 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #include "IXWebSocketProxyServer.h" 8 | 9 | #include "IXWebSocketServer.h" 10 | #include 11 | 12 | namespace ix 13 | { 14 | class ProxyConnectionState : public ix::ConnectionState 15 | { 16 | public: 17 | ProxyConnectionState() 18 | : _connected(false) 19 | { 20 | } 21 | 22 | ix::WebSocket& webSocket() 23 | { 24 | return _serverWebSocket; 25 | } 26 | 27 | bool isConnected() 28 | { 29 | return _connected; 30 | } 31 | 32 | void setConnected() 33 | { 34 | _connected = true; 35 | } 36 | 37 | private: 38 | ix::WebSocket _serverWebSocket; 39 | bool _connected; 40 | }; 41 | 42 | int websocket_proxy_server_main(int port, 43 | const std::string& hostname, 44 | const ix::SocketTLSOptions& tlsOptions, 45 | const std::string& remoteUrl, 46 | const RemoteUrlsMapping& remoteUrlsMapping, 47 | bool /*verbose*/) 48 | { 49 | ix::WebSocketServer server(port, hostname); 50 | server.setTLSOptions(tlsOptions); 51 | 52 | auto factory = []() -> std::shared_ptr { 53 | return std::make_shared(); 54 | }; 55 | server.setConnectionStateFactory(factory); 56 | 57 | server.setOnConnectionCallback( 58 | [remoteUrl, remoteUrlsMapping](std::weak_ptr webSocket, 59 | std::shared_ptr connectionState) { 60 | auto state = std::dynamic_pointer_cast(connectionState); 61 | auto remoteIp = connectionState->getRemoteIp(); 62 | 63 | // Server connection 64 | state->webSocket().setOnMessageCallback( 65 | [webSocket, state, remoteIp](const WebSocketMessagePtr& msg) { 66 | if (msg->type == ix::WebSocketMessageType::Close) 67 | { 68 | state->setTerminated(); 69 | } 70 | else if (msg->type == ix::WebSocketMessageType::Message) 71 | { 72 | auto ws = webSocket.lock(); 73 | if (ws) 74 | { 75 | ws->send(msg->str, msg->binary); 76 | } 77 | } 78 | }); 79 | 80 | // Client connection 81 | auto ws = webSocket.lock(); 82 | if (ws) 83 | { 84 | ws->setOnMessageCallback([state, remoteUrl, remoteUrlsMapping]( 85 | const WebSocketMessagePtr& msg) { 86 | if (msg->type == ix::WebSocketMessageType::Open) 87 | { 88 | // Connect to the 'real' server 89 | std::string url(remoteUrl); 90 | 91 | // maybe we want a different url based on the mapping 92 | std::string host = msg->openInfo.headers["Host"]; 93 | auto it = remoteUrlsMapping.find(host); 94 | if (it != remoteUrlsMapping.end()) 95 | { 96 | url = it->second; 97 | } 98 | 99 | // append the uri to form the full url 100 | // (say ws://localhost:1234/foo/?bar=baz) 101 | url += msg->openInfo.uri; 102 | 103 | state->webSocket().setUrl(url); 104 | state->webSocket().disableAutomaticReconnection(); 105 | state->webSocket().start(); 106 | 107 | // we should sleep here for a bit until we've established the 108 | // connection with the remote server 109 | while (state->webSocket().getReadyState() != ReadyState::Open) 110 | { 111 | std::this_thread::sleep_for(std::chrono::milliseconds(10)); 112 | } 113 | } 114 | else if (msg->type == ix::WebSocketMessageType::Close) 115 | { 116 | state->webSocket().close(msg->closeInfo.code, msg->closeInfo.reason); 117 | } 118 | else if (msg->type == ix::WebSocketMessageType::Message) 119 | { 120 | state->webSocket().send(msg->str, msg->binary); 121 | } 122 | }); 123 | } 124 | }); 125 | 126 | auto res = server.listen(); 127 | if (!res.first) 128 | { 129 | return 1; 130 | } 131 | 132 | server.start(); 133 | server.wait(); 134 | 135 | return 0; 136 | } 137 | } // namespace ix 138 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketProxyServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketProxyServer.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019-2020 Machine Zone, Inc. All rights reserved. 5 | */ 6 | #pragma once 7 | 8 | #include "IXSocketTLSOptions.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace ix 15 | { 16 | using RemoteUrlsMapping = std::map; 17 | 18 | int websocket_proxy_server_main(int port, 19 | const std::string& hostname, 20 | const ix::SocketTLSOptions& tlsOptions, 21 | const std::string& remoteUrl, 22 | const RemoteUrlsMapping& remoteUrlsMapping, 23 | bool verbose); 24 | } // namespace ix 25 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketSendData.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketSendData.h 3 | * 4 | * WebSocket (Binary/Text) send data buffer 5 | */ 6 | 7 | #pragma once 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace ix 15 | { 16 | /* 17 | * IXWebSocketSendData implements a wrapper for std::string, std:vector and char*. 18 | * It removes the necessarity to copy the data or string into a std::string 19 | */ 20 | class IXWebSocketSendData { 21 | public: 22 | 23 | template 24 | struct IXWebSocketSendData_const_iterator 25 | //: public std::iterator 26 | { 27 | typedef IXWebSocketSendData_const_iterator const_iterator; 28 | 29 | using iterator_category = std::forward_iterator_tag; 30 | using difference_type = std::ptrdiff_t; 31 | using value_type = T; 32 | using pointer = value_type*; 33 | using reference = const value_type&; 34 | 35 | pointer _ptr; 36 | public: 37 | IXWebSocketSendData_const_iterator() : _ptr(nullptr) {} 38 | IXWebSocketSendData_const_iterator(pointer ptr) : _ptr(ptr) {} 39 | ~IXWebSocketSendData_const_iterator() {} 40 | 41 | const_iterator operator++(int) { return const_iterator(_ptr++); } 42 | const_iterator& operator++() { ++_ptr; return *this; } 43 | reference operator* () const { return *_ptr; } 44 | pointer operator->() const { return _ptr; } 45 | const_iterator operator+ (const difference_type offset) const { return const_iterator(_ptr + offset); } 46 | const_iterator operator- (const difference_type offset) const { return const_iterator(_ptr - offset); } 47 | difference_type operator- (const const_iterator& rhs) const { return _ptr - rhs._ptr; } 48 | bool operator==(const const_iterator& rhs) const { return _ptr == rhs._ptr; } 49 | bool operator!=(const const_iterator& rhs) const { return _ptr != rhs._ptr; } 50 | const_iterator& operator+=(const difference_type offset) { _ptr += offset; return *this; } 51 | const_iterator& operator-=(const difference_type offset) { _ptr -= offset; return *this; } 52 | }; 53 | 54 | using const_iterator = IXWebSocketSendData_const_iterator; 55 | 56 | /* The assigned std::string must be kept alive for the lifetime of the input buffer */ 57 | IXWebSocketSendData(const std::string& str) 58 | : _data(str.data()) 59 | , _size(str.size()) 60 | { 61 | } 62 | 63 | /* The assigned std::vector must be kept alive for the lifetime of the input buffer */ 64 | IXWebSocketSendData(const std::vector& v) 65 | : _data(v.data()) 66 | , _size(v.size()) 67 | { 68 | } 69 | 70 | /* The assigned std::vector must be kept alive for the lifetime of the input buffer */ 71 | IXWebSocketSendData(const std::vector& v) 72 | : _data(reinterpret_cast(v.data())) 73 | , _size(v.size()) 74 | { 75 | } 76 | 77 | /* The assigned memory must be kept alive for the lifetime of the input buffer */ 78 | IXWebSocketSendData(const char* data, size_t size) 79 | : _data(data) 80 | , _size(data == nullptr ? 0 : size) 81 | { 82 | } 83 | 84 | bool empty() const 85 | { 86 | return _data == nullptr || _size == 0; 87 | } 88 | 89 | const char* c_str() const 90 | { 91 | return _data; 92 | } 93 | 94 | const char* data() const 95 | { 96 | return _data; 97 | } 98 | 99 | size_t size() const 100 | { 101 | return _size; 102 | } 103 | 104 | inline const_iterator begin() const 105 | { 106 | return const_iterator(const_cast(_data)); 107 | } 108 | 109 | inline const_iterator end() const 110 | { 111 | return const_iterator(const_cast(_data) + _size); 112 | } 113 | 114 | inline const_iterator cbegin() const 115 | { 116 | return begin(); 117 | } 118 | 119 | inline const_iterator cend() const 120 | { 121 | return end(); 122 | } 123 | 124 | private: 125 | const char* _data; 126 | const size_t _size; 127 | }; 128 | 129 | } -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketSendInfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketSendInfo.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | namespace ix 10 | { 11 | struct WebSocketSendInfo 12 | { 13 | bool success; 14 | bool compressionError; 15 | size_t payloadSize; 16 | size_t wireSize; 17 | 18 | WebSocketSendInfo(bool s = false, bool c = false, size_t p = 0, size_t w = 0) 19 | : success(s) 20 | , compressionError(c) 21 | , payloadSize(p) 22 | , wireSize(w) 23 | { 24 | ; 25 | } 26 | }; 27 | } // namespace ix 28 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketServer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketServer.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #include "IXSocketServer.h" 10 | #include "IXWebSocket.h" 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include // pair 19 | 20 | namespace ix 21 | { 22 | class WebSocketServer : public SocketServer 23 | { 24 | public: 25 | using OnConnectionCallback = 26 | std::function, std::shared_ptr)>; 27 | 28 | using OnClientMessageCallback = std::function, WebSocket&, const WebSocketMessagePtr&)>; 30 | 31 | WebSocketServer(int port = SocketServer::kDefaultPort, 32 | const std::string& host = SocketServer::kDefaultHost, 33 | int backlog = SocketServer::kDefaultTcpBacklog, 34 | size_t maxConnections = SocketServer::kDefaultMaxConnections, 35 | int handshakeTimeoutSecs = WebSocketServer::kDefaultHandShakeTimeoutSecs, 36 | int addressFamily = SocketServer::kDefaultAddressFamily); 37 | virtual ~WebSocketServer(); 38 | virtual void stop() final; 39 | 40 | void enablePong(); 41 | void disablePong(); 42 | void disablePerMessageDeflate(); 43 | 44 | void setOnConnectionCallback(const OnConnectionCallback& callback); 45 | void setOnClientMessageCallback(const OnClientMessageCallback& callback); 46 | 47 | // Get all the connected clients 48 | std::set> getClients(); 49 | 50 | void makeBroadcastServer(); 51 | bool listenAndStart(); 52 | 53 | const static int kDefaultHandShakeTimeoutSecs; 54 | 55 | int getHandshakeTimeoutSecs(); 56 | bool isPongEnabled(); 57 | bool isPerMessageDeflateEnabled(); 58 | 59 | private: 60 | // Member variables 61 | int _handshakeTimeoutSecs; 62 | bool _enablePong; 63 | bool _enablePerMessageDeflate; 64 | 65 | OnConnectionCallback _onConnectionCallback; 66 | OnClientMessageCallback _onClientMessageCallback; 67 | 68 | std::mutex _clientsMutex; 69 | std::set> _clients; 70 | 71 | const static bool kDefaultEnablePong; 72 | 73 | // Methods 74 | virtual void handleConnection(std::unique_ptr socket, 75 | std::shared_ptr connectionState); 76 | virtual size_t getConnectedClientsCount() final; 77 | 78 | protected: 79 | void handleUpgrade(std::unique_ptr socket, 80 | std::shared_ptr connectionState, 81 | HttpRequestPtr request = nullptr); 82 | }; 83 | } // namespace ix 84 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/IXWebSocketVersion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * IXWebSocketVersion.h 3 | * Author: Benjamin Sergeant 4 | * Copyright (c) 2019 Machine Zone, Inc. All rights reserved. 5 | */ 6 | 7 | #pragma once 8 | 9 | #define IX_WEBSOCKET_VERSION "11.4.4" 10 | -------------------------------------------------------------------------------- /UwpDumper/third-party/ixwebsocket/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Machine Zone, Inc. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright 11 | notice, this list of conditions and the following disclaimer in the 12 | documentation and/or other materials provided with the 13 | distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived 17 | from this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/LICENSE: -------------------------------------------------------------------------------- 1 | MinHook - The Minimalistic API Hooking Library for x64/x86 2 | Copyright (C) 2009-2017 Tsuda Kageyu. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions 7 | are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright 10 | notice, this list of conditions and the following disclaimer. 11 | 2. Redistributions in binary form must reproduce the above copyright 12 | notice, this list of conditions and the following disclaimer in the 13 | documentation and/or other materials provided with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 18 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 19 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 22 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 23 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 24 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | ================================================================================ 28 | Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov. 29 | ================================================================================ 30 | Hacker Disassembler Engine 32 C 31 | Copyright (c) 2008-2009, Vyacheslav Patkov. 32 | All rights reserved. 33 | 34 | Redistribution and use in source and binary forms, with or without 35 | modification, are permitted provided that the following conditions 36 | are met: 37 | 38 | 1. Redistributions of source code must retain the above copyright 39 | notice, this list of conditions and the following disclaimer. 40 | 2. Redistributions in binary form must reproduce the above copyright 41 | notice, this list of conditions and the following disclaimer in the 42 | documentation and/or other materials provided with the distribution. 43 | 44 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 45 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 46 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 47 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 48 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 49 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 50 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 51 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 52 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 53 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 54 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 | 56 | ------------------------------------------------------------------------------- 57 | Hacker Disassembler Engine 64 C 58 | Copyright (c) 2008-2009, Vyacheslav Patkov. 59 | All rights reserved. 60 | 61 | Redistribution and use in source and binary forms, with or without 62 | modification, are permitted provided that the following conditions 63 | are met: 64 | 65 | 1. Redistributions of source code must retain the above copyright 66 | notice, this list of conditions and the following disclaimer. 67 | 2. Redistributions in binary form must reproduce the above copyright 68 | notice, this list of conditions and the following disclaimer in the 69 | documentation and/or other materials provided with the distribution. 70 | 71 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 72 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 73 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 74 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 75 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 76 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 77 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 78 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 79 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 80 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 81 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 82 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/buffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | // Size of each memory slot. 32 | #if defined(_M_X64) || defined(__x86_64__) 33 | #define MEMORY_SLOT_SIZE 64 34 | #else 35 | #define MEMORY_SLOT_SIZE 32 36 | #endif 37 | 38 | VOID InitializeBuffer(VOID); 39 | VOID UninitializeBuffer(VOID); 40 | LPVOID AllocateBuffer(LPVOID pOrigin); 41 | VOID FreeBuffer(LPVOID pBuffer); 42 | BOOL IsExecutableAddress(LPVOID pAddress); 43 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/hde/hde32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_DISP8 0x00000020 30 | #define F_DISP16 0x00000040 31 | #define F_DISP32 0x00000080 32 | #define F_RELATIVE 0x00000100 33 | #define F_2IMM16 0x00000800 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_ANY 0x3f000000 47 | 48 | #define PREFIX_SEGMENT_CS 0x2e 49 | #define PREFIX_SEGMENT_SS 0x36 50 | #define PREFIX_SEGMENT_DS 0x3e 51 | #define PREFIX_SEGMENT_ES 0x26 52 | #define PREFIX_SEGMENT_FS 0x64 53 | #define PREFIX_SEGMENT_GS 0x65 54 | #define PREFIX_LOCK 0xf0 55 | #define PREFIX_REPNZ 0xf2 56 | #define PREFIX_REPX 0xf3 57 | #define PREFIX_OPERAND_SIZE 0x66 58 | #define PREFIX_ADDRESS_SIZE 0x67 59 | 60 | #pragma pack(push,1) 61 | 62 | typedef struct { 63 | uint8_t len; 64 | uint8_t p_rep; 65 | uint8_t p_lock; 66 | uint8_t p_seg; 67 | uint8_t p_66; 68 | uint8_t p_67; 69 | uint8_t opcode; 70 | uint8_t opcode2; 71 | uint8_t modrm; 72 | uint8_t modrm_mod; 73 | uint8_t modrm_reg; 74 | uint8_t modrm_rm; 75 | uint8_t sib; 76 | uint8_t sib_scale; 77 | uint8_t sib_index; 78 | uint8_t sib_base; 79 | union { 80 | uint8_t imm8; 81 | uint16_t imm16; 82 | uint32_t imm32; 83 | } imm; 84 | union { 85 | uint8_t disp8; 86 | uint16_t disp16; 87 | uint32_t disp32; 88 | } disp; 89 | uint32_t flags; 90 | } hde32s; 91 | 92 | #pragma pack(pop) 93 | 94 | #ifdef __cplusplus 95 | extern "C" { 96 | #endif 97 | 98 | /* __cdecl */ 99 | unsigned int hde32_disasm(const void *code, hde32s *hs); 100 | 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | #endif /* _HDE32_H_ */ 106 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/hde/hde64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include "pstdint.h" 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_ERROR 0x00001000 35 | #define F_ERROR_OPCODE 0x00002000 36 | #define F_ERROR_LENGTH 0x00004000 37 | #define F_ERROR_LOCK 0x00008000 38 | #define F_ERROR_OPERAND 0x00010000 39 | #define F_PREFIX_REPNZ 0x01000000 40 | #define F_PREFIX_REPX 0x02000000 41 | #define F_PREFIX_REP 0x03000000 42 | #define F_PREFIX_66 0x04000000 43 | #define F_PREFIX_67 0x08000000 44 | #define F_PREFIX_LOCK 0x10000000 45 | #define F_PREFIX_SEG 0x20000000 46 | #define F_PREFIX_REX 0x40000000 47 | #define F_PREFIX_ANY 0x7f000000 48 | 49 | #define PREFIX_SEGMENT_CS 0x2e 50 | #define PREFIX_SEGMENT_SS 0x36 51 | #define PREFIX_SEGMENT_DS 0x3e 52 | #define PREFIX_SEGMENT_ES 0x26 53 | #define PREFIX_SEGMENT_FS 0x64 54 | #define PREFIX_SEGMENT_GS 0x65 55 | #define PREFIX_LOCK 0xf0 56 | #define PREFIX_REPNZ 0xf2 57 | #define PREFIX_REPX 0xf3 58 | #define PREFIX_OPERAND_SIZE 0x66 59 | #define PREFIX_ADDRESS_SIZE 0x67 60 | 61 | #pragma pack(push,1) 62 | 63 | typedef struct { 64 | uint8_t len; 65 | uint8_t p_rep; 66 | uint8_t p_lock; 67 | uint8_t p_seg; 68 | uint8_t p_66; 69 | uint8_t p_67; 70 | uint8_t rex; 71 | uint8_t rex_w; 72 | uint8_t rex_r; 73 | uint8_t rex_x; 74 | uint8_t rex_b; 75 | uint8_t opcode; 76 | uint8_t opcode2; 77 | uint8_t modrm; 78 | uint8_t modrm_mod; 79 | uint8_t modrm_reg; 80 | uint8_t modrm_rm; 81 | uint8_t sib; 82 | uint8_t sib_scale; 83 | uint8_t sib_index; 84 | uint8_t sib_base; 85 | union { 86 | uint8_t imm8; 87 | uint16_t imm16; 88 | uint32_t imm32; 89 | uint64_t imm64; 90 | } imm; 91 | union { 92 | uint8_t disp8; 93 | uint16_t disp16; 94 | uint32_t disp32; 95 | } disp; 96 | uint32_t flags; 97 | } hde64s; 98 | 99 | #pragma pack(pop) 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | /* __cdecl */ 106 | unsigned int hde64_disasm(const void *code, hde64s *hs); 107 | 108 | #ifdef __cplusplus 109 | } 110 | #endif 111 | 112 | #endif /* _HDE64_H_ */ 113 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/hde/pstdint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #pragma once 28 | 29 | #include 30 | 31 | // Integer types for HDE. 32 | typedef INT8 int8_t; 33 | typedef INT16 int16_t; 34 | typedef INT32 int32_t; 35 | typedef INT64 int64_t; 36 | typedef UINT8 uint8_t; 37 | typedef UINT16 uint16_t; 38 | typedef UINT32 uint32_t; 39 | typedef UINT64 uint64_t; 40 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/hde/table32.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xf1 30 | #define DELTA_FPU_MODRM 0xf8 31 | #define DELTA_PREFIXES 0x130 32 | #define DELTA_OP_LOCK_OK 0x1a1 33 | #define DELTA_OP2_LOCK_OK 0x1b9 34 | #define DELTA_OP_ONLY_MEM 0x1cb 35 | #define DELTA_OP2_ONLY_MEM 0x1da 36 | 37 | unsigned char hde32_table[] = { 38 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 39 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 40 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 41 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 42 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 43 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 44 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 45 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 46 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 47 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 48 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 49 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 50 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 51 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 52 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 53 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 54 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 55 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 56 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 57 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 59 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 60 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 61 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 62 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 63 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 64 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 65 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 66 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 67 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 68 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 69 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 70 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 71 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 72 | 0xe7,0x08,0x00,0xf0,0x02,0x00 73 | }; 74 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/hde/table64.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /UwpDumper/third-party/minhook/src/trampoline.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MinHook - The Minimalistic API Hooking Library for x64/x86 3 | * Copyright (C) 2009-2017 Tsuda Kageyu. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 19 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 20 | * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 21 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 22 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 23 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 24 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 26 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #pragma once 30 | 31 | #pragma pack(push, 1) 32 | 33 | // Structs for writing x86/x64 instructions. 34 | 35 | // 8-bit relative jump. 36 | typedef struct _JMP_REL_SHORT 37 | { 38 | UINT8 opcode; // EB xx: JMP +2+xx 39 | UINT8 operand; 40 | } JMP_REL_SHORT, *PJMP_REL_SHORT; 41 | 42 | // 32-bit direct relative jump/call. 43 | typedef struct _JMP_REL 44 | { 45 | UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx 46 | UINT32 operand; // Relative destination address 47 | } JMP_REL, *PJMP_REL, CALL_REL; 48 | 49 | // 64-bit indirect absolute jump. 50 | typedef struct _JMP_ABS 51 | { 52 | UINT8 opcode0; // FF25 00000000: JMP [+6] 53 | UINT8 opcode1; 54 | UINT32 dummy; 55 | UINT64 address; // Absolute destination address 56 | } JMP_ABS, *PJMP_ABS; 57 | 58 | // 64-bit indirect absolute call. 59 | typedef struct _CALL_ABS 60 | { 61 | UINT8 opcode0; // FF15 00000002: CALL [+6] 62 | UINT8 opcode1; 63 | UINT32 dummy0; 64 | UINT8 dummy1; // EB 08: JMP +10 65 | UINT8 dummy2; 66 | UINT64 address; // Absolute destination address 67 | } CALL_ABS; 68 | 69 | // 32-bit direct relative conditional jumps. 70 | typedef struct _JCC_REL 71 | { 72 | UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx 73 | UINT8 opcode1; 74 | UINT32 operand; // Relative destination address 75 | } JCC_REL; 76 | 77 | // 64bit indirect absolute conditional jumps that x64 lacks. 78 | typedef struct _JCC_ABS 79 | { 80 | UINT8 opcode; // 7* 0E: J** +16 81 | UINT8 dummy0; 82 | UINT8 dummy1; // FF25 00000000: JMP [+6] 83 | UINT8 dummy2; 84 | UINT32 dummy3; 85 | UINT64 address; // Absolute destination address 86 | } JCC_ABS; 87 | 88 | #pragma pack(pop) 89 | 90 | typedef struct _TRAMPOLINE 91 | { 92 | LPVOID pTarget; // [In] Address of the target function. 93 | LPVOID pDetour; // [In] Address of the detour function. 94 | LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function. 95 | 96 | #if defined(_M_X64) || defined(__x86_64__) 97 | LPVOID pRelay; // [Out] Address of the relay function. 98 | #endif 99 | BOOL patchAbove; // [Out] Should use the hot patch area? 100 | UINT nIP; // [Out] Number of the instruction boundaries. 101 | UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function. 102 | UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function. 103 | } TRAMPOLINE, *PTRAMPOLINE; 104 | 105 | BOOL CreateTrampolineFunction(PTRAMPOLINE ct); 106 | -------------------------------------------------------------------------------- /UwpDumperConsole/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /UwpDumperConsole/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using WebSocketSharp.Server; 7 | using WebSocketSharp; 8 | using System.Net.Sockets; 9 | using static System.Net.Mime.MediaTypeNames; 10 | using System.Net; 11 | using System.Runtime.InteropServices; 12 | using System.Diagnostics; 13 | using System.IO; 14 | using System.Security.AccessControl; 15 | using System.Security.Cryptography; 16 | using System.Security.Principal; 17 | 18 | namespace UwpDumperConsole 19 | { 20 | internal class Program 21 | { 22 | public static WebSocketServer socket = null; 23 | 24 | public class ipc_class : WebSocketBehavior 25 | { 26 | protected override void OnMessage(MessageEventArgs e) 27 | { 28 | Console.Write(e.Data.ToString()); 29 | } 30 | 31 | protected override void OnClose(CloseEventArgs e) 32 | { 33 | Environment.Exit(0); 34 | } 35 | } 36 | 37 | static IntPtr phandle; 38 | static int pid = 0; 39 | 40 | public enum Result : uint 41 | { 42 | Success, 43 | DLLNotFound, 44 | OpenProcFail, 45 | AllocFail, 46 | LoadLibFail, 47 | AlreadyInjected, 48 | ProcNotOpen, 49 | Unknown, 50 | } 51 | 52 | static readonly IntPtr NULL = (IntPtr)0; 53 | 54 | [DllImport("kernel32.dll", SetLastError = true)] 55 | static extern IntPtr OpenProcess(uint access, bool inhert_handle, int pid); 56 | 57 | [DllImport("kernel32.dll", SetLastError = true)] 58 | static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, IntPtr dwSize, uint flAllocationType, uint flProtect); 59 | 60 | [DllImport("kernel32.dll", SetLastError = true)] 61 | static extern int WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, IntPtr nSize, int lpNumberOfBytesWritten); 62 | 63 | [DllImport("kernel32.dll", SetLastError = true)] 64 | static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); 65 | 66 | [DllImport("kernel32.dll", SetLastError = true)] 67 | static extern IntPtr GetModuleHandle(string lpModuleName); 68 | 69 | [DllImport("kernel32.dll", SetLastError = true)] 70 | static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttribute, IntPtr dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, IntPtr lpThreadId); 71 | 72 | static Result r_inject(string dll_path) 73 | { 74 | FileInfo finfo = new FileInfo(dll_path); 75 | FileSecurity fs = finfo.GetAccessControl(); 76 | SecurityIdentifier se = new SecurityIdentifier("S-1-15-2-1"); 77 | fs.AddAccessRule(new FileSystemAccessRule(se, FileSystemRights.FullControl, InheritanceFlags.None, PropagationFlags.NoPropagateInherit, AccessControlType.Allow)); 78 | finfo.SetAccessControl(fs); 79 | 80 | var proc_list = Process.GetProcessesByName("Windows10Universal"); 81 | 82 | if (proc_list.Length == 0) 83 | return Result.ProcNotOpen; 84 | 85 | for (uint i = 0; i < proc_list.Length; i++) 86 | { 87 | var proc = proc_list[i]; 88 | if (pid != proc.Id) 89 | { 90 | var _phandle = OpenProcess(0x0002 | 0x0400 | 0x0008 | 0x0020 | 0x0010, false, proc.Id); 91 | if (_phandle == NULL) 92 | return Result.OpenProcFail; 93 | 94 | var alloc = VirtualAllocEx(_phandle, NULL, (IntPtr)((dll_path.Length + 1) * Marshal.SizeOf(typeof(char))), 0x00002000 | 0x00001000, 0x40); 95 | 96 | if (alloc == NULL) 97 | return Result.AllocFail; 98 | 99 | var bytes = Encoding.Default.GetBytes(dll_path); 100 | var permissions = WriteProcessMemory(_phandle, alloc, bytes, (IntPtr)((dll_path.Length + 1) * Marshal.SizeOf(typeof(char))), 0); 101 | if (permissions == 0 || permissions == 6L) 102 | return Result.Unknown; 103 | 104 | if (CreateRemoteThread(_phandle, NULL, NULL, GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA"), alloc, 0, NULL) == NULL) 105 | return Result.LoadLibFail; 106 | 107 | pid = proc.Id; 108 | phandle = _phandle; 109 | 110 | return Result.Success; 111 | } 112 | else if (pid == proc.Id) 113 | return Result.AlreadyInjected; 114 | } 115 | 116 | return Result.Unknown; 117 | } 118 | 119 | static void Main(string[] args) 120 | { 121 | Console.Title = "UwpDumper!"; 122 | 123 | 124 | socket = new WebSocketServer(64609, false); 125 | socket.AddWebSocketService("/dumper_ipc"); 126 | socket.Start(); 127 | 128 | 129 | if (!File.Exists(Environment.CurrentDirectory + "\\UwpDumper.dll")) 130 | { 131 | Console.WriteLine("Failure to find UwpDumper.dll!"); 132 | } 133 | 134 | r_inject(Environment.CurrentDirectory + "\\UwpDumper.dll"); 135 | 136 | while (socket.IsListening) 137 | { 138 | 139 | } 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /UwpDumperConsole/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("UwpDumperConsole")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UwpDumperConsole")] 13 | [assembly: AssemblyCopyright("Copyright © 2023")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("7c380859-c28d-4102-91a0-9f055a270504")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /UwpDumperConsole/UwpDumperConsole.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {7C380859-C28D-4102-91A0-9F055A270504} 8 | Exe 9 | UwpDumperConsole 10 | UwpDumperConsole 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | ..\packages\WebSocketSharp-netstandard.1.0.1\lib\net45\websocket-sharp.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /UwpDumperConsole/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | --------------------------------------------------------------------------------