- Timestamp:
- Mar 4, 2007, 12:27:30 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kLdr/kLdrModLX.c
r2974 r2979 4 4 * kLdr - The Module Interpreter for the Linear eXecutable (LX) Format. 5 5 * 6 * Copyright (c) 2006 knut st. osmundsen <bird@anduin.net>6 * Copyright (c) 2006-2007 knut st. osmundsen <bird@anduin.net> 7 7 * 8 8 * … … 119 119 static const uint8_t *kldrModLXDoNameTableLookupByOrdinal(const uint8_t *pbNameTable, int32_t cbNameTable, uint32_t iOrdinal); 120 120 static int kldrModLXDoNameLookup(PKLDRMODLX pModLX, const char *pchSymbol, uint32_t cchSymbol, uint32_t *piSymbol); 121 #if 0122 121 static const uint8_t *kldrModLXDoNameTableLookupByName(const uint8_t *pbNameTable, int32_t cbNameTable, 123 char *pchSymbol, size_t cchSymbol); 124 #endif 122 const char *pchSymbol, size_t cchSymbol); 125 123 static int kldrModLXDoLoadBits(PKLDRMODLX pModLX, void *pvBits); 126 124 static int kldrModLXDoIterDataUnpacking(uint8_t *pbDst, const uint8_t *pbSrc, int cbSrc); … … 595 593 * (The entry table is made up of bundles of similar exports.) 596 594 */ 597 iOrdinal = 0;595 iOrdinal = 1; 598 596 pBundle = (const struct b32_bundle *)pModLX->pbEntryTab; 599 while ( !pBundle->b32_cnt && iOrdinal <= iSymbol)597 while (pBundle->b32_cnt && iOrdinal <= iSymbol) 600 598 { 601 599 static const size_t s_cbEntry[] = { 0, 3, 5, 5, 7 }; … … 609 607 uint32_t offObject; 610 608 const struct e32_entry *pEntry = (const struct e32_entry *)((uintptr_t)(pBundle + 1) 611 + iSymbol - (iOrdinal - pBundle->b32_cnt)); 609 + (iSymbol - (iOrdinal - pBundle->b32_cnt)) 610 * s_cbEntry[pBundle->b32_type]); 612 611 613 612 /* … … 676 675 pBundle = (const struct b32_bundle *)((const uint8_t *)pBundle + 2); 677 676 else 678 pBundle = (const struct b32_bundle *)((const uint8_t *) pBundle+ s_cbEntry[pBundle->b32_type] * pBundle->b32_cnt);677 pBundle = (const struct b32_bundle *)((const uint8_t *)(pBundle + 1) + s_cbEntry[pBundle->b32_type] * pBundle->b32_cnt); 679 678 } 680 679 … … 698 697 * First do a hash table lookup. 699 698 */ 700 701 702 703 /* 704 705 */ 706 707 return -1; 699 /** @todo hash name table for speed. */ 700 701 /* 702 * Search the name tables. 703 */ 704 const uint8_t *pbName = kldrModLXDoNameTableLookupByName(pModLX->pbResNameTab, 705 pModLX->pbLoaderSectionLast - pModLX->pbResNameTab + 1, 706 pchSymbol, cchSymbol); 707 if (!pbName) 708 { 709 if (!pModLX->pbNonResNameTab) 710 { 711 /* lazy load it */ 712 /** @todo non-resident name table. */ 713 } 714 if (pModLX->pbNonResNameTab) 715 pbName = kldrModLXDoNameTableLookupByName(pModLX->pbResNameTab, 716 pModLX->pbNonResNameTabLast - pModLX->pbResNameTab + 1, 717 pchSymbol, cchSymbol); 718 } 719 if (!pbName) 720 return KLDR_ERR_SYMBOL_NOT_FOUND; 721 722 *piSymbol = *(const uint16_t *)(pbName + 1 + *pbName); 723 return 0; 708 724 } 709 725 … … 737 753 return hash; 738 754 } 755 #endif 739 756 740 757 … … 750 767 */ 751 768 static const uint8_t *kldrModLXDoNameTableLookupByName(const uint8_t *pbNameTable, int32_t cbNameTable, 752 c har *pchSymbol, size_t cchSymbol)769 const char *pchSymbol, size_t cchSymbol) 753 770 { 754 771 /* … … 780 797 return NULL; 781 798 } 782 #endif783 799 784 800 … … 2101 2117 2102 2118 /* calculate the symbol info. */ 2103 uValue = offTrgObject + pMod->aSegments[iSeg].MapAddress;2119 uValue = offTrgObject + NewBaseAddress + pMod->aSegments[iTrgObject].RVA; 2104 2120 } 2105 2121 else 2106 uValue = pMod->aSegments[iSeg].MapAddress;2122 uValue = NewBaseAddress + pMod->aSegments[iTrgObject].RVA; 2107 2123 if ( (u.prlc->nr_stype & NRALIAS) 2108 || (pMod->aSegments[i Seg].fFlags & KLDRSEG_FLAG_16BIT))2109 iSelector = pMod->aSegments[i Seg].Sel16bit;2124 || (pMod->aSegments[iTrgObject].fFlags & KLDRSEG_FLAG_16BIT)) 2125 iSelector = pMod->aSegments[iTrgObject].Sel16bit; 2110 2126 else 2111 iSelector = pMod->aSegments[i Seg].SelFlat;2127 iSelector = pMod->aSegments[iTrgObject].SelFlat; 2112 2128 fKind = 0; 2113 2129 break; … … 2235 2251 2236 2252 /* 2237 * Deal with the 'source' (i.e. the place that should be modified (very logical).2253 * Deal with the 'source' (i.e. the place that should be modified - very logical). 2238 2254 */ 2239 2255 if (!(u.prlc->nr_stype & NRCHAIN)) … … 2249 2265 && off >= 0 2250 2266 && off <= OBJPAGELEN - 4) 2251 *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off );2267 *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off + 4); 2252 2268 else 2253 2269 { … … 2285 2301 int off = *poffSrc++; 2286 2302 if (off >= 0 && off <= OBJPAGELEN - 4) 2287 *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off );2303 *(uint32_t *)&pbPage[off] = uValue - (PageAddress + off + 4); 2288 2304 else 2289 2305 { … … 2334 2350 int iSelector, KLDRADDR uValue, uint32_t fKind) 2335 2351 { 2336 static const uint8_t s_acb[16] =2337 {2338 1, /* 0: NRSBYT */2339 0,2340 2, /* 2: NRSSEG - selector */2341 4, /* 3: NRSPTR - 16:16 */2342 0,2343 2, /* 5: NRSOFF - 16-bit offset */2344 6, /* 6: NRPTR48 - 16:32 */2345 4, /* 7: NROFF32 - 32-bit offset */2346 4, /* 8: NRSOFF32 - 32-bit offset self relative */2347 0, 0, 0, 0, 0, 0, 02348 };2349 2352 #pragma pack(1) /* just to be sure */ 2350 2353 union … … 2414 2417 break; 2415 2418 case NRSOFF32: 2416 uData.off32 = (uint32_t)uValue - (PageAddress + off );2419 uData.off32 = (uint32_t)uValue - (PageAddress + off + 4); 2417 2420 cb = 4; 2418 2421 break;
Note:
See TracChangeset
for help on using the changeset viewer.