1 // Copyright 2005-2019 The Mumble Developers. All rights reserved. 2 // Use of this source code is governed by a BSD-style license 3 // that can be found in the LICENSE file at the root of the 4 // Mumble source tree or at <https://www.mumble.info/LICENSE>. 5 6 #ifndef MUMBLE_LIB_H_ 7 #define MUMBLE_LIB_H_ 8 9 #define _UNICODE 10 #ifdef _WIN32_WINNT 11 # undef _WIN32_WINNT 12 #endif 13 #define _WIN32_WINNT 0x0501 14 #include <stdio.h> 15 #include <stdarg.h> 16 #include <ctype.h> 17 #include <windows.h> 18 #include <math.h> 19 #include <map> 20 #include <vector> 21 #include <string> 22 #include <boost/optional.hpp> 23 #include "overlay.h" 24 #include "HardHook.h" 25 #include "ods.h" 26 27 #define lround(x) static_cast<long int>((x) + (((x) >= 0.0) ? 0.5 : -0.5)) 28 29 #define ARRAY_SIZE_BYTES(x) sizeof(x) 30 #define ARRAY_NUM_ELEMENTS(x) (sizeof(x)/sizeof((x)[0])) 31 32 using namespace std; 33 34 void __cdecl ods(const char *format, ...); 35 36 const int MODULEFILEPATH_BUFLEN = 2048; 37 const int PROCNAMEFILEPATH_BUFLEN = 1024; 38 const int PROCNAMEFILEPATH_EXTENDED_EXTLEN = 64; 39 const int PROCNAMEFILEPATH_EXTENDED_BUFFER_BUFLEN = PROCNAMEFILEPATH_BUFLEN + PROCNAMEFILEPATH_EXTENDED_EXTLEN; 40 41 struct Direct3D9Data { 42 /// Filepath of the module the offsets are for. 43 wchar_t wcFileName[MODULEFILEPATH_BUFLEN]; 44 size_t offsetCreate; 45 size_t offsetCreateEx; 46 }; 47 48 struct DXGIData { 49 /// Filepath of the module the offsets are for. 50 wchar_t wcFileName[MODULEFILEPATH_BUFLEN]; 51 size_t offsetPresent; 52 size_t offsetResize; 53 }; 54 55 struct D3D10Data { 56 /// Filepath of the module the offsets are for. 57 wchar_t wcFileName[MODULEFILEPATH_BUFLEN]; 58 size_t offsetAddRef; 59 size_t offsetRelease; 60 }; 61 62 struct D3D11Data { 63 /// Filepath of the module the offsets are for. 64 wchar_t wcFileName[MODULEFILEPATH_BUFLEN]; 65 size_t offsetAddRef; 66 size_t offsetRelease; 67 }; 68 69 struct SharedData { 70 bool bHooked; 71 }; 72 73 class Mutex { 74 protected: 75 static CRITICAL_SECTION cs; 76 public: 77 static void init(); 78 Mutex(); 79 ~Mutex(); 80 }; 81 82 class Pipe { 83 private: 84 HANDLE hSocket; 85 HANDLE hMemory; 86 87 void release(); 88 protected: 89 unsigned int uiWidth, uiHeight; 90 unsigned int uiLeft, uiTop, uiRight, uiBottom; 91 unsigned char *a_ucTexture; 92 DWORD dwAlreadyRead; 93 OverlayMsg omMsg; 94 95 void checkMessage(unsigned int w, unsigned int h); 96 bool sendMessage(const OverlayMsg &m); 97 virtual void blit(unsigned int x, unsigned int y, unsigned int w, unsigned int h) = 0; 98 virtual void setRect() = 0; 99 virtual void newTexture(unsigned int w, unsigned int h) = 0; 100 Pipe(); 101 virtual ~Pipe(); 102 public: 103 void disconnect(); 104 }; 105 106 // From lib.cpp 107 extern void checkHooks(bool preonly = false); 108 // From dxgi.cpp 109 extern void checkDXGIHook(bool preonly = false); 110 // From d3d10.cpp 111 extern void checkDXGI10Hook(bool preonly = false); 112 // From d3d11.cpp 113 extern void checkDXGI11Hook(bool preonly = false); 114 // From d3d9.cpp 115 extern void checkD3D9Hook(bool preonly = false); 116 // From opengl.cpp 117 extern void checkOpenGLHook(); 118 119 // From d3d9.cpp 120 extern Direct3D9Data *d3dd; 121 // From dxgi.cpp 122 extern DXGIData *dxgi; 123 // From d3d10.cpp 124 extern D3D10Data *d3d10; 125 // From d3d11.cpp 126 extern D3D11Data *d3d11; 127 // From lib.cpp 128 extern BOOL bIsWin8; 129 130 // From lib.cpp 131 /// Checks if the module of the function pointer fnptr equals the module filepath 132 /// of refmodulepath. 133 /// 134 /// @param fnptr 135 /// @param refmodulepath the module path to compare against 136 /// @param logPrefix Used for debug logging. 137 /// @param fnName name of the method fnptr points to. used for debug logging 138 /// @return true if the module filepath of the function pointer matches the reference one 139 extern bool IsFnInModule(voidFunc fnptr, wchar_t *refmodulepath, const std::string &logPrefix, const std::string &fnName); 140 141 // From lib.cpp 142 /// Checks fnptr is in a loaded module with module path refmodulepath. 143 /// 144 /// @return Offset as int or < 0 on failure. 145 extern boost::optional<size_t> GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName); 146 147 #endif 148