projects/libpws

changeset 3:2b9244d20ecf

Add awk script to pretty print pwsdump output
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Fri Apr 03 14:57:57 2015 +0200 (2015-04-03)
parents 97097b4b6bfb
children dfd3ddbdb201
files tools/format-dump.awk
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tools/format-dump.awk	Fri Apr 03 14:57:57 2015 +0200
     1.3 @@ -0,0 +1,168 @@
     1.4 +#
     1.5 +# Copyright (C) 2016 Guido Berhoerster <guido+pws@berhoerster.name>
     1.6 +#
     1.7 +# Permission is hereby granted, free of charge, to any person obtaining
     1.8 +# a copy of this software and associated documentation files (the
     1.9 +# "Software"), to deal in the Software without restriction, including
    1.10 +# without limitation the rights to use, copy, modify, merge, publish,
    1.11 +# distribute, sublicense, and/or sell copies of the Software, and to
    1.12 +# permit persons to whom the Software is furnished to do so, subject to
    1.13 +# the following conditions:
    1.14 +#
    1.15 +# The above copyright notice and this permission notice shall be included
    1.16 +# in all copies or substantial portions of the Software.
    1.17 +#
    1.18 +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.19 +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.20 +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.21 +# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.22 +# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.23 +# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.24 +# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    1.25 +#
    1.26 +
    1.27 +function hextodec(hex,  len, dec, i, xdigit, decdigit) {
    1.28 +    len = length(hex)
    1.29 +    dec = 0
    1.30 +
    1.31 +    for (i = 1; i <= len; i++) {
    1.32 +        xdigit = tolower(substr(hex, i, 1))
    1.33 +        if (xdigit ~ /[0123456789abcdef]/) {
    1.34 +            decdigit = xdigits[xdigit]
    1.35 +        } else {
    1.36 +            return 0
    1.37 +        }
    1.38 +        dec += decdigit * (16 ^ (len - i))
    1.39 +    }
    1.40 +
    1.41 +    return dec
    1.42 +}
    1.43 +
    1.44 +function get_header_field_description(type) {
    1.45 +    return (type in header_field_description) ? \
    1.46 +            header_field_description[type] : "Unknown"
    1.47 +}
    1.48 +
    1.49 +function get_record_field_description(type) {
    1.50 +    return (type in record_field_description) ? \
    1.51 +            record_field_description[type] : "Unknown"
    1.52 +}
    1.53 +
    1.54 +BEGIN {
    1.55 +    xdigits["0"] = 0
    1.56 +    xdigits["1"] = 1
    1.57 +    xdigits["2"] = 2
    1.58 +    xdigits["3"] = 3
    1.59 +    xdigits["4"] = 4
    1.60 +    xdigits["5"] = 5
    1.61 +    xdigits["6"] = 6
    1.62 +    xdigits["7"] = 7
    1.63 +    xdigits["8"] = 8
    1.64 +    xdigits["9"] = 9
    1.65 +    xdigits["a"] = 10
    1.66 +    xdigits["b"] = 11
    1.67 +    xdigits["c"] = 12
    1.68 +    xdigits["d"] = 13
    1.69 +    xdigits["e"] = 14
    1.70 +    xdigits["f"] = 15
    1.71 +
    1.72 +    header_field_description[0] =  "Version"
    1.73 +    header_field_description[1] =  "UUID"
    1.74 +    header_field_description[2] =  "Non-default preferences"
    1.75 +    header_field_description[3] =  "Tree Display Status"
    1.76 +    header_field_description[4] =  "Timestamp of last save"
    1.77 +    header_field_description[5] =  "Who performed last save"
    1.78 +    header_field_description[6] =  "What performed last save"
    1.79 +    header_field_description[7] =  "Last saved by user"
    1.80 +    header_field_description[8] =  "Last saved on host"
    1.81 +    header_field_description[9] =  "Database Name"
    1.82 +    header_field_description[10] =  "Database Description"
    1.83 +    header_field_description[11] =  "Database Filters"
    1.84 +    header_field_description[12] =  "Reserved"
    1.85 +    header_field_description[13] =  "Reserved"
    1.86 +    header_field_description[14] =  "Reserved"
    1.87 +    header_field_description[15] =  "Recently Used Entries"
    1.88 +    header_field_description[16] =  "Named Password Policies"
    1.89 +    header_field_description[17] =  "Empty Groups"
    1.90 +    header_field_description[18] =  "Yubico"
    1.91 +
    1.92 +    record_field_description[1] =  "UUID"
    1.93 +    record_field_description[2] =  "Group"
    1.94 +    record_field_description[3] =  "Title"
    1.95 +    record_field_description[4] =  "Username"
    1.96 +    record_field_description[5] =  "Notes"
    1.97 +    record_field_description[6] =  "Password"
    1.98 +    record_field_description[7] =  "Creation Time"
    1.99 +    record_field_description[8] =  "Password Modification Time"
   1.100 +    record_field_description[9] =  "Last Access Time"
   1.101 +    record_field_description[10] =  "Password Expiry Time"
   1.102 +    record_field_description[11] =  "Reserved"
   1.103 +    record_field_description[12] =  "Last Modification Time"
   1.104 +    record_field_description[13] =  "URL"
   1.105 +    record_field_description[14] =  "Autotype"
   1.106 +    record_field_description[15] =  "Password History"
   1.107 +    record_field_description[16] =  "Password Policy"
   1.108 +    record_field_description[17] =  "Password Expiry Interval"
   1.109 +    record_field_description[18] =  "Run command"
   1.110 +    record_field_description[19] =  "Double-Click Action"
   1.111 +    record_field_description[20] =  "EMail address"
   1.112 +    record_field_description[21] =  "Protected Entry"
   1.113 +    record_field_description[22] =  "Own symbols for password"
   1.114 +    record_field_description[23] =  "Shift Double-Click Action"
   1.115 +    record_field_description[24] =  "Password Policy Name"
   1.116 +    record_field_description[25] =  "Entry keyboard shortcut"
   1.117 +
   1.118 +    for (type in header_field_description) {
   1.119 +        description_len = length(record_field_description[type])
   1.120 +        if (description_len > header_field_description_max_len) {
   1.121 +            header_field_description_max_len = description_len
   1.122 +        }
   1.123 +    }
   1.124 +    for (type in record_field_description) {
   1.125 +        description_len = length(record_field_description[type])
   1.126 +        if (description_len > record_field_description_max_len) {
   1.127 +            record_field_description_max_len = description_len
   1.128 +        }
   1.129 +    }
   1.130 +
   1.131 +    lineno = 1
   1.132 +    record = 1
   1.133 +    state = "INITIAL"
   1.134 +}
   1.135 +
   1.136 +{
   1.137 +    lineno++
   1.138 +}
   1.139 +
   1.140 +/^#/ {
   1.141 +    next
   1.142 +}
   1.143 +
   1.144 +state == "INITIAL" && /^[Hh][eE][Aa][Dd][Ee][Rr]$/ {
   1.145 +    print "Header:"
   1.146 +    state = "HEADER"
   1.147 +    next
   1.148 +}
   1.149 +
   1.150 +state ~ /HEADER|RECORD/ && /^[Rr][Ee][Cc][Oo][Rr][Dd] / {
   1.151 +    printf("\nRecord %d:\n", record++)
   1.152 +    state = "RECORD"
   1.153 +    next
   1.154 +}
   1.155 +
   1.156 +state ~ /HEADER|RECORD/ && \
   1.157 +        /^[0123456789AaBbCcDdEeFf][0123456789AaBbCcDdEeFf]:/ {
   1.158 +    type = hextodec(substr($0, 1, 2))
   1.159 +    value = substr($0, 4)
   1.160 +    printf("%*s (0x%02x): %s\n", state == "HEADER" ? \
   1.161 +            header_field_description_max_len : \
   1.162 +            record_field_description_max_len, \
   1.163 +            state == "HEADER" ? get_header_field_description(type) : \
   1.164 +            get_record_field_description(type), type, value)
   1.165 +    next
   1.166 +}
   1.167 +
   1.168 +{
   1.169 +    print "syntax error in line " lineno
   1.170 +    exit(1)
   1.171 +}