blob: d729a9656614669e7858ce1a50a89eb4a517f939 [file] [log] [blame]
a256fx89dcf842010-05-12 02:28:19 +00001/*
Jonathan Yongc1fe0192013-03-29 15:04:11 +00002 gendef - Generate list of exported symbols from a Portable Executable.
Jonathan Yong41071fb2016-08-10 07:07:29 +08003 Copyright (C) 2009-2016 mingw-w64 project
a256fx89dcf842010-05-12 02:28:19 +00004
Jonathan Yongc1fe0192013-03-29 15:04:11 +00005 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.
a256fx89dcf842010-05-12 02:28:19 +00009
Jonathan Yongc1fe0192013-03-29 15:04:11 +000010 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.
a256fx89dcf842010-05-12 02:28:19 +000014
Jonathan Yongc1fe0192013-03-29 15:04:11 +000015 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/>.
a256fx89dcf842010-05-12 02:28:19 +000017*/
Jonathan Yongd3842372010-05-01 12:45:00 +000018#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
26static PVOID revert; /*revert pointer*/
27static HMODULE kernel32handle;
28typedef WINBOOL (__stdcall (*redirector))(PVOID *);
29typedef WINBOOL (__stdcall (*revertor))(PVOID);
30static redirector redirectorfunction; /*Wow64DisableWow64FsRedirection*/
31static revertor revertorfunction; /*Wow64RevertWow64FsRedirection*/
32
33static void undoredirect(void) {
34 revertorfunction(revert);
Jonathan Yongd3842372010-05-01 12:45:00 +000035}
36
37void doredirect(const int redir) {
38 if (redir) {
Jonathan Yong7e92ca62010-08-29 12:46:33 +000039 kernel32handle = GetModuleHandleW(L"kernel32.dll");
Jonathan Yongd3842372010-05-01 12:45:00 +000040 if (!kernel32handle) {
41 fprintf(stderr, "kernel32.dll failed to load, failed to disable FS redirection.\n");
42 return;
43 }
Liu Haoebd3e572018-05-02 10:48:01 +080044 redirectorfunction = (redirector)(INT_PTR)GetProcAddress(kernel32handle, "Wow64DisableWow64FsRedirection");
45 revertorfunction = (revertor)(INT_PTR)GetProcAddress(kernel32handle, "Wow64RevertWow64FsRedirection");
Jonathan Yongd3842372010-05-01 12:45:00 +000046 if (!redirectorfunction || ! revertorfunction) {
47 FreeLibrary(kernel32handle);
48 fprintf(stderr, "Wow64DisableWow64FsRedirection or Wow64RevertWow64FsRedirection functions missing.\n");
49 return;
50 }
51 if (!redirectorfunction(&revert)) {
Jonathan Yongd3842372010-05-01 12:45:00 +000052 fprintf(stderr, "Wow64DisableWow64FsRedirection failed.\n");
53 return;
54 } else {
55 atexit(undoredirect);
56 }
57 }
58}
59#endif