[10397] | 1 | /* $Id: windllpeldr.cpp,v 1.13 2004-01-15 10:39:08 sandervl Exp $ */
|
---|
[956] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Win32 PE loader Dll class
|
---|
| 5 | *
|
---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
[10397] | 7 | * Copyright 2003 Innotek Systemberatung GmbH (sandervl@innotek.de)
|
---|
[956] | 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
|
---|
[6015] | 19 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
---|
[956] | 20 | #include <stdio.h>
|
---|
| 21 | #include <string.h>
|
---|
| 22 | #include <stdlib.h>
|
---|
[21916] | 23 | #ifndef __GNUC__
|
---|
[956] | 24 | #include <iostream.h>
|
---|
| 25 | #include <fstream.h>
|
---|
[21916] | 26 | #endif
|
---|
[956] | 27 | #include <misc.h>
|
---|
| 28 | #include <win32type.h>
|
---|
| 29 | #include <pefile.h>
|
---|
[21916] | 30 | #include "windllpeldr.h"
|
---|
[956] | 31 | #include <wprocess.h>
|
---|
| 32 |
|
---|
| 33 | #include "oslibmisc.h"
|
---|
| 34 | #include "oslibdos.h"
|
---|
| 35 |
|
---|
[6015] | 36 | #define DBG_LOCALLOG DBG_windllpeldr
|
---|
[2811] | 37 | #include "dbglocal.h"
|
---|
[956] | 38 |
|
---|
[2811] | 39 |
|
---|
[956] | 40 | //******************************************************************************
|
---|
| 41 | //******************************************************************************
|
---|
[6015] | 42 | Win32PeLdrDll::Win32PeLdrDll(char *szDllName, Win32ImageBase *parentImage)
|
---|
| 43 | : Win32ImageBase(-1),
|
---|
| 44 | Win32DllBase(-1, 0, parentImage),
|
---|
[1833] | 45 | Win32PeLdrImage(szDllName, FALSE)
|
---|
[956] | 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 | //******************************************************************************
|
---|
[9975] | 58 | DWORD Win32PeLdrDll::init(ULONG reservedMem, ULONG ulPEOffset)
|
---|
[956] | 59 | {
|
---|
| 60 | char modname[CCHMAXPATH];
|
---|
| 61 | char *syspath;
|
---|
| 62 | HFILE dllfile;
|
---|
| 63 | APIRET rc;
|
---|
[9975] | 64 | DWORD dwRet;
|
---|
[956] | 65 |
|
---|
| 66 | strupr(szFileName);
|
---|
[1496] | 67 | if(!strchr(szFileName, (int)'.')) {
|
---|
[6015] | 68 | strcat(szFileName, DLL_EXTENSION);
|
---|
[956] | 69 | }
|
---|
[9975] | 70 |
|
---|
[956] | 71 | dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
|
---|
| 72 | if(dllfile == NULL) {//search in libpath for dll
|
---|
[6015] | 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 | }
|
---|
[956] | 82 | }
|
---|
[6015] | 83 | else OSLibDosClose(dllfile);
|
---|
[9975] | 84 |
|
---|
| 85 | dwRet = Win32PeLdrImage::init(0);
|
---|
[956] | 86 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
---|
[3615] | 87 |
|
---|
[10397] | 88 | if(!(Characteristics & IMAGE_FILE_DLL)) {
|
---|
[6015] | 89 | //executable loaded as dll; don't call entrypoint
|
---|
| 90 | dprintf(("WARNING: Exe %s loaded as dll; entrypoint not called", szFileName));
|
---|
| 91 | dllEntryPoint = NULL;
|
---|
[3615] | 92 | }
|
---|
[9975] | 93 | return dwRet;
|
---|
[956] | 94 | }
|
---|
| 95 | //******************************************************************************
|
---|
| 96 | //******************************************************************************
|
---|
[6015] | 97 | BOOL Win32PeLdrDll::isPe2LxDll() const
|
---|
[956] | 98 | {
|
---|
| 99 | return FALSE;
|
---|
| 100 | }
|
---|
| 101 | //******************************************************************************
|
---|
| 102 | //******************************************************************************
|
---|
[6015] | 103 | BOOL Win32PeLdrDll::isLxDll() const
|
---|
| 104 | {
|
---|
| 105 | return FALSE;
|
---|
| 106 | }
|
---|
| 107 | //******************************************************************************
|
---|
| 108 | //******************************************************************************
|
---|