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

Last change on this file since 4265 was 4249, checked in by bird, 25 years ago

Added compare function matchModName.

File size: 6.9 KB
Line 
1/* $Id: winimagebase.h,v 1.16 2000-09-12 22:45:19 bird 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#ifdef OS2_INCLUDED
19#include <winconst.h>
20#else
21#include <win\winnls.h>
22#endif
23
24#define MAGIC_WINIMAGE 0x11223344
25
26#ifndef CCHMAXPATH
27#define CCHMAXPATH 260
28#endif
29
30#define ID_GETFIRST 0xF0000000
31
32#ifndef ENUMRESNAMEPROC
33 typedef BOOL (* CALLBACK ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);
34 typedef BOOL (* CALLBACK ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);
35 typedef BOOL (* CALLBACK ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);
36 typedef BOOL (* CALLBACK ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);
37 typedef BOOL (* CALLBACK ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);
38 typedef BOOL (* CALLBACK ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);
39#endif
40
41class Win32Resource;
42class Win32DllBase;
43
44
45class Win32ImageBase
46{
47protected:
48 DWORD magic;
49public:
50 void checkObject()
51 {
52 if (magic != MAGIC_WINIMAGE) {
53 eprintf(("Corrupt this pointer %X %X!!", this, magic));
54 DebugInt3();
55 }
56 };
57
58public:
59 // Constructors and destructors
60 Win32ImageBase(HINSTANCE hInstance);
61virtual ~Win32ImageBase();
62
63 ULONG getError() { return errorState; };
64 HINSTANCE getInstanceHandle() { return hinstance; };
65
66//Returns required OS version for this image
67virtual ULONG getVersion();
68
69virtual void setFullPath(char *name);
70 char *getFullPath() { return fullpath; };
71 char *getModuleName() { return szModule; };
72
73 //findResource returns the pointer of the resource's IMAGE_RESOURCE_DATA_ENTRY structure
74 HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
75 HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
76
77 ULONG getResourceSizeA(LPSTR lpszName, LPSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
78 ULONG getResourceSizeW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL));
79 BOOL enumResourceNamesA(HMODULE hmod, LPCTSTR lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam);
80 BOOL enumResourceNamesW(HMODULE hmod, LPCWSTR lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam);
81 BOOL enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
82 LONG lParam);
83 BOOL enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
84 LONG lParam);
85 BOOL enumResourceLanguagesA(HMODULE hmod, LPCSTR lpType, LPCSTR lpName,
86 ENUMRESLANGPROCA lpEnumFunc, LONG lParam);
87 BOOL enumResourceLanguagesW(HMODULE hmod, LPCWSTR lpType, LPCWSTR lpName,
88 ENUMRESLANGPROCW lpEnumFunc, LONG lParam);
89
90 ULONG getVersionSize();
91 BOOL getVersionStruct(char *verstruct, ULONG bufLength);
92
93 //Returns pointer to data of resource handle
94 char *getResourceAddr(HRSRC hResource);
95 ULONG getResourceSize(HRSRC hResource);
96
97 //returns ERROR_SUCCESS or error code
98static ULONG isPEImage(char *szFileName);
99static BOOL findDll(const char *pszFileName, char *pszFullName,
100 int cchFullName, const char *pszAltPath = NULL);
101
102 void setEntryPoint(ULONG startAddress) { entryPoint = startAddress; };
103
104 void setTLSAddress(LPVOID dwTlsAddress) { tlsAddress = dwTlsAddress; };
105 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr) { tlsIndexAddr = dwTlsIndexAddr; };
106 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; };
107 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; };
108 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)
109 {
110 tlsCallBackAddr = dwTlsCallBackAddr;
111 };
112
113 void tlsAttachThread(); //setup TLS structures for new thread
114 void tlsDetachThread(); //destroy TLS structures
115
116virtual BOOL insideModule(ULONG address);
117virtual BOOL insideModuleCode(ULONG address);
118
119virtual ULONG getApi(char *name) = 0;
120virtual ULONG getApi(int ordinal) = 0;
121
122virtual ULONG getImageSize();
123
124virtual BOOL isDll() = 0;
125
126static Win32ImageBase * findModule(HMODULE hModule);
127 BOOL matchModName(const char *pszFilename) const;
128
129 /* @cat Depencies */
130 //Add image to dependency list of this image
131 void addDependency(Win32DllBase *dll);
132 BOOL dependsOn(Win32DllBase *dll);
133
134protected:
135 void tlsAlloc(); //Allocate TLS index for this module
136 void tlsDelete(); //Destroy TLS index for this module
137
138 ULONG errorState,
139 entryPoint;
140
141 char * fullpath;
142 char szModule[CCHMAXPATH];
143 char szFileName[CCHMAXPATH];
144
145 HINSTANCE hinstance;
146
147 LPVOID tlsAddress; //address of TLS data
148 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
149 ULONG tlsInitSize; //size of initialized TLS memory block
150 ULONG tlsTotalSize; //size of TLS memory block
151 PIMAGE_TLS_CALLBACK * tlsCallBackAddr; //ptr to TLS callback array
152 ULONG tlsIndex; //module TLS index
153
154 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
155 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
156
157 PIMAGE_RESOURCE_DATA_ENTRY getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDir, ULONG language, BOOL fGetDefault = FALSE);
158
159 HRSRC getResourceLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch);
160 HRSRC getResourceLangEx(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
161 DWORD lang);
162
163 PIMAGE_RESOURCE_DIRECTORY pResRootDir;
164
165 //substracted from RVA data offsets
166 ULONG ulRVAResourceSection;
167
168 //linked list of dlls loaded on behalf of this executable image (dll or exe)
169 Queue loadedDlls;
170
171private:
172 friend class Win32Resource;
173 friend ULONG SYSTEM GetVersionSize(char *modname);
174};
175
176//SvL: This structure is placed at the end of the first page of the image (header
177// page), so we can determine the Win32Image pointer from a HINSTANCE variable
178// (which is actually the address of the win32 module)
179typedef struct
180{
181 ULONG magic1;
182 Win32ImageBase *image;
183 ULONG magic2;
184} WINIMAGE_LOOKUP;
185
186#define WINIMAGE_LOOKUPADDR(a) (WINIMAGE_LOOKUP *)((ULONG)a + PAGE_SIZE - sizeof(WINIMAGE_LOOKUP))
187
188#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.