| 1 | /* $Id: windllpeldr.cpp,v 1.13 2004-01-15 10:39:08 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 PE loader Dll class | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de) | 
|---|
| 8 | * | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 | #define INCL_DOSFILEMGR          /* File Manager values      */ | 
|---|
| 14 | #define INCL_DOSERRORS           /* DOS Error values         */ | 
|---|
| 15 | #define INCL_DOSPROCESS          /* DOS Process values       */ | 
|---|
| 16 | #define INCL_DOSMODULEMGR | 
|---|
| 17 | #define INCL_DOSMISC             /* DOS Miscellanous values  */ | 
|---|
| 18 | #define INCL_WIN | 
|---|
| 19 | #include <os2wrap.h>    //Odin32 OS/2 api wrappers | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <stdlib.h> | 
|---|
| 23 | #ifndef __GNUC__ | 
|---|
| 24 | #include <iostream.h> | 
|---|
| 25 | #include <fstream.h> | 
|---|
| 26 | #endif | 
|---|
| 27 | #include <misc.h> | 
|---|
| 28 | #include <win32type.h> | 
|---|
| 29 | #include <pefile.h> | 
|---|
| 30 | #include "windllpeldr.h" | 
|---|
| 31 | #include <wprocess.h> | 
|---|
| 32 |  | 
|---|
| 33 | #include "oslibmisc.h" | 
|---|
| 34 | #include "oslibdos.h" | 
|---|
| 35 |  | 
|---|
| 36 | #define DBG_LOCALLOG    DBG_windllpeldr | 
|---|
| 37 | #include "dbglocal.h" | 
|---|
| 38 |  | 
|---|
| 39 |  | 
|---|
| 40 | //****************************************************************************** | 
|---|
| 41 | //****************************************************************************** | 
|---|
| 42 | Win32PeLdrDll::Win32PeLdrDll(char *szDllName, Win32ImageBase *parentImage) | 
|---|
| 43 | : Win32ImageBase(-1), | 
|---|
| 44 | Win32DllBase(-1, 0, parentImage), | 
|---|
| 45 | Win32PeLdrImage(szDllName, FALSE) | 
|---|
| 46 | { | 
|---|
| 47 | dprintf(("Win32PeLdrDll::Win32PeLdrDll %s %s loaded by %s", szFileName, szModule, | 
|---|
| 48 | (parentImage) ? parentImage->getModuleName() : "Unknown")); | 
|---|
| 49 | } | 
|---|
| 50 | //****************************************************************************** | 
|---|
| 51 | //****************************************************************************** | 
|---|
| 52 | Win32PeLdrDll::~Win32PeLdrDll() | 
|---|
| 53 | { | 
|---|
| 54 | dprintf(("Win32PeLdrDll::~Win32PeLdrDll %s", szModule)); | 
|---|
| 55 | } | 
|---|
| 56 | //****************************************************************************** | 
|---|
| 57 | //****************************************************************************** | 
|---|
| 58 | DWORD Win32PeLdrDll::init(ULONG reservedMem, ULONG ulPEOffset) | 
|---|
| 59 | { | 
|---|
| 60 | char   modname[CCHMAXPATH]; | 
|---|
| 61 | char  *syspath; | 
|---|
| 62 | HFILE  dllfile; | 
|---|
| 63 | APIRET rc; | 
|---|
| 64 | DWORD  dwRet; | 
|---|
| 65 |  | 
|---|
| 66 | strupr(szFileName); | 
|---|
| 67 | if(!strchr(szFileName, (int)'.')) { | 
|---|
| 68 | strcat(szFileName, DLL_EXTENSION); | 
|---|
| 69 | } | 
|---|
| 70 |  | 
|---|
| 71 | dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE); | 
|---|
| 72 | if(dllfile == NULL) {//search in libpath for dll | 
|---|
| 73 | syspath = getenv("WIN32LIBPATH"); | 
|---|
| 74 | if(syspath) { | 
|---|
| 75 | strcpy(modname, syspath); | 
|---|
| 76 | if(modname[strlen(modname)-1] != '\\') { | 
|---|
| 77 | strcat(modname, "\\"); | 
|---|
| 78 | } | 
|---|
| 79 | strcat(modname, szFileName); | 
|---|
| 80 | strcpy(szFileName, modname); | 
|---|
| 81 | } | 
|---|
| 82 | } | 
|---|
| 83 | else  OSLibDosClose(dllfile); | 
|---|
| 84 |  | 
|---|
| 85 | dwRet = Win32PeLdrImage::init(0); | 
|---|
| 86 | dllEntryPoint = (WIN32DLLENTRY)entryPoint; | 
|---|
| 87 |  | 
|---|
| 88 | if(!(Characteristics & IMAGE_FILE_DLL)) { | 
|---|
| 89 | //executable loaded as dll; don't call entrypoint | 
|---|
| 90 | dprintf(("WARNING: Exe %s loaded as dll; entrypoint not called", szFileName)); | 
|---|
| 91 | dllEntryPoint = NULL; | 
|---|
| 92 | } | 
|---|
| 93 | return dwRet; | 
|---|
| 94 | } | 
|---|
| 95 | //****************************************************************************** | 
|---|
| 96 | //****************************************************************************** | 
|---|
| 97 | BOOL Win32PeLdrDll::isPe2LxDll() const | 
|---|
| 98 | { | 
|---|
| 99 | return FALSE; | 
|---|
| 100 | } | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | //****************************************************************************** | 
|---|
| 103 | BOOL Win32PeLdrDll::isLxDll() const | 
|---|
| 104 | { | 
|---|
| 105 | return FALSE; | 
|---|
| 106 | } | 
|---|
| 107 | //****************************************************************************** | 
|---|
| 108 | //****************************************************************************** | 
|---|