4 ms·
Here is a script that I use, mainly composed with the Toybox version of awk, that will extract all of the WiFi passwords stored on an Android device. This is e
by chasil 4y ago
Here is a script that I use, mainly composed with the Toybox version of awk, that will extract all of the WiFi passwords stored on an Android device.
This is enormously portable, and does not require any new software installations for Android users who have root.
Requiring xsv would reduce availability to a fraction of where it can be run now.
#!/bin/sh
find /data \
-name WifiConfigStore.xml \
-print0 |
xargs -0 awk '
/"SSID/ { s = 1 }
/PreShared/ { p = 1 }
s || p {
gsub(/[<][^>]+[>]/, "")
sub(/^[&]quot;/, "")
sub(/[&]quot;$/, "")
gsub(/[&]quot;/, "\"")
gsub(/[&]amp;/, "\\&")
gsub(/[&]lt;/, "<")
gsub(/[&]gt;/, ">")
}
s { s = 0; printf "%-32.32s ", $0 }
p { p = 0; print }
' | sort -f
Note that the -print0 null processing is not POSIX. This is a reasonable compromise of standards compliance, as it does not reduce the base of available users.
I did try to do this first with arrarys, but awk segfaulted.
- masklinn 4y agoXSV is a tool for exploring and manipulating X-separated value files (CSV, TSV, …), which is why I mentioned it in reply to a comment which talks about the exploration of CSV files, and furthermore specifically mentions that > parsing csv can get tricky
- version_five 4y ago> tricky Yes I'd say awk is unsuitable for csv files that can contain text fields with arbitrary text, that includes commas, newlines, quotes etc. It gets hackier and becomes the wrong tool as the number of edge cases to handle increases.
- deleted 4y ago[deleted]
- nousermane 4y agoThat is quite nifty implementation of reverse HTML escaping. But in python that could be done with much less work: import html print(html.unescape(foo)) And the best part - you don't need to debug/update the (g)sub list every time you stumble upon new weird &whatever; too. And there are a lot of those out there: https://www.freeformatter.com/html-entities.html https://www.freeformatter.com/html-entities.html
- chasil 4y agoThe only thing that changed since I originally wrote it was the location of the file. https://www.reddit.com/r/LineageOS/comments/gzm7to/wifi_password_extraction_script/?rdt=62369 https://www.reddit.com/r/LineageOS/comments/gzm7to/wifi_pass...
- pacaro 4y agoI think that the ordering of your substitutions is potentially incorrect. The code as written will convert &lt; to < When it should (presumably) be <
- chasil 4y agoWhile the perfect is the enemy of the good, you are correct.