Skip to content

Commit

Permalink
Windows WLAN PSK retrieval: unescape XML
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maxnet committed Jan 25, 2023
1 parent 6d69ff0 commit d972d5b
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/imagewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,25 @@ QString ImageWriter::getSSID()
return ssid;
}

inline QString unescapeXml(QString str)
{
static const char *table[] = {
"&lt;", "<",
"&gt;", ">",
"&quot;", "\"",
"&apos;", "'",
"&amp;", "&"
};
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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit d972d5b

Please sign in to comment.