diff options
Diffstat (limited to 'llvm/lib/Object/Minidump.cpp')
-rw-r--r-- | llvm/lib/Object/Minidump.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/llvm/lib/Object/Minidump.cpp b/llvm/lib/Object/Minidump.cpp index d0d49b4e8d3..3e3255a2f17 100644 --- a/llvm/lib/Object/Minidump.cpp +++ b/llvm/lib/Object/Minidump.cpp @@ -8,6 +8,7 @@ #include "llvm/Object/Minidump.h" #include "llvm/Object/Error.h" +#include "llvm/Support/ConvertUTF.h" using namespace llvm; using namespace llvm::object; @@ -21,6 +22,33 @@ MinidumpFile::getRawStream(minidump::StreamType Type) const { return None; } +Expected<std::string> MinidumpFile::getString(size_t Offset) const { + // Minidump strings consist of a 32-bit length field, which gives the size of + // the string in *bytes*. This is followed by the actual string encoded in + // UTF16. + auto ExpectedSize = + getDataSliceAs<support::ulittle32_t>(getData(), Offset, 1); + if (!ExpectedSize) + return ExpectedSize.takeError(); + size_t Size = (*ExpectedSize)[0]; + if (Size % 2 != 0) + return createError("String size not even"); + Size /= 2; + if (Size == 0) + return ""; + + Offset += sizeof(support::ulittle32_t); + auto ExpectedData = getDataSliceAs<UTF16>(getData(), Offset, Size); + if (!ExpectedData) + return ExpectedData.takeError(); + + std::string Result; + if (!convertUTF16ToUTF8String(*ExpectedData, Result)) + return createError("String decoding failed"); + + return Result; +} + Expected<ArrayRef<uint8_t>> MinidumpFile::getDataSlice(ArrayRef<uint8_t> Data, size_t Offset, size_t Size) { // Check for overflow. |