Imprime el fichero binario por pantalla
This commit is contained in:
+12
@@ -0,0 +1,12 @@
|
|||||||
|
.vscode
|
||||||
|
*.DS_Store
|
||||||
|
thumbs.db
|
||||||
|
*.exe
|
||||||
|
*_macos
|
||||||
|
*_linux
|
||||||
|
*.dmg
|
||||||
|
*.tar.gz
|
||||||
|
*.zip
|
||||||
|
*.app
|
||||||
|
*_debug*
|
||||||
|
main
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
all:
|
||||||
|
clang++ main.cpp -std=c++11 -Wall -Os -ffunction-sections -fdata-sections -o main
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream> // std::cout
|
||||||
|
#include <fstream> // ifstream, ofstream
|
||||||
|
#include <libgen.h> // basename()
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
ifstream inputFile;
|
||||||
|
string filePath = "";
|
||||||
|
vector<unsigned char> buffer;
|
||||||
|
|
||||||
|
void checkParameters(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
if (argc != 2)
|
||||||
|
{
|
||||||
|
cout << "Uso: " << basename(argv[0]) << " FILE" << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
filePath = argv[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadFile(string s)
|
||||||
|
{
|
||||||
|
inputFile.open(s, ios::binary);
|
||||||
|
if (!inputFile.good())
|
||||||
|
{
|
||||||
|
cout << "No se puede abrir el archivo: " << s << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copia el stream al buffer
|
||||||
|
vector<unsigned char> temp(std::istreambuf_iterator<char>(inputFile), {});
|
||||||
|
buffer = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
void printBuffer()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (auto i : buffer)
|
||||||
|
{
|
||||||
|
cout << static_cast<unsigned>(i) << " ";
|
||||||
|
count++;
|
||||||
|
if (count % 16 == 0)
|
||||||
|
cout << static_cast<unsigned>(i) << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
checkParameters(argc, argv);
|
||||||
|
loadFile(filePath);
|
||||||
|
printBuffer();
|
||||||
|
cout << "Fin del programa" << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user