@@ -22,6 +22,8 @@ import (
22
22
"fmt"
23
23
"io"
24
24
"os"
25
+ "regexp"
26
+ "strings"
25
27
26
28
"github.com/aquasecurity/table"
27
29
"github.com/fatih/color"
@@ -109,6 +111,98 @@ func ParseDump(dump string, keys bool) {
109
111
110
112
}
111
113
114
+ // ParseDumpFlipper will open the .NFC file from Flipper Zero
115
+ // and print it in a readable way
116
+ func ParseDumpFlipper (dump string , keys bool ) {
117
+ dumpFile , err := os .Open (dump )
118
+ CheckErr (err )
119
+
120
+ defer dumpFile .Close ()
121
+
122
+ //Regex
123
+ re := regexp .MustCompile (`^Block\s\d+\:\s(.*)$` )
124
+
125
+ // Array to store matching lines
126
+ var matchingLines []string
127
+ var bytesLines []string
128
+
129
+ // Read file line by line
130
+ scanner := bufio .NewScanner (dumpFile )
131
+ for scanner .Scan () {
132
+ line := scanner .Text ()
133
+ // Check if the line matches the pattern
134
+ if re .MatchString (line ) {
135
+ matchingLines = append (matchingLines , line )
136
+ }
137
+ }
138
+
139
+ // Check for any errors during scanning
140
+ CheckErr (err )
141
+
142
+ pattern := `^Block\d+\:`
143
+ regex := regexp .MustCompile (pattern )
144
+
145
+ for _ , text := range matchingLines {
146
+ text = strings .Replace (text , " " , "" , - 1 )
147
+ modifiedText := regex .ReplaceAllString (text , "" )
148
+ //Making it lowercase for output compatibility with proxmark dump
149
+ lowerCaseLine := strings .ToLower (modifiedText )
150
+ bytesLines = append (bytesLines , lowerCaseLine )
151
+ }
152
+
153
+ i := 1
154
+ x := 0
155
+ var keyDictionary []string
156
+ var uid string
157
+
158
+ // Start table
159
+ t := table .New (os .Stdout )
160
+ t .SetRowLines (false )
161
+ t .SetHeaders (
162
+ fmt .Sprintf ("%v" , white .Sprintf ("%v" , "Offset" )),
163
+ fmt .Sprintf ("%v" , white .Sprintf ("%v" , "A" )),
164
+ fmt .Sprintf ("%v" , white .Sprintf ("%v" , "Access" )),
165
+ fmt .Sprintf ("%v" , white .Sprintf ("%v" , "B" )),
166
+ )
167
+
168
+ for _ , bytesLine := range bytesLines {
169
+
170
+ if i == 1 {
171
+ t .AddRow (
172
+ fmt .Sprintf ("%v" , gray .Sprintf ("%08x" , x )),
173
+ fmt .Sprintf ("%v%v%v" , yellow .Sprintf ("%s" , bytesLine [0 :8 ]), cyan .Sprintf ("%s" , bytesLine [8 :10 ]), hired .Sprintf ("%s" , bytesLine [10 :12 ])),
174
+ fmt .Sprintf ("%v%v" , magenta .Sprintf ("%s" , bytesLine [12 :14 ]), bytesLine [14 :20 ]),
175
+ fmt .Sprintf ("%s" , bytesLine [20 :32 ]),
176
+ )
177
+ uid = fmt .Sprintf ("%s" , bytesLine [0 :8 ])
178
+ } else if i % 4 == 0 {
179
+ t .AddRow (
180
+ fmt .Sprintf ("%v" , gray .Sprintf ("%08x" , x )),
181
+ fmt .Sprintf ("%v" , green .Sprintf ("%s" , bytesLine [0 :12 ])),
182
+ fmt .Sprintf ("%v" , red .Sprintf ("%s" , bytesLine [12 :20 ])),
183
+ fmt .Sprintf ("%v" , blue .Sprintf ("%s" , bytesLine [20 :32 ])),
184
+ )
185
+ keyDictionary = append (keyDictionary , fmt .Sprintf ("%s" , bytesLine [0 :12 ]), fmt .Sprintf ("%s" , bytesLine [20 :32 ]))
186
+ } else {
187
+ t .AddRow (
188
+ fmt .Sprintf ("%v" , gray .Sprintf ("%08x" , x )),
189
+ fmt .Sprintf ("%v" , bytesLine [0 :12 ]),
190
+ fmt .Sprintf ("%v" , bytesLine [12 :20 ]),
191
+ fmt .Sprintf ("%v" , bytesLine [20 :32 ]),
192
+ )
193
+ }
194
+ i = i + 1
195
+ x = x + 16
196
+ }
197
+
198
+ t .Render ()
199
+
200
+ if keys {
201
+ SaveKeys (keyDictionary , uid )
202
+ }
203
+
204
+ }
205
+
112
206
// SaveKeys will store the keys of a dumo
113
207
// into a file named UID-keys.dic
114
208
func SaveKeys (keyDictionary []string , uid string ) {
0 commit comments