ReactOS 0.4.15-dev-7958-gcd0bb1a
ignorefreelib.c File Reference
#include <windef.h>
#include <winbase.h>
#include <shimlib.h>
#include <strsafe.h>
#include <setup_shim.inl>
#include <implement_shim.inl>
Include dependency graph for ignorefreelib.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define SHIM_NS   IgnoreFreeLibrary
 
#define SHIM_NOTIFY_FN   SHIM_OBJ_NAME(Notify)
 
#define SHIM_NUM_HOOKS   1
 
#define SHIM_SETUP_HOOKS    SHIM_HOOK(0, "KERNEL32.DLL", "FreeLibrary", SHIM_OBJ_NAME(FreeLibrary))
 

Typedefs

typedef BOOL(WINAPIFREELIBRARYPROC) (HMODULE)
 

Functions

BOOL WINAPI SHIM_OBJ_NAME() FreeLibrary (HMODULE hModule)
 
static VOID InitIgnoreFreeLibrary (PCSTR CommandLine)
 
BOOL WINAPI SHIM_OBJ_NAME() Notify (DWORD fdwReason, PVOID ptr)
 

Variables

const char ** g_Names
 
static int g_NameCount
 

Macro Definition Documentation

◆ SHIM_NOTIFY_FN

#define SHIM_NOTIFY_FN   SHIM_OBJ_NAME(Notify)

Definition at line 139 of file ignorefreelib.c.

◆ SHIM_NS

#define SHIM_NS   IgnoreFreeLibrary

Definition at line 15 of file ignorefreelib.c.

◆ SHIM_NUM_HOOKS

#define SHIM_NUM_HOOKS   1

Definition at line 140 of file ignorefreelib.c.

◆ SHIM_SETUP_HOOKS

#define SHIM_SETUP_HOOKS    SHIM_HOOK(0, "KERNEL32.DLL", "FreeLibrary", SHIM_OBJ_NAME(FreeLibrary))

Definition at line 141 of file ignorefreelib.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 8 of file ignorefreelib.c.

Typedef Documentation

◆ FREELIBRARYPROC

typedef BOOL(WINAPI * FREELIBRARYPROC) (HMODULE)

Definition at line 18 of file ignorefreelib.c.

Function Documentation

◆ FreeLibrary()

BOOL WINAPI SHIM_OBJ_NAME() FreeLibrary ( HMODULE  hModule)

Definition at line 23 of file ignorefreelib.c.

24{
25 char Buffer[MAX_PATH], *Ptr = Buffer;
26 DWORD len, wanted = ARRAYSIZE(Buffer);
27 for (;;)
28 {
30 if (len < wanted)
31 break;
32
33 wanted *= 2;
34 if (Ptr != Buffer)
36
37 Ptr = ShimLib_ShimMalloc(wanted);
38 if (!Ptr)
39 break;
40 }
41
42 if (Ptr && len)
43 {
44 char* ModuleName = NULL;
45 int n;
46 for (; len; len--)
47 {
48 ModuleName = Ptr + len;
49 if (ModuleName[-1] == '/' || ModuleName[-1] == '\\')
50 break;
51 }
52 for (n = 0; n < g_NameCount; ++n)
53 {
55 {
56 SHIM_INFO("Prevented unload of %s\n", ModuleName);
57 if (Ptr && Ptr != Buffer)
59 return TRUE;
60 }
61 }
62 }
63
64 if (Ptr && Ptr != Buffer)
66
67 return CALL_SHIM(0, FREELIBRARYPROC)(hModule);
68}
ACPI_BUFFER *RetBuffer ACPI_BUFFER *RetBuffer char ACPI_WALK_RESOURCE_CALLBACK void *Context ACPI_BUFFER *RetBuffer UINT16 ACPI_RESOURCE **ResourcePtr ACPI_GENERIC_ADDRESS *Reg UINT32 *ReturnValue UINT8 UINT8 *Slp_TypB ACPI_PHYSICAL_ADDRESS PhysicalAddress64 UINT32 UINT32 *TimeElapsed UINT32 ACPI_STATUS const char UINT32 ACPI_STATUS const char UINT32 const char const char * ModuleName
Definition: acpixf.h:1280
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
static int g_NameCount
Definition: ignorefreelib.c:21
BOOL(WINAPI * FREELIBRARYPROC)(HMODULE)
Definition: ignorefreelib.c:18
const char ** g_Names
Definition: ignorefreelib.c:20
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
HMODULE hModule
Definition: animate.c:44
#define stricmp(_String1, _String2)
Definition: compat.h:24
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetModuleFileNameA(HINSTANCE hModule, LPSTR lpFilename, DWORD nSize)
Definition: loader.c:539
unsigned long DWORD
Definition: ntddk_ex.h:95
_Must_inspect_result_ _In_ PFSRTL_PER_STREAM_CONTEXT Ptr
Definition: fsrtlfuncs.h:898
GLdouble n
Definition: glext.h:7729
GLenum GLsizei len
Definition: glext.h:6722
#define SHIM_INFO(fmt,...)
Definition: sdbpapi.h:78
PVOID ShimLib_ShimMalloc(SIZE_T dwSize)
Definition: shimlib.c:45
void ShimLib_ShimFree(PVOID pData)
Definition: shimlib.c:50

◆ InitIgnoreFreeLibrary()

static VOID InitIgnoreFreeLibrary ( PCSTR  CommandLine)
static

Definition at line 70 of file ignorefreelib.c.

71{
72 PCSTR prev, cur;
73 int count = 1, n = 0;
74 const char** names;
75
76 if (!CommandLine || !*CommandLine)
77 return;
78
79 prev = CommandLine;
80 while ((cur = strchr(prev, ';')))
81 {
82 count++;
83 prev = cur + 1;
84 }
85
86 names = ShimLib_ShimMalloc(sizeof(char*) * count);
87 if (!names)
88 {
89 SHIM_WARN("Unable to allocate %u bytes\n", sizeof(char*) * count);
90 return;
91 }
92
93 prev = CommandLine;
94 while ((cur = strchr(prev, ';')))
95 {
96 names[n] = ShimLib_StringNDuplicateA(prev, cur - prev + 1);
97 if (!names[n])
98 {
99 SHIM_WARN("Unable to allocate %u bytes\n", cur - prev + 2);
100 goto fail;
101 }
102 n++;
103 prev = cur + 1;
104 }
106 if (!names[n])
107 {
108 SHIM_WARN("Unable to allocate last string\n");
109 goto fail;
110 }
111
112 g_Names = names;
114 return;
115
116fail:
117 --n;
118 while (n >= 0)
119 {
120 if (names[n])
122
123 --n;
124 }
126}
char * strchr(const char *String, int ch)
Definition: utclib.c:501
FxCollectionEntry * cur
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLuint GLuint * names
Definition: glext.h:11545
#define SHIM_WARN(fmt,...)
Definition: sdbpapi.h:77
PCSTR ShimLib_StringDuplicateA(PCSTR szString)
Definition: shimlib.c:67
PCSTR ShimLib_StringNDuplicateA(PCSTR szString, SIZE_T stringLengthIncludingNullTerm)
Definition: shimlib.c:60
const char * PCSTR
Definition: typedefs.h:52

Referenced by Notify().

◆ Notify()

BOOL WINAPI SHIM_OBJ_NAME() Notify ( DWORD  fdwReason,
PVOID  ptr 
)

Definition at line 128 of file ignorefreelib.c.

129{
130 if (fdwReason == SHIM_NOTIFY_ATTACH)
131 {
132 SHIM_MSG("IgnoreFreeLibrary(%s)\n", SHIM_OBJ_NAME(g_szCommandLine));
133 InitIgnoreFreeLibrary(SHIM_OBJ_NAME(g_szCommandLine));
134 }
135 return TRUE;
136}
static VOID InitIgnoreFreeLibrary(PCSTR CommandLine)
Definition: ignorefreelib.c:70
#define SHIM_MSG(fmt,...)
Definition: shimlib.h:75
#define SHIM_NOTIFY_ATTACH
Definition: shimlib.h:50

Referenced by AcpiEvAsynchExecuteGpeMethod(), AcpiEvDeleteGpeHandlers(), AcpiSetupGpeForWake(), DECLARE_INTERFACE_(), DoNotifyPositionEvents(), IDirectSoundNotify_fnSetNotificationPositions(), NewDirectSoundNotify(), NotifyGPEvents(), RegisterGPNotification(), ShimLib_NotifyShims(), and UnregisterGPNotification().

Variable Documentation

◆ g_NameCount

int g_NameCount
static

Definition at line 21 of file ignorefreelib.c.

Referenced by FreeLibrary(), and InitIgnoreFreeLibrary().

◆ g_Names

const char** g_Names

Definition at line 20 of file ignorefreelib.c.

Referenced by FreeLibrary(), and InitIgnoreFreeLibrary().