source: trunk/include/winimagebase.h@ 1879

Last change on this file since 1879 was 1879, checked in by sandervl, 26 years ago

EnumResourceTypesA/W changes

File size: 5.5 KB
Line 
1/* $Id: winimagebase.h,v 1.7 1999-11-29 20:42:20 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
17#define MAGIC_WINIMAGE 0x11223344
18
19#ifndef CCHMAXPATH
20#define CCHMAXPATH 260
21#endif
22
23#define LANG_GETFIRST 0x80000000
24#define ID_GETFIRST LANG_GETFIRST
25#define IDLANG_GETFIRST LANG_GETFIRST
26
27#ifndef ENUMRESNAMEPROC
28 typedef BOOL (* CALLBACK ENUMRESTYPEPROCA)(HMODULE,LPSTR,LONG);
29 typedef BOOL (* CALLBACK ENUMRESTYPEPROCW)(HMODULE,LPWSTR,LONG);
30 typedef BOOL (* CALLBACK ENUMRESNAMEPROCA)(HMODULE,LPCSTR,LPSTR,LONG);
31 typedef BOOL (* CALLBACK ENUMRESNAMEPROCW)(HMODULE,LPCWSTR,LPWSTR,LONG);
32 typedef BOOL (* CALLBACK ENUMRESLANGPROCA)(HMODULE,LPCSTR,LPCSTR,WORD,LONG);
33 typedef BOOL (* CALLBACK ENUMRESLANGPROCW)(HMODULE,LPCWSTR,LPCWSTR,WORD,LONG);
34#endif
35
36class Win32Resource;
37
38class Win32ImageBase
39{
40#ifdef DEBUG
41protected:
42 DWORD magic;
43public:
44 void checkObject()
45 {
46 if(magic != MAGIC_WINIMAGE) {
47 eprintf(("Corrupt this pointer %X %X!!", this, magic));
48 DebugInt3();
49 }
50 };
51#endif
52
53public:
54 // Constructors and destructors
55 Win32ImageBase(HINSTANCE hInstance);
56virtual ~Win32ImageBase();
57
58 ULONG getError() { return errorState; };
59 HINSTANCE getInstanceHandle() { return hinstance; };
60
61virtual void setFullPath(char *name);
62 char *getFullPath() { return fullpath; };
63
64 char *getModuleName() { return szModule; };
65
66virtual HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
67 HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
68virtual ULONG getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
69 ULONG getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
70virtual BOOL enumResourceNamesA(HMODULE hmod, LPCTSTR lpszType, ENUMRESNAMEPROCA lpEnumFunc, LONG lParam);
71virtual BOOL enumResourceNamesW(HMODULE hmod, LPCWSTR lpszType, ENUMRESNAMEPROCW lpEnumFunc, LONG lParam);
72virtual BOOL enumResourceTypesA(HMODULE hmod, ENUMRESTYPEPROCA lpEnumFunc,
73 LONG lParam);
74virtual BOOL enumResourceTypesW(HMODULE hmod, ENUMRESTYPEPROCW lpEnumFunc,
75 LONG lParam);
76
77virtual ULONG getVersionSize();
78virtual BOOL getVersionStruct(char *verstruct, ULONG bufLength);
79
80static BOOL isPEImage(char *szFileName);
81
82 void setEntryPoint(ULONG startAddress) { entryPoint = startAddress; };
83
84 void setTLSAddress(LPVOID dwTlsAddress) { tlsAddress = dwTlsAddress; };
85 void setTLSIndexAddr(LPDWORD dwTlsIndexAddr) { tlsIndexAddr = dwTlsIndexAddr; };
86 void setTLSInitSize(ULONG dwTlsSize) { tlsInitSize = dwTlsSize; };
87 void setTLSTotalSize(ULONG dwTlsSize) { tlsTotalSize = dwTlsSize; };
88 void setTLSCallBackAddr(PIMAGE_TLS_CALLBACK *dwTlsCallBackAddr)
89 {
90 tlsCallBackAddr = dwTlsCallBackAddr;
91 };
92
93 void tlsAttachThread(); //setup TLS structures for new thread
94 void tlsDetachThread(); //destroy TLS structures
95
96virtual ULONG getApi(char *name) = 0;
97virtual ULONG getApi(int ordinal) = 0;
98
99virtual BOOL isDll() = 0;
100
101static Win32ImageBase * findModule(HMODULE hModule);
102
103protected:
104 void tlsAlloc(); //Allocate TLS index for this module
105 void tlsDelete(); //Destroy TLS index for this module
106
107 Win32Resource *winres;
108
109 ULONG errorState, entryPoint;
110
111 char *fullpath;
112 char szModule[CCHMAXPATH];
113 char szFileName[CCHMAXPATH];
114
115 HINSTANCE hinstance;
116
117 LPVOID tlsAddress; //address of TLS data
118 LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
119 ULONG tlsInitSize; //size of initialized TLS memory block
120 ULONG tlsTotalSize; //size of TLS memory block
121 PIMAGE_TLS_CALLBACK *tlsCallBackAddr; //ptr to TLS callback array
122 ULONG tlsIndex; //module TLS index
123
124 ULONG getPEResourceSize(ULONG id, ULONG type, ULONG lang = LANG_GETFIRST);
125
126 PIMAGE_RESOURCE_DATA_ENTRY getPEResourceEntry(ULONG id, ULONG type, ULONG lang = LANG_GETFIRST);
127 PIMAGE_RESOURCE_DATA_ENTRY ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
128 ULONG *nodeData, int level);
129 PIMAGE_RESOURCE_DIRECTORY getResSubDirW(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCWSTR lpszName);
130 PIMAGE_RESOURCE_DIRECTORY getResSubDirA(PIMAGE_RESOURCE_DIRECTORY pResDir, LPCTSTR lpszName);
131
132 PIMAGE_RESOURCE_DIRECTORY pResDir;
133
134 //substracted from RVA data offsets
135 ULONG ulRVAResourceSection;
136
137private:
138
139 friend class Win32Resource;
140 friend ULONG SYSTEM GetVersionSize(char *modname);
141};
142
143//SvL: This structure is placed at the end of the first page of the image (header
144// page), so we can determine the Win32Image pointer from a HINSTANCE variable
145// (which is actually the address of the win32 module)
146typedef struct
147{
148 ULONG magic1;
149 Win32ImageBase *image;
150 ULONG magic2;
151} WINIMAGE_LOOKUP;
152
153#define WINIMAGE_LOOKUPADDR(a) (WINIMAGE_LOOKUP *)((ULONG)a + PAGE_SIZE - sizeof(WINIMAGE_LOOKUP))
154
155#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.