Fix pointer offset in PE relocation code
All checks were successful
ci/woodpecker/push/build Pipeline was successful
All checks were successful
ci/woodpecker/push/build Pipeline was successful
This commit is contained in:
parent
ddffd0c582
commit
2bf15a5bb8
@ -450,9 +450,9 @@ PepRelocateLoadedImage(IN PPECOFF_IMAGE_CONTEXT Image)
|
|||||||
while(RelocationDir < RelocationEnd && RelocationDir->SizeOfBlock > 0)
|
while(RelocationDir < RelocationEnd && RelocationDir->SizeOfBlock > 0)
|
||||||
{
|
{
|
||||||
/* Calculate number of relocations needed, address and type offset */
|
/* Calculate number of relocations needed, address and type offset */
|
||||||
Count = (RelocationDir->SizeOfBlock - sizeof(PECOFF_IMAGE_BASE_RELOCATION)) / sizeof(UINT16);
|
Count = (RelocationDir->SizeOfBlock - sizeof(PECOFF_IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
||||||
Address = (UINT32*)((UINT8*)Image->Data + RelocationDir->VirtualAddress);
|
Address = (PUINT)((PUCHAR)Image->Data + RelocationDir->VirtualAddress);
|
||||||
TypeOffset = (UINT16*)((UINT8*)RelocationDir + sizeof(PECOFF_IMAGE_BASE_RELOCATION));
|
TypeOffset = (PUSHORT)((PUCHAR)RelocationDir + sizeof(PECOFF_IMAGE_BASE_RELOCATION));
|
||||||
|
|
||||||
/* Do relocations */
|
/* Do relocations */
|
||||||
while(Count--)
|
while(Count--)
|
||||||
@ -480,12 +480,12 @@ PepRelocateLoadedImage(IN PPECOFF_IMAGE_CONTEXT Image)
|
|||||||
break;
|
break;
|
||||||
case PECOFF_IMAGE_REL_BASED_DIR64:
|
case PECOFF_IMAGE_REL_BASED_DIR64:
|
||||||
/* 64-bit relocation */
|
/* 64-bit relocation */
|
||||||
LongPtr = (UINT64*)((UINT8*)Address + Offset);
|
LongPtr = (PULONGLONG)((PUCHAR)Address + Offset);
|
||||||
*LongPtr = *LongPtr - ImageBase + (UINT_PTR)Image->VirtualAddress;
|
*LongPtr = *LongPtr - ImageBase + (UINT_PTR)Image->VirtualAddress;
|
||||||
break;
|
break;
|
||||||
case PECOFF_IMAGE_REL_BASED_HIGHLOW:
|
case PECOFF_IMAGE_REL_BASED_HIGHLOW:
|
||||||
/* 32-bit relocation of hight and low half of address */
|
/* 32-bit relocation of hight and low half of address */
|
||||||
ShortPtr = (UINT32*)((UINT8*)Address + Offset);
|
ShortPtr = (PUINT32)((PUCHAR)Address + Offset);
|
||||||
*ShortPtr = *ShortPtr - ImageBase + (UINT_PTR)Image->VirtualAddress;
|
*ShortPtr = *ShortPtr - ImageBase + (UINT_PTR)Image->VirtualAddress;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -496,8 +496,9 @@ PepRelocateLoadedImage(IN PPECOFF_IMAGE_CONTEXT Image)
|
|||||||
/* Increment the type offset */
|
/* Increment the type offset */
|
||||||
TypeOffset++;
|
TypeOffset++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next relocation */
|
/* Next relocation */
|
||||||
RelocationDir += RelocationDir->SizeOfBlock;
|
RelocationDir = (PPECOFF_IMAGE_BASE_RELOCATION)((PUCHAR)RelocationDir + RelocationDir->SizeOfBlock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return SUCCESS */
|
/* Return SUCCESS */
|
||||||
|
Loading…
Reference in New Issue
Block a user