]> git.zerfleddert.de Git - proxmark3-svn/blame - tools/rfidtest.pl
fix help typo
[proxmark3-svn] / tools / rfidtest.pl
CommitLineData
14ac2f1e 1#!/usr/bin/perl
2# -samy kamkar, rfid@samy.pl
3
4use strict;
5
6die "usage: $0 <file with data> <binary to search for>\n" unless @ARGV == 2;
7
8my ($file, $search) = @ARGV;
9$search =~ s/\s//g;
10
11# sure, these aren't perfect, but simplifies usability if you know what you're doing
12# if in doubt, use binary
13
14# binary, cool
15if ($search =~ /^[01]+$/) { }
16# decimal
17elsif ($search =~ /^\d+$/)
18{
19 $search = unpack("B*", pack("N", $search));
20 $search =~ s/^0*//;
21}
22# hex
23elsif ($search =~ /^[\da-fA-F]+$/)
24{
25 $search = unpack("B*", pack("H*", $search));
26 $search =~ s/^0*//;
27}
28# ascii
29else
30{
31 $search = unpack("B*", $search);
32 $search =~ s/^0*//;
33}
34
35
36# read file contents
37open(F, "<$file") || die "Can't read $file: $!";
38my $data = join("", <F>);
39close(F);
40
41# convert to binary
42$data =~ s/\s//g;
43# binary, great
44if ($data =~ /^[01]+$/) { }
45elsif ($data =~ /^[\da-fA-F]+$/)
46{
47 $data = unpack("B*", pack("H*", $data));
48 $search =~ s/^0*//;
49}
50else
51{
52 die "Seriously. What sort of data is this file? Binary or hex only please.\n";
53}
54
55
56# search every method we know how
57print "Testing normally...\n";
58test_all($data, $search);
59
60print "Testing with flipped bits...\n";
61test_all($data, $search, 1);
62
63# now try manchester demodulating
64my @bits = split(//, $data);
65my $man;
66my $last = 0;
67for (my $i = 1; $i < @bits; $i++)
68{
69 # if we changed, flip our bit
70 if ($bits[$i-1] == 1)
71 {
72 $last ^= 1;
73 }
74 $man .= $last;
75}
76
77print "Testing with manchester demodulation...\n";
78test_all($man, $search);
79
80print "Testing with flipped manchester demodulation...\n";
81test_all($man, $search, 1);
82
83
84sub test_all
85{
86 my ($data, $search, $flip) = @_;
87
88 if ($flip)
89 {
90 $data =~ s/(.)/$1 ^ 1/eg;
91 }
92
93 # first just see if our data is in the stream
94 if ($data =~ /$search/)
95 {
96 print "Found $search in our stream ($data)\n";
97 }
98
99 # try removing parity every 4 and 8 bits
100 foreach my $parity (4, 8)
101 {
102 # try removing a parity bit every $parity bits
103 # test by cutting off a bit at a time in case we're in the wrong bit position
104 my $tmp = $data;
105 foreach (1 .. $parity)
106 {
107 my $test = $tmp;
108 $test =~ s/(.{$parity})./$1/g;
109
110 if ($test =~ /$search/)
111 {
112 print "Found $search with parity every " . ($parity + 1) . "th bit, round $_ out of $parity ($test)\n";
113 }
114
115 # chop of a bit to change our bit position next round
116 $tmp =~ s/^.//;
117 }
118 }
119}
Impressum, Datenschutz