| 1 | /* $Id: ModuleBase.h,v 1.3 2000-02-27 02:16:43 bird Exp $
|
|---|
| 2 | *
|
|---|
| 3 | * ModuleBase - Declaration of the Basic module class.
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright (c) 1999 knut st. osmundsen
|
|---|
| 6 | *
|
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 | #ifndef _MODULEBASE_H_
|
|---|
| 11 | #define _MODULEBASE_H_
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /*******************************************************************************
|
|---|
| 15 | * Defined Constants And Macros *
|
|---|
| 16 | *******************************************************************************/
|
|---|
| 17 | /*
|
|---|
| 18 | * Error definitions (used in addition to them in bseerr.h)
|
|---|
| 19 | */
|
|---|
| 20 | #define ERROR_FAILED_TO_ADD_OBJECT 0x42000000UL
|
|---|
| 21 | #define ERROR_INITMETHOD_NOT_INITTIME 0x42000001UL
|
|---|
| 22 | #define ERROR_INTERNAL_PROCESSING_ERROR 0x42000002UL
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | /*
|
|---|
| 26 | * Some useful macros.
|
|---|
| 27 | */
|
|---|
| 28 | #define NOREF(a) (a=a) /* Not referenced parameter warning fix. */
|
|---|
| 29 | #define ALIGN(a, alignment) (((a) + (alignment - 1UL)) & ~(alignment - 1UL))
|
|---|
| 30 | /* aligns something, a, up to nearest alignment boundrary-
|
|---|
| 31 | * Note: Aligment must be a 2**n number. */
|
|---|
| 32 |
|
|---|
| 33 | #define PAGESHIFT 12 /* bytes to pages or pages to bytes shift value. */
|
|---|
| 34 | #ifndef PAGESIZE
|
|---|
| 35 | #define PAGESIZE 0x1000 /* pagesize on i386 */
|
|---|
| 36 | #endif
|
|---|
| 37 | #define PAGEOFFSET(addr) ((addr) & (PAGESIZE-1)) /* Gets the offset into the page addr points into. */
|
|---|
| 38 | #define PAGESTART(addr) ((addr) & ~(PAGESIZE-1)) /* Gets the address of the page addr points into. */
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 | /*
|
|---|
| 42 | * Output macros.
|
|---|
| 43 | * Macros: option infolevel
|
|---|
| 44 | * printIPE -W1 Error
|
|---|
| 45 | * printErr -W1 Error
|
|---|
| 46 | * printWar -W2 Warning
|
|---|
| 47 | * printInf -W3 Info
|
|---|
| 48 | * printInfA -W4 InfoAll
|
|---|
| 49 | */
|
|---|
| 50 | #define printIPE(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
|---|
| 51 | ModuleBase::printf("\nerror(%d:"__FUNCTION__"): !Internal Processing Error!\n\t", __LINE__), \
|
|---|
| 52 | ModuleBase::printf a, \
|
|---|
| 53 | ModuleBase::printf("\n") \
|
|---|
| 54 | : (void)0,(void)0,(void)0 )
|
|---|
| 55 | #define printErr(a) (ModuleBase::ulInfoLevel >= ModuleBase::Error ? \
|
|---|
| 56 | ModuleBase::printf("error(%d:"__FUNCTION__"): ", __LINE__), \
|
|---|
| 57 | ModuleBase::printf a \
|
|---|
| 58 | : (void)0,(void)0 )
|
|---|
| 59 | #define printWar(a) (ModuleBase::ulInfoLevel >= ModuleBase::Warning ? \
|
|---|
| 60 | ModuleBase::printf("warning("__FUNCTION__"): "), \
|
|---|
| 61 | ModuleBase::printf a \
|
|---|
| 62 | : (void)0,(void)0 )
|
|---|
| 63 | #define printInf(a) (ModuleBase::ulInfoLevel >= ModuleBase::Info ? \
|
|---|
| 64 | ModuleBase::printf a : (void)0 )
|
|---|
| 65 | #define printInfA(a)(ModuleBase::ulInfoLevel >= ModuleBase::InfoAll ? \
|
|---|
| 66 | ModuleBase::printf a : (void)0 )
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | /*
|
|---|
| 70 | * Read macros.
|
|---|
| 71 | * ReadAt: Reads from a file, hFile, at a given offset, ulOffset, into a buffer, pvBuffer,
|
|---|
| 72 | * an amount of bytes, cbToRead.
|
|---|
| 73 | * RING0: Map this to ldrRead with 0UL as flFlags.
|
|---|
| 74 | * RING3: Implementes this function as a static function, ReadAt.
|
|---|
| 75 | * ReadAtF: Same as ReadAt but two extra parameters; an additional flag and a pointer to an MTE.
|
|---|
| 76 | * Used in the read method.
|
|---|
| 77 | * RING0: Map directly to ldrRead.
|
|---|
| 78 | * RING3: Map to ReadAt, ignoring the two extra parameters.
|
|---|
| 79 | */
|
|---|
| 80 | #ifdef RING0
|
|---|
| 81 | #define ReadAt(hFile, ulOffset, pvBuffer, cbToRead) \
|
|---|
| 82 | ldrRead(hFile, ulOffset, pvBuffer, 0UL, cbToRead, NULL)
|
|---|
| 83 | #define ReadAtF(hFile, ulOffset, pvBuffer, cbToRead, flFlags, pMTE) \
|
|---|
| 84 | ldrRead(hFile, ulOffset, pvBuffer, flFlags, cbToRead, pMTE)
|
|---|
| 85 | #else
|
|---|
| 86 | #define ReadAtF(hFile, ulOffset, pvBuffer, cbToRead, flFlags, pMTE) \
|
|---|
| 87 | ReadAt(hFile, ulOffset, pvBuffer, cbToRead)
|
|---|
| 88 | #endif
|
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 | /*******************************************************************************
|
|---|
| 92 | * Functions *
|
|---|
| 93 | *******************************************************************************/
|
|---|
| 94 | #ifndef RING0
|
|---|
| 95 | APIRET ReadAt(SFN hFile, ULONG ulOffset, PVOID pvBuffer, ULONG cbToRead);
|
|---|
| 96 | #endif
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 | /**
|
|---|
| 101 | * Base class for executable modules.
|
|---|
| 102 | * @author knut st. osmundsen
|
|---|
| 103 | * @approval not approved yet...
|
|---|
| 104 | */
|
|---|
| 105 | class ModuleBase
|
|---|
| 106 | {
|
|---|
| 107 | public:
|
|---|
| 108 | /** @cat Constructor/Destructor */
|
|---|
| 109 | ModuleBase(SFN hFile);
|
|---|
| 110 | virtual ~ModuleBase();
|
|---|
| 111 |
|
|---|
| 112 | /** @cat Public Main methods */
|
|---|
| 113 | virtual ULONG init(PCSZ pszFilename);
|
|---|
| 114 | virtual ULONG read(ULONG offLXFile, PVOID pvBuffer, ULONG cbToRead, ULONG flFlags, PMTE pMTE) = 0;
|
|---|
| 115 | virtual ULONG applyFixups(PMTE pMTE, ULONG iObject, ULONG iPageTable, PVOID pvPage,
|
|---|
| 116 | ULONG ulPageAddress, PVOID pvPTDA); /*(ldrEnum32bitRelRecs)*/
|
|---|
| 117 | #ifndef RING0
|
|---|
| 118 | virtual ULONG writeFile(PCSZ pszLXFilename);
|
|---|
| 119 | #endif
|
|---|
| 120 |
|
|---|
| 121 | /** @cat public Helper methods */
|
|---|
| 122 | virtual VOID dumpVirtualLxFile() = 0;
|
|---|
| 123 | BOOL queryIsModuleName(PCSZ pszFilename);
|
|---|
| 124 |
|
|---|
| 125 | /** @cat static print method */
|
|---|
| 126 | static VOID printf(PCSZ pszFormat, ...);
|
|---|
| 127 |
|
|---|
| 128 | protected:
|
|---|
| 129 | /** @cat private data members. */
|
|---|
| 130 | #ifdef DEBUG
|
|---|
| 131 | BOOL fInitTime; /* init time indicator (debug) */
|
|---|
| 132 | #endif
|
|---|
| 133 | SFN hFile; /* filehandle */
|
|---|
| 134 | PSZ pszFilename; /* fullpath */
|
|---|
| 135 | PSZ pszModuleName; /* filename without extention. */
|
|---|
| 136 |
|
|---|
| 137 | /** @cat public static data. */
|
|---|
| 138 | public:
|
|---|
| 139 | static ULONG ulInfoLevel; /* Current output message detail level. */
|
|---|
| 140 | enum {Quiet, Error, Warning, Info, InfoAll}; /* Output message detail levels. */
|
|---|
| 141 | };
|
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 | #endif
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|