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

Last change on this file since 9304 was 7811, checked in by sandervl, 24 years ago

SetWin32TIB update + force change to win32 FS selector for calling PE image entrypoints

File size: 6.7 KB
Line 
1/* $Id: winimagebase.h,v 1.21 2002-02-06 16:33:39 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#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 (Characteristics will contain
98//the Characteristics member of the file header structure)
99static ULONG isPEImage(char *szFileName, DWORD *Characteristics, DWORD *subsystem, DWORD *fNEExe = NULL);
100static BOOL findDll(const char *pszFileName, char *pszFullName,
101 int cchFullName, const char *pszAltPath = NULL);
102
103 void setEntryPoint(ULONG startAddress) { entryPoint = startAddress; };
104
105 void setTLSAddress(LPVOID dwTlsAddress) { tlsAddress = dwTlsAddress; };
106 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr) { tlsIndexAddr = dwTlsIndexAddr; };
107 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; };
108 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; };
109 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)
110 {
111 tlsCallBackAddr = dwTlsCallBackAddr;
112 };
113
114 void tlsAttachThread(); //setup TLS structures for new thread
115 void tlsDetachThread(); //destroy TLS structures
116
117virtual BOOL insideModule(ULONG address);
118virtual BOOL insideModuleCode(ULONG address);
119
120virtual ULONG getApi(char *name) = 0;
121virtual ULONG getApi(int ordinal) = 0;
122
123virtual ULONG getImageSize();
124
125virtual BOOL isDll() = 0;
126 BOOL isPEImage() { return fIsPEImage; };
127
128static Win32ImageBase * findModule(HMODULE hModule);
129 BOOL matchModName(const char *pszFilename) const;
130
131 /* @cat Depencies */
132 //Add image to dependency list of this image
133 void addDependency(Win32DllBase *dll);
134 BOOL dependsOn(Win32DllBase *dll);
135
136protected:
137 void tlsAlloc(); //Allocate TLS index for this module
138 void tlsDelete(); //Destroy TLS index for this module
139
140 ULONG errorState,
141 entryPoint;
142
143 char * fullpath;
144 char szModule[CCHMAXPATH];
145 char szFileName[CCHMAXPATH];
146
147 HINSTANCE hinstance;
148 BOOL fIsPEImage;
149
150 LPVOID tlsAddress; //address of TLS data
151 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
152 ULONG tlsInitSize; //size of initialized TLS memory block
153 ULONG tlsTotalSize; //size of TLS memory block
154 PIMAGE_TLS_CALLBACK * tlsCallBackAddr; //ptr to TLS callback array
155 ULONG tlsIndex; //module TLS index
156
157 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
158 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
159
160 PIMAGE_RESOURCE_DATA_ENTRY getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDir, ULONG language, BOOL fGetDefault = FALSE);
161
162 HRSRC getResourceLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch);
163 HRSRC getResourceLangEx(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
164 DWORD lang);
165
166 PIMAGE_RESOURCE_DIRECTORY pResRootDir;
167
168 //substracted from RVA data offsets
169 ULONG ulRVAResourceSection;
170
171 //linked list of dlls loaded on behalf of this executable image (dll or exe)
172 Queue loadedDlls;
173
174private:
175 friend class Win32Resource;
176 friend ULONG SYSTEM GetVersionSize(char *modname);
177};
178
179#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.