少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
 * \file
 * Interface to the dynamic linker
 *
 * Author:
 *    Mono Team (http://www.mono-project.com)
 *
 * Copyright 2001-2004 Ximian, Inc.
 * Copyright 2004-2009 Novell, Inc.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */
#include <config.h>
 
#if defined(HOST_WIN32)
 
#include "mono/utils/mono-dl.h"
#include "mono/utils/mono-dl-windows-internals.h"
#include "mono/utils/mono-embed.h"
#include "mono/utils/mono-path.h"
 
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <glib.h>
 
#include <windows.h>
#include <psapi.h>
 
const char*
mono_dl_get_so_prefix (void)
{
    return "";
}
 
const char**
mono_dl_get_so_suffixes (void)
{
    static const char *suffixes[] = {
        ".dll",
        "",
    };
    return suffixes;
}
 
void*
mono_dl_open_file (const char *file, int flags)
{
    gpointer hModule = NULL;
    if (file) {
        gunichar2* file_utf16 = g_utf8_to_utf16 (file, strlen (file), NULL, NULL, NULL);
 
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
        guint last_sem = SetErrorMode (SEM_FAILCRITICALERRORS);
#endif
        guint32 last_error = 0;
 
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT | HAVE_XBOXONE_WINAPI_SUPPORT)
        hModule = LoadLibrary (file_utf16);
#else
        hModule = LoadPackagedLibrary (file_utf16, NULL);
#endif
        if (!hModule)
            last_error = GetLastError ();
 
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
        SetErrorMode (last_sem);
#endif
 
        g_free (file_utf16);
 
        if (!hModule)
            SetLastError (last_error);
    } else {
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
        hModule = GetModuleHandle (NULL);
#else
        g_assert(0 && "Not supported");
#endif
    }
    return hModule;
}
 
void
mono_dl_close_handle (MonoDl *module)
{
    if (!module->main_module)
        FreeLibrary (module->handle);
}
 
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
void*
mono_dl_lookup_symbol_in_process (const char *symbol_name)
{
    HMODULE *modules;
    DWORD buffer_size = sizeof (HMODULE) * 1024;
    DWORD needed, i;
    gpointer proc = NULL;
 
    /* get the symbol from the loaded DLLs */
    modules = (HMODULE *) g_malloc (buffer_size);
    if (modules == NULL)
        return NULL;
 
    if (!EnumProcessModules (GetCurrentProcess (), modules,
                 buffer_size, &needed)) {
        g_free (modules);
        return NULL;
    }
 
    /* check whether the supplied buffer was too small, realloc, retry */
    if (needed > buffer_size) {
        g_free (modules);
 
        buffer_size = needed;
        modules = (HMODULE *) g_malloc (buffer_size);
 
        if (modules == NULL)
            return NULL;
 
        if (!EnumProcessModules (GetCurrentProcess (), modules,
                     buffer_size, &needed)) {
            g_free (modules);
            return NULL;
        }
    }
 
    for (i = 0; i < needed / sizeof (HANDLE); i++) {
        proc = GetProcAddress (modules [i], symbol_name);
        if (proc != NULL) {
            g_free (modules);
            return proc;
        }
    }
 
    g_free (modules);
    return NULL;
}
#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
 
void*
mono_dl_lookup_symbol (MonoDl *module, const char *symbol_name)
{
    gpointer proc = NULL;
 
    /* get the symbol directly from the specified module */
    if (!module->main_module)
        return GetProcAddress (module->handle, symbol_name);
 
    /* get the symbol from the main module */
    proc = GetProcAddress (module->handle, symbol_name);
    if (proc != NULL)
        return proc;
 
    /* get the symbol from the loaded DLLs */
    return mono_dl_lookup_symbol_in_process (symbol_name);
}
 
int
mono_dl_convert_flags (int flags)
{
    return 0;
}
 
#if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
char*
mono_dl_current_error_string (void)
{
    char* ret = NULL;
    wchar_t* buf = NULL;
    DWORD code = GetLastError ();
 
    if (FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,
        code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&buf, 0, NULL))
    {
        ret = g_utf16_to_utf8 (buf, wcslen(buf), NULL, NULL, NULL);
        LocalFree (buf);
    } else {
        g_assert_not_reached ();
    }
    return ret;
}
#endif /* G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT) */
 
int
mono_dl_get_executable_path (char *buf, int buflen)
{
    return -1; //TODO
}
 
const char*
mono_dl_get_system_dir (void)
{
    return NULL;
}
#endif