source: trunk/include/winimagebase.h@ 1812

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

PE loader rewrite changes

File size: 4.2 KB
Line 
1/* $Id: winimagebase.h,v 1.4 1999-11-22 20:36:53 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
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
57virtual HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
58 HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
59virtual ULONG getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
60 ULONG getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
61
62virtual ULONG getVersionSize();
63virtual BOOL getVersionStruct(char *verstruct, ULONG bufLength);
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
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
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 ULONG magic1;
126 Win32ImageBase *image;
127 ULONG magic2;
128} WINIMAGE_LOOKUP;
129
130#define WINIMAGE_LOOKUPADDR(a) (WINIMAGE_LOOKUP *)((ULONG)a + PAGE_SIZE - sizeof(WINIMAGE_LOOKUP))
131
132#endif //__WINIMAGEBASE_H__
Note: See TracBrowser for help on using the repository browser.