| 1 | /* $Id: ldr.h,v 1.5 2000-01-22 18:20:59 bird Exp $ | 
|---|
| 2 | * | 
|---|
| 3 | * ldr - loader header file. | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright (c)  1999 knut  St.  osmundsen | 
|---|
| 6 | * | 
|---|
| 7 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 8 | * | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 |  | 
|---|
| 12 | #ifndef _ldr_h_ | 
|---|
| 13 | #define _ldr_h_ | 
|---|
| 14 | #ifndef LDR_INCL_INITONLY | 
|---|
| 15 | /* state variable */ | 
|---|
| 16 | extern BOOL fQAppType; | 
|---|
| 17 |  | 
|---|
| 18 | /* | 
|---|
| 19 | * handle state - Array of handle states. Eight state per byte! | 
|---|
| 20 | */ | 
|---|
| 21 | #define MAX_FILE_HANDLES 0x10000 | 
|---|
| 22 |  | 
|---|
| 23 | extern unsigned char achHandleStates[MAX_FILE_HANDLES/8]; | 
|---|
| 24 |  | 
|---|
| 25 | #define HSTATE_UNUSED       0x00    /* Handle not used (or OS/2). */ | 
|---|
| 26 | #define HSTATE_OS2          0x00    /* OS/2 module filehandle. */ | 
|---|
| 27 | #define HSTATE_OUR          0x01    /* Our module filehandle. */ | 
|---|
| 28 | #define HSTATE_MASK         0xFE | 
|---|
| 29 | #define HSTATE_UMASK        0x01 | 
|---|
| 30 |  | 
|---|
| 31 | #define GetState(a)         (HSTATE_UMASK & (achHandleStates[(a)/8] >> ((a)%8))) | 
|---|
| 32 | #define SetState(a,b)       (achHandleStates[(a)/8] = (achHandleStates[(a)/8] & (HSTATE_MASK << ((a)%8) | HSTATE_MASK >> 8-((a)%8)) | ((b) & 0x1) << ((a)%8))) | 
|---|
| 33 |  | 
|---|
| 34 |  | 
|---|
| 35 | /* | 
|---|
| 36 | * Module struct. | 
|---|
| 37 | */ | 
|---|
| 38 | typedef struct _Module | 
|---|
| 39 | { | 
|---|
| 40 | AVLNODECORE     coreKey;    /* Key is hFile. */ | 
|---|
| 41 | AVLNODECORE     coreMTE;    /* Key is pMTE. */ | 
|---|
| 42 |  | 
|---|
| 43 | SFN             hFile;      /* System file number or file handle if you prefer that. */ | 
|---|
| 44 | PMTE            pMTE;       /* Pointer to MTE if we got one - NULL is allowed. */ | 
|---|
| 45 |  | 
|---|
| 46 | ULONG           fFlags;     /* Flags. Flags if coreMte is in use and what Data contains. */ | 
|---|
| 47 | union | 
|---|
| 48 | { | 
|---|
| 49 | ModuleBase *pModule;    /* Pointer to a Pe2Lx object. (Win32 executables) */ | 
|---|
| 50 | #if defined(_PE2LX_H_) | 
|---|
| 51 | Pe2Lx *     pPe2Lx;     /* Pointer to a Pe2Lx object. (Win32 executables) */ | 
|---|
| 52 | #endif | 
|---|
| 53 | #if defined(_ELF2LX_H_) | 
|---|
| 54 | Elf2Lx *    pElf2Lx;    /* Pointer to a Elf2Lx object. (ELF executables) */ | 
|---|
| 55 | #endif | 
|---|
| 56 | #if defined(_SCRIPT_H_) | 
|---|
| 57 | Script *    pScript;    /* Pointer to a Script object. (Shell scripts) */ | 
|---|
| 58 | #endif | 
|---|
| 59 | #if defined(_PE_H_) | 
|---|
| 60 | Pe *        pPe;        /* Pointer to a Pe object. (Ring3 loader) */ | 
|---|
| 61 | #endif | 
|---|
| 62 | } Data;                     /* Pointer to data. Currently it's allways a Pe2Lx object! */ | 
|---|
| 63 | } MODULE, *PMODULE; | 
|---|
| 64 |  | 
|---|
| 65 | #define MOD_FLAGS_IN_MTETREE    0x00000010UL /* The node is present in the MTE-tree. */ | 
|---|
| 66 | #define MOD_TYPE_MASK           0x0000000FUL /* Type mask. */ | 
|---|
| 67 | #define MOD_TYPE_PE2LX          0x00000001UL /* Pe2Lx module. */ | 
|---|
| 68 | #define MOD_TYPE_ELF2LX         0x00000002UL /* Elf2Lx module. */ | 
|---|
| 69 | #define MOD_TYPE_SCRIPT         0x00000003UL /* Script module. */ | 
|---|
| 70 | #define MOD_TYPE_PE             0x00000004UL /* Pe module. */ | 
|---|
| 71 |  | 
|---|
| 72 |  | 
|---|
| 73 | /* | 
|---|
| 74 | * Modules operations. | 
|---|
| 75 | */ | 
|---|
| 76 | PMODULE     getModuleBySFN(SFN hFile); | 
|---|
| 77 | PMODULE     getModuleByMTE(PMTE pMTE); | 
|---|
| 78 | PMODULE     getModuleByFilename(PCSZ pszFilename); | 
|---|
| 79 |  | 
|---|
| 80 | ULONG       addModule(SFN hFile, PMTE pMTE, ULONG fFlags, ModuleBase *pModObj); | 
|---|
| 81 | ULONG       removeModule(SFN hFile); | 
|---|
| 82 |  | 
|---|
| 83 | #endif | 
|---|
| 84 |  | 
|---|
| 85 | /*************/ | 
|---|
| 86 | /* functions */ | 
|---|
| 87 | /*************/ | 
|---|
| 88 | #ifdef __cplusplus | 
|---|
| 89 | extern "C" { | 
|---|
| 90 | #endif | 
|---|
| 91 |  | 
|---|
| 92 | ULONG ldrInit(void); | 
|---|
| 93 |  | 
|---|
| 94 | #ifdef __cplusplus | 
|---|
| 95 | } | 
|---|
| 96 | #endif | 
|---|
| 97 |  | 
|---|
| 98 | #pragma pack() | 
|---|
| 99 |  | 
|---|
| 100 | #endif | 
|---|