1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
|
#include <string.h>
#include "ntsdp.h"
#include "types.h"
#include "cvtypes.h"
#include "shapi.h"
#include "cvproto.h"
#include "cvinfo.h"
#include "sapi.h"
#include "shiproto.h"
#include "ntempd.h"
#include "ntimage.h"
#include "ntsapi.h"
/*
* Function Prototypes
*/
PIMAGE_INFO pImageFromIndex( UCHAR); // NTSYM.C
/*
* Global Memory (File)
*/
static LPV OmfTemp = NULL;
static CHAR OmfBuff[256] = {0};
/*
* Da Code
*/
/*** MH_OmfSetupLocal
**
** Synopsis:
** LPV MH_OmfSetupLocal( HDEP handle);
**
** Entry:
** handle - Handle to the local hsym
**
** Returns:
** Returns a pointer to void of the OMF record
**
** Description:
** Creates an BPREL32 omf record and returns the address.
**
*/
LPV MH_OmfSetupLocal(HDEP handle)
{
int length;
PLOCAL pLocal = (PLOCAL)handle;
BPRELSYM32 *Omf;
MEMSET( OmfBuff, 0, sizeof(OmfBuff) ); // Zero the name buffer
SHGetSymName( (HSYM)handle, OmfBuff); // Get the Symbol's name
length = STRLEN(OmfBuff);
OmfTemp = malloc( sizeof(BPRELSYM32) + length + 1);
Omf = (BPRELSYM32 *)OmfTemp;
if ( Omf ) {
Omf->name[0] = (UCHAR)length;
STRNCPY( &Omf->name[1], OmfBuff, Omf->name[0]);
Omf->reclen = (short)(sizeof(BPRELSYM32) + length);
Omf->rectyp = S_BPREL32;
Omf->off = (LONG)pLocal->value;
Omf->typind = pLocal->cvtype;
}
return OmfTemp;
}
/*** MH_OmfSetupProc
**
** Synopsis:
** LPV MH_OmfSetupProc( HDEP handle);
**
** Entry:
** handle - Handle to the proc hsym
**
** Returns:
** Returns a pointer to void of the OMF record
**
** Description:
** Creates an PROCSYM32 omf record and returns the address.
**
*/
LPV MH_OmfSetupProc(HDEP handle)
{
int i,length;
PSYMBOL pProc = (PSYMBOL)handle;
ULONG offset;
PIMAGE_INFO pImage;
PROCSYM32 * Omf;
pImage = pImageFromIndex( pProc->modIndex );
assert( pImage );
offset = pProc->offset - (ULONG)pImage->lpBaseOfImage;
MEMSET( OmfBuff, 0, sizeof(OmfBuff) ); // Zero the name buffer
SHGetSymName( (HSYM)handle, OmfBuff); // Get the Symbol's name
length = STRLEN(OmfBuff);
OmfTemp = malloc( sizeof(PROCSYM32) + length + 1);
Omf = (PROCSYM32 *)OmfTemp;
if ( Omf ) {
for ( i=1; i < pImage->ObjectCount; i++)
if ( pImage->pRVA[i] <= offset && offset <= pImage->pRVA[i+1] )
break;
Omf->name[0] = (UCHAR)length;
STRNCPY( &Omf->name[1], OmfBuff, Omf->name[0]);
Omf->reclen = (short)(sizeof(DATASYM32) + length);
Omf->rectyp = S_GPROC32;
Omf->off = offset - pImage->pRVA[i];
Omf->seg = (SEGMENT)i;
Omf->typind = pProc->cvtype;
Omf->pParent = 0;
Omf->pEnd = 0;
Omf->pNext = 0;
Omf->len = 0;
Omf->DbgStart = 0;
Omf->DbgEnd = 0xffffffff;
Omf->rtntyp = 0;
}
return (LPV)Omf;
}
/*** MH_OmfSetupPublic
**
** Synopsis:
** LPV MH_OmfSetupPublic( HDEP handle);
**
** Entry:
** handle - Handle to the proc hsym
**
** Returns:
** Returns a pointer to void of the OMF record
**
** Description:
** Creates an DATASYM32 omf record and returns the address.
**
*/
LPV MH_OmfSetupPublic(HDEP handle)
{
int i,length;
PSYMBOL pSymbol = (PSYMBOL)handle;
ULONG offset;
PIMAGE_INFO pImage;
DATASYM32 *Omf;
pImage = pImageFromIndex( pSymbol->modIndex );
assert( pImage );
offset = pSymbol->offset - (ULONG)pImage->lpBaseOfImage;
MEMSET( OmfBuff, 0, sizeof(OmfBuff) ); // Zero the name buffer
SHGetSymName( (HSYM)handle, OmfBuff); // Get the Symbol's name
length = STRLEN(OmfBuff);
OmfTemp = malloc( sizeof(DATASYM32) + length + 1);
Omf = (DATASYM32 *)OmfTemp;
if ( Omf ) {
for ( i=1; i < pImage->ObjectCount; i++)
if ( pImage->pRVA[i] <= offset && offset <= pImage->pRVA[i+1] )
break;
Omf->name[0] = (UCHAR)length;
STRNCPY( &Omf->name[1], OmfBuff, Omf->name[0]);
Omf->reclen = (short)(sizeof(DATASYM32) + length);
Omf->rectyp = S_PUB32;
Omf->off = offset - pImage->pRVA[i];
Omf->seg = (SEGMENT)i;
Omf->typind = pSymbol->cvtype;
}
return OmfTemp;
}
/*** MHOmfLock
**
** Synopsis:
** LPV MHOmfLock( HDEP handle);
**
** Entry:
** handle - Handle to the an hsym
**
** Returns:
** Returns a pointer to void of the OMF record that was created
**
** Description:
** Creates an approriate OMF record for the kind of hsym we're passed,\
** and returns a pointer to the record.
**
** WARNING: THE CURRENT SYSTEM ONLY ALLOWS ONE HSYM TO BE LOCKED DOWN
** AT ONE TIME.
**
*/
LPV LOADDS PASCAL MHOmfLock( HDEP handle)
{
PUSHORT kind = (PUSHORT)handle;
LPV point;
assert( OmfTemp == NULL);
assert( handle );
switch ( *kind ) {
case K_PUBLIC: point = MH_OmfSetupPublic(handle);
break;
case K_LOCAL: point = MH_OmfSetupLocal(handle);
break;
case K_PROC: point = MH_OmfSetupProc(handle);
break;
case K_TYPE: OmfTemp = (LPV)-1;
point = (LPV)(handle + sizeof(LONG));
break;
default: assert( FALSE );
point = NULL;
}
return point;
}
/*** MHOmfUnlock
**
** Synopsis:
** LPV MHOmfunlock( HDEP handle);
**
** Entry:
** handle - Not Referenced
**
** Returns:
**
** Description:
** Releases the OMF record that was created by a MHOmfLock() call
**
** WARNING: THE CURRENT SYSTEM ONLY ALLOWS ONE HSYM TO BE LOCKED DOWN
** AT ONE TIME.
**
*/
void LOADDS PASCAL MHOmfUnLock(HDEP handle)
{
Unreferenced(handle);
assert( OmfTemp != NULL);
if ( OmfTemp != (LPV)-1) free(OmfTemp);
OmfTemp = NULL;
}
|