1 | /* $Id: windll.h,v 1.7 1999-08-23 18:06:45 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * Win32 PE Dll class
|
---|
10 | *
|
---|
11 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #ifndef __WINDLL_H__
|
---|
15 | #define __WINDLL_H__
|
---|
16 |
|
---|
17 | #include "winimage.h"
|
---|
18 |
|
---|
19 | #ifndef HINSTANCE
|
---|
20 | #define HINSTANCE ULONG
|
---|
21 | #endif
|
---|
22 |
|
---|
23 | #define DLL_PROCESS_ATTACH 1
|
---|
24 | #define DLL_THREAD_ATTACH 2
|
---|
25 | #define DLL_THREAD_DETACH 3
|
---|
26 | #define DLL_PROCESS_DETACH 0
|
---|
27 |
|
---|
28 | #define DONT_RESOLVE_DLL_REFERENCES 0x00000001
|
---|
29 | #define LOAD_LIBRARY_AS_DATAFILE 0x00000002
|
---|
30 | #define LOAD_WITH_ALTERED_SEARCH_PATH 0x00000008
|
---|
31 |
|
---|
32 | typedef ULONG (* WIN32API WIN32DLLENTRY)(ULONG hInstance, ULONG reason, ULONG reserved);
|
---|
33 |
|
---|
34 | class Win32Dll : public Win32Image
|
---|
35 | {
|
---|
36 | public:
|
---|
37 | Win32Dll(HINSTANCE hinstance, int NameTableId, int Win32TableId, WIN32DLLENTRY DllEntryPoint);
|
---|
38 | Win32Dll(char *szDllName, Win32Image *parentImage = NULL);
|
---|
39 | ~Win32Dll();
|
---|
40 |
|
---|
41 | void OS2DllInit(HINSTANCE hinstance, int NameTableId, int Win32TableId,
|
---|
42 | WIN32DLLENTRY DllEntryPoint);
|
---|
43 |
|
---|
44 | BOOL init(ULONG reservedMem);
|
---|
45 |
|
---|
46 | ULONG AddRef() { return ++referenced; };
|
---|
47 | //ASSUMPTION: called by FreeLibrary only
|
---|
48 | ULONG Release();
|
---|
49 | char *getName() { return szModule; };
|
---|
50 | void setNoEntryCalls() { fSkipEntryCalls = TRUE; };
|
---|
51 |
|
---|
52 | Win32Dll *getNext() { return next; };
|
---|
53 | static Win32Dll *getFirst();
|
---|
54 |
|
---|
55 | //Send DLL_THREAD_ATTACH message to all dlls for a new thread
|
---|
56 | static void attachThreadToAllDlls();
|
---|
57 |
|
---|
58 | //Send DLL_THREAD_DETACH message to all dlls for thread that's about to die
|
---|
59 | static void detachThreadFromAllDlls();
|
---|
60 |
|
---|
61 | //Setup TLS structure for all dlls for a new thread
|
---|
62 | static void tlsAttachThreadToAllDlls();
|
---|
63 |
|
---|
64 | //Destroy TLS structure for all dlls for a thread that's about to die
|
---|
65 | static void tlsDetachThreadFromAllDlls();
|
---|
66 |
|
---|
67 | ULONG getApi(char *name);
|
---|
68 | ULONG getApi(int ordinal);
|
---|
69 | BOOL attachProcess();
|
---|
70 | BOOL detachProcess();
|
---|
71 | BOOL attachThread();
|
---|
72 | BOOL detachThread();
|
---|
73 |
|
---|
74 | static void deleteAll();
|
---|
75 |
|
---|
76 | static BOOL isSystemDll(char *szFileName);
|
---|
77 |
|
---|
78 | static Win32Dll *findModule(char *dllname);
|
---|
79 | static Win32Dll *findModule(HINSTANCE hinstance);
|
---|
80 | static Win32Dll *findModule(WIN32DLLENTRY DllEntryPoint);
|
---|
81 |
|
---|
82 |
|
---|
83 | virtual BOOL isDll();
|
---|
84 |
|
---|
85 | protected:
|
---|
86 | BOOL fSystemDll, fSkipEntryCalls, fUnloaded, fAttachedToProcess;
|
---|
87 |
|
---|
88 | WIN32DLLENTRY dllEntryPoint;
|
---|
89 | private:
|
---|
90 | ULONG referenced;
|
---|
91 |
|
---|
92 |
|
---|
93 | static Win32Dll *head;
|
---|
94 | Win32Dll *next;
|
---|
95 | };
|
---|
96 |
|
---|
97 | #endif
|
---|