From d972d5b87b4a271ff22ffccbf1b8621fc1c70d59 Mon Sep 17 00:00:00 2001 From: Floris Bos Date: Wed, 25 Jan 2023 14:02:03 +0100 Subject: [PATCH] Windows WLAN PSK retrieval: unescape XML Assuming unescaping standard XML entities is sufficient. (Skipping numerical unicode XML entities for now, as there is not a proper standardized way to represent non-ascii characters in a PSK anyway) Ref #541 --- src/imagewriter.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/imagewriter.cpp b/src/imagewriter.cpp index fc0f7a2a1..1a757d7ee 100644 --- a/src/imagewriter.cpp +++ b/src/imagewriter.cpp @@ -912,6 +912,25 @@ QString ImageWriter::getSSID() return ssid; } +inline QString unescapeXml(QString str) +{ + static const char *table[] = { + "<", "<", + ">", ">", + """, "\"", + "'", "'", + "&", "&" + }; + int tableLen = sizeof(table) / sizeof(table[0]); + + for (int i=0; i < tableLen; i+=2) + { + str.replace(table[i], table[i+1]); + } + + return str; +} + QString ImageWriter::getPSK(const QString &ssid) { #ifdef Q_OS_WIN @@ -956,7 +975,7 @@ QString ImageWriter::getPSK(const QString &ssid) QRegularExpressionMatch match = rx.match(xml); if (match.hasMatch()) { - psk = match.captured(1); + psk = unescapeXml(match.captured(1)); } WlanFreeMemory(xmlstr);