1 | /* $Id: kFileLX.cpp,v 1.1 2000-03-27 10:18:41 bird Exp $
|
---|
2 | *
|
---|
3 | *
|
---|
4 | *
|
---|
5 | * Copyright (c) 2000 knut st. osmundsen (knut.stange.osmundsen@pmsc.no)
|
---|
6 | *
|
---|
7 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
8 | *
|
---|
9 | */
|
---|
10 |
|
---|
11 | /*******************************************************************************
|
---|
12 | * Defined Constants *
|
---|
13 | *******************************************************************************/
|
---|
14 | /* emx fixups */
|
---|
15 | #ifdef __EMX__
|
---|
16 | #define __stdcall
|
---|
17 | #define max(a,b) (((a) > (b)) ? (a) : (b))
|
---|
18 | #define min(a,b) (((a) < (b)) ? (a) : (b))
|
---|
19 | #endif
|
---|
20 | #define INCL_DOSERRORS
|
---|
21 | #define FOR_EXEHDR 1 /* exe386.h flag */
|
---|
22 | #define DWORD ULONG /* Used by exe386.h / newexe.h */
|
---|
23 | #define WORD USHORT /* Used by exe386.h / newexe.h */
|
---|
24 |
|
---|
25 |
|
---|
26 | /******************************************************************************
|
---|
27 | * Header Files *
|
---|
28 | ******************************************************************************/
|
---|
29 | #ifdef __EMX__
|
---|
30 | #define INT INT_
|
---|
31 | #define PCHAR PCHAR_
|
---|
32 | #endif
|
---|
33 | #include <os2.h>
|
---|
34 | #ifdef __EMX__
|
---|
35 | #undef PCHAR
|
---|
36 | #undef INT
|
---|
37 | #endif
|
---|
38 | #include <newexe.h>
|
---|
39 | #include <exe386.h>
|
---|
40 |
|
---|
41 | #include <stdio.h>
|
---|
42 | #include <stdlib.h>
|
---|
43 | #include <string.h>
|
---|
44 | #include <malloc.h>
|
---|
45 |
|
---|
46 | #include <assert.h>
|
---|
47 |
|
---|
48 | #include "kFileFormatBase.h"
|
---|
49 | #include "kFileLX.h"
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Create an LX file object from an LX executable image.
|
---|
56 | * @param pszFilename LX executable image name.
|
---|
57 | */
|
---|
58 | kFileLX::kFileLX(const char *pszFilename)
|
---|
59 | : pvBase(NULL)
|
---|
60 | {
|
---|
61 | struct exe_hdr * pehdr;
|
---|
62 |
|
---|
63 | /* create filemapping */
|
---|
64 | pvBase = kFileFormatBase::readfile(pszFilename);
|
---|
65 | if (pvBase == NULL)
|
---|
66 | throw(1);
|
---|
67 |
|
---|
68 | pehdr = (struct exe_hdr*)pvBase;
|
---|
69 | if (pehdr->e_magic == EMAGIC)
|
---|
70 | offLXHdr = pehdr->e_lfanew;
|
---|
71 | else
|
---|
72 | offLXHdr = 0;
|
---|
73 |
|
---|
74 | pe32 = (struct e32_exe*)((char*)pvBase + offLXHdr);
|
---|
75 | if (*(PUSHORT)pe32 == E32MAGIC)
|
---|
76 | {
|
---|
77 | paObject = (struct o32_obj*)((char*)pvBase + pe32->e32_objtab + offLXHdr);
|
---|
78 | }
|
---|
79 | else
|
---|
80 | {
|
---|
81 | free(pvBase);
|
---|
82 | pvBase = NULL;
|
---|
83 | throw(2);
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 |
|
---|
88 |
|
---|
89 | /**
|
---|
90 | * Destructor.
|
---|
91 | */
|
---|
92 | kFileLX::~kFileLX()
|
---|
93 | {
|
---|
94 | if (pvBase != NULL)
|
---|
95 | free(pvBase);
|
---|
96 | pvBase = NULL;
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 |
|
---|
101 | BOOL kFileLX::queryModuleName(char *pszBuffer)
|
---|
102 | {
|
---|
103 | /* not implemented */
|
---|
104 | assert("not implemented!");
|
---|
105 | return FALSE;
|
---|
106 | }
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport)
|
---|
111 | {
|
---|
112 | /* not implemented */
|
---|
113 | assert("not implemented!");
|
---|
114 | return FALSE;
|
---|
115 | }
|
---|
116 |
|
---|
117 |
|
---|
118 |
|
---|
119 | BOOL kFileLX::findNextExport(PEXPORTENTRY pExport)
|
---|
120 | {
|
---|
121 | /* not implemented */
|
---|
122 | assert("not implemented!");
|
---|
123 | return FALSE;
|
---|
124 | }
|
---|
125 |
|
---|
126 |
|
---|
127 |
|
---|
128 | /**
|
---|
129 | * Gets a specific LX object.
|
---|
130 | * @returns Pointer to object. NULL on error / invalid index.
|
---|
131 | * @param iObject object number (0-based)
|
---|
132 | */
|
---|
133 | struct o32_obj * kFileLX::getObject(int iObject)
|
---|
134 | {
|
---|
135 |
|
---|
136 | if (iObject < pe32->e32_objcnt)
|
---|
137 | return &paObject[iObject];
|
---|
138 | return NULL;
|
---|
139 | }
|
---|
140 |
|
---|
141 |
|
---|