Last active
February 26, 2017 04:20
-
-
Save Malayke/cd5ba987bfc822f78a7d to your computer and use it in GitHub Desktop.
Colorful output M1(Mifare Classic) Card data from mfoc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # coding = utf-8 | |
| # Colorful print Mfoc data | |
| # date: 2015-3-21 ,Nuruz | |
| # changelog: | |
| # 2017-2-26: | |
| # change output color to similar with Mifare Classic Tools. | |
| __author__ = 'Malayke' | |
| import os | |
| import sys | |
| import binascii | |
| try: | |
| from termcolor import colored | |
| except ImportError: | |
| print "Please Install Termcolor Module" | |
| print "eg: \n\tsudo pip install termcolor" | |
| exit(1) | |
| def console_print(): | |
| mfc_file = open(sys.argv[1], 'r') | |
| section_num = 1 | |
| n = 0 | |
| x = 32 | |
| for data in mfc_file: | |
| lines = binascii.hexlify(data[n:n+64]).upper() | |
| print "Section 0:" | |
| print "%s%s%s\n%s\n%s\n%s%s%s\n" % ( | |
| colored(lines[0:8], 'yellow'), # UID | |
| colored(lines[8:10], 'blue'), # UID CRC | |
| colored(lines[10:x], 'green'), # Company data | |
| colored(lines[x:x*2], 'cyan'), # data block | |
| colored(lines[x*2:x*3], 'cyan'), # data block | |
| colored(lines[x*3:x*3+12], 'green'), # Key A | |
| colored(lines[x*3+12:x*3+12+8], 'red'), # Access Condition | |
| colored(lines[x*3+12+8:x*3+20+12], 'green') # Key B | |
| ) | |
| n = 64 | |
| while section_num <= 15: | |
| print 'Section %d:' % section_num | |
| # section | |
| lines = binascii.hexlify(data[n:n+64]).upper() | |
| print "%s\n" \ | |
| "%s\n" \ | |
| "%s\n" \ | |
| "%s%s%s\n" % \ | |
| (colored(lines[0:x], 'cyan'), # first line | |
| colored(lines[x:x*2], 'cyan'), # data block | |
| colored(lines[x*2:x*3], 'cyan'), # data block | |
| colored(lines[x*3:x*3+12], 'green'), # Key A | |
| colored(lines[x*3+12:x*3+12+8], 'red'), # Access Condition | |
| colored(lines[x*3+12+8:x*3+20+12], 'green') # Key B | |
| ) | |
| n += 64 | |
| section_num += 1 | |
| if __name__ == '__main__': | |
| if len(sys.argv) == 1: | |
| print "Usage: \n\t"+__file__+" mycard.mfd" | |
| exit(1) | |
| if os.path.isfile(sys.argv[1]): | |
| console_print() | |
| else: | |
| print "Error:\n\t%s not found" % sys.argv[1] |
Author
Malayke
commented
Mar 21, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
