1 | /* $Id: winimagepe2lx.h,v 1.10 2004-01-15 10:39:13 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 PE2LX Image base class
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright 1999-2000 knut st. osmundsen (knut.stange.osmundsen@mynd.no)
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #ifndef __WINIMAGEPE2LX_H__
|
---|
13 | #define __WINIMAGEPE2LX_H__
|
---|
14 |
|
---|
15 | #include "winimagebase.h"
|
---|
16 |
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Section struct - used to translate RVAs to pointers.
|
---|
20 | */
|
---|
21 | typedef struct _Section
|
---|
22 | {
|
---|
23 | ULONG ulRVA; /* RVA of section. If not a PE section ~0UL. */
|
---|
24 | ULONG cbVirtual; /* Virtual size (the larger of the physical and virtual) of the section. */
|
---|
25 | ULONG ulAddress; /* Current load address of the section. */
|
---|
26 | } SECTION, *PSECTION;
|
---|
27 |
|
---|
28 |
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Base class for Pe2lx (and Win32k) dlls. There is currently no difference between
|
---|
32 | * Pe2Lx and Win32k images, though the image on disk is different...
|
---|
33 | * @shortdesc Pe2Lx and Win32k base image class.
|
---|
34 | * @author knut st. osmundsen, Sander van Leeuwen
|
---|
35 | * @approval -
|
---|
36 | */
|
---|
37 | class Win32Pe2LxImage : public virtual Win32ImageBase
|
---|
38 | {
|
---|
39 | public:
|
---|
40 | /** @cat constructor and destructor */
|
---|
41 | Win32Pe2LxImage(HINSTANCE hinstance, BOOL fWin32k);
|
---|
42 | virtual ~Win32Pe2LxImage();
|
---|
43 | virtual DWORD init();
|
---|
44 |
|
---|
45 | /** @cat Queries */
|
---|
46 | /** Get the OS/2 module handle.
|
---|
47 | * @returns OS/2 module handle. */
|
---|
48 | HINSTANCE getHMOD() const { return hmod; }
|
---|
49 |
|
---|
50 | private:
|
---|
51 | /** @cat constructor helpers */
|
---|
52 | ULONG getSections();
|
---|
53 | ULONG setSectionRVAs();
|
---|
54 | ULONG doResources();
|
---|
55 | ULONG doTLS();
|
---|
56 | ULONG doImports();
|
---|
57 | Win32ImageBase *importsGetModule(const char *pszModName);
|
---|
58 | Win32DllBase *importsLoadModule(const char *pszModName);
|
---|
59 | ULONG importsByOrdinal(Win32ImageBase *pModule, unsigned uOrdinal, void **ppvAddr);
|
---|
60 | ULONG importsByName(Win32ImageBase *pModule, const char *pszSymName, void **ppvAddr);
|
---|
61 | VOID cleanup();
|
---|
62 |
|
---|
63 | protected:
|
---|
64 | /** @cat RVA -> pointer */
|
---|
65 | /* these should be moved to winimagebase some day... */
|
---|
66 | void * getPointerFromRVA(ULONG ulRVA, BOOL fOverride = FALSE);
|
---|
67 | ULONG getRVAFromPointer(void *pv, BOOL fOverride = FALSE);
|
---|
68 | PVOID getPointerFromPointer(PVOID pv);
|
---|
69 | LONG getSectionIndexFromRVA(ULONG ulRVA);
|
---|
70 | BOOL validateRealPointer(PVOID pv);
|
---|
71 |
|
---|
72 | /** Used by getPointerFromRVA and created by getSections and setSectionRVAs. */
|
---|
73 | PSECTION paSections;
|
---|
74 | /** Count of entires in the section array (paSection) */
|
---|
75 | int cSections;
|
---|
76 |
|
---|
77 | /** @cat Misc */
|
---|
78 | /** Pointer to NT headers. */
|
---|
79 | PIMAGE_NT_HEADERS pNtHdrs;
|
---|
80 | /** Flag which indicates wether this is a Win32k loaded
|
---|
81 | * module (TRUE) or and Pe2Lx module (FALSE). */
|
---|
82 | BOOL fWin32k;
|
---|
83 | /** OS/2 handle of the module. */
|
---|
84 | HMODULE hmod;
|
---|
85 | /** Set by Win32Pe2LxDll. */
|
---|
86 | BOOL fDll;
|
---|
87 | };
|
---|
88 |
|
---|
89 |
|
---|
90 | #endif //__WINIMAGEPE2LX_H__
|
---|
91 |
|
---|