Author: tkreuzer
Date: Wed Jun 8 12:42:04 2011
New Revision: 52146
URL:
http://svn.reactos.org/svn/reactos?rev=52146&view=rev
Log:
[OBJ2BIN]
- Fix relocation for gas build objetcs
- Protect from buffer overwrite
Modified:
trunk/reactos/tools/obj2bin/obj2bin.c
Modified: trunk/reactos/tools/obj2bin/obj2bin.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/tools/obj2bin/obj2bin.c?re…
==============================================================================
--- trunk/reactos/tools/obj2bin/obj2bin.c [iso-8859-1] (original)
+++ trunk/reactos/tools/obj2bin/obj2bin.c [iso-8859-1] Wed Jun 8 12:42:04 2011
@@ -8,13 +8,14 @@
Usage(void)
{
printf("Converts a coff object file into a raw binary file.\n"
- "Syntax: obj2bin <source file> <dest file>\n");
+ "Syntax: obj2bin <source file> <dest file> <base
address>\n");
}
static
void
RelocateImage(
char *pData,
+ unsigned int nSize,
PIMAGE_RELOCATION pReloc,
unsigned int cNumRelocs,
PIMAGE_SYMBOL pSymbols,
@@ -25,15 +26,19 @@
for (i = 0; i < cNumRelocs; i++)
{
+ if (pReloc->VirtualAddress > nSize) continue;
+
switch (pReloc->Type)
{
case IMAGE_REL_I386_ABSOLUTE:
+ case 16:
p16 = (void*)(pData + pReloc->VirtualAddress);
- *p16 = (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + iOffset);
+ *p16 += (WORD)(pSymbols[pReloc->SymbolTableIndex].Value + iOffset);
break;
default:
- printf("Unknown relocatation type %ld\n", pReloc->Type);
+ printf("Unknown relocatation type %ld address %ld\n",
+ pReloc->Type, pReloc->VirtualAddress);
}
pReloc++;
@@ -183,12 +188,14 @@
return -15;
}
- RelocateImage(pData, pReloc, SectionHeader.NumberOfRelocations, pSymbols, iOffset);
+ RelocateImage(pData, SectionHeader.SizeOfRawData,
+ pReloc, SectionHeader.NumberOfRelocations, pSymbols, iOffset);
/* Write the section to the destination file */
if (!fwrite(pData, SectionHeader.SizeOfRawData, 1, pDestFile))
{
- fprintf(stderr, "Failed to write data\n");
+ fprintf(stderr, "Failed to write data %ld\n",
+ SectionHeader.SizeOfRawData);
return -16;
}