Skip to content

Commit debcb33

Browse files
authored
Merge pull request #2 from joanbono/flipper_support
adding Flipper zero dump support
2 parents 46e0aa8 + 1c5432e commit debcb33

File tree

3 files changed

+112
-5
lines changed

3 files changed

+112
-5
lines changed

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,29 @@ Based on the mighty [`mfdread`](https://github.com/zhovner/mfdread).
66
## Usage
77

88
```sh
9-
$> gofare -dump MifareDump.bin
9+
$ gofare -dump MifareDump.bin
1010
```
1111

1212
![](img/img0001.png)
1313

1414
To get the color codes:
1515

1616
```sh
17-
$> gofare -dump MifareDump.bin -v
17+
$ gofare -dump MifareDump.bin -v
1818
```
1919

2020
![](img/img0002.png)
2121

2222
To save the keys from a dump:
2323

2424
```sh
25-
$> gofare -dump MifareDump.bin -keys
25+
$ gofare -dump MifareDump.bin -keys
2626
```
2727

28-
![](img/img0003.png)
28+
![](img/img0003.png)
29+
30+
Parse dump from Flipper Zero:
31+
32+
```sh
33+
$ gofare -dump MifareDump.bin -keys -flipper
34+
```

main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ var (
2828
dump string
2929
verbose bool
3030
keys bool
31+
flipper bool
3132
)
3233

3334
func init() {
3435
flag.StringVar(&dump, "dump", "", "Dump to print")
3536
flag.BoolVar(&verbose, "v", false, "Display color codes")
3637
flag.BoolVar(&keys, "keys", false, "Save keys to UID-key.dic")
38+
flag.BoolVar(&flipper, "flipper", false, "Parse Flipper Zero NFC file")
3739
flag.Parse()
3840
}
3941

@@ -44,7 +46,12 @@ func main() {
4446
if verbose {
4547
parser.CodeColor()
4648
}
47-
parser.ParseDump(dump, keys)
49+
50+
if !flipper {
51+
parser.ParseDump(dump, keys)
52+
} else {
53+
parser.ParseDumpFlipper(dump, keys)
54+
}
4855

4956
} else {
5057
fmt.Printf("\nGofare - Mifare pretty print utility\n\n")

modules/parser/parser.go

+94
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"fmt"
2323
"io"
2424
"os"
25+
"regexp"
26+
"strings"
2527

2628
"github.com/aquasecurity/table"
2729
"github.com/fatih/color"
@@ -109,6 +111,98 @@ func ParseDump(dump string, keys bool) {
109111

110112
}
111113

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+
112206
// SaveKeys will store the keys of a dumo
113207
// into a file named UID-keys.dic
114208
func SaveKeys(keyDictionary []string, uid string) {

0 commit comments

Comments
 (0)