diff --git a/src/USBAnalyzerResults.cpp b/src/USBAnalyzerResults.cpp index dca7d3b..dbfde77 100644 --- a/src/USBAnalyzerResults.cpp +++ b/src/USBAnalyzerResults.cpp @@ -1,7 +1,8 @@ #include #include #include - +#include +#include #include #include @@ -517,7 +518,13 @@ void GetCtrlTransFrameDesc( const Frame& frm, DisplayBase display_base, std::vec } else if( formatter == Fld_Wchar ) { - desc = std::string( " char='" ) + char( val & 0xff ) + '\''; + // utf-8 encode the utf-16 character. + std::u16string utf_16_str; + char16_t u16_char = static_cast( val ); + utf_16_str.push_back( u16_char ); + std::wstring_convert, char16_t> convert; + std::string utf8_str = convert.to_bytes( utf_16_str ); + desc = std::string( " char='" ) + utf8_str + '\''; } else if( formatter == Fld_wLANGID ) { diff --git a/src/USBControlTransfers.cpp b/src/USBControlTransfers.cpp index eb4a742..8dce6ad 100644 --- a/src/USBControlTransfers.cpp +++ b/src/USBControlTransfers.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include @@ -371,12 +373,13 @@ bool USBControlTransferParser::ParseStringDescriptor() else { if( mParsedOffset == 2 ) - stringDescriptor.clear(); + utf16StringDescriptor.clear(); // the actual UNICODE string while( mDescBytes > mParsedOffset && mPacketDataBytes > mPacketOffset ) { - stringDescriptor += ( char )pPacket->GetDataPayload( mPacketOffset, 1 ); + char16_t code_unit = static_cast( pPacket->GetDataPayload( mPacketOffset, 2 ) ); + utf16StringDescriptor.push_back( code_unit ); pResults->AddFrame( pPacket->GetDataPayloadField( mPacketOffset, 2, mAddress, "wchar", Fld_Wchar ) ); mPacketOffset += 2; @@ -386,7 +389,9 @@ bool USBControlTransferParser::ParseStringDescriptor() // do we have the entire string? if( mDescBytes == mParsedOffset ) { - pResults->AddStringDescriptor( mAddress, mRequest.GetRequestedDescriptorIndex(), stringDescriptor ); + std::wstring_convert, char16_t> convert; + std::string utf8_string_descriptor = convert.to_bytes( utf16StringDescriptor ); + pResults->AddStringDescriptor( mAddress, mRequest.GetRequestedDescriptorIndex(), utf8_string_descriptor ); } } // return true if we've finished parsing the string descriptor, according to the parsed bLength diff --git a/src/USBControlTransfers.h b/src/USBControlTransfers.h index adb11d7..3e466bf 100644 --- a/src/USBControlTransfers.h +++ b/src/USBControlTransfers.h @@ -233,7 +233,8 @@ class USBControlTransferParser USBRequest mRequest; - std::string stringDescriptor; + std::u16string utf16StringDescriptor; + // these are only valid during a ParsePacket call, and invalid before and after USBPacket* pPacket;