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

Last change on this file since 4224 was 4224, checked in by sandervl, 25 years ago

exception changes, implemented enumresourcelanguages + put back some old code

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