⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 一个将binary转化为cpp的转换程序
💻 CPP
字号:
/*************************************************************************** *  Filename :  main.cpp *  Started  :  10/??/04 *  Copyright:  (C) 2004 Christian Petri *  Email    :  viperb0y@users.sourceforge.net * * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2 of the License, or *  (at your option) any later version. * **************************************************************************/#include <iostream>#include <iomanip>#include "functions.h"#include "Time.h"using namespace std;int main(int argc, char *argv[]){  const string VERSION = "0.3.10";  if (argc > 1)  {    if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help") && argc > 1)    {      cout << "Aufruf: bin2cpp [OPTION]... QUELLE ZIEL [NAME]" << endl;      cout << "Erzeugt eine C++/C Headerdatei um Dateien in einem Programm weiter zu verarbeiten" << endl << endl;      cout << "  -h, --help		diese Hilfe anzeigen und beenden" << endl;      cout << "      --version		Versionsinformationen anzeigen und beeden" << endl << endl;      cout << "Beispiel:" << endl << endl;      cout << "  ./bin2cpp Datei.bin HeaderDatei DateiKopie" << endl << endl;      cout << "\"ZIEL\" bitte ohne .h angeben, die Endung wird automatisch erzeugt." << endl << endl;      cout << "Melden Sie Fehler bitte an <viperb0y@t-online.de>" << endl;      return 0;    }    if (!strcmp(argv[1], "--version") && argc > 1)    {      cout << "bin2cpp " << VERSION << endl;      cout << "Geschrieben von Christian Petri." << endl << endl;      cout << "Copyright (C) 2004 Christian Petri" << endl;      return 0;    }  }  if (argc < 3)  {    cout << "Fehler: Zuwenig Parameter angegeben! \"bin2cpp -h\" aufrufen fuer Hilfe!" << endl;    return 1;  }  if (argc > 4)  {    cout << "Fehler: Zuviele Parameter angegeben! \"bin2cpp -h\" aufrufen fuer Hilfe!" << endl;    return 1;  }  ifstream infile (argv[1], ios_base::in | ios_base::binary);  if (!infile)  {    cout << "Fehler: Eingabedatei konnte nicht gefunden werden!" << endl;    return 1;  }  stringstream headername, structname_buffer;  string structname;  structname_buffer << argv[2];  structname = strtoupper(structname_buffer.str());  headername << argv[2] << ".h";  Time pack_clock;  pack_clock.start();  ofstream outfile (headername.str().c_str());  if (!outfile)  {    cout << "Fehler: Konnte Ausgabedatei nicht erstellen!" << endl;    outfile.close();    return 1;  }  long int ifilesize = filesize(argv[1]);  outfile << "const unsigned int " << structname << "_LENGTH = " << ifilesize << endl;    if (argc < 4)  {    outfile << "const string " << structname << "_NAME \"" << argv[1] << "\"" << endl;  } else {    outfile << "const string " << structname << "_NAME \"" << argv[3] << "\"" << endl;  }  outfile << "\nconst unsigned char " << structname << "[]=\n{\n  ";    char buff[1];  int b = 1;  int bar_size = ifilesize / 50;  int ic = 0;  string bar = "[                                                  ]";   cout << "Aktueller Fortschritt: " << bar << " 0%" << flush;  while (!infile.eof())  {    infile.read(buff, 1);    if (ic != 0)    {      if (ic % 30 == 0)      {        outfile << endl << "  ";      }    }    if ((ic+1) % bar_size == 0)    {      bar[b] = '=';      cout << "\rAktueller Fortschritt: " << bar << " " << (b*2) << "%" << flush;      ++b;    }    if (!infile.eof())    {      outfile << "0x" << hex << setfill('0')<<  setw(2) << static_cast<int>(*buff & 0xFF) << ",";    } else {      outfile << "0x" << hex << setfill('0')<<  setw(2) << static_cast<int>(*buff & 0xFF);    }    ic++;  }  outfile << "\n};" << endl;  infile.close();    outfile.close();  pack_clock.stop();  cout << "\n\"" << argv[1] << "\" wurde in " << setprecision(2) << fixed << pack_clock.result() << " Sekunden in \"" << headername.str() << "\" umgewandelt." << endl;  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -