Changeset 4129 for trunk/tools/common/kFileLX.cpp
- Timestamp:
- Aug 31, 2000, 5:00:13 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFileLX.cpp
r3246 r4129 1 /* $Id: kFileLX.cpp,v 1. 1 2000-03-27 10:18:41bird Exp $1 /* $Id: kFileLX.cpp,v 1.2 2000-08-31 03:00:13 bird Exp $ 2 2 * 3 3 * … … 49 49 #include "kFileLX.h" 50 50 51 /******************************************************************************* 52 * Structures and Typedefs * 53 *******************************************************************************/ 54 typedef struct _export_state 55 { 56 struct b32_bundle * pb32; /* Pointer to current bundle. */ 57 int iOrdinalBundle; /* The ordinal the bundle starts at. */ 58 struct e32_entry * pe32; /* Pointer to the current bundle entry. */ 59 int iOrdinal; /* The current ordinal. */ 60 } EXPSTATE, *PEXPSTATE; 61 62 63 64 BOOL kFileLX::queryExportName(int iOrdinal, char *pszBuffer) 65 { 66 PUSHORT pus; 67 PUCHAR puch; 68 69 /* resident name table */ 70 if (pe32->e32_restab) 71 { 72 puch = (PUCHAR)pvBase + offLXHdr + pe32->e32_restab; 73 while (*puch != 0) 74 { 75 pus = (PUSHORT)(puch + 1 + *puch); 76 if (*pus == iOrdinal) 77 { 78 memcpy(pszBuffer, puch + 1, *puch); 79 pszBuffer[*puch] = '\0'; 80 return TRUE; 81 } 82 puch += *puch + 1 + 2; 83 } 84 } 85 86 /* not found, check the non-resident name table too */ 87 if (pe32->e32_nrestab) 88 { 89 puch = (PUCHAR)pvBase + pe32->e32_nrestab; 90 while (*puch != 0) 91 { 92 pus = (PUSHORT)(puch + 1 + *puch); 93 if (*pus == iOrdinal) 94 { 95 memcpy(pszBuffer, puch + 1, *puch); 96 pszBuffer[*puch] = '\0'; 97 return TRUE; 98 } 99 puch += *puch + 1 + 2; 100 } 101 } 102 103 return FALSE; 104 } 51 105 52 106 … … 101 155 BOOL kFileLX::queryModuleName(char *pszBuffer) 102 156 { 103 /* not implemented */ 104 assert("not implemented!"); 157 /* The module name is the 0 ordinal entry in resident name table */ 158 return queryExportName(0, pszBuffer); 159 } 160 161 162 163 BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport) 164 { 165 struct b32_bundle * pBundle = (struct b32_bundle*)((char*)pvBase + pe32->e32_enttab + offLXHdr); 166 struct e32_entry * pEntry; 167 int iOrdinal = 1; 168 169 if (pe32->e32_enttab) 170 { 171 while (pBundle->b32_cnt != 0) 172 { 173 /* skip empty bundles */ 174 while (pBundle->b32_cnt != 0 && pBundle->b32_type == EMPTY) 175 { 176 iOrdinal += pBundle->b32_cnt; 177 pBundle = (struct b32_bundle*)((char*)pBundle + 2); 178 } 179 180 /* FIXME forwarders are not implemented so we'll skip them too. */ 181 while (pBundle->b32_cnt != 0 && (pBundle->b32_type & ~TYPEINFO) == ENTRYFWD) 182 { 183 iOrdinal += pBundle->b32_cnt; 184 pBundle = (struct b32_bundle*)((char*)(pBundle + 1) + pBundle->b32_cnt * 7); 185 } 186 187 /* we'll ignore any flags for the moment - TODO */ 188 if (pBundle->b32_cnt != 0) 189 { 190 pExport->ulOrdinal = iOrdinal; 191 pExport->iObject = pBundle->b32_obj; 192 193 /* look for name */ 194 pExport->achIntName[0] = '\0'; 195 if (!queryExportName(iOrdinal, pExport->achName)) 196 pExport->achName[0] = '\0'; 197 198 pEntry = (struct e32_entry*)(pBundle+1); 199 switch (pBundle->b32_type & ~TYPEINFO) 200 { 201 case ENTRY16: 202 pExport->offset = pEntry->e32_variant.e32_offset.offset16; 203 break; 204 205 case ENTRY32: 206 pExport->offset = pEntry->e32_variant.e32_offset.offset32; 207 break; 208 209 case GATE16: 210 pExport->offset = pEntry->e32_variant.e32_callgate.offset; 211 break; 212 default: 213 assert(!"ARG!!!! invalid bundle type!"); 214 } 215 216 /* store status - current export entry */ 217 PEXPSTATE pExpState = (PEXPSTATE)malloc(sizeof(EXPSTATE)); 218 pExport->pv = pExpState; 219 pExpState->pb32 = pBundle; 220 pExpState->iOrdinalBundle = iOrdinal; 221 pExpState->pe32 = pEntry; 222 pExpState->iOrdinal = iOrdinal; 223 return TRUE; 224 } 225 } 226 227 } 228 105 229 return FALSE; 106 230 } … … 108 232 109 233 110 BOOL kFileLX::findFirstExport(PEXPORTENTRY pExport) 111 { 112 /* not implemented */ 113 assert("not implemented!"); 234 BOOL kFileLX::findNextExport(PEXPORTENTRY pExport) 235 { 236 static int acbEntry[] = 237 { 238 0, /* EMPTY */ 239 3, /* ENTRY16 */ 240 5, /* GATE16 */ 241 5, /* ENTRY32 */ 242 7 /* ENTRYFWD */ 243 }; 244 245 PEXPSTATE pExpState = (PEXPSTATE)pExport->pv; 246 247 /* 248 * Get more ordinals from the current bundle if any left. 249 */ 250 if (pExpState->pb32->b32_cnt > (pExpState->iOrdinal - pExpState->iOrdinalBundle + 1)) 251 { 252 /* skip to the next entry */ 253 pExpState->iOrdinal++; 254 pExpState->pe32 = (struct e32_entry*)((char*)pExpState->pe32 255 + acbEntry[pExpState->pb32->b32_type & ~TYPEINFO]); 256 257 /* fill output struct */ 258 pExport->ulOrdinal = pExpState->iOrdinal; 259 pExport->iObject = pExpState->pb32->b32_obj; 260 261 /* look for name */ 262 pExport->achIntName[0] = '\0'; 263 if (!queryExportName(pExpState->iOrdinal, pExport->achName)) 264 pExport->achName[0] = '\0'; 265 266 /* offset */ 267 switch (pExpState->pb32->b32_type & ~TYPEINFO) 268 { 269 case ENTRY16: 270 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16; 271 break; 272 273 case ENTRY32: 274 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32; 275 break; 276 277 case GATE16: 278 pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset; 279 break; 280 } 281 282 return TRUE; 283 } 284 285 /* 286 * next bundle. 287 */ 288 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + 289 pExpState->pb32->b32_cnt * acbEntry[pExpState->pb32->b32_type & ~TYPEINFO]); 290 while (pExpState->pb32->b32_cnt != 0) 291 { 292 /* skip empty bundles */ 293 while (pExpState->pb32->b32_cnt != 0 && pExpState->pb32->b32_type == EMPTY) 294 { 295 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 296 pExpState->pb32 = (struct b32_bundle*)((char*)pExpState->pb32 + 2); 297 } 298 299 /* FIXME forwarders are not implemented so we'll skip them too. */ 300 while (pExpState->pb32->b32_cnt != 0 && (pExpState->pb32->b32_type & ~TYPEINFO) == ENTRYFWD) 301 { 302 pExpState->iOrdinal += pExpState->pb32->b32_cnt; 303 pExpState->pb32 = (struct b32_bundle*)((char*)(pExpState->pb32 + 1) + pExpState->pb32->b32_cnt * 7); 304 } 305 306 /* we'll ignore any flags for the moment - TODO */ 307 if (pExpState->pb32->b32_cnt != 0) 308 { 309 pExpState->iOrdinalBundle = pExpState->iOrdinal; 310 311 pExport->ulOrdinal = pExpState->iOrdinal; 312 pExport->iObject = pExpState->pb32->b32_obj; 313 314 /* look for name */ 315 pExport->achIntName[0] = '\0'; 316 if (!queryExportName(pExpState->iOrdinal, pExport->achName)) 317 pExport->achName[0] = '\0'; 318 319 pExpState->pe32 = (struct e32_entry*)(pExpState->pb32+1); 320 switch (pExpState->pb32->b32_type & ~TYPEINFO) 321 { 322 case ENTRY16: 323 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset16; 324 break; 325 326 case ENTRY32: 327 pExport->offset = pExpState->pe32->e32_variant.e32_offset.offset32; 328 break; 329 330 case GATE16: 331 pExport->offset = pExpState->pe32->e32_variant.e32_callgate.offset; 332 break; 333 default: 334 assert(!"ARG!!!! invalid bundle type!"); 335 } 336 337 return TRUE; 338 } 339 } 340 341 342 /* 343 * No more exports - clean up 344 */ 345 free(pExport->pv); 346 pExport->pv = NULL; 114 347 return FALSE; 115 348 } 116 117 118 119 BOOL kFileLX::findNextExport(PEXPORTENTRY pExport)120 {121 /* not implemented */122 assert("not implemented!");123 return FALSE;124 }125 126 349 127 350 … … 140 363 141 364 365 /** 366 * Gets the count of LX objects. 367 * @returns Count of LX objects. 368 */ 369 int kFileLX::getObjectCount() 370 { 371 return (int)pe32->e32_objcnt; 372 } 373
Note:
See TracChangeset
for help on using the changeset viewer.