├── Makefile ├── README.md └── converter.cpp /Makefile: -------------------------------------------------------------------------------- 1 | GXX = g++ 2 | EXEC = converter 3 | 4 | all : $(EXEC) 5 | 6 | $(EXEC) : converter.cpp 7 | $(GXX) $< -o $@ 8 | 9 | clean : 10 | rm $(EXEC) 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dump converter - Mifare Classic Tool <-> LibNfc 2 | 3 | This is a simple C++ script to convert dump files from Mifare Classic Tool Android app to LibNfc binary formats. Conversion can be done in both sided. 4 | 5 | # Compile 6 | 7 | ``` 8 | g++ converter.cpp -o converter 9 | ``` 10 | 11 | # How To Use 12 | 13 | ### Mifare Classic Tool -> LibNfc 14 | 15 | ``` 16 | converter -bin -f mct_dump -o libnfc_dump 17 | ``` 18 | 19 | ### LibNfc -> Mifare Classic Tool 20 | 21 | ``` 22 | converter -mct -f libnfc_dump -o mct_dump 23 | ``` -------------------------------------------------------------------------------- /converter.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int char2int(char input){ 7 | if(input >= '0' && input <= '9') 8 | return input - '0'; 9 | if(input >= 'A' && input <= 'F') 10 | return input - 'A' + 10; 11 | if(input >= 'a' && input <= 'f') 12 | return input - 'a' + 10; 13 | return -1; 14 | } 15 | 16 | void hex2bin(const char* src, char* target){ 17 | while(*src && src[1]){ 18 | *(target++) = char2int(*src)*16 + char2int(src[1]); 19 | src += 2; 20 | } 21 | } 22 | 23 | bool mct2binary(const std::string& inputFile, const std::string& outputFile){ 24 | std::ifstream in(inputFile.c_str()); 25 | std::ofstream out(outputFile.c_str(), std::ios::binary); 26 | if(in && out){ 27 | std::string line; 28 | char buffer[16]; 29 | while(!in.eof()){ 30 | std::getline(in, line); 31 | if(line[0]!='+' && line!=""){ 32 | hex2bin(line.c_str(), buffer); 33 | out.write(buffer, 16); 34 | } 35 | } 36 | return true; 37 | } 38 | return false; 39 | } 40 | 41 | bool binary2mct(const std::string& inputFile, const std::string& outputFile){ 42 | std::ifstream in(inputFile.c_str(), std::ios::binary); 43 | std::ofstream out(outputFile.c_str()); 44 | if(in && out){ 45 | char buffer[16]; 46 | for(int i=0 ; i<16 ; i++){ 47 | out << "+Sector: " << std::dec << i << std::endl; 48 | for(int j=0 ; j<4 ; j++){ 49 | in.read(buffer, 16); 50 | for(int k=0 ; k<16 ; k++){ 51 | out << std::setfill('0') << std::setw(2) << std::hex << (int) (unsigned char) buffer[k]; 52 | } 53 | out << std::endl; 54 | } 55 | } 56 | return true; 57 | } 58 | return false; 59 | } 60 | 61 | std::map getArgs(int argc, char* argv[]){ 62 | std::map args; 63 | for(int i=1 ; i& args, const std::string& flag){ 74 | return args.find(flag) != args.end(); 75 | } 76 | 77 | void printHelp(){ 78 | std::cout << "Converts Mifare Classic Tool dumps into LibNfc dumps and vice-versa." << std::endl << std::endl; 79 | std::cout << "PARAMETERS :" << std::endl; 80 | std::cout << "\t-f \t:\tfile to convert" << std::endl; 81 | std::cout << "\t-bin \t:\tconvert to binary format (libnfc)" << std::endl; 82 | std::cout << "\t-mct \t:\tconvert to Mifare Classic Tool format (Android App)" << std::endl; 83 | std::cout << "OPTIONS :" << std::endl; 84 | std::cout << "\t-o \t:\toutput file - default to ($input)_{bin|mct}" << std::endl; 85 | } 86 | 87 | int main(int argc, char* argv[]){ 88 | std::map args = getArgs(argc, argv); 89 | if(has(args, "-f") && has(args, "-bin")){ 90 | std::string inputFile = args["-f"]; 91 | std::string outputFile = has(args, "-o") ? args["-o"] : inputFile+"_bin"; 92 | bool done = mct2binary(inputFile, outputFile); 93 | std::cout << (done ? "Success." : "Error. Could not read input file.") << std::endl; 94 | } 95 | else if(has(args, "-f") && has(args, "-mct")){ 96 | std::string inputFile = args["-f"]; 97 | std::string outputFile = has(args, "-o") ? args["-o"] : inputFile+"_mct"; 98 | bool done = binary2mct(inputFile, outputFile); 99 | std::cout << (done ? "Success." : "Error. Could not read input file.") << std::endl; 100 | } 101 | else{ 102 | printHelp(); 103 | } 104 | } 105 | --------------------------------------------------------------------------------