diff --git a/Include/Acidanthera/Library/OcXmlLib.h b/Include/Acidanthera/Library/OcXmlLib.h index 2d009ef0..5dc3e406 100755 --- a/Include/Acidanthera/Library/OcXmlLib.h +++ b/Include/Acidanthera/Library/OcXmlLib.h @@ -137,9 +137,10 @@ XmlDocumentParse ( // // Exports parsed document into the buffer. // -// @param Document XML_DOCUMENT to export -// @param Length Resulting length of the buffer without trailing \0 (optional) -// @param Skip N root levels before exporting, normally 0. +// @param Document XML_DOCUMENT to export +// @param Length Resulting length of the buffer without trailing \0 (optional) +// @param Skip N root levels before exporting, normally 0. +// @param PrependPlistInfo Prepend XML plist doc info to exported document. // // @return Exported buffer allocated from pool or NULL. // @@ -147,7 +148,8 @@ CHAR8 * XmlDocumentExport ( XML_DOCUMENT *Document, UINT32 *Length, - UINT32 Skip + UINT32 Skip, + BOOLEAN PrependPlistInfo ); // diff --git a/Library/OcAppleKernelLib/PrelinkedContext.c b/Library/OcAppleKernelLib/PrelinkedContext.c index 6288ea7c..41385039 100644 --- a/Library/OcAppleKernelLib/PrelinkedContext.c +++ b/Library/OcAppleKernelLib/PrelinkedContext.c @@ -668,7 +668,7 @@ PrelinkedInjectComplete ( } } - ExportedInfo = XmlDocumentExport (Context->PrelinkedInfoDocument, &ExportedInfoSize, 0); + ExportedInfo = XmlDocumentExport (Context->PrelinkedInfoDocument, &ExportedInfoSize, 0, FALSE); if (ExportedInfo == NULL) { return EFI_OUT_OF_RESOURCES; } @@ -1002,7 +1002,7 @@ PrelinkedInjectKext ( // // Strip outer plist & dict. // - NewInfoPlist = XmlDocumentExport (InfoPlistDocument, &NewInfoPlistSize, 2); + NewInfoPlist = XmlDocumentExport (InfoPlistDocument, &NewInfoPlistSize, 2, FALSE); XmlDocumentFree (InfoPlistDocument); FreePool (TmpInfoPlist); diff --git a/Library/OcXmlLib/OcXmlLib.c b/Library/OcXmlLib/OcXmlLib.c index 321e1a7f..9b0c530c 100755 --- a/Library/OcXmlLib/OcXmlLib.c +++ b/Library/OcXmlLib/OcXmlLib.c @@ -52,6 +52,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. // #define XML_EXPORT_MIN_ALLOCATION_SIZE 4096 +#define XML_PLIST_HEADER "" + struct XML_NODE_LIST_; struct XML_PARSER_; @@ -1146,22 +1148,36 @@ CHAR8 * XmlDocumentExport ( XML_DOCUMENT *Document, UINT32 *Length, - UINT32 Skip + UINT32 Skip, + BOOLEAN PrependPlistInfo ) { CHAR8 *Buffer; + CHAR8 *BufferXmlContent; UINT32 AllocSize; UINT32 CurrentSize; AllocSize = Document->Buffer.Length + 1; - Buffer = AllocatePool (AllocSize); + if (PrependPlistInfo && OcOverflowAddU32 (AllocSize, L_STR_SIZE_NT (XML_PLIST_HEADER), &AllocSize)) { + return NULL; + } + Buffer = AllocatePool (AllocSize); if (Buffer == NULL) { XML_USAGE_ERROR ("XmlDocumentExport::failed to allocate"); return NULL; } + BufferXmlContent = PrependPlistInfo ? &Buffer[L_STR_LEN (XML_PLIST_HEADER)] : Buffer; CurrentSize = 0; - XmlNodeExportRecursive (Document->Root, &Buffer, &AllocSize, &CurrentSize, Skip); + XmlNodeExportRecursive (Document->Root, &BufferXmlContent, &AllocSize, &CurrentSize, Skip); + + if (PrependPlistInfo) { + if (OcOverflowAddU32 (CurrentSize, L_STR_SIZE_NT (XML_PLIST_HEADER), &CurrentSize)) { + FreePool (Buffer); + return NULL; + } + CopyMem (Buffer, XML_PLIST_HEADER, L_STR_SIZE_NT (XML_PLIST_HEADER)); + } if (Length != NULL) { *Length = CurrentSize;