| 1 | /* $Id: windllpeldr.cpp,v 1.4 1999-11-26 00:05:19 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 PE loader Dll class
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #define INCL_DOSFILEMGR /* File Manager values */
|
|---|
| 13 | #define INCL_DOSERRORS /* DOS Error values */
|
|---|
| 14 | #define INCL_DOSPROCESS /* DOS Process values */
|
|---|
| 15 | #define INCL_DOSMODULEMGR
|
|---|
| 16 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
|---|
| 17 | #define INCL_WIN
|
|---|
| 18 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 19 | #include <stdio.h>
|
|---|
| 20 | #include <string.h>
|
|---|
| 21 | #include <stdlib.h>
|
|---|
| 22 | #include <iostream.h>
|
|---|
| 23 | #include <fstream.h>
|
|---|
| 24 | #include <misc.h>
|
|---|
| 25 | #include <win32type.h>
|
|---|
| 26 | #include <pefile.h>
|
|---|
| 27 | #include <windllpeldr.h>
|
|---|
| 28 | #include <wprocess.h>
|
|---|
| 29 |
|
|---|
| 30 | #include "oslibmisc.h"
|
|---|
| 31 | #include "oslibdos.h"
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 | //******************************************************************************
|
|---|
| 35 | //******************************************************************************
|
|---|
| 36 | Win32PeLdrDll::Win32PeLdrDll(char *szDllName, Win32ImageBase *parentImage)
|
|---|
| 37 | : Win32ImageBase(-1),
|
|---|
| 38 | Win32DllBase(-1, 0),
|
|---|
| 39 | Win32PeLdrImage(szDllName, FALSE)
|
|---|
| 40 | {
|
|---|
| 41 | dprintf(("Win32PeLdrDll::Win32PeLdrDll %s %s loaded by %s", szFileName, szModule,
|
|---|
| 42 | (parentImage) ? parentImage->getModuleName() : "Unknown"));
|
|---|
| 43 | }
|
|---|
| 44 | //******************************************************************************
|
|---|
| 45 | //******************************************************************************
|
|---|
| 46 | Win32PeLdrDll::~Win32PeLdrDll()
|
|---|
| 47 | {
|
|---|
| 48 | dprintf(("Win32PeLdrDll::~Win32PeLdrDll %s", szModule));
|
|---|
| 49 | }
|
|---|
| 50 | //******************************************************************************
|
|---|
| 51 | //******************************************************************************
|
|---|
| 52 | BOOL Win32PeLdrDll::init(ULONG reservedMem)
|
|---|
| 53 | {
|
|---|
| 54 | char modname[CCHMAXPATH];
|
|---|
| 55 | char *syspath;
|
|---|
| 56 | HFILE dllfile;
|
|---|
| 57 | APIRET rc;
|
|---|
| 58 | BOOL fRet;
|
|---|
| 59 |
|
|---|
| 60 | strupr(szFileName);
|
|---|
| 61 | if(!strchr(szFileName, (int)'.')) {
|
|---|
| 62 | strcat(szFileName,".DLL");
|
|---|
| 63 | }
|
|---|
| 64 | dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
|
|---|
| 65 | if(dllfile == NULL) {//search in libpath for dll
|
|---|
| 66 | syspath = getenv("WIN32LIBPATH");
|
|---|
| 67 | if(syspath) {
|
|---|
| 68 | strcpy(modname, syspath);
|
|---|
| 69 | if(modname[strlen(modname)-1] != '\\') {
|
|---|
| 70 | strcat(modname, "\\");
|
|---|
| 71 | }
|
|---|
| 72 | strcat(modname, szFileName);
|
|---|
| 73 | strcpy(szFileName, modname);
|
|---|
| 74 | }
|
|---|
| 75 | }
|
|---|
| 76 | else OSLibDosClose(dllfile);
|
|---|
| 77 | fRet = Win32PeLdrImage::init(0);
|
|---|
| 78 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
|---|
| 79 | return fRet;
|
|---|
| 80 | }
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | BOOL Win32PeLdrDll::isLxDll()
|
|---|
| 84 | {
|
|---|
| 85 | return FALSE;
|
|---|
| 86 | }
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | //******************************************************************************
|
|---|