source: trunk/src/kernel32/winimagebase.h@ 10010

Last change on this file since 10010 was 9617, checked in by sandervl, 23 years ago

added dll load hook and function to override named or ordinal exports

File size: 6.4 KB
Line 
1/* $Id: winimagebase.h,v 1.23 2003-01-05 12:31:25 sandervl Exp $ */
2
3/*
4 * Win32 PE Image base class
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#ifndef __WINIMAGEBASE_H__
14#define __WINIMAGEBASE_H__
15
16#include <peexe.h>
17#include "queue.h"
18#include <odinpe.h>
19#ifdef OS2_INCLUDED
20#include <winconst.h>
21#else
22#include <win\winnls.h>
23#endif
24
25#define MAGIC_WINIMAGE 0x11223344
26
27#ifndef CCHMAXPATH
28#define CCHMAXPATH 260
29#endif
30
31#define ID_GETFIRST 0xF0000000
32
33class Win32Resource;
34class Win32DllBase;
35
36
37class Win32ImageBase
38{
39protected:
40 DWORD magic;
41public:
42 void checkObject()
43 {
44 if (magic != MAGIC_WINIMAGE) {
45 eprintf(("Corrupt this pointer %X %X!!", this, magic));
46 DebugInt3();
47 }
48 };
49
50public:
51 // Constructors and destructors
52 Win32ImageBase(HINSTANCE hInstance);
53virtual ~Win32ImageBase();
54
55 ULONG getError() { return errorState; };
56 HINSTANCE getInstanceHandle() { return hinstance; };
57
58//Returns required OS version for this image
59virtual ULONG getVersion();
60
61virtual void setFullPath(char *name);
62 char *getFullPath() { return fullpath; };
63 char *getModuleName() { return szModule; };
64
65 //findResource returns the pointer of the resource's IMAGE_RESOURCE_DATA_ENTRY structure
66 HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
67 HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
68
69 ULONG getResourceSizeA(LPSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
70 ULONG getResourceSizeW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
71 BOOL enumResourceNamesA(HMODULE hmod, LPCTSTR lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam);
72 BOOL enumResourceNamesW(HMODULE hmod, LPCWSTR lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam);
73 BOOL enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
74 LONG lParam);
75 BOOL enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
76 LONG lParam);
77 BOOL enumResourceLanguagesA(HMODULE hmod, LPCSTR lpType, LPCSTR lpName,
78 ENUMRESLANGPROCA lpEnumFunc, LONG lParam);
79 BOOL enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpType, LPCWSTR lpName,
80 ENUMRESLANGPROCW lpEnumFunc, LONG lParam);
81
82 ULONG getVersionSize();
83 BOOL getVersionStruct(char *verstruct, ULONG bufLength);
84
85 //Returns pointer to data of resource handle
86 char *getResourceAddr(HRSRC hResource);
87 ULONG getResourceSize(HRSRC hResource);
88
89//returns ERROR_SUCCESS or error code (Characteristics will contain
90//the Characteristics member of the file header structure)
91static ULONG isPEImage(char *szFileName, DWORD *Characteristics, DWORD *subsystem, DWORD *fNEExe = NULL);
92static BOOL findDll(const char *pszFileName, char *pszFullName,
93 int cchFullName, const char *pszAltPath = NULL);
94
95 void setEntryPoint(ULONG startAddress) { entryPoint = startAddress; };
96
97 void setTLSAddress(LPVOID dwTlsAddress) { tlsAddress = dwTlsAddress; };
98 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr) { tlsIndexAddr = dwTlsIndexAddr; };
99 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; };
100 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; };
101 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)
102 {
103 tlsCallBackAddr = dwTlsCallBackAddr;
104 };
105
106 void tlsAttachThread(); //setup TLS structures for new thread
107 void tlsDetachThread(); //destroy TLS structures
108
109virtual BOOL insideModule(ULONG address);
110virtual BOOL insideModuleCode(ULONG address);
111
112virtual ULONG getApi(char *name) = 0;
113virtual ULONG getApi(int ordinal) = 0;
114
115virtual ULONG setApi(char *name, ULONG pfnNewProc);
116virtual ULONG setApi(int ordinal, ULONG pfnNewProc);
117
118virtual ULONG getImageSize();
119
120virtual BOOL isDll() = 0;
121 BOOL isPEImage() { return fIsPEImage; };
122
123static Win32ImageBase * findModule(HMODULE hModule);
124 BOOL matchModName(const char *pszFilename) const;
125
126 /* @cat Depencies */
127 //Add image to dependency list of this image
128 void addDependency(Win32DllBase *dll);
129 BOOL dependsOn(Win32DllBase *dll);
130
131protected:
132 void tlsAlloc(); //Allocate TLS index for this module
133 void tlsDelete(); //Destroy TLS index for this module
134
135 ULONG errorState,
136 entryPoint;
137
138 char * fullpath;
139 char szModule[CCHMAXPATH];
140 char szFileName[CCHMAXPATH];
141
142 HINSTANCE hinstance;
143 BOOL fIsPEImage;
144
145 LPVOID tlsAddress; //address of TLS data
146 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
147 ULONG tlsInitSize; //size of initialized TLS memory block
148 ULONG tlsTotalSize; //size of TLS memory block
149 PIMAGE_TLS_CALLBACK * tlsCallBackAddr; //ptr to TLS callback array
150 ULONG tlsIndex; //module TLS index
151
152 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
153 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
154
155 PIMAGE_RESOURCE_DATA_ENTRY getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDir, ULONG language, BOOL fGetDefault = FALSE);
156
157 HRSRC getResourceLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch);
158 HRSRC getResourceLangEx(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
159 DWORD lang);
160
161 PIMAGE_RESOURCE_DIRECTORY pResRootDir;
162
163 //substracted from RVA data offsets
164 ULONG ulRVAResourceSection;
165
166 //linked list of dlls loaded on behalf of this executable image (dll or exe)
167 Queue loadedDlls;
168
169private:
170 friend class Win32Resource;
171 friend ULONG SYSTEM GetVersionSize(char *modname);
172};
173
174#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.