/// @param hDXGI must be a valid module handle. void hookDXGI(HMODULE hDXGI, bool preonly) { wchar_t modulename[MODULEFILEPATH_BUFLEN]; GetModuleFileNameW(NULL, modulename, ARRAY_NUM_ELEMENTS(modulename)); ods("DXGI: hookDXGI in App '%ls'", modulename); // Add a ref to ourselves; we do NOT want to get unloaded directly from this process. HMODULE hTempSelf = NULL; GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<LPCTSTR>(&hookDXGI), &hTempSelf); bHooked = true; // Can we use the prepatch data? GetModuleFileNameW(hDXGI, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(dxgi->wcFileName, modulename) == 0) { // The module seems to match the one we prepared d3dd for. unsigned char *raw = (unsigned char *) hDXGI; HookPresentRaw((voidFunc)(raw + dxgi->offsetPresent)); HookResizeRaw((voidFunc)(raw + dxgi->offsetResize)); } else if (! preonly) { ods("DXGI: Interface changed, can't rawpatch. Current: %ls ; Previously: %ls", modulename, dxgi->wcFileName); } else { bHooked = false; } }
BOOL CBtWin8Interface::SetDescriptors() { HRESULT hr = E_FAIL; GUID guid = GUID_SPI_COMM_SERVICE; HANDLE hService = OpenBleService(&m_bth, &guid); if (hService == INVALID_HANDLE_VALUE) return FALSE; FP_BluetoothGATTSetDescriptorValue pSetDescr = (FP_BluetoothGATTSetDescriptorValue)GetProcAddress(m_hLib, "BluetoothGATTSetDescriptorValue"); if (pSetDescr) { BTH_LE_GATT_DESCRIPTOR_VALUE DescriptorValue; RtlZeroMemory(&DescriptorValue, sizeof(DescriptorValue)); DescriptorValue.DescriptorType = ClientCharacteristicConfiguration; DescriptorValue.ClientCharacteristicConfiguration.IsSubscribeToNotification = 1; // DescriptorValue.ClientCharacteristicConfiguration.IsSubscribeToIndication = 1; hr = pSetDescr(hService, &m_descrSpiDataClientConfig, &DescriptorValue, BLUETOOTH_GATT_FLAG_NONE); ods ("BluetoothGATTSetDescriptorValue hr:0x%x\n", hr); if (hr == S_OK) { hr = pSetDescr(hService, &m_descrSpiControlClientConfig, &DescriptorValue, BLUETOOTH_GATT_FLAG_NONE); ods ("BluetoothGATTSetDescriptorValue hr:0x%x\n", hr); } } CloseHandle(hService); return hr == S_OK; }
static HRESULT __stdcall myResetEx(IDirect3DDevice9Ex *idd, D3DPRESENT_PARAMETERS *param, D3DDISPLAYMODEEX *param2) { ods("D3D9: Chaining ResetEx"); DevMapType::iterator it = devMap.find(idd); DevState *ds = it != devMap.end() ? it->second : NULL; if (ds) { if (ds->dwMyThread) { ods("D3D9: myResetEx from other thread"); } Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ResetExType oResetEx = (ResetExType) hhResetEx.call; hhResetEx.restore(); HRESULT hr = oResetEx(idd, param, param2); hhResetEx.inject(); if (ds) ds->createCleanState(); return hr; }
static ULONG __stdcall myRelease(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); DevState *ds = it != devMap.end() ? it->second : NULL; if (ds) { // Release is called very often. Thus, we do not want to always log here. #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to Release."); #endif if (ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount--; return ds->initRefCount + ds->refCount; } else { ds->refCount--; } if (ds->refCount <= 1) { ds->disconnect(); } if (ds->refCount >= 0) { return ds->initRefCount + ds->refCount; } ods("D3D9: Final release is following. MyRefs = %d, Tot = %d", ds->myRefCount, ds->refCount); if (ds->dwMyThread != 0) { ods("D3D9: finalRelease from other thread"); } // Codeblock for stashing threadid { Stash<DWORD> stashThread(&(ds->dwMyThread), GetCurrentThreadId()); ds->releaseAll(); } ods("D3D9: Final release of %p. MyRefs = %d Tot = %d", idd, ds->myRefCount, ds->refCount); devMap.erase(it); delete ds; ds = NULL; } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ReleaseType oRelease = (ReleaseType) hhRelease.call; hhRelease.restore(); ULONG res = oRelease(idd); hhRelease.inject(); // Release is called very often. Thus, we do not want to always log here. #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained Release with result %d", res); #endif return res; }
static ULONG __stdcall myRelease(ID3D10Device *pDevice) { //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ReleaseType oRelease = (ReleaseType) hhRelease.call; hhRelease.restore(); ULONG res = oRelease(pDevice); hhRelease.inject(); Mutex m; DeviceMap::iterator it = devices.find(pDevice); if (it != devices.end()) { D10State *ds = it->second; // If we are receiving a lot of subsequent releases lets eagerly drop // our state object. If the device presents something again a state // object is created again just fine anyway. if (res < ds->lHighMark / 2) { ods("D3D10: Deleting resources %u < 0.5 * %u", res, ds->lHighMark); devices.erase(it); chains.erase(ds->pSwapChain); delete ds; ods("D3D10: Deleted"); ds = NULL; } } return res; }
extern "C" BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID) { char procname[PROCNAMEFILEPATH_EXTENDED_BUFFER_BUFLEN]; GetModuleFileNameA(NULL, procname, ARRAY_NUM_ELEMENTS(procname)); // Fix for windows XP; on length nSize does not include null-termination // @see http://msdn.microsoft.com/en-us/library/windows/desktop/ms683197%28v=vs.85%29.aspx procname[ARRAY_NUM_ELEMENTS(procname) - 1] = '\0'; switch (fdwReason) { case DLL_PROCESS_ATTACH: ods("Lib: ProcAttach: %s", procname); dllmainProcAttach(procname); break; case DLL_PROCESS_DETACH: ods("Lib: ProcDetach: %s", procname); dllmainProcDetach(); break; case DLL_THREAD_ATTACH: ods("Lib: ThreadAttach: %s", procname); dllmainThreadAttach(); break; default: break; } return TRUE; }
static IDirect3DDevice9* findOriginalDevice(IDirect3DDevice9 *device) { IDirect3DSwapChain9 *pSwap = NULL; device->GetSwapChain(0, &pSwap); if (pSwap) { IDirect3DDevice9 *originalDevice = NULL; if (SUCCEEDED(pSwap->GetDevice(&originalDevice))) { if (originalDevice == device) { // Found the original device. Release responsibility is passed // to the caller. } else { device = findOriginalDevice(originalDevice); originalDevice->Release(); } } else { ods("D3D9: Failed to recurse to find original device. Could not get Device from Swapchain."); } pSwap->Release(); } else { ods("D3D9: Failed to recurse to find original device. Could not get Swapchain."); } return device; }
DWORD GattRequestCallback( LPVOID pRefData, BLUETOOTH_ADDRESS *pAddress, GUID *pGuidService, DWORD dwServiceInstance, GUID *pGuidChar, DWORD dwCharInstance, GUID *pGuidDescr, DWORD security, BTW_GATT_OPTYPE Op, BTW_GATT_VALUE *pValue ) { ods ("Op:%d\n", Op); if ((Op != BTW_GATT_OPTYPE_NOTIFICATION) && (Op != BTW_GATT_OPTYPE_INDICATION)) return ERROR_SUCCESS; if (*pGuidService != guidSvcLongChar) { ods ("Notification from %04x dropped\n", pGuidService->Data1); return ERROR_SUCCESS; } BTW_GATT_VALUE *p = (BTW_GATT_VALUE *)malloc (sizeof (BTW_GATT_VALUE)); if (!p) return ERROR_SUCCESS; *p = *pValue; PostMessage(((CLongCharDlg *)pRefData)->m_hWnd, WM_USER + (pGuidChar->Data1 & 0xff), (WPARAM)dwCharInstance, (LPARAM)p); return ERROR_SUCCESS; }
static ULONG __stdcall myWin8AddRef(IDirect3DDevice9 *idd) { Mutex m; DevMapType::iterator it = devMap.find(idd); DevState *ds = it != devMap.end() ? it->second : NULL; if (ds && ds->dwMyThread == GetCurrentThreadId()) { // AddRef is called very often. Thus, we do not want to always log here. #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Using own Refcount implementation for call to AddRef (Win8)."); #endif ds->myRefCount++; return ds->refCount; } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. AddRefType oAddRef = (AddRefType) hhAddRef.call; hhAddRef.restore(); ULONG res = oAddRef(idd); hhAddRef.inject(); if (ds) ds->refCount = res; // AddRef is called very often. Thus, we do not want to always log here. #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT ods("D3D9: Chained AddRef (Win8) with result %d", res); #endif return res; }
static HRESULT __stdcall myReset(IDirect3DDevice9 * idd, D3DPRESENT_PARAMETERS *param) { ods("D3D9: Chaining Reset"); DevState *ds = devMap[idd]; if (ds) { DWORD dwOldThread = ds->dwMyThread; if (dwOldThread) ods("D3D9: myReset from other thread"); ds->dwMyThread = GetCurrentThreadId(); ds->releaseAll(); ds->dwMyThread = dwOldThread; } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ResetType oReset = (ResetType) hhReset.call; hhReset.restore(); HRESULT hr = oReset(idd, param); hhReset.inject(); if (ds) ds->createCleanState(); return hr; }
static HRESULT __stdcall myReset(IDirect3DDevice9 * idd, D3DPRESENT_PARAMETERS *param) { ods("D3D9: Chaining Reset"); DevState *ds = devMap[idd]; if (ds) { DWORD dwOldThread = ds->dwMyThread; if (dwOldThread) ods("myReset from other thread"); ds->dwMyThread = GetCurrentThreadId(); ds->releaseAll(); ds->dwMyThread = dwOldThread; resetAdditions(); } ResetType oReset = (ResetType) hhReset.call; hhReset.restore(); HRESULT hr=oReset(idd, param); hhReset.inject(); if (ds) ds->createCleanState(); return hr; }
int GetFnOffsetInModule(voidFunc fnptr, wchar_t *refmodulepath, unsigned int refmodulepathLen, const std::string &logPrefix, const std::string &fnName) { HMODULE hModule = NULL; if (! GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, (char *) fnptr, &hModule)) { ods((logPrefix + ": Failed to get module for " + fnName).c_str()); return -1; } const bool bInit = refmodulepath[0] == '\0'; if (bInit) { GetModuleFileNameW(hModule, refmodulepath, refmodulepathLen); } else { wchar_t modulename[MODULEFILEPATH_BUFLEN]; GetModuleFileNameW(hModule, modulename, ARRAY_NUM_ELEMENTS(modulename)); if (_wcsicmp(modulename, refmodulepath) != 0) { ods((logPrefix + ": " + fnName + " functions module path does not match previously found. Now: '%ls', Previously: '%ls'").c_str(), modulename, refmodulepath); return -2; } } unsigned char *fn = reinterpret_cast<unsigned char *>(fnptr); unsigned char *base = reinterpret_cast<unsigned char *>(hModule); unsigned long off = static_cast<unsigned long>(fn - base); // XXX: convert this function to use something other than int. // Issue mumble-voip/mumble#1924. if (off > static_cast<unsigned long>(std::numeric_limits<int>::max())) { ods("Internal overlay error: GetFnOffsetInModule() offset greater than return type can hold."); return -1; } return static_cast<int>(off); }
void checkDXGIHook(bool preonly) { static bool bCheckHookActive = false; if (bCheckHookActive) { ods("DXGI: Recursion in checkDXGIHook"); return; } if (dxgi->offsetPresent == 0 || dxgi->offsetResize == 0) return; bCheckHookActive = true; HMODULE hDXGI = GetModuleHandleW(L"DXGI.DLL"); if (hDXGI) { if (! bHooked) { hookDXGI(hDXGI, preonly); } #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT } else { ods("DXGI: No DXGI.DLL found as loaded. No hooking at this point."); #endif } bCheckHookActive = false; }
static ULONG __stdcall myWin8AddRef(IDirect3DDevice9 *idd) { Mutex m; ods("D3D9: Chaining AddRef (Win8)"); DevState *ds = devMap[idd]; if (ds && ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount++; return ds->refCount; } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. AddRefType oAddRef = (AddRefType) hhAddRef.call; hhAddRef.restore(); ULONG res = oAddRef(idd); hhAddRef.inject(); if (ds) ds->refCount = res; ods("D3D9: Chained AddRef (Win8) with result %d", res); return res; }
void checkDXGI10Hook(bool preonly) { static bool bCheckHookActive = false; if (bCheckHookActive) { ods("D3D10: Recursion in checkDXGI10Hook"); return; } if (d3d10->iOffsetAddRef == 0 || d3d10->iOffsetRelease == 0) { return; } bCheckHookActive = true; HMODULE hD3D10 = GetModuleHandleW(L"D3D10CORE.DLL"); if (hD3D10) { if (! bHooked) { hookD3D10(hD3D10, preonly); } } else { #ifdef EXTENDED_OVERLAY_DEBUGOUTPUT if (hDXGI) { ods("D3D10: No DXGI.DLL found as loaded. No hooking at this point."); } else { ods("D3D10: No D3D10CORE.DLL found as loaded. No hooking at this point."); } #endif } bCheckHookActive = false; }
BOOL CBtWin7Interface::GetDescriptorValue(GUID uuidChar, USHORT inx, USHORT uuidDescr, BTW_GATT_VALUE *pValue) { ods("+%S\n", __FUNCTIONW__); DWORD dwResult; BTW_GATT_VALUE value = {0}; GUID guidChar = uuidChar; GUID guidDescr = guidBT; guidDescr.Data1 = uuidDescr; FP_BtwGattReadDescriptor pReadDescr = (FP_BtwGattReadDescriptor)GetProcAddress(m_hLib, "BtwGattReadDescriptor"); if (pReadDescr) { value.value[0] = 0; value.value[1] = 0; value.len = 2; dwResult = (*pReadDescr)(m_hReg, &m_bth, &m_guid, 0, &guidChar, inx, &guidDescr, 0, pValue, TRUE, NULL); if (dwResult == ERROR_SUCCESS) { ods("-%S %d\n", __FUNCTIONW__, dwResult); return TRUE; } } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; }
void OFrame :: ValueReset ( ) { if ( !ods()->IsSingleReference() || ods()->Item()->AutoPosition() ) OEHControlValue::ValueReset(); else OEHControlValue::ValueSelected(); }
static HRESULT __stdcall myCreateDeviceEx(IDirect3D9Ex * id3d, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS *pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, IDirect3DDevice9Ex** ppReturnedDeviceInterface) { Mutex m; ods("D3D9: Chaining CreateDeviceEx"); // BehaviorFlags &= ~D3DCREATE_PUREDEVICE; //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. CreateDeviceExType oCreateDeviceEx = (CreateDeviceExType) hhCreateDeviceEx.call; hhCreateDeviceEx.restore(); HRESULT hr = oCreateDeviceEx(id3d, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface); hhCreateDeviceEx.inject(); if (FAILED(hr)) return hr; IDirect3DDevice9Ex *idd = *ppReturnedDeviceInterface; DevState *ds = new DevState; ds->dev = idd; idd->AddRef(); ds->initRefCount = idd->Release(); devMap[idd] = ds; // The offsets are dependent on the declaration order of the struct. // See IDirect3DDevice9 (2nd, 3rd, 17th, 18th functions) const unsigned int offsetAddref = 1; const unsigned int offsetRelease = 2; const unsigned int offsetReset = 16; const unsigned int offsetPresent = 17; if (bIsWin8) { hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myWin8AddRef)); hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myWin8Release)); } else { hhAddRef.setupInterface(idd, offsetAddref, reinterpret_cast<voidFunc>(myAddRef)); hhRelease.setupInterface(idd, offsetRelease, reinterpret_cast<voidFunc>(myRelease)); } hhReset.setupInterface(idd, offsetReset, reinterpret_cast<voidFunc>(myReset)); hhPresent.setupInterface(idd, offsetPresent, reinterpret_cast<voidFunc>(myPresent)); IDirect3DSwapChain9 *pSwap = NULL; idd->GetSwapChain(0, &pSwap); if (pSwap) { // The offset is dependent on the declaration order of the struct. // See IDirect3DSwapChain9 (Present is the fourth function) const unsigned int offsetPresent = 3; hhSwapPresent.setupInterface(pSwap, offsetPresent, reinterpret_cast<voidFunc>(mySwapPresent)); pSwap->Release(); } else { ods("D3D9: Failed to get swapchain for DevEx"); } ds->createCleanState(); return hr; }
BOOL CBtWin7Interface::SendWsUpgradeCommand(BYTE Command, USHORT sParam) { ods("+%S\n", __FUNCTIONW__); BTW_GATT_VALUE value = {3, Command, sParam & 0xff, (sParam >> 8) & 0xff}; DWORD dwResult = 0; FP_BtwGattWriteCharacteristic pWriteChar = (FP_BtwGattWriteCharacteristic)GetProcAddress(m_hLib, "BtwGattWriteCharacteristic"); if (pWriteChar) { dwResult = (*pWriteChar)(m_hReg, &m_bth, &guidSvcWSUpgrade, 0, &guidCharWSUpgradeControlPoint, 0, 0, &value, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; } BOOL CBtWin7Interface::SendWsUpgradeCommand(BYTE Command, ULONG lParam) { ods("+%S\n", __FUNCTIONW__); BTW_GATT_VALUE value = {5, Command, lParam & 0xff, (lParam >> 8) & 0xff, (lParam >> 16) & 0xff, (lParam >> 24) & 0xff}; DWORD dwResult = 0; FP_BtwGattWriteCharacteristic pWriteChar = (FP_BtwGattWriteCharacteristic)GetProcAddress(m_hLib, "BtwGattWriteCharacteristic"); if (pWriteChar) { dwResult = (*pWriteChar)(m_hReg, &m_bth, &guidSvcWSUpgrade, 0, &guidCharWSUpgradeControlPoint, 0, 0, &value, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; } BOOL CBtWin7Interface::SendWsUpgradeData(BYTE *Data, DWORD len) { ods("+%S\n", __FUNCTIONW__); BTW_GATT_VALUE value; if (len > sizeof (value.value)) { ods("-%S data too long\n", __FUNCTIONW__); return (FALSE); } value.len = (USHORT)len; memcpy (value.value, Data, len); DWORD dwResult = 0; FP_BtwGattWriteCharacteristic pWriteChar = (FP_BtwGattWriteCharacteristic)GetProcAddress(m_hLib, "BtwGattWriteCharacteristic"); if (pWriteChar) { dwResult = (*pWriteChar)(m_hReg, &m_bth, &guidSvcWSUpgrade, 0, &guidCharWSUpgradeData, 0, 0, &value, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; }
void HardHook::check() { if (memcmp(baseptr, replace, 6) != 0) { if (memcmp(baseptr, orig, 6) == 0) { ods("HH: Restoring function %p", baseptr); inject(true); } else { ods("HH: Function %p replaced by third party. Lost."); } } }
/// This function is called by the Mumble client in Mumble's scope /// mainly to extract the offsets of various functions in the IDXGISwapChain /// and IDXGIObject interfaces that need to be hooked in target /// applications. The data is stored in the dxgi shared memory structure. extern "C" __declspec(dllexport) void __cdecl PrepareDXGI() { if (! dxgi) return; ods("DXGI: Preparing static data for DXGI Injection"); dxgi->wcFileName[0] = 0; dxgi->offsetPresent = 0; dxgi->offsetResize = 0; // Make sure this is Vista or greater as quite a number of <=WinXP users have fake DX10 libs installed OSVERSIONINFOEXW ovi; memset(&ovi, 0, sizeof(ovi)); ovi.dwOSVersionInfoSize = sizeof(ovi); GetVersionExW(reinterpret_cast<OSVERSIONINFOW *>(&ovi)); if (ovi.dwMajorVersion < 6 || (ovi.dwMajorVersion == 6 && ovi.dwBuildNumber < 6001)) { ods("DXGI: No DXGI pre-Vista - skipping prepare"); return; } HMODULE hDXGI = LoadLibrary("DXGI.DLL"); if (hDXGI != NULL) { GetModuleFileNameW(hDXGI, dxgi->wcFileName, ARRAY_NUM_ELEMENTS(dxgi->wcFileName)); CreateDXGIFactory1Type pCreateDXGIFactory1 = reinterpret_cast<CreateDXGIFactory1Type>(GetProcAddress(hDXGI, "CreateDXGIFactory1")); ods("DXGI: Got CreateDXGIFactory1 at %p", pCreateDXGIFactory1); if (pCreateDXGIFactory1) { IDXGIFactory1 * pFactory; HRESULT hr = pCreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)(&pFactory)); if (FAILED(hr)) ods("DXGI: Call to pCreateDXGIFactory1 failed!"); if (pFactory) { IDXGIAdapter1 *pAdapter = NULL; pFactory->EnumAdapters1(0, &pAdapter); /// Offsets have to be identified and initialized only once. bool initializeDXGIData = !dxgi->offsetPresent && !dxgi->offsetResize; PrepareDXGI10(pAdapter, initializeDXGIData); initializeDXGIData = !dxgi->offsetPresent && !dxgi->offsetResize; PrepareDXGI11(pAdapter, initializeDXGIData); pFactory->Release(); } else { FreeLibrary(hDXGI); } } else { FreeLibrary(hDXGI); } } else { FreeLibrary(hDXGI); } }
static void doSwap(HDC hdc) { Context *c = contexts[hdc]; if (!c) { ods("OpenGL: New context for device %p", hdc); c = new Context(hdc); contexts[hdc] = c; } else { ods("OpenGL: Reusing old context"); } c->draw(hdc); }
BOOL CBtWin7Interface::GetHelloInput(BTW_GATT_VALUE *pValue) { ods("+%S\n", __FUNCTIONW__); FP_BtwGattReadCharacteristic pReadChar = (FP_BtwGattReadCharacteristic)GetProcAddress(m_hLib, "BtwGattReadCharacteristic"); DWORD dwResult = 0; if (pReadChar) { dwResult = (*pReadChar)(m_hReg, &m_bth, &guidSvcHello, 0, &guidCharHelloNotify, 0, 0, pValue, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; }
void checkD3D9Hook(bool preonly) { if (bChaining) { ods("D3D9: Causing a chain"); return; } bChaining = true; HMODULE hD3D = GetModuleHandle("D3D9.DLL"); if (hD3D != NULL) { if (! bHooked) { char procname[2048]; GetModuleFileName(NULL, procname, 2048); fods("D3D9: CreateWnd in unhooked D3D App %s", procname); bHooked = true; // Add a ref to ourselves; we do NOT want to get unloaded directly from this process. GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, reinterpret_cast<char *>(&HookCreate), &hSelf); // Can we use the prepatch data? GetModuleFileName(hD3D, procname, 2048); if (_stricmp(d3dd->cFileName, procname) == 0) { unsigned char *raw = (unsigned char *) hD3D; HookCreateRaw((voidFunc)(raw + d3dd->iOffsetCreate)); if (d3dd->iOffsetCreateEx) HookCreateRawEx((voidFunc)(raw + d3dd->iOffsetCreateEx)); } else if (! preonly) { fods("D3D9 Interface changed, can't rawpatch"); pDirect3DCreate9 d3dc9 = reinterpret_cast<pDirect3DCreate9>(GetProcAddress(hD3D, "Direct3DCreate9")); ods("Got %p", d3dc9); if (d3dc9) { IDirect3D9 *id3d9 = d3dc9(D3D_SDK_VERSION); if (id3d9) { HookCreate(id3d9); id3d9->Release(); } else { ods("Failed Direct3DCreate9"); } } else { ods("D3D Library without Direct3DCreate9?"); } } else { bHooked = false; } } } bChaining = false; }
void D10State::newTexture(unsigned int w, unsigned int h) { HRESULT hr; ods("D3D10: newTexture %d %d", w, h); if (pTexture) { pTexture->Release(); pTexture = NULL; } if (pSRView) { pSRView->Release(); pSRView = NULL; } D3D10_TEXTURE2D_DESC desc; ZeroMemory(&desc, sizeof(desc)); desc.Width = w; desc.Height = h; desc.MipLevels = desc.ArraySize = 1; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; desc.SampleDesc.Count = 1; desc.Usage = D3D10_USAGE_DYNAMIC; desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; hr = pDevice->CreateTexture2D(&desc, NULL, &pTexture); if (FAILED(hr)) { pTexture = NULL; ods("D3D10: Failed to create texture."); return; } D3D10_SHADER_RESOURCE_VIEW_DESC srvDesc; ZeroMemory(&srvDesc, sizeof(srvDesc)); srvDesc.Format = desc.Format; srvDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MipLevels = desc.MipLevels; hr = pDevice->CreateShaderResourceView(pTexture, &srvDesc, &pSRView); if (FAILED(hr)) { pSRView = NULL; pTexture->Release(); pTexture = NULL; ods("D3D10: Failed to create resource view."); return; } }
BOOL CBtWin7Interface::SendWsUpgradeCommand(BYTE Command) { ods("+%S\n", __FUNCTIONW__); BTW_GATT_VALUE value = {1, Command}; DWORD dwResult = 0; FP_BtwGattWriteCharacteristic pWriteChar = (FP_BtwGattWriteCharacteristic)GetProcAddress(m_hLib, "BtwGattWriteCharacteristic"); if (pWriteChar) { dwResult = (*pWriteChar)(m_hReg, &m_bth, &guidSvcWSUpgrade, 0, &guidCharWSUpgradeControlPoint, 0, 0, &value, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; }
VOID CALLBACK acceptingIoThreadProc(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PVOID Overlapped, ULONG IoResult, ULONG_PTR NumberOfBytesTransferred, PTP_IO Io) { ods("acceptingIoThreadProc start\n"); BOOL success; LPOVERLAPPED_ACCEPT ola=(LPOVERLAPPED_ACCEPT)Overlapped; SecureZeroMemory(Overlapped, sizeof(OVERLAPPED)); ola->oas=OAS_RECV; DWORD numRead=0; StartThreadpoolIo(ola->tp); success=ReadFile((HANDLE)ola->s, ola->acceptBuf, ola->bufSize, &numRead, &ola->overlapped); if(!success && GetLastError()!=ERROR_IO_PENDING){ int wsaError=WSAGetLastError(); DebugBreak(); } ods("acceptingIoThreadProc return\n"); }
BOOL CBtWin7Interface::SetHelloConfig(BYTE Blinks) { ods("+%S\n", __FUNCTIONW__); BTW_GATT_VALUE value = {1, Blinks}; DWORD dwResult = 0; FP_BtwGattWriteCharacteristic pWriteChar = (FP_BtwGattWriteCharacteristic)GetProcAddress(m_hLib, "BtwGattWriteCharacteristic"); if (pWriteChar) { dwResult = (*pWriteChar)(m_hReg, &m_bth, &guidSvcHello, 0, &guidCharHelloConfig, 0, 0, &value, TRUE, this); ods("-%S %d\n", __FUNCTIONW__, dwResult); return (dwResult == ERROR_SUCCESS); } ods("-%S %d\n", __FUNCTIONW__, dwResult); return FALSE; }
static ULONG __stdcall myRelease(IDirect3DDevice9 *idd) { Mutex m; ods("D3D9: Chaining Release"); DevState *ds = devMap[idd]; if (ds) { if (ds->dwMyThread == GetCurrentThreadId()) { ds->myRefCount--; return ds->refCount + ds->initRefCount; } else { ds->refCount--; } if (ds->refCount <= 1) ds->disconnect(); if (ds->refCount >= 0) return ds->refCount + ds->initRefCount; ods("D3D9: Final release is following. MyRefs = %d, Tot = %d", ds->myRefCount, ds->refCount); DWORD dwOldThread = ds->dwMyThread; if (dwOldThread) ods("D3D9: finalRelease from other thread"); ds->dwMyThread = GetCurrentThreadId(); ds->releaseAll(); ds->dwMyThread = dwOldThread; ods("D3D9: Final release. MyRefs = %d Tot = %d", ds->myRefCount, ds->refCount); devMap.erase(idd); delete ds; } //TODO: Move logic to HardHook. // Call base without active hook in case of no trampoline. ReleaseType oRelease = (ReleaseType) hhRelease.call; hhRelease.restore(); ULONG res = oRelease(idd); hhRelease.inject(); ods("D3D9: Chained Release with result %d", res); return res; }
static bool createSharedDataMap() { DWORD dwSharedSize = sizeof(SharedData) + sizeof(Direct3D9Data) + sizeof(DXGIData) + sizeof(D3D10Data) + sizeof(D3D11Data); #if defined(_M_IX86) const char *name = "MumbleOverlayPrivate-x86"; #elif defined(_M_X64) const char *name = "MumbleOverlayPrivate-x64"; #else # error Unsupported architecture #endif hMapObject = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, dwSharedSize, name); if (hMapObject == NULL) { ods("Lib: CreateFileMapping failed"); return false; } //Note: If the mapping exists dwSharedSize value will be ignored and existing handle returned bool bInit = (GetLastError() != ERROR_ALREADY_EXISTS); unsigned char *rawSharedPointer = static_cast<unsigned char *>( MapViewOfFile(hMapObject, FILE_MAP_ALL_ACCESS, 0, 0, dwSharedSize)); if (rawSharedPointer == NULL) { ods("Lib: MapViewOfFile failed"); return false; } if (bInit) memset(rawSharedPointer, 0, dwSharedSize); sd = reinterpret_cast<SharedData *>(rawSharedPointer); rawSharedPointer += sizeof(SharedData); d3dd = reinterpret_cast<Direct3D9Data *>(rawSharedPointer); rawSharedPointer += sizeof(Direct3D9Data); dxgi = reinterpret_cast<DXGIData *>(rawSharedPointer); rawSharedPointer += sizeof(DXGIData); d3d10 = reinterpret_cast<D3D10Data *>(rawSharedPointer); rawSharedPointer += sizeof(D3D10Data); d3d11 = reinterpret_cast<D3D11Data *>(rawSharedPointer); rawSharedPointer += sizeof(D3D11Data); return true; }