[1843] | 1 | /* $Id: winimagebase.h,v 1.5 1999-11-26 00:04:33 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 |
|
---|
| 27 | class Win32Resource;
|
---|
| 28 |
|
---|
| 29 | class Win32ImageBase
|
---|
| 30 | {
|
---|
| 31 | #ifdef DEBUG
|
---|
| 32 | protected:
|
---|
| 33 | DWORD magic;
|
---|
| 34 | public:
|
---|
| 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 |
|
---|
| 44 | public:
|
---|
| 45 | // Constructors and destructors
|
---|
| 46 | Win32ImageBase(HINSTANCE hInstance);
|
---|
| 47 | virtual ~Win32ImageBase();
|
---|
| 48 |
|
---|
| 49 | ULONG getError() { return errorState; };
|
---|
| 50 | HINSTANCE getInstanceHandle() { return hinstance; };
|
---|
| 51 |
|
---|
| 52 | virtual void setFullPath(char *name);
|
---|
| 53 | char *getFullPath() { return fullpath; };
|
---|
| 54 |
|
---|
| 55 | char *getModuleName() { return szModule; };
|
---|
| 56 |
|
---|
[978] | 57 | virtual HRSRC findResourceA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
|
---|
[953] | 58 | HRSRC findResourceW(LPWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
|
---|
[978] | 59 | virtual ULONG getResourceSizeA(LPCSTR lpszName, LPSTR lpszType, ULONG lang = LANG_GETFIRST);
|
---|
[953] | 60 | ULONG getResourceSizeW(LPCWSTR lpszName, LPWSTR lpszType, ULONG lang = LANG_GETFIRST);
|
---|
| 61 |
|
---|
[978] | 62 | virtual ULONG getVersionSize();
|
---|
| 63 | virtual BOOL getVersionStruct(char *verstruct, ULONG bufLength);
|
---|
[953] | 64 |
|
---|
| 65 | static 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 |
|
---|
[1843] | 81 | virtual ULONG getApi(char *name) = 0;
|
---|
| 82 | virtual ULONG getApi(int ordinal) = 0;
|
---|
| 83 |
|
---|
[953] | 84 | virtual BOOL isDll() = 0;
|
---|
| 85 |
|
---|
| 86 | protected:
|
---|
| 87 | void tlsAlloc(); //Allocate TLS index for this module
|
---|
| 88 | void tlsDelete(); //Destroy TLS index for this module
|
---|
| 89 |
|
---|
| 90 | Win32Resource *winres;
|
---|
| 91 |
|
---|
| 92 | ULONG errorState, entryPoint;
|
---|
| 93 |
|
---|
| 94 | char *fullpath;
|
---|
| 95 | char szModule[CCHMAXPATH];
|
---|
| 96 | char szFileName[CCHMAXPATH];
|
---|
| 97 |
|
---|
| 98 | HINSTANCE hinstance;
|
---|
| 99 |
|
---|
| 100 | LPVOID tlsAddress; //address of TLS data
|
---|
| 101 | LPDWORD tlsIndexAddr; //address of DWORD that receives the TLS index
|
---|
| 102 | ULONG tlsInitSize; //size of initialized TLS memory block
|
---|
| 103 | ULONG tlsTotalSize; //size of TLS memory block
|
---|
| 104 | PIMAGE_TLS_CALLBACK *tlsCallBackAddr; //ptr to TLS callback array
|
---|
| 105 | ULONG tlsIndex; //module TLS index
|
---|
| 106 |
|
---|
[978] | 107 | ULONG getPEResourceSize(ULONG id, ULONG type, ULONG lang = LANG_GETFIRST);
|
---|
| 108 |
|
---|
| 109 | PIMAGE_RESOURCE_DATA_ENTRY getPEResourceEntry(ULONG id, ULONG type, ULONG lang = LANG_GETFIRST);
|
---|
| 110 | PIMAGE_RESOURCE_DATA_ENTRY ProcessResSubDir(PIMAGE_RESOURCE_DIRECTORY prdType,
|
---|
| 111 | ULONG *nodeData, int level);
|
---|
| 112 | PIMAGE_RESOURCE_DIRECTORY pResDir;
|
---|
| 113 |
|
---|
| 114 | //substracted from RVA data offsets
|
---|
| 115 | ULONG pResourceSectionStart;
|
---|
| 116 |
|
---|
[953] | 117 | private:
|
---|
| 118 |
|
---|
| 119 | friend class Win32Resource;
|
---|
| 120 | friend ULONG SYSTEM GetVersionSize(char *modname);
|
---|
| 121 | };
|
---|
| 122 |
|
---|
| 123 | //SvL: This structure is placed at the end of the first page of the image (header
|
---|
| 124 | // page), so we can determine the Win32Image pointer from a HINSTANCE variable
|
---|
| 125 | // (which is actually the address of the win32 module)
|
---|
| 126 | typedef struct
|
---|
| 127 | {
|
---|
[1812] | 128 | ULONG magic1;
|
---|
[953] | 129 | Win32ImageBase *image;
|
---|
[1812] | 130 | ULONG magic2;
|
---|
[953] | 131 | } WINIMAGE_LOOKUP;
|
---|
| 132 |
|
---|
| 133 | #define WINIMAGE_LOOKUPADDR(a) (WINIMAGE_LOOKUP *)((ULONG)a + PAGE_SIZE - sizeof(WINIMAGE_LOOKUP))
|
---|
| 134 |
|
---|
| 135 | #endif //__WINIMAGEBASE_H__
|
---|