diff --git a/snapshot/minidump/minidump_string_reader.cc b/snapshot/minidump/minidump_string_reader.cc index 4a5cb136..d642e9d4 100644 --- a/snapshot/minidump/minidump_string_reader.cc +++ b/snapshot/minidump/minidump_string_reader.cc @@ -17,14 +17,18 @@ #include #include "base/logging.h" +#include "base/strings/utf_string_conversions.h" #include "minidump/minidump_extensions.h" namespace crashpad { namespace internal { -bool ReadMinidumpUTF8String(FileReaderInterface* file_reader, +namespace { + +template +bool ReadMinidumpString(FileReaderInterface* file_reader, RVA rva, - std::string* string) { + StringType* string) { if (rva == 0) { string->clear(); return true; @@ -39,7 +43,7 @@ bool ReadMinidumpUTF8String(FileReaderInterface* file_reader, return false; } - std::string local_string(string_size, '\0'); + StringType local_string(string_size / sizeof((*string)[0]), '\0'); if (!file_reader->ReadExactly(&local_string[0], string_size)) { return false; } @@ -48,5 +52,33 @@ bool ReadMinidumpUTF8String(FileReaderInterface* file_reader, return true; } +} // namespace + +bool ReadMinidumpUTF8String(FileReaderInterface* file_reader, + RVA rva, + std::string* string) { + return ReadMinidumpString(file_reader, rva, string); +} + +bool ReadMinidumpUTF16String(FileReaderInterface* file_reader, + RVA rva, + base::string16* string) { + return ReadMinidumpString(file_reader, rva, string); +} + +bool ReadMinidumpUTF16String(FileReaderInterface* file_reader, + RVA rva, + std::string* string) { + base::string16 string_raw; + + if (!ReadMinidumpString(file_reader, rva, &string_raw)) { + return false; + } + + base::UTF16ToUTF8(string_raw.data(), string_raw.size(), string); + + return true; +} + } // namespace internal } // namespace crashpad diff --git a/snapshot/minidump/minidump_string_reader.h b/snapshot/minidump/minidump_string_reader.h index e5667ec2..b7ecdac3 100644 --- a/snapshot/minidump/minidump_string_reader.h +++ b/snapshot/minidump/minidump_string_reader.h @@ -20,6 +20,7 @@ #include +#include "base/strings/string16.h" #include "util/file/file_reader.h" namespace crashpad { @@ -34,6 +35,24 @@ bool ReadMinidumpUTF8String(FileReaderInterface* file_reader, RVA rva, std::string* string); +//! \brief Reads a MinidumpUTF16String from a minidump file at offset \a rva in +//! \a file_reader, and returns it in \a string. +//! +//! \return `true` on success, with \a string set. `false` on failure, with a +//! message logged. +bool ReadMinidumpUTF16String(FileReaderInterface* file_reader, + RVA rva, + base::string16* string); + +//! \brief Reads a MinidumpUTF16String from a minidump file at offset \a rva in +//! \a file_reader, and returns it in \a string. +//! +//! \return `true` on success, with \a string set. `false` on failure, with a +//! message logged. +bool ReadMinidumpUTF16String(FileReaderInterface* file_reader, + RVA rva, + std::string* string); + } // namespace internal } // namespace crashpad