@@ -677,8 +677,10 @@ ImgpLoadPEImage (
677
677
BOOLEAN First , ImageHashValid ;
678
678
UCHAR LocalBuffer [1024 ];
679
679
UCHAR TrustedBootInformation [52 ];
680
+ ULONG WorkaroundForBinutils ;
680
681
681
682
/* Initialize locals */
683
+ WorkaroundForBinutils = 0 ;
682
684
LocalFile = NULL ;
683
685
ImageBuffer = NULL ;
684
686
FileSize = 0 ;
@@ -881,6 +883,7 @@ ImgpLoadPEImage (
881
883
882
884
/* Record our current position (right after the headers) */
883
885
EndOfHeaders = (ULONG_PTR )VirtualAddress + HeaderSize ;
886
+ EfiPrintf (L"here\r\n" );
884
887
885
888
/* Get the first section and iterate through each one */
886
889
Section = IMAGE_FIRST_SECTION (NtHeaders );
@@ -893,6 +896,7 @@ ImgpLoadPEImage (
893
896
if ((VirtualSize < Section -> VirtualAddress ) ||
894
897
((PVOID )SectionStart < VirtualAddress ))
895
898
{
899
+ EfiPrintf (L"fail 1\r\n" );
896
900
Status = STATUS_INVALID_IMAGE_FORMAT ;
897
901
goto Quickie ;
898
902
}
@@ -940,6 +944,7 @@ ImgpLoadPEImage (
940
944
& SectionEnd );
941
945
if (!NT_SUCCESS (Status ))
942
946
{
947
+ EfiPrintf (L"fail 21\r\n" );
943
948
Status = STATUS_INVALID_IMAGE_FORMAT ;
944
949
goto Quickie ;
945
950
}
@@ -957,6 +962,7 @@ ImgpLoadPEImage (
957
962
& SectionEnd );
958
963
if (!NT_SUCCESS (Status ))
959
964
{
965
+ EfiPrintf (L"fail 31\r\n" );
960
966
Status = STATUS_INVALID_IMAGE_FORMAT ;
961
967
goto Quickie ;
962
968
}
@@ -974,6 +980,20 @@ ImgpLoadPEImage (
974
980
/* Are we in the first iteration? */
975
981
if (!First )
976
982
{
983
+ /* FUCK YOU BINUTILS */
984
+ if ((* (PULONG )& Section -> Name == 'ler.' ) && (RawSize < AlignSize ))
985
+ {
986
+ /* Piece of shit won't build relocations when you tell it to,
987
+ * either by using --emit-relocs or --dynamicbase. People online
988
+ * have found out that by using -pie-executable you can get this
989
+ * to happen, but then it turns out that the .reloc section is
990
+ * incorrectly sized, and results in a corrupt PE. However, they
991
+ * still compute the checksum using the correct value. What idiots.
992
+ */
993
+ WorkaroundForBinutils = AlignSize - RawSize ;
994
+ AlignSize -= WorkaroundForBinutils ;
995
+ }
996
+
977
997
/* Yes, read the section data */
978
998
Status = ImgpReadAtFileOffset (LocalFile ,
979
999
AlignSize ,
@@ -994,6 +1014,7 @@ ImgpLoadPEImage (
994
1014
AlignSize ,
995
1015
BL_UTL_CHECKSUM_COMPLEMENT |
996
1016
BL_UTL_CHECKSUM_USHORT_BUFFER );
1017
+ AlignSize += WorkaroundForBinutils ;
997
1018
}
998
1019
}
999
1020
@@ -1075,7 +1096,7 @@ ImgpLoadPEImage (
1075
1096
}
1076
1097
1077
1098
/* Finally, calculate the final checksum and compare it */
1078
- FinalSum = FileSize + PartialSum ;
1099
+ FinalSum = FileSize + PartialSum + WorkaroundForBinutils ;
1079
1100
if ((FinalSum != CheckSum ) && (PartialSum == 0xFFFF ))
1080
1101
{
1081
1102
/* It hit overflow, so set it to the file size */
@@ -1148,9 +1169,6 @@ ImgpLoadPEImage (
1148
1169
* ImageSize = VirtualSize ;
1149
1170
}
1150
1171
1151
- EfiPrintf (L"MORE PE TODO: %lx\r\n" , NtHeaders -> OptionalHeader .AddressOfEntryPoint );
1152
- EfiStall (100000000 );
1153
-
1154
1172
Quickie :
1155
1173
/* Check if we computed the image hash OK */
1156
1174
if (ImageHashValid )
0 commit comments