source: trunk/src/kernel32/windllpeldr.cpp@ 1496

Last change on this file since 1496 was 1496, checked in by sandervl, 26 years ago

dll + stippath fixes

File size: 4.3 KB
Line 
1/* $Id: windllpeldr.cpp,v 1.2 1999-10-28 18:23:34 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//******************************************************************************
36Win32PeLdrDll::Win32PeLdrDll(char *szDllName, Win32ImageBase *parentImage)
37 : Win32ImageBase(-1),
38 Win32DllBase(-1, 0),
39 Win32PeLdrImage(szDllName)
40{
41 dprintf(("Win32PeLdrDll::Win32PeLdrDll %s %s loaded by %s", szFileName, szModule,
42 (parentImage) ? parentImage->getModuleName() : "Unknown"));
43}
44//******************************************************************************
45//******************************************************************************
46Win32PeLdrDll::~Win32PeLdrDll()
47{
48 dprintf(("Win32PeLdrDll::~Win32PeLdrDll %s", szModule));
49}
50//******************************************************************************
51//******************************************************************************
52BOOL 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//******************************************************************************
83ULONG Win32PeLdrDll::getApi(char *name)
84{
85 ULONG apiaddr, i, apilen;
86 char *apiname;
87 char tmp[4];
88 NameExport *curexport;
89 ULONG ulAPIOrdinal; /* api requested by ordinal */
90
91 apilen = strlen(name) + 1;
92 if(apilen < 4)
93 {
94 *(ULONG *)tmp = 0;
95 strcpy(tmp, name);
96 apiname = tmp;
97 }
98 else apiname = name;
99
100 curexport = nameexports;
101 for(i=0; i<nrNameExports; i++)
102 {
103 if(apilen == curexport->nlength &&
104 *(ULONG *)curexport->name == *(ULONG *)name)
105 {
106 if(strcmp(curexport->name, name) == 0)
107 return(curexport->virtaddr);
108 }
109 curexport = (NameExport *)((ULONG)curexport->name + curexport->nlength);
110 }
111 return(0);
112}
113//******************************************************************************
114//******************************************************************************
115ULONG Win32PeLdrDll::getApi(int ordinal)
116{
117 ULONG apiaddr, i;
118 OrdExport *curexport;
119 NameExport *nexport;
120
121 curexport = ordexports;
122 for(i=0;i<nrOrdExports;i++) {
123 if(curexport->ordinal == ordinal)
124 return(curexport->virtaddr);
125 curexport++;
126 }
127 //Name exports also contain an ordinal, so check this
128 nexport = nameexports;
129 for(i=0;i<nrNameExports;i++) {
130 if(nexport->ordinal == ordinal)
131 return(nexport->virtaddr);
132
133 nexport = (NameExport *)((ULONG)nexport->name + nexport->nlength);
134 }
135 return(0);
136}
137//******************************************************************************
138//******************************************************************************
139BOOL Win32PeLdrDll::isLxDll()
140{
141 return FALSE;
142}
143//******************************************************************************
144//******************************************************************************
Note: See TracBrowser for help on using the repository browser.