| a256fx | 89dcf84 | 2010-05-12 02:28:19 +0000 | [diff] [blame] | 1 | /* |
| Jonathan Yong | c1fe019 | 2013-03-29 15:04:11 +0000 | [diff] [blame] | 2 | gendef - Generate list of exported symbols from a Portable Executable. |
| Jonathan Yong | 41071fb | 2016-08-10 07:07:29 +0800 | [diff] [blame] | 3 | Copyright (C) 2009-2016 mingw-w64 project |
| a256fx | 89dcf84 | 2010-05-12 02:28:19 +0000 | [diff] [blame] | 4 | |
| Jonathan Yong | c1fe019 | 2013-03-29 15:04:11 +0000 | [diff] [blame] | 5 | This program is free software: you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by |
| 7 | the Free Software Foundation, either version 3 of the License, or |
| 8 | (at your option) any later version. |
| a256fx | 89dcf84 | 2010-05-12 02:28:19 +0000 | [diff] [blame] | 9 | |
| Jonathan Yong | c1fe019 | 2013-03-29 15:04:11 +0000 | [diff] [blame] | 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| a256fx | 89dcf84 | 2010-05-12 02:28:19 +0000 | [diff] [blame] | 14 | |
| Jonathan Yong | c1fe019 | 2013-03-29 15:04:11 +0000 | [diff] [blame] | 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| a256fx | 89dcf84 | 2010-05-12 02:28:19 +0000 | [diff] [blame] | 17 | */ |
| Jonathan Yong | d384237 | 2010-05-01 12:45:00 +0000 | [diff] [blame] | 18 | #include "fsredir.h" |
| 19 | |
| 20 | #ifdef REDIRECTOR |
| 21 | #define WIN32_LEAN_AND_MEAN |
| 22 | #include <windows.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | static PVOID revert; /*revert pointer*/ |
| 27 | static HMODULE kernel32handle; |
| 28 | typedef WINBOOL (__stdcall (*redirector))(PVOID *); |
| 29 | typedef WINBOOL (__stdcall (*revertor))(PVOID); |
| 30 | static redirector redirectorfunction; /*Wow64DisableWow64FsRedirection*/ |
| 31 | static revertor revertorfunction; /*Wow64RevertWow64FsRedirection*/ |
| 32 | |
| 33 | static void undoredirect(void) { |
| 34 | revertorfunction(revert); |
| Jonathan Yong | d384237 | 2010-05-01 12:45:00 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void doredirect(const int redir) { |
| 38 | if (redir) { |
| Jonathan Yong | 7e92ca6 | 2010-08-29 12:46:33 +0000 | [diff] [blame] | 39 | kernel32handle = GetModuleHandleW(L"kernel32.dll"); |
| Jonathan Yong | d384237 | 2010-05-01 12:45:00 +0000 | [diff] [blame] | 40 | if (!kernel32handle) { |
| 41 | fprintf(stderr, "kernel32.dll failed to load, failed to disable FS redirection.\n"); |
| 42 | return; |
| 43 | } |
| Liu Hao | ebd3e57 | 2018-05-02 10:48:01 +0800 | [diff] [blame] | 44 | redirectorfunction = (redirector)(INT_PTR)GetProcAddress(kernel32handle, "Wow64DisableWow64FsRedirection"); |
| 45 | revertorfunction = (revertor)(INT_PTR)GetProcAddress(kernel32handle, "Wow64RevertWow64FsRedirection"); |
| Jonathan Yong | d384237 | 2010-05-01 12:45:00 +0000 | [diff] [blame] | 46 | if (!redirectorfunction || ! revertorfunction) { |
| 47 | FreeLibrary(kernel32handle); |
| 48 | fprintf(stderr, "Wow64DisableWow64FsRedirection or Wow64RevertWow64FsRedirection functions missing.\n"); |
| 49 | return; |
| 50 | } |
| 51 | if (!redirectorfunction(&revert)) { |
| Jonathan Yong | d384237 | 2010-05-01 12:45:00 +0000 | [diff] [blame] | 52 | fprintf(stderr, "Wow64DisableWow64FsRedirection failed.\n"); |
| 53 | return; |
| 54 | } else { |
| 55 | atexit(undoredirect); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | #endif |