>From 8b14872e2954c6dc3a43ce5eec0fc72753176cdf Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Mon, 21 Apr 2014 21:11:06 +0100 Subject: [PATCH] pe/coff: Swap GUID build-id on read and write Byte-swap GUID build-id on read and write so it is consistently displayed in the conventional way. bfd/ChangeLog: 2014-04-21 Jon TURNEY * peXXigen.c (_bfd_XXi_slurp_codeview_record) (_bfd_XXi_write_codeview_record): Byte-swap GUID from little-endian to big-endian order for consistent and conventional display. Signed-off-by: Jon TURNEY --- bfd/peXXigen.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/bfd/peXXigen.c b/bfd/peXXigen.c index ea7846f..2de64a2 100644 --- a/bfd/peXXigen.c +++ b/bfd/peXXigen.c @@ -1088,7 +1088,15 @@ _bfd_XXi_slurp_codeview_record (bfd * abfd, file_ptr where, unsigned long length CV_INFO_PDB70 *cvinfo70 = (CV_INFO_PDB70 *)(buffer); cvinfo->Age = H_GET_32(abfd, cvinfo70->Age); - memcpy (cvinfo->Signature, cvinfo70->Signature, CV_INFO_SIGNATURE_LENGTH); + + /* A GUID consists of 4,2,2 byte values in little-endian order, followed + by 8 single bytes. Byte swap then so we can conveniently treat the GUID + as 16 bytes in big-endian order. */ + bfd_putb32 (bfd_getl32 (cvinfo70->Signature), cvinfo->Signature); + bfd_putb16 (bfd_getl16 (&(cvinfo70->Signature[4])), &(cvinfo->Signature[4])); + bfd_putb16 (bfd_getl16 (&(cvinfo70->Signature[6])), &(cvinfo->Signature[6])); + memcpy (&(cvinfo->Signature[8]), &(cvinfo70->Signature[8]), 8); + cvinfo->SignatureLength = CV_INFO_SIGNATURE_LENGTH; // cvinfo->PdbFileName = cvinfo70->PdbFileName; @@ -1121,7 +1129,14 @@ _bfd_XXi_write_codeview_record (bfd * abfd, file_ptr where, CODEVIEW_INFO *cvinf cvinfo70 = (CV_INFO_PDB70 *) buffer; H_PUT_32 (abfd, CVINFO_PDB70_CVSIGNATURE, cvinfo70->CvSignature); - memcpy (&(cvinfo70->Signature), cvinfo->Signature, CV_INFO_SIGNATURE_LENGTH); + + /* Byte swap the GUID from 16 bytes in big-endian order to 4,2,2 byte values + in little-endian order, followed by 8 single bytes. */ + bfd_putl32 (bfd_getb32 (cvinfo->Signature), cvinfo70->Signature); + bfd_putl16 (bfd_getb16 (&(cvinfo->Signature[4])), &(cvinfo70->Signature[4])); + bfd_putl16 (bfd_getb16 (&(cvinfo->Signature[6])), &(cvinfo70->Signature[6])); + memcpy (&(cvinfo70->Signature[8]), &(cvinfo->Signature[8]), 8); + H_PUT_32 (abfd, cvinfo->Age, cvinfo70->Age); cvinfo70->PdbFileName[0] = '\0'; -- 1.8.5.5