Advertisement
Guest User

/question/199566223

a guest
Apr 3rd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. #define USE_UPTR
  5. #if defined(USE_UPTR)
  6. #include <memory>
  7. #endif
  8.  
  9. using namespace std;
  10.  
  11. int main( int argc, char* argv[] ){
  12.  
  13.     if( argc < 2 ){
  14.         cout << "No input file...\n";
  15.         return 1;
  16.     }
  17.  
  18.     ifstream getfilesize( argv[1], ios::binary | ios::ate);
  19.  
  20.     if( !getfilesize.good() ){
  21.         cout << "Can't open file...\n"<<argv;
  22.         return 1;
  23.     }
  24.     size_t file_size = static_cast<size_t>(getfilesize.tellg());
  25.     getfilesize.close();
  26.  
  27.     if( file_size ){
  28.  
  29. #if defined(USE_UPTR)
  30.         std::unique_ptr<char> bufer(new char[file_size]);
  31.         auto p = bufer.get();
  32. #else
  33.         char* p = new char[file_size];
  34. #endif
  35.         ifstream file( argv[1], ios::binary);
  36.         file.read(p, file_size);
  37.         for(std::size_t i = 0; i < file_size; ++i){
  38.            
  39.             if( p[i] == 0x0 )               cout << "[NUL]";
  40.             else if( p[i] == 0x1 )          cout << "[SOH]";
  41.             else if( p[i] == 0x2 )          cout << "[STX]";
  42.             else if( p[i] == 0x3 )          cout << "[ETX]";
  43.             else if( p[i] == 0x4 )          cout << "[EOT]";
  44.             else if( p[i] == 0x5 )          cout << "[ENQ]";
  45.             else if( p[i] == 0x6 )          cout << "[ACK]";
  46.             else if( p[i] == 0x7 )          cout << "[BEL]";
  47.             else if( p[i] == 0x8 )          cout << "[BS]";
  48.             else if( p[i] == 0x9 )          cout << "[HT]";
  49.             else if( p[i] == 0x0A )         cout << "[LF]";
  50.             else if( p[i] == 0x0B )         cout << "[VT]";
  51.             else if( p[i] == 0x0C )         cout << "[FF]";
  52.             else if( p[i] == 0x0D )         cout << "[CR]";
  53.             else if( p[i] == 0x0E )         cout << "[SO]";
  54.             else if( p[i] == 0x0F )         cout << "[SI]";
  55.             else if( p[i] == 0x10 )         cout << "[DLE]";
  56.             else if( p[i] == 0x11 )         cout << "[DC1]";
  57.             else if( p[i] == 0x12 )         cout << "[DC2]";
  58.             else if( p[i] == 0x13 )         cout << "[DC3]";
  59.             else if( p[i] == 0x14 )         cout << "[DC4]";
  60.             else if( p[i] == 0x15 )         cout << "[NAK]";
  61.             else if( p[i] == 0x16 )         cout << "[SYN]";
  62.             else if( p[i] == 0x17 )         cout << "[ETB]";
  63.             else if( p[i] == 0x18 )         cout << "[CAN]";
  64.             else if( p[i] == 0x19 )         cout << "[EM]";
  65.             else if( p[i] == 0x1A )         cout << "[SUB]";
  66.             else if( p[i] == 0x1B )         cout << "[ESC]";
  67.             else if( p[i] == 0x1C )         cout << "[FS]";
  68.             else if( p[i] == 0x1D )         cout << "[GS]";
  69.             else if( p[i] == 0x1E )         cout << "[RS]";
  70.             else if( p[i] == 0x1A )         cout << "[US]";
  71.             else if( p[i] == 0x7F )         cout << "[DEL]";
  72.             else                            cout << p[i];
  73.         }
  74.  
  75. #if !defined(USE_UPTR)
  76.         delete []p;
  77. #endif
  78.     }
  79.  
  80.     cin.get();
  81.  
  82.     return 0;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement