mirror of
https://github.com/reactos/reactos.git
synced 2025-04-21 04:37:15 +00:00
[RSYM]
- Include string table in checksum calculation CORE-7547 #resolve svn path=/trunk/; revision=60852
This commit is contained in:
parent
d5e5e58ebf
commit
16c4fe33fb
1 changed files with 45 additions and 29 deletions
|
@ -901,6 +901,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
ULONG StartOfRawData;
|
ULONG StartOfRawData;
|
||||||
unsigned Section;
|
unsigned Section;
|
||||||
void *OutHeader, *ProcessedRelocs, *PaddedRosSym, *Data;
|
void *OutHeader, *ProcessedRelocs, *PaddedRosSym, *Data;
|
||||||
|
unsigned char *PaddedStringTable;
|
||||||
PIMAGE_DOS_HEADER OutDosHeader;
|
PIMAGE_DOS_HEADER OutDosHeader;
|
||||||
PIMAGE_FILE_HEADER OutFileHeader;
|
PIMAGE_FILE_HEADER OutFileHeader;
|
||||||
PIMAGE_OPTIONAL_HEADER OutOptHeader;
|
PIMAGE_OPTIONAL_HEADER OutOptHeader;
|
||||||
|
@ -909,6 +910,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
ULONG Length, i;
|
ULONG Length, i;
|
||||||
ULONG ProcessedRelocsLength;
|
ULONG ProcessedRelocsLength;
|
||||||
ULONG RosSymOffset, RosSymFileLength;
|
ULONG RosSymOffset, RosSymFileLength;
|
||||||
|
ULONG PaddedStringTableLength;
|
||||||
int InRelocSectionIndex;
|
int InRelocSectionIndex;
|
||||||
PIMAGE_SECTION_HEADER OutRelocSection;
|
PIMAGE_SECTION_HEADER OutRelocSection;
|
||||||
/* Each coff symbol is 18 bytes and the string table follows */
|
/* Each coff symbol is 18 bytes and the string table follows */
|
||||||
|
@ -1014,7 +1016,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
OutRelocSection = CurrentSectionHeader;
|
OutRelocSection = CurrentSectionHeader;
|
||||||
}
|
}
|
||||||
StringTableLocation = CurrentSectionHeader->PointerToRawData + CurrentSectionHeader->SizeOfRawData;
|
StringTableLocation = CurrentSectionHeader->PointerToRawData + CurrentSectionHeader->SizeOfRawData;
|
||||||
(OutFileHeader->NumberOfSections)++;
|
OutFileHeader->NumberOfSections++;
|
||||||
CurrentSectionHeader++;
|
CurrentSectionHeader++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1058,7 +1060,7 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
| IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_TYPE_NOLOAD;
|
| IMAGE_SCN_LNK_REMOVE | IMAGE_SCN_TYPE_NOLOAD;
|
||||||
OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress + CurrentSectionHeader->Misc.VirtualSize,
|
OutOptHeader->SizeOfImage = ROUND_UP(CurrentSectionHeader->VirtualAddress + CurrentSectionHeader->Misc.VirtualSize,
|
||||||
OutOptHeader->SectionAlignment);
|
OutOptHeader->SectionAlignment);
|
||||||
(OutFileHeader->NumberOfSections)++;
|
OutFileHeader->NumberOfSections++;
|
||||||
|
|
||||||
PaddedRosSym = malloc(RosSymFileLength);
|
PaddedRosSym = malloc(RosSymFileLength);
|
||||||
if (PaddedRosSym == NULL)
|
if (PaddedRosSym == NULL)
|
||||||
|
@ -1120,6 +1122,37 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
}
|
}
|
||||||
Length += OutSectionHeaders[Section].SizeOfRawData;
|
Length += OutSectionHeaders[Section].SizeOfRawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (OutFileHeader->PointerToSymbolTable)
|
||||||
|
{
|
||||||
|
int PaddingFrom = (OutFileHeader->PointerToSymbolTable + StringTableLength) %
|
||||||
|
OutOptHeader->FileAlignment;
|
||||||
|
int PaddingSize = PaddingFrom ? OutOptHeader->FileAlignment - PaddingFrom : 0;
|
||||||
|
|
||||||
|
PaddedStringTableLength = StringTableLength + PaddingSize;
|
||||||
|
PaddedStringTable = malloc(PaddedStringTableLength);
|
||||||
|
/* COFF string section is preceeded by a length */
|
||||||
|
assert(sizeof(StringTableLength) == 4);
|
||||||
|
memcpy(PaddedStringTable, &StringTableLength, sizeof(StringTableLength));
|
||||||
|
/* We just copy enough of the string table to contain the strings we want
|
||||||
|
The string table length technically counts as part of the string table
|
||||||
|
space itself. */
|
||||||
|
memcpy(PaddedStringTable + 4, StringTable + 4, StringTableLength - 4);
|
||||||
|
memset(PaddedStringTable + StringTableLength, 0, PaddingSize);
|
||||||
|
|
||||||
|
assert(OutFileHeader->PointerToSymbolTable % 2 == 0);
|
||||||
|
for (i = 0; i < PaddedStringTableLength / 2; i++)
|
||||||
|
{
|
||||||
|
CheckSum += ((unsigned short*)PaddedStringTable)[i];
|
||||||
|
CheckSum = 0xffff & (CheckSum + (CheckSum >> 16));
|
||||||
|
}
|
||||||
|
Length += PaddedStringTableLength;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
PaddedStringTable = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
CheckSum += Length;
|
CheckSum += Length;
|
||||||
OutOptHeader->CheckSum = CheckSum;
|
OutOptHeader->CheckSum = CheckSum;
|
||||||
|
|
||||||
|
@ -1161,28 +1194,11 @@ CreateOutputFile(FILE *OutFile, void *InData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OutFileHeader->PointerToSymbolTable)
|
if (PaddedStringTable)
|
||||||
{
|
{
|
||||||
int PaddingFrom = (OutFileHeader->PointerToSymbolTable + StringTableLength) %
|
fseek(OutFile, OutFileHeader->PointerToSymbolTable, SEEK_SET);
|
||||||
OutOptHeader->FileAlignment;
|
fwrite(PaddedStringTable, 1, PaddedStringTableLength, OutFile);
|
||||||
fseek(OutFile, OutFileHeader->PointerToSymbolTable, 0);
|
free(PaddedStringTable);
|
||||||
|
|
||||||
/* COFF string section is preceeded by a length */
|
|
||||||
assert(sizeof(StringTableLength) == 4);
|
|
||||||
fwrite((char*)&StringTableLength, 1, sizeof(StringTableLength), OutFile);
|
|
||||||
/* We just copy enough of the string table to contain the strings we want
|
|
||||||
The string table length technically counts as part of the string table
|
|
||||||
space itself. */
|
|
||||||
fwrite(StringTable + 4, 1, StringTableLength - 4, OutFile);
|
|
||||||
|
|
||||||
if (PaddingFrom)
|
|
||||||
{
|
|
||||||
int PaddingSize = OutOptHeader->FileAlignment - PaddingFrom;
|
|
||||||
char *Padding = (char *)malloc(PaddingSize);
|
|
||||||
memset(Padding, 0, PaddingFrom);
|
|
||||||
fwrite(Padding, 1, PaddingSize, OutFile);
|
|
||||||
free(Padding);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PaddedRosSym)
|
if (PaddedRosSym)
|
||||||
|
|
Loading…
Reference in a new issue