comparison tools/format-dump.awk @ 3:2b9244d20ecf

Add awk script to pretty print pwsdump output
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Fri, 03 Apr 2015 14:57:57 +0200
parents
children
comparison
equal deleted inserted replaced
2:97097b4b6bfb 3:2b9244d20ecf
1 #
2 # Copyright (C) 2016 Guido Berhoerster <guido+pws@berhoerster.name>
3 #
4 # Permission is hereby granted, free of charge, to any person obtaining
5 # a copy of this software and associated documentation files (the
6 # "Software"), to deal in the Software without restriction, including
7 # without limitation the rights to use, copy, modify, merge, publish,
8 # distribute, sublicense, and/or sell copies of the Software, and to
9 # permit persons to whom the Software is furnished to do so, subject to
10 # the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 #
23
24 function hextodec(hex, len, dec, i, xdigit, decdigit) {
25 len = length(hex)
26 dec = 0
27
28 for (i = 1; i <= len; i++) {
29 xdigit = tolower(substr(hex, i, 1))
30 if (xdigit ~ /[0123456789abcdef]/) {
31 decdigit = xdigits[xdigit]
32 } else {
33 return 0
34 }
35 dec += decdigit * (16 ^ (len - i))
36 }
37
38 return dec
39 }
40
41 function get_header_field_description(type) {
42 return (type in header_field_description) ? \
43 header_field_description[type] : "Unknown"
44 }
45
46 function get_record_field_description(type) {
47 return (type in record_field_description) ? \
48 record_field_description[type] : "Unknown"
49 }
50
51 BEGIN {
52 xdigits["0"] = 0
53 xdigits["1"] = 1
54 xdigits["2"] = 2
55 xdigits["3"] = 3
56 xdigits["4"] = 4
57 xdigits["5"] = 5
58 xdigits["6"] = 6
59 xdigits["7"] = 7
60 xdigits["8"] = 8
61 xdigits["9"] = 9
62 xdigits["a"] = 10
63 xdigits["b"] = 11
64 xdigits["c"] = 12
65 xdigits["d"] = 13
66 xdigits["e"] = 14
67 xdigits["f"] = 15
68
69 header_field_description[0] = "Version"
70 header_field_description[1] = "UUID"
71 header_field_description[2] = "Non-default preferences"
72 header_field_description[3] = "Tree Display Status"
73 header_field_description[4] = "Timestamp of last save"
74 header_field_description[5] = "Who performed last save"
75 header_field_description[6] = "What performed last save"
76 header_field_description[7] = "Last saved by user"
77 header_field_description[8] = "Last saved on host"
78 header_field_description[9] = "Database Name"
79 header_field_description[10] = "Database Description"
80 header_field_description[11] = "Database Filters"
81 header_field_description[12] = "Reserved"
82 header_field_description[13] = "Reserved"
83 header_field_description[14] = "Reserved"
84 header_field_description[15] = "Recently Used Entries"
85 header_field_description[16] = "Named Password Policies"
86 header_field_description[17] = "Empty Groups"
87 header_field_description[18] = "Yubico"
88
89 record_field_description[1] = "UUID"
90 record_field_description[2] = "Group"
91 record_field_description[3] = "Title"
92 record_field_description[4] = "Username"
93 record_field_description[5] = "Notes"
94 record_field_description[6] = "Password"
95 record_field_description[7] = "Creation Time"
96 record_field_description[8] = "Password Modification Time"
97 record_field_description[9] = "Last Access Time"
98 record_field_description[10] = "Password Expiry Time"
99 record_field_description[11] = "Reserved"
100 record_field_description[12] = "Last Modification Time"
101 record_field_description[13] = "URL"
102 record_field_description[14] = "Autotype"
103 record_field_description[15] = "Password History"
104 record_field_description[16] = "Password Policy"
105 record_field_description[17] = "Password Expiry Interval"
106 record_field_description[18] = "Run command"
107 record_field_description[19] = "Double-Click Action"
108 record_field_description[20] = "EMail address"
109 record_field_description[21] = "Protected Entry"
110 record_field_description[22] = "Own symbols for password"
111 record_field_description[23] = "Shift Double-Click Action"
112 record_field_description[24] = "Password Policy Name"
113 record_field_description[25] = "Entry keyboard shortcut"
114
115 for (type in header_field_description) {
116 description_len = length(record_field_description[type])
117 if (description_len > header_field_description_max_len) {
118 header_field_description_max_len = description_len
119 }
120 }
121 for (type in record_field_description) {
122 description_len = length(record_field_description[type])
123 if (description_len > record_field_description_max_len) {
124 record_field_description_max_len = description_len
125 }
126 }
127
128 lineno = 1
129 record = 1
130 state = "INITIAL"
131 }
132
133 {
134 lineno++
135 }
136
137 /^#/ {
138 next
139 }
140
141 state == "INITIAL" && /^[Hh][eE][Aa][Dd][Ee][Rr]$/ {
142 print "Header:"
143 state = "HEADER"
144 next
145 }
146
147 state ~ /HEADER|RECORD/ && /^[Rr][Ee][Cc][Oo][Rr][Dd] / {
148 printf("\nRecord %d:\n", record++)
149 state = "RECORD"
150 next
151 }
152
153 state ~ /HEADER|RECORD/ && \
154 /^[0123456789AaBbCcDdEeFf][0123456789AaBbCcDdEeFf]:/ {
155 type = hextodec(substr($0, 1, 2))
156 value = substr($0, 4)
157 printf("%*s (0x%02x): %s\n", state == "HEADER" ? \
158 header_field_description_max_len : \
159 record_field_description_max_len, \
160 state == "HEADER" ? get_header_field_description(type) : \
161 get_record_field_description(type), type, value)
162 next
163 }
164
165 {
166 print "syntax error in line " lineno
167 exit(1)
168 }