source: trunk/include/winimagebase.h@ 2859

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

* empty log message *

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