Escape XML chars for file, exe, and guid strings

This commit is contained in:
mikewintersjr 2020-03-30 15:01:59 -04:00 committed by ghizard
parent fb5ab7569d
commit 19fb47a909
2 changed files with 10 additions and 5 deletions

View file

@ -313,6 +313,7 @@ void dumpFunctionLines( IDiaSymbol& symbol, IDiaSession& session )
bstr_t sourceFileName; bstr_t sourceFileName;
pSrc->get_fileName(sourceFileName.GetAddress()); pSrc->get_fileName(sourceFileName.GetAddress());
std::wstring wsSourceFileName(sourceFileName.GetBSTR(), SysStringLen(sourceFileName));
DWORD addr = 0; DWORD addr = 0;
pLine->get_relativeVirtualAddress( &addr ); pLine->get_relativeVirtualAddress( &addr );
@ -323,7 +324,7 @@ void dumpFunctionLines( IDiaSymbol& symbol, IDiaSession& session )
pLine->get_lineNumberEnd( &end ); pLine->get_lineNumberEnd( &end );
printf("%S<line_number source_file=\"%ws\" start=\"%d\" end=\"%d\" addr=\"0x%x\" /> \n", printf("%S<line_number source_file=\"%ws\" start=\"%d\" end=\"%d\" addr=\"0x%x\" /> \n",
indent(12).c_str(), escapeXmlEntities(sourceFileName.GetBSTR()).data(), start, end, addr); indent(12).c_str(), escapeXmlEntities(wsSourceFileName).c_str(), start, end, addr);
} }
} }
@ -400,7 +401,8 @@ void iterateSourceFiles(IDiaEnumSourceFiles * pSourceFiles) {
bstr_t name; bstr_t name;
DWORD id = 0; DWORD id = 0;
if( (pSourceFile->get_fileName( name.GetAddress() ) == S_OK) && (pSourceFile->get_uniqueId( &id ) == S_OK) ) { if( (pSourceFile->get_fileName( name.GetAddress() ) == S_OK) && (pSourceFile->get_uniqueId( &id ) == S_OK) ) {
printf("%S<source_file name=\"%ws\" id=\"0x%x\" /> \n", indent(12).c_str(), escapeXmlEntities(name.GetBSTR()).data(), id); std::wstring wsName(name.GetBSTR(), SysStringLen(name));
printf("%S<source_file name=\"%ws\" id=\"0x%x\" /> \n", indent(12).c_str(), escapeXmlEntities(wsName).c_str(), id);
} }
pSourceFile = NULL; pSourceFile = NULL;
} }
@ -490,9 +492,11 @@ void iterateInjectedSource(IDiaEnumInjectedSources * pInjectedSrcs) {
bstr_t filename; bstr_t filename;
pInjectedSrc->get_filename(filename.GetAddress()); pInjectedSrc->get_filename(filename.GetAddress());
std::wstring wsFileName(filename.GetBSTR(), SysStringLen(filename));
bstr_t objectname; bstr_t objectname;
pInjectedSrc->get_objectFilename(objectname.GetAddress()); pInjectedSrc->get_objectFilename(objectname.GetAddress());
std::wstring wsObjectname(objectname.GetBSTR(), SysStringLen(objectname));
DWORD crc; DWORD crc;
pInjectedSrc->get_crc(&crc); pInjectedSrc->get_crc(&crc);
@ -502,8 +506,8 @@ void iterateInjectedSource(IDiaEnumInjectedSources * pInjectedSrcs) {
printf("%S<injected_source filename=\"%ws\" objectname=\"%ws\" crc=\"0x%x\" length=\"0x%I64x\" />\n", printf("%S<injected_source filename=\"%ws\" objectname=\"%ws\" crc=\"0x%x\" length=\"0x%I64x\" />\n",
indent(8).c_str(), indent(8).c_str(),
filename.GetBSTR(), escapeXmlEntities(wsFileName).c_str(),
objectname.GetBSTR(), escapeXmlEntities(wsObjectname).c_str(),
crc, crc,
length); length);

View file

@ -17,6 +17,7 @@
#include "find.h" #include "find.h"
#include "print.h" #include "print.h"
#include "symbol.h" #include "symbol.h"
#include "xml.h"
#include <stdlib.h> #include <stdlib.h>
PDBApiContext::PDBApiContext(const std::wstring& szFilename, const std::wstring& szSignature, const std::wstring& szAge) PDBApiContext::PDBApiContext(const std::wstring& szFilename, const std::wstring& szSignature, const std::wstring& szAge)
@ -112,7 +113,7 @@ int PDBApiContext::init(const std::wstring& szFilename, const std::wstring& szSi
fatal("Unable to get GUID\n"); fatal("Unable to get GUID\n");
} }
printf("<pdb file=\"%S\" exe=\"%S\" guid=\"%S\" age=\"%ld\">\n", szFilename.c_str(), exename.c_str(), guidStr.c_str(), currAge); printf("<pdb file=\"%S\" exe=\"%S\" guid=\"%S\" age=\"%ld\">\n", escapeXmlEntities(szFilename).c_str(), escapeXmlEntities(exename).c_str(), escapeXmlEntities(guidStr).c_str(), currAge);
return hr; return hr;
} }