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 | #include <iostream.h>
|
---|
24 | #include <fstream.h>
|
---|
25 | #include <misc.h>
|
---|
26 | #include <win32type.h>
|
---|
27 | #include <pefile.h>
|
---|
28 | #include <windllpeldr.h>
|
---|
29 | #include <wprocess.h>
|
---|
30 |
|
---|
31 | #include "oslibmisc.h"
|
---|
32 | #include "oslibdos.h"
|
---|
33 |
|
---|
34 | #define DBG_LOCALLOG DBG_windllpeldr
|
---|
35 | #include "dbglocal.h"
|
---|
36 |
|
---|
37 |
|
---|
38 | //******************************************************************************
|
---|
39 | //******************************************************************************
|
---|
40 | Win32PeLdrDll::Win32PeLdrDll(char *szDllName, Win32ImageBase *parentImage)
|
---|
41 | : Win32ImageBase(-1),
|
---|
42 | Win32DllBase(-1, 0, parentImage),
|
---|
43 | Win32PeLdrImage(szDllName, FALSE)
|
---|
44 | {
|
---|
45 | dprintf(("Win32PeLdrDll::Win32PeLdrDll %s %s loaded by %s", szFileName, szModule,
|
---|
46 | (parentImage) ? parentImage->getModuleName() : "Unknown"));
|
---|
47 | }
|
---|
48 | //******************************************************************************
|
---|
49 | //******************************************************************************
|
---|
50 | Win32PeLdrDll::~Win32PeLdrDll()
|
---|
51 | {
|
---|
52 | dprintf(("Win32PeLdrDll::~Win32PeLdrDll %s", szModule));
|
---|
53 | }
|
---|
54 | //******************************************************************************
|
---|
55 | //******************************************************************************
|
---|
56 | DWORD Win32PeLdrDll::init(ULONG reservedMem, ULONG ulPEOffset)
|
---|
57 | {
|
---|
58 | char modname[CCHMAXPATH];
|
---|
59 | char *syspath;
|
---|
60 | HFILE dllfile;
|
---|
61 | APIRET rc;
|
---|
62 | DWORD dwRet;
|
---|
63 |
|
---|
64 | strupr(szFileName);
|
---|
65 | if(!strchr(szFileName, (int)'.')) {
|
---|
66 | strcat(szFileName, DLL_EXTENSION);
|
---|
67 | }
|
---|
68 |
|
---|
69 | dllfile = OSLibDosOpen(szFileName, OSLIB_ACCESS_READONLY|OSLIB_ACCESS_SHAREDENYNONE);
|
---|
70 | if(dllfile == NULL) {//search in libpath for dll
|
---|
71 | syspath = getenv("WIN32LIBPATH");
|
---|
72 | if(syspath) {
|
---|
73 | strcpy(modname, syspath);
|
---|
74 | if(modname[strlen(modname)-1] != '\\') {
|
---|
75 | strcat(modname, "\\");
|
---|
76 | }
|
---|
77 | strcat(modname, szFileName);
|
---|
78 | strcpy(szFileName, modname);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | else OSLibDosClose(dllfile);
|
---|
82 |
|
---|
83 | dwRet = Win32PeLdrImage::init(0);
|
---|
84 | dllEntryPoint = (WIN32DLLENTRY)entryPoint;
|
---|
85 |
|
---|
86 | if(!(Characteristics & IMAGE_FILE_DLL)) {
|
---|
87 | //executable loaded as dll; don't call entrypoint
|
---|
88 | dprintf(("WARNING: Exe %s loaded as dll; entrypoint not called", szFileName));
|
---|
89 | dllEntryPoint = NULL;
|
---|
90 | }
|
---|
91 | return dwRet;
|
---|
92 | }
|
---|
93 | //******************************************************************************
|
---|
94 | //******************************************************************************
|
---|
95 | BOOL Win32PeLdrDll::isPe2LxDll() const
|
---|
96 | {
|
---|
97 | return FALSE;
|
---|
98 | }
|
---|
99 | //******************************************************************************
|
---|
100 | //******************************************************************************
|
---|
101 | BOOL Win32PeLdrDll::isLxDll() const
|
---|
102 | {
|
---|
103 | return FALSE;
|
---|
104 | }
|
---|
105 | //******************************************************************************
|
---|
106 | //******************************************************************************
|
---|