[OBJ2BIN] Add support for IMAGE_REL_I386_REL16

Also return error in case of unknown relocation type.
This commit is contained in:
Hervé Poussineau 2021-02-22 10:06:20 +01:00
parent 5367ae5760
commit 77d69c68b8
2 changed files with 19 additions and 5 deletions

View file

@ -42,6 +42,7 @@
#define IMAGE_NUMBEROF_DIRECTORY_ENTRIES 16
#define IMAGE_REL_I386_ABSOLUTE 0x0001
#define IMAGE_REL_I386_REL16 0x0002
#define IMAGE_REL_I386_DIR32 0x0006
#pragma pack(push,2)

View file

@ -13,7 +13,7 @@ Usage(void)
}
static
void
int
RelocateSection(
char *pData,
IMAGE_SECTION_HEADER *pSectionHeader,
@ -46,6 +46,11 @@ RelocateSection(
*p16 += (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + iOffset);
break;
case IMAGE_REL_I386_REL16:
p16 = (void*)(pSection + nOffset);
*p16 += (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + iOffset);
break;
case IMAGE_REL_I386_DIR32:
p32 = (void*)(pSection + nOffset);
*p32 += (DWORD)(pSymbols[pReloc->SymbolTableIndex].Value + iOffset);
@ -54,10 +59,13 @@ RelocateSection(
default:
printf("Unknown relocation type %u, address 0x%x\n",
pReloc->Type, (unsigned)pReloc->VirtualAddress);
return 0;
}
pReloc++;
}
return 1;
}
int main(int argc, char *argv[])
@ -136,10 +144,15 @@ int main(int argc, char *argv[])
if ((strcmp((char*)pSectionHeader->Name, ".text") == 0) &&
(pSectionHeader->SizeOfRawData != 0))
{
RelocateSection(pData,
pSectionHeader,
pSymbols,
nBaseAddress);
if (!RelocateSection(pData,
pSectionHeader,
pSymbols,
nBaseAddress))
{
free(pData);
fclose(pDestFile);
return -7;
}
/* Write the section to the destination file */
if (!fwrite(pData + pSectionHeader->PointerToRawData,