source: trunk/include/winimagebase.h@ 1036

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

Changes for LX image resource support

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