Changeset 14935
- Timestamp:
- Oct 2, 2000, 3:35:23 PM (25 years ago)
- Location:
- tags/trunk/src/kernel32
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified tags/trunk/src/kernel32/winimagepe2lx.cpp ¶
r14924 r14935 1 /* $Id: winimagepe2lx.cpp,v 1.1 6 2000-10-02 04:00:35bird Exp $ */1 /* $Id: winimagepe2lx.cpp,v 1.17 2000-10-02 13:35:23 bird Exp $ */ 2 2 3 3 /* … … 324 324 { 325 325 PVOID pv; 326 ULONG ulBorlandRVAFix = 0UL;327 326 328 327 /* 329 * Borland seems to have problems getting things right... 330 * Uses real pointers with baserelocations. 331 * Needs to subtract image loadaddress to make the TLSDir them RVAs. 328 * According to the docs StartAddressOfRawData and EndAddressOfRawData is 329 * real pointers with a baserelocs. 332 330 * 333 * We'll check if the StartAddressOfRawData pointer is an RVA or an real address by334 * check if it is within the TLS section or not.335 * ASSUMES: StartAddressOfRawData is in the same section as the TLS Directory.331 * The docs says nothing about the two AddressOf pointers. So, we'll assume that 332 * these also are real pointers. But, we'll try compensate if they should not have 333 * base realocations. 336 334 */ 337 if (paSections[iSection].ulRVA > pTLSDir->StartAddressOfRawData || 338 paSections[iSection].ulRVA + paSections[iSection].cbVirtual <= pTLSDir->StartAddressOfRawData) 339 { /* StartAddressOfRawData was not an RVA within the same section as the TLS directory */ 340 ulBorlandRVAFix = paSections[iSection].ulAddress - paSections[iSection].ulRVA; 335 if (validateRealPointer((PVOID)pTLSDir->StartAddressOfRawData) 336 && 337 validateRealPointer((PVOID)pTLSDir->EndAddressOfRawData) 338 ) 339 { 340 setTLSAddress((PVOID)pTLSDir->StartAddressOfRawData); 341 setTLSInitSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData); 342 setTLSTotalSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData + pTLSDir->SizeOfZeroFill); 343 344 if (pTLSDir->AddressOfIndex) 345 { 346 if (validateRealPointer(pTLSDir->AddressOfIndex)) 347 /* assume baserelocations for thepointer; use it without any change. */ 348 setTLSIndexAddr((LPDWORD)(void*)pTLSDir->AddressOfIndex); 349 else 350 { /* assume no baserelocs for these pointers? Complain and debugint3 */ 351 eprintf(("Win32Pe2LxImage::init: TLS - AddressOfIndex(%#8x) is not a pointer with basereloc.\n", 352 pTLSDir->AddressOfIndex)); 353 pv = getPointerFromPointer(pTLSDir->AddressOfIndex); 354 if (pv == NULL) 355 { 356 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOfIndex - %#8x.\n", 357 pTLSDir->AddressOfIndex)); 358 return FALSE; 359 } 360 setTLSIndexAddr((LPDWORD)pv); 361 } 341 362 } 342 pv = getPointerFromRVA(pTLSDir->StartAddressOfRawData - ulBorlandRVAFix); 343 if (pv == NULL || pTLSDir->StartAddressOfRawData == 0UL) 344 { 345 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS StartAddressOfRawData - %#8x.\n", 346 pTLSDir->StartAddressOfRawData)); 347 return FALSE; 348 } 349 setTLSAddress(pv); 350 setTLSInitSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData); 351 setTLSTotalSize(pTLSDir->EndAddressOfRawData - pTLSDir->StartAddressOfRawData + pTLSDir->SizeOfZeroFill); 352 pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfIndex - ulBorlandRVAFix); 353 if (pv == NULL) 354 { 355 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n", 356 pTLSDir->AddressOfIndex)); 357 return FALSE; 358 } 359 setTLSIndexAddr((LPDWORD)pv); 360 if (pTLSDir->AddressOfCallBacks != 0) 361 { 362 pv = getPointerFromRVA((ULONG)pTLSDir->AddressOfCallBacks - ulBorlandRVAFix); 363 if (pv == NULL) 363 364 if (pTLSDir->AddressOfCallBacks) 364 365 { 365 eprintf(("Win32Pe2LxImage::init: invalid RVA to TLS AddressOffIndex - %#8x.\n", 366 pTLSDir->AddressOfIndex)); 367 return FALSE; 366 if (validateRealPointer(pTLSDir->AddressOfCallBacks)) 367 /* assume baserelocations for thepointer; use it without any change. */ 368 setTLSCallBackAddr(pTLSDir->AddressOfCallBacks); 369 else 370 { /* assume no baserelocs for these pointers? Complain and debugint3 */ 371 eprintf(("Win32Pe2LxImage::init: Warning: TLS - AddressOfCallBacks(%#8x) is not a pointer with basereloc.\n", 372 pTLSDir->AddressOfCallBacks)); 373 pv = getPointerFromPointer(pTLSDir->AddressOfCallBacks); 374 if (pv == NULL) 375 { 376 eprintf(("Win32Pe2LxImage::init: invalid pointer to TLS AddressOfCallBacks - %#8x.\n", 377 pTLSDir->AddressOfIndex)); 378 return FALSE; 379 } 380 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv); 381 } 368 382 } 369 setTLSCallBackAddr((PIMAGE_TLS_CALLBACK*)pv);370 383 } 371 384 } … … 700 713 { 701 714 int i; 715 702 716 #ifdef DEBUG 703 if (paSections == NULL) 704 return NULL; 717 if (paSections == NULL) 718 { 719 eprintf(("Win32Pe2LxImage::getPointerFromRVA: paSections is NULL!\n")); 720 return NULL; 721 } 705 722 #endif 706 723 … … 710 727 i = 0; 711 728 while (i < cSections && 712 !(paSections[i].ulRVA <= ulRVA && paSections[i].ulRVA + paSections[i].cbVirtual >ulRVA)) /* ALIGN on page too? */729 (paSections[i].ulRVA > ulRVA || paSections[i].ulRVA + paSections[i].cbVirtual <= ulRVA)) /* ALIGN on page too? */ 713 730 i++; 714 731 … … 717 734 718 735 return (PVOID)(ulRVA - paSections[i].ulRVA + paSections[i].ulAddress); 736 } 737 738 739 /** 740 * Converts a pointer with not basereloc to a pointer. 741 * @returns Pointer with baserelocation applied. 742 * @param pv Pointer without baserelocation. 743 * @status completely implemented. 744 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 745 */ 746 PVOID Win32Pe2LxImage::getPointerFromPointer(PVOID pv) 747 { 748 if (pv == NULL) 749 return NULL; 750 751 return getPointerFromRVA((ULONG)pv - pNtHdrs->OptionalHeader.ImageBase); 719 752 } 720 753 … … 739 772 { 740 773 LONG i; 774 741 775 #ifdef DEBUG 742 if (paSections == NULL) 743 return -1; 776 if (paSections == NULL) 777 { 778 eprintf(("Win32Pe2LxImage::getSectionIndexFromRVA: paSections is NULL!\n")); 779 return NULL; 780 } 744 781 #endif 745 782 … … 749 786 i = 0; 750 787 while (i < cSections && 751 !(paSections[i].ulRVA <= ulRVA && paSections[i].ulRVA + paSections[i].cbVirtual >ulRVA)) /* ALIGN on page too? */788 (paSections[i].ulRVA > ulRVA && paSections[i].ulRVA + paSections[i].cbVirtual <= ulRVA)) /* ALIGN on page too? */ 752 789 i++; 753 790 754 791 return i < cSections ? i : -1; 792 } 793 794 795 /** 796 * Validates that a given pointer is pointing to valid memory within 797 * the loaded executable image. 798 * @returns TRUE if the pointer is valid. 799 * FALSE if the pointer is invalid. 800 * @param pv Pointer to validate. 801 * @sketch 802 * @status completely implemented. 803 * @author knut st. osmundsen (knut.stange.osmundsen@mynd.no) 804 */ 805 BOOL Win32Pe2LxImage::validateRealPointer(PVOID pv) 806 { 807 int i; 808 809 #ifdef DEBUG 810 if (paSections == NULL) 811 { 812 eprintf(("Win32Pe2LxImage::validateRealPointer: paSections is NULL!\n")); 813 return NULL; 814 } 815 #endif 816 817 if (pv == NULL) 818 return FALSE; 819 820 i = 0; 821 while (i < cSections && 822 (paSections[i].ulAddress < (ULONG)pv || 823 paSections[i].ulAddress + paSections[i].cbVirtual <= (ULONG)pv) /* Align on page too? */ 824 ) 825 i++; 826 827 return i < cSections; 755 828 } 756 829 -
TabularUnified tags/trunk/src/kernel32/winimagepe2lx.h ¶
r14924 r14935 1 /* $Id: winimagepe2lx.h,v 1. 5 2000-10-02 04:00:36bird Exp $ */1 /* $Id: winimagepe2lx.h,v 1.6 2000-10-02 13:35:23 bird Exp $ */ 2 2 3 3 /* … … 57 57 /* these should be moved to winimagebase some day... */ 58 58 PVOID getPointerFromRVA(ULONG ulRVA); 59 PVOID getPointerFromPointer(PVOID pv); 59 60 LONG getSectionIndexFromRVA(ULONG ulRVA); 61 BOOL validateRealPointer(PVOID pv); 60 62 61 63 PSECTION paSections; /* Used by getPointerFromRVA and created by getSections and
Note:
See TracChangeset
for help on using the changeset viewer.