idlize

Форк
0
/
win-dll-hook.cc 
59 строк · 1.6 Кб
1
/*
2
 * Copyright (c) 2024 Huawei Device Co., Ltd.
3
 * Licensed under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License.
5
 * You may obtain a copy of the License at
6
 *
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 *
9
 * Unless required by applicable law or agreed to in writing, software
10
 * distributed under the License is distributed on an "AS IS" BASIS,
11
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 * See the License for the specific language governing permissions and
13
 * limitations under the License.
14
 */
15

16
// Heavily inspired by node-gyp
17

18
/*
19
 * When this file is linked to a DLL, it sets up a delay-load hook that
20
 * intervenes when the DLL is trying to load the host executable
21
 * dynamically. Instead of trying to locate the .exe file it'll just
22
 * return a handle to the process image.
23
 *
24
 * This allows compiled addons to work when the host executable is renamed.
25
 */
26

27
#ifdef _MSC_VER
28

29
#pragma managed(push, off)
30

31
#ifndef WIN32_LEAN_AND_MEAN
32
#define WIN32_LEAN_AND_MEAN
33
#endif
34

35
#include <windows.h>
36

37
#include <delayimp.h>
38
#include <string.h>
39

40

41
static FARPROC WINAPI load_exe_hook(unsigned int event, PDelayLoadInfo info) {
42
    if (event != dliNotePreLoadLibrary) {
43
        return NULL;
44
    }
45

46
    if (_stricmp(info->szDll, "node.exe") != 0) {
47
        // Case-insensitive comparision is necessary
48
        return NULL;
49
    }
50

51
    HMODULE thisModule = GetModuleHandle(NULL);
52
    return reinterpret_cast<FARPROC>(thisModule);
53
}
54

55
ExternC const PfnDliHook __pfnDliNotifyHook2 = load_exe_hook;
56

57
#pragma managed(pop)
58

59
#endif

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.