test.c

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h> void dump_line(const unsigned char* buf, int w, int l)
{
#define YYYGET(X) ( X >= 32 && X <= 126) ? X : '.'
unsigned int i = 0;
printf("%08x: ", l);
for (; i < w; ++i)
printf((i % 8 == 7) ? "%02x " : "%02x ", *(buf+i));
if (w < 0x10)
{
for (i = 0; i < 0x10 - w; ++i) printf(" ");
printf(" ");
}
printf ("|");
for (i = 0; i < w; ++i)
printf ("%c", YYYGET(*(buf+i)));
if (w < 0x10)
for (i = 0; i < 0x10 - w; ++i) printf(" ");
printf ("|\n");
#undef YYYGET
} void dump_buffer(const unsigned char* buf, int max)
{
int l = max / 0x10 + ((max % 0x10) ? 1 : 0);
printf ("l = %d\n",l);
int i = 0;
int w = l - i > 1 ? 0x10 : max;
const unsigned char* ptr = buf;
for (; i < l; ++i,w = l - i > 1 ? 0x10 : max - 0x10 * i)
{
dump_line(ptr, w, i);
ptr += w;
}
} int main(int argc, char *argv[])
{
if (argc < 3)
{
printf ("Usage: %s FileName, number.\n", argv[0]);
exit(1);
} int fd = open(argv[1], O_RDONLY);
if (fd != -1)
{
int s = atoi(argv[2]);
unsigned char* buf = malloc(s+1);
memset(buf, 0, s+1);
read(fd, buf, s);
dump_buffer(buf, s);
}
return 0;
}

随机推荐

  1. c++操作mysql入门详解

    首先,根据你当前的操作系统,还有开发工具,选择相应的mysql版本.本人选择的环境是win10 + vs2013 需要解决三个问题:1.下载安装mysql服务器,并登录mysql测试一下是否安装成功: ...

  2. c动态分配结构体二维数组

    这个问题我纠结了蛮久了,因为前面一直忙(自己也懒了点),所以没有能好好研究这个.希望这篇文章能够帮助你们. #include <stdio.h> #include <stdlib.h ...

  3. HDU1532最大流 Edmonds-Karp,Dinic算法 模板

    Drainage Ditches Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...

  4. ubuntu thrift

    1.下载 http://www.apache.org/dyn/closer.cgi?path=/thrift/0.9.2/thrift-0.9.2.tar.gz 2.解压 tar -xvf thrif ...

  5. python3.5无法安装pip,报错ImportError: cannot import name 'HTTPSHandler'

    本人系统为:centos6 解决方法: 1  安装openssl yum install openssl 2  安装openssl-devel yum install openssl-devel 3  ...

  6. python3中SSLError错误处理

    在deepin中安装了python3.6,安装路径为/usr/local/python36,然后通过deepin自带的python2.7的pip安装了virtualenv: sudo pip inst ...

  7. kubernetes node管理

    目录 Node的扩缩容 删除node节点 Node的隔离与恢复 通过配置文件实现 通过命令行的方式实现 恢复 更新资源对象的label 给一个node添加一个label 将pod调度到指定的node ...

  8. NATS_11:NATS集群构建与验证

    NATS服务集群化 NATS支持每一个服务按照集群模式方式运行.你可以将这些服务组织在一起形成一个集群来提高服务器的容量的消息传递系统,并可以提升整个系统的弹性话和高可用性. 注意,NATS集群服务器 ...

  9. Vue 的style绑定显示background-image

    data () { return { img: require('你的json资源路径') } } :style="{backgroundImage: 'url(' + img + ')'} ...

  10. 【AtCoder】AGC022 F - Leftmost Ball 计数DP

    [题目]F - Leftmost Ball [题意]给定n种颜色的球各k个,每次以任意顺序排列所有球并将每种颜色最左端的球染成颜色0,求有多少种不同的颜色排列.n,k<=2000. [算法]计数 ...