Linux C | 查看二进制文件的小工具HexView

Linux C | 查看二进制文件的小工具HexView

源码:

/*******************************************************************
 *   > File Name: HexView.cpp
 *   > Create Time: 2021年11月22日 星期一 17时47分27秒
 ******************************************************************/

#include 
#include 
#include 
using namespace std;

int main(int argc, char* argv[])
{
   if(argc != 2) {
       cout << "Usage:" << argv[0] << " " << endl;
       return (-1);
   }

   FILE *fp = NULL;
   int c;

   if((fp = fopen(argv[1], "r")) == NULL){
        cout << "file " << argv[1] << " open error" << endl;
        return (-2);
   }

   int count = 1;
   while((c = fgetc(fp)) != EOF){
       if (count %  17 == 0){
            cout << endl;
       }else{
            cout << hex << setw(2) << setfill('0') << c << " ";
       }

       count ++;
   }
   cout << endl;

   fclose(fp);

    return 0;
}

编译:

lanfeiy@msil-virtual-machine:~/test$ make
g++ -o HexView HexView.cpp -g -Wall

运行:

lanfeiy@msil-virtual-machine:~/test$ ./HexView white.bmp
42 4d 76 01 00 00 00 00 00 00 36 00 00 00 28 00
00 0a 00 00 00 0a 00 00 00 01 00 18 00 00 00 00
40 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff 00 00 ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff 00 00 ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff 00 00 ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff 00 00 ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff 00 00 ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff 00 00 ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff
ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00

lanfeiy@msil-virtual-machine:~/test$ ./HexView black.bmp
42 4d 76 01 00 00 00 00 00 00 36 00 00 00 28 00
00 0a 00 00 00 0a 00 00 00 01 00 18 00 00 00 00
40 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00


拓展链接

BMP图片的文件结构

BMP图像格式及文件构成

MP4文件格式的解析,以及MP4文件的分割算法

SOA/软件架构设计—面向服务的架构(SOA详细解释)

CommonAPI C++ Tutorial

D-Bus Tutorial

Qt实战小项目

这些C++的练手项目,相当于你2年的工作经验,拿走不谢

openwrt安装GPS设备,使用GPSD获取GPS信息

GPSD架构介绍及交叉编译和使用

内存模型系列(下)- 内存持久性模型(Memory Persistency

联咏和海思哪个好 - CSDN

玩转Google开源C++单元测试框架Google Test系列(gtest)(总)

googletest安装与使用

dlt-daemon安装教程

DLT(Diagnostic Log and Trace)嵌入式系统程序运行记录

dlt-logDBus

你可能感兴趣的:(1.C/C++编程,uml,容器,c++)