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

Last change on this file since 9552 was 9537, checked in by sandervl, 23 years ago

Don't display message boxes for module load errors. Pass errors back to the PE loader.

File size: 6.3 KB
Line 
1/* $Id: winimagebase.h,v 1.22 2002-12-20 11:39:41 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 getImageSize();
116
117virtual BOOL isDll() = 0;
118 BOOL isPEImage() { return fIsPEImage; };
119
120static Win32ImageBase * findModule(HMODULE hModule);
121 BOOL matchModName(const char *pszFilename) const;
122
123 /* @cat Depencies */
124 //Add image to dependency list of this image
125 void addDependency(Win32DllBase *dll);
126 BOOL dependsOn(Win32DllBase *dll);
127
128protected:
129 void tlsAlloc(); //Allocate TLS index for this module
130 void tlsDelete(); //Destroy TLS index for this module
131
132 ULONG errorState,
133 entryPoint;
134
135 char * fullpath;
136 char szModule[CCHMAXPATH];
137 char szFileName[CCHMAXPATH];
138
139 HINSTANCE hinstance;
140 BOOL fIsPEImage;
141
142 LPVOID tlsAddress; //address of TLS data
143 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
144 ULONG tlsInitSize; //size of initialized TLS memory block
145 ULONG tlsTotalSize; //size of TLS memory block
146 PIMAGE_TLS_CALLBACK * tlsCallBackAddr; //ptr to TLS callback array
147 ULONG tlsIndex; //module TLS index
148
149 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
150 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
151
152 PIMAGE_RESOURCE_DATA_ENTRY getResDataLang(PIMAGE_RESOURCE_DIRECTORY pResDir, ULONG language, BOOL fGetDefault = FALSE);
153
154 HRSRC getResourceLang(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch);
155 HRSRC getResourceLangEx(PIMAGE_RESOURCE_DIRECTORY pResDirToSearch,
156 DWORD lang);
157
158 PIMAGE_RESOURCE_DIRECTORY pResRootDir;
159
160 //substracted from RVA data offsets
161 ULONG ulRVAResourceSection;
162
163 //linked list of dlls loaded on behalf of this executable image (dll or exe)
164 Queue loadedDlls;
165
166private:
167 friend class Win32Resource;
168 friend ULONG SYSTEM GetVersionSize(char *modname);
169};
170
171#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.