Commit Graph

101 Commits

Author SHA1 Message Date
Mikkel Krautz
a3e7958f16 overlay: add runtime check for when GetFnOffsetInModule()'s return value would have overflowed its return type.
See also mumble-voip/mumble#1924
2015-11-24 22:53:42 +01:00
Mikkel Krautz
5f79a3e4e9 overlay: fix a few MSVC signed/unsigned conversion warnings. 2015-11-24 22:50:59 +01:00
Kissaki
da004cf82f Overlay: Resolve undefined behavior
* Now that we no longer do anything when unloading the overlay DLL,
remove the injection of FreeLibrary. This also drops some undefined
behavior.
** If we inject into rendering (D3Dxx.cpp) we hold a self-reference to
prevent to ever be unloaded. For this case, there is no issue as the
hooks will always exist.
** In case of no rendering-injection, our module can actually be
unloaded. In that case, MyFreeLibrary would call the original function
which in turn would lead to a call to DllMain with DLL_PROCESS_DETACH,
at which point we restore the hooks to their original equivalents in
dllmainProcDetach.
However, afterwards, execution returns to our MyFreeLibrary function,
whichs code is no longer the code we began executing.
** This also leads to the question whether the non-trampoline hooking
ever worked/even works. We restore, call the original (which is already
code that no longer exists) and then inject again.
2015-05-23 20:01:00 +02:00
Kissaki
70451a60ce Fix #1637 application crashes on Mumble exit
* When unloading the overlay DLL freeD3D9Hook was called *after* unloading the DLL. This is incorrect.
** For applications that actually use D3D and we inject into, the DLL is
never unloaded because we hold a refernce to it ourselves. So in this case,
the problematic code is never executed.
** When not actually injecting, the DLL will be unloaded, and then the
function freeD3D9Hook is called which is from that DLL.
** As we’re executing code in undefined space which previously held the
function, this may or may not crash.
* Remove the freeD3D9Hook function
** The function freeD3D9Hook just resets some fields to NULL and a flag
to false. As the DLL is unloaded anyway, these are never used again.
Hence, we can just remove it altogether (rather than just calling it
before unloading).
2015-05-16 11:48:01 +02:00
Mikkel Krautz
6c446e4ead Ensure overlay helpers exit when the Mumble process terminates.
Normally, Mumble itself will terminate the helper processes.
But if Mumble crashes, or is manually killed by the user, it
will not be able to terminate the helper processes itself.

In order to fix this, we create a way for the helpers to know
when their parent process has terminated.

This is implemented by creating an inheritable process handle
in Mumble, and passing its value to the helpers.

The helpers then WaitForSingleObject() on the parent handle, and
exits with status code 0 if it the WaitForSingleObject() call
returns successfully.
2015-04-22 21:03:53 +02:00
Mikkel Krautz
3018c5e90a Handle WM_CLOSE messages in overlay helper.
When Qt terminates a QProcess via the terminate()
method, it sends a WM_CLOSE message.

However, the overlay helper did not know of WM_CLOSE,
so it would quietly ignore it.

This commit teaches the overlay helper to exit on
WM_CLOSE.
2015-04-22 21:03:48 +02:00
Mikkel Krautz
d609879695 Use arch-specific shared memory regions in the Windows overlay.
Vtable offsetes is almost all that we store in the shared memory,
and they vary by architecture.

So, don't share the memory between arches. Instead, crate
arch-specific shared memory regions.
2015-04-22 21:03:41 +02:00
Mikkel Krautz
9f1e60507b Move Windows overlay setup and injection to mumble_ol.exe.
This changes Mumble on Windows to run a helper process,
mumble_ol.exe, instead of loading mumble_ol.dll itself.

Prior to this change, Mumble would load mumble_ol.dll and
call PrepareD3D9() and PrepareDXGI() to set up the overlay.
Then, if the overlay was enabled, it would call InstallHooks()
to enable automatic injection of the overlay into new processes.
Similarly, it would call RemoveHooks() to disable automatic
overlay injection when the overlay was disabled in Mmuble.

With this change, Mumble instead runs a helper process called
mumble_ol.exe. This process sets up the overlay (equivalent
to calling PrepareD3D9(), PrepareDXGI() and calling InstallHooks()).
While running, it'll automatically inject the overlay into new
processes, just like Mumble itself did previously. On normal exit,
the helper process calls RemoveHooks() to ensure automatic overlay
injection is disabled.

To enable the overlay, Mumble starts the helper process.
To disable the overlay, Mumble terminates the helper process.
If the helper process dies when it is supposed to be running,
Mumble restarts it to ensure that overlay injection keeps
working as intended.

This change is the first part of enabling both an x86 and an x64
overlay to be active in Mumble at the same time. Since we cannot
load a 32-bit DLL into a 64-bit process (or vice versa), we need
a helper process for each architecture to reach our goal.
Note however that this commit in itself does not make it possible
for Mumble to run both an x86 and an x64 overlay at the same time.
This will come later.
2015-01-15 16:48:27 +01:00
Mikkel Krautz
93ad74b467 Add MinHook-based overlay for Windows x64.
This commit adds MinHook as a 3rd party
dependency and adds an alternative HardHook
implementation that makes use of MinHook.

This new MinHook-based HardHook implementation
allows us to provide an overlay for Mumble on
Windows x64.

The x64 overlay hasn't seen much testing in
real-world x64 games, except some minor testing
for World of Warcraft running in x64 mode, where
it works just fine.

There seems to be a compatibility with the Uplay
overlay, which causes Far Cry 4 to crash at the
"Press any key to continue" screen that is shown
just after launching the game. However,
Assassin's Creed: Unity works fine, so it might
just be a Far Cry 4 issue.

The x64 overlay also seems to interoperate with
the Steam overlay just fine.

I think this is a good starting point for the
feature. Let us get it into snapshots and let
us try to squash any addition bugs we find.
2015-01-03 19:44:02 +01:00
Mikkel Krautz
f1dbd922b8 Ensure up-to-date built-in overlay blacklist.
This changeset makes the following modifications:

 1. The overlay DLL is changed to always consider the built-in blacklist,
    even if a blacklist is present in the registry.
    For Mumble users who have been running with the old blacklist behavior,
    this means that we'll be doing some duplicate checking for blacklist
    entries, but I don't think this matters in practice.

 2. Settings.cpp is changed to not do anything with overlay_blacklist.h.
    Effectively, this means that qslBlacklist now represents the items
    the user has added to the blacklist, and not the combination of both
    an outdated built-in list and the user's own entries.

 3. OverlayConfig.cpp is changed to always show all entries from
    overlay_blacklist.h. Entries from the built-in list are 'disabled',
    so they can't be interacted with.

For more information, see PR #1461
2014-11-04 21:53:21 +01:00
Mikkel Krautz
c31269ad67 Make Mumble and Murmur build on Windows/amd64. 2014-07-13 13:32:41 +02:00
Kissaki
9544bec1f9 Overlay: Add Direct3D 11 support
* Based on an initial patch by Benjamin Jemlich
* Effects11 code based on changes by nyet
2014-01-10 22:51:11 +01:00
Stefan Hacker
ab12d35621 Fix handling of failed shared data map creation in overlay.
createSharedDataMap can fail to map the shared data used by other
functionality in the overlay dll. In this case pointers including
"sd" remain NULLd. With the recent overlay changes the modified
shared data structures changed, triggering this case when running
different versions. This crashed Mumble on startup due to an
unchecked dereference of the "sd" pointer.

Also when extracting createSharedDataMap during refactoring behavior
was changed. The overlay kept injecting itself even if the mapping
failed. This also addresses this by making createSharedDataMap return
a bool indicating success or failure.
2013-11-30 18:08:15 +01:00
Jan Klass
5f98a65698 Merge pull request #1075 from mumble-voip/olay-changes
Overlay: Rework Code.
2013-11-27 10:38:51 -08:00
Kissaki
80a9350309 Overlay: Code improvements
* Use ARRAY_NUM_ELEMENTS(array) instead of constant
2013-11-26 18:51:56 +01:00
Kissaki
cd4e8350a5 Overlay: Changes as per PR-comments
* Use sizeof() rather then size constant where possible
2013-11-24 23:18:29 +01:00
Kissaki
dfbc1b9279 Overlay: Changes as per PR-comments
* Make cpp-local functions static so they are local file/translation unit
scope.
* Remove unused variables uiAudioCount and bVideoHooked
* Comment extern declarations, where there definitions are located.
* Improve constant naming JUMPOP_OFFSET => JMP_OP_SIZE.
* Remove extern declaration from method definitions.
* Adjust type declaration formatting to typical formatting.
* Use voidFunc typedef to pass around function address pointers.
** C++-style casts instead of C-style raw casts.
* Other minor formatting (/whitespace) adjustments
* Fix log text.
* Improve log text.
* Consistent, improved varnaming in d3d9.cpp on address calculation;
naming fn and base.
2013-11-24 19:20:24 +01:00
Kissaki
250835e83b Overlay: Rework Code.
* Separate DXGI logic from D3D10 into a separate file dxgi.cpp
* Structure code and logic, introduce additional functions
* Introduce constants
* Code commenting
* d3d9.cpp:
** Access devMap via std::find rather than operator[]
** Introduce class Stash to temporarily set variable value and revert on
destruction
** Move logic to function findOriginalDevice
** Use widestring for modulename (consistency)
** Implement Hook for Direct3DCreate9Ex
** Move function IsFnInModule to common lib.cpp/.h
* opengl.cpp:
** Add whitespace to format code
** Fix logging scope prefix
** Remove static global variable
2013-11-22 19:27:52 +01:00
Mikkel Krautz
087e38a258 overlay: fix blacklist debug ods call. 2013-11-16 13:01:30 +01:00
Kissaki
9d0de38af1 Overlay: Pass on procname buffer 2013-06-17 00:14:45 +02:00
Kissaki
3c787be130 Overlay: Move logic into function ..IsBlacklisted 2013-06-17 00:14:44 +02:00
Kissaki
0e7d86094c Overlay: Move DllMain logic into functions 2013-06-17 00:14:37 +02:00
Kissaki
3865e8cab0 Overlay: Code comments 2013-06-16 23:56:45 +02:00
Kissaki
04b344dc42 Overlay: Var init, comment, error loggin. 2013-06-16 14:34:44 +02:00
Kissaki
f09e943b6c * Commenting, varnaming, fix indent
* commenting and adjusting debug output
* more descriptive varnaming
2013-06-11 23:03:31 +02:00
Kissaki
cab4a3d852 Extend Windows Overlay code and clean it up.
Extend to handle library freeing.
Codeformatting and -cleanup, robustness, and make debugoutput more consistent.

* Indroduce hook for freeing loaded DLLs.
This separates logic between loading and freeing, leading to adjustments to
the recently introduced checks for freed DLLs.
* In HardHook::reset() do a clean and complete reset rather than minimal.
* Memvarinitialisation in HardHook
* Remove logically unused variable bPresenting in d3d9.cpp (always false)
* In d3d10.cpp prefix debugoutput with D3D10 consistently; no more DXGI
which is ambiguous with a d3d11 file that also uses DXGI.
* Consistently use ods instead of fods in the overlay files.
Not in HardHook yet, as that class is used in the Mumble client as well atm
* Fix forwarded return value types (LONG to ULONG)
* TODOs for hook-call-logic in multiple places
* Commenting, formatting and scope / order adjustments
* Introduce variables with constant values (replacing magic/undescriptive constants/numbers)
2013-06-11 23:02:14 +02:00
Kissaki
46fc3ccfc1 Commenting, formatting. Remove obsolete/wrong comment. 2013-06-04 22:37:40 +02:00
Wesley W. Terpstra
10b2d00043 Prevent overlay from disappearing on D3D DLL reloading.
This is confirmed to fix the missing overlay in Guild Wars 2.

When D3D was used by a process thus loading the DLL, but then unloaded we did not inject on subsequent loading of the D3D DLL (in the same exe). Guild Wars 2 did un- and reload the DLL when switching from their launcher to the game.
This commit introduces HardHook::reset() and checks for inactive hardhooks for a newly loaded DLL.

The changes were submitted on sourceforge
https://sourceforge.net/p/mumble/bugs/909/#bf9e
2013-06-04 22:37:36 +02:00
Mikkel Krautz
46d659d415 overlay/d3d9: pass through IDirect3DDevice9 AddRef/Release methods to originals on Windows 8.
We were getting unbalanced AddRef/Releases on Direct3D9 apps running on Windows 8 that ran
fine on Windows 7.  Windows 8 seems to be doing somthing funky with the internal ref count
of IDirect3DDevice9.

For now, piggyback on the orignal ref count methods to be able to determine when to release
ourselves. And cross our fingers that we won't be getting useless ref counts from some other
overlay.

This is a band-aid solution until we find something better.
2012-11-16 01:05:50 +01:00
Kissaki
9bd10b0001 refacs; initialization, var-scope reduction, replace c-style casts, rm unused
* DBus.h, AudioOutputSpeech.cpp: initialize uninitialized members,
* d3d10.cpp: actually use assigned results for a dbg output
* lib.cpp, link.cpp: c-style to c++-style casts
* SpeexMark.cpp, ResampMark.cpp: rm unused var
* AGC.cpp, ResampMark.cpp:
rm unused var (ineffective return statement after prior return;
thus removing unused code - but someone check if sth. was missed there)
2012-10-24 19:24:33 +02:00
Benjamin Jemlich
491cd1eb44 Misc fixes 2012-02-26 08:36:19 +01:00
Kissaki
5fe6801b1b handle some cppcheck-found issues:
* uninitialized membervars,
* AudioOutput.cpp: fix delete on array to delete[]
* OSS.cpp: close file descriptor in false data case
* OverlayEditorScene.cpp: rm duplicate logic
* fix ifndef to match usage of declared variable
* member var initializations
* check for null (ds in d3d9 as some lines above),
* lower scope of var decl.,
* swap bufsize check and array dereference so check is before! deref,
* initialize member vars in constr.
2011-10-09 14:01:58 +02:00
Benjamin Jemlich
6a52586995 Move overlay blacklist to its own file 2011-05-16 19:51:21 +02:00
Thorvald Natvig
f3437a6ba7 Update copyright year ranges of dev team. 2011-03-18 05:52:51 +01:00
Stefan Hacker
8c952c3bd2 Remove duplicate overlay debug output code.
Factor fods and its base function out to ods.h/cpp and use it in HardHook as well as lib functionality. This also fixes previous divergence between the two ods functions.
2011-03-06 20:39:35 +01:00
Stefan Hacker
3db23e6b5f Make mumble overlay able to detect mumble independent of executable name 2011-02-27 02:54:17 +01:00
Thorvald Natvig
1161c9a1c4 Remove 1.1.x - no longer maintained 2011-02-20 04:21:34 +01:00
Thorvald Natvig
8a44cb950d Indent, changelog, submodule and language update 2011-01-21 03:47:51 +01:00
Thorvald Natvig
e1b24d25f0 Clean up a few compiler warnings. 2011-01-20 18:25:15 -08:00
Stefan Hacker
194ab5697f Fix overlay causing stack overflow when closing vs2010 solution
The amount of stack allocated for reading the black/whitelist values from the registry caused a stack overflow when closing solutions in vs2010. The fix is to switch to dynamic allocation on the heap for this variable. This fix also contains minor refactoring for better readability and adds a bit of additional debug output.
2011-01-09 15:42:42 +01:00
Stefan Hacker
ee8dcd8e55 Fix some problems with overlay backlisting not preventing dx hooking. Improve checking for WPF. 2010-12-23 19:53:07 +01:00
Stefan Hacker
0813b58cd5 Add 'M:' prefix to fods/ods overlay debugging function output 2010-12-23 19:36:01 +01:00
Benjamin Jemlich
34ff2e7aee More potential a_ucTexture == NULL crash fixes 2010-11-19 15:42:25 +01:00
Benjamin Jemlich
bee5338dda Readd overlay hook on DLL_THREAD_ATTACH 2010-11-02 17:14:38 +01:00
Benjamin Jemlich
ab2ed68d8e Blacklist WPF apps in the overlay 2010-09-27 18:44:21 +02:00
Benjamin Jemlich
385f25684a Fix overlay dll debug output 2010-07-26 13:36:09 +02:00
Benjamin Jemlich
8f0a2bdbb6 Revert "Overlay blacklist wmpnscfg.exe and fix the mumble_ol.dll's debug output" because it breaks the overlay
This reverts commit c24b79e5f0.
2010-07-26 08:26:54 +02:00
Stefan Hacker
c24b79e5f0 Overlay blacklist wmpnscfg.exe and fix the mumble_ol.dll's debug output 2010-07-24 15:58:55 +02:00
Stefan Hacker
ec31de1b25 Add black/whitelist icon loading for Windows. Make lists match on full path as well as executable names 2010-05-04 18:07:33 +02:00
Stefan Hacker
620f169d2f Make sure the overlay closes its registry handle 2010-03-16 20:25:30 +01:00